org.eclipse.jdt.core.JavaConventions Java Examples

The following examples show how to use org.eclipse.jdt.core.JavaConventions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExpandWithConstructorsConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Validates the entered type or member and updates the status.
 */
private void doValidation() {
	StatusInfo status= new StatusInfo();
	String newText= fNameDialogField.getText();
	if (newText.length() == 0) {
		status.setError(""); //$NON-NLS-1$
	} else {
		IStatus val= JavaConventions.validateJavaTypeName(newText, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
		if (val.matches(IStatus.ERROR)) {
			if (fIsEditingMember)
				status.setError(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_error_invalidMemberName);
			else
				status.setError(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_error_invalidTypeName);
		} else {
			if (doesExist(newText)) {
				status.setError(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_error_entryExists);
			}
		}
	}
	updateStatus(status);
}
 
Example #2
Source File: NewOrEditDependencyDialog.java    From tesb-studio-se with Apache License 2.0 6 votes vote down vote up
/**
 * Validate name.
 *
 * @return the i status
 */
public String validateName() {
	final String name = getDependencyName();
	if (origin != null && name.equals(origin.getName())) {
		return null;
	}
	for (ManifestItem o : input) {
		if (name.equals(o.getName())) {
			return Messages.NewDependencyItemDialog_existCheckMessage;
		}
	}
       // Bundle-SymbolicName could include dash (-) and other characters
       if (!this.type.equals(ManifestItem.REQUIRE_BUNDLE)) {
           final IStatus status = JavaConventions.validatePackageName(name);
           if (!status.isOK()) {
               return status.getMessage();
           }
       }
	return null;
}
 
Example #3
Source File: ClasspathChange.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Change perform(IProgressMonitor pm) throws CoreException {
	pm.beginTask(RefactoringCoreMessages.ClasspathChange_progress_message, 1);
	try {
		if (!JavaConventions.validateClasspath(fProject, fNewClasspath, fOutputLocation).matches(IStatus.ERROR)) {
			IClasspathEntry[] oldClasspath= fProject.getRawClasspath();
			IPath oldOutputLocation= fProject.getOutputLocation();

			fProject.setRawClasspath(fNewClasspath, fOutputLocation, new SubProgressMonitor(pm, 1));

			return new ClasspathChange(fProject, oldClasspath, oldOutputLocation);
		} else {
			return new NullChange();
		}
	} finally {
		pm.done();
	}
}
 
Example #4
Source File: JavaUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static IStatus validateMethodName(String methodName) {
  String complianceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.compliance");
  String sourceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.source");
  IStatus nameStatus = JavaConventions.validateMethodName(methodName,
      sourceLevel, complianceLevel);

  if (!nameStatus.isOK()) {
    return nameStatus;
  }

  // The JavaConventions class doesn't seem to be flagging method names with
  // an uppercase first character, so we need to check it ourselves.
  if (!Character.isLowerCase(methodName.charAt(0))) {
    return StatusUtilities.newWarningStatus(
        "Method name should start with a lowercase letter.",
        CorePlugin.PLUGIN_ID);
  }

  return StatusUtilities.OK_STATUS;
}
 
Example #5
Source File: ModuleUtils.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Validates a simple module name. The name should be a camel-cased valid Java identifier.
 *
 * @param simpleName the simple module name
 * @return a status object with code <code>IStatus.OK</code> if the given name is valid, otherwise
 *         a status object indicating what is wrong with the name
 */
public static IStatus validateSimpleModuleName(String simpleName) {
  String complianceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.compliance");
  String sourceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.source");

  // Make sure that the simple name does not have any dots in it. We need
  // to do this validation before passing the simpleName to JavaConventions,
  // because validateTypeName accepts both simple and fully-qualified type
  // names.
  if (simpleName.indexOf('.') != -1) {
    return Util.newErrorStatus("Module name should not contain dots.");
  }

  // Validate the module name according to Java type name conventions
  IStatus nameStatus = JavaConventions.validateJavaTypeName(simpleName, complianceLevel, sourceLevel);
  if (nameStatus.matches(IStatus.ERROR)) {
    return Util.newErrorStatus("The module name is invalid");
  }

  return Status.OK_STATUS;
}
 
Example #6
Source File: NewTxtUMLProjectWizardPage.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected boolean validatePage() {
	if (!super.validatePage())
		return false;
	IStatus status = JavaConventions.validatePackageName(getProjectName(), JavaCore.VERSION_1_5,
			JavaCore.VERSION_1_5);
	if (!status.isOK()) {
		if (status.matches(IStatus.WARNING)) {
			setMessage(status.getMessage(), IStatus.WARNING);
			return true;
		}
		setErrorMessage(Messages.WizardNewtxtUMLProjectCreationPage_ErrorMessageProjectName + status.getMessage());
		return false;
	}
	setErrorMessage(null);
	setMessage(null);
	return true;
}
 
Example #7
Source File: ClasspathChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Change perform(IProgressMonitor pm) throws CoreException {
	pm.beginTask(RefactoringCoreMessages.ClasspathChange_progress_message, 1);
	try {
		if (!JavaConventions.validateClasspath(fProject, fNewClasspath, fOutputLocation).matches(IStatus.ERROR)) {
			IClasspathEntry[] oldClasspath= fProject.getRawClasspath();
			IPath oldOutputLocation= fProject.getOutputLocation();

			fProject.setRawClasspath(fNewClasspath, fOutputLocation, new SubProgressMonitor(pm, 1));

			return new ClasspathChange(fProject, oldClasspath, oldOutputLocation);
		} else {
			return new NullChange();
		}
	} finally {
		pm.done();
	}
}
 
Example #8
Source File: BuildPathsBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void updateBuildPathStatus() {
	List<CPListElement> elements= fClassPathList.getElements();
	IClasspathEntry[] entries= new IClasspathEntry[elements.size()];

	for (int i= elements.size()-1 ; i >= 0 ; i--) {
		CPListElement currElement= elements.get(i);
		entries[i]= currElement.getClasspathEntry();
	}

	IJavaModelStatus status= JavaConventions.validateClasspath(fCurrJProject, entries, fOutputLocationPath);
	if (!status.isOK()) {
		fBuildPathStatus.setError(status.getMessage());
		return;
	}
	fBuildPathStatus.setOK();
}
 
Example #9
Source File: ImportOrganizeInputDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void doValidation() {
	StatusInfo status= new StatusInfo();
	String newText= fNameDialogField.getText();
	if (newText.length() == 0) {
		status.setError(""); //$NON-NLS-1$
	} else {
		if (newText.equals("*")) { //$NON-NLS-1$
			if (doesExist("", fIsStatic)) { //$NON-NLS-1$
				status.setError(PreferencesMessages.ImportOrganizeInputDialog_error_entryExists);
			}
		} else {
			IStatus val= JavaConventions.validateJavaTypeName(newText, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
			if (val.matches(IStatus.ERROR)) {
				status.setError(PreferencesMessages.ImportOrganizeInputDialog_error_invalidName);
			} else {
				if (doesExist(newText, fIsStatic)) {
					status.setError(PreferencesMessages.ImportOrganizeInputDialog_error_entryExists);
				}
			}
		}
	}
	updateStatus(status);
}
 
Example #10
Source File: CodeAssistFavoritesConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void doValidation() {
	StatusInfo status= new StatusInfo();
	String newText= fNameDialogField.getText();
	if (newText.length() == 0) {
		status.setError(""); //$NON-NLS-1$
	} else {
		IStatus val= JavaConventions.validateJavaTypeName(newText, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
		if (val.matches(IStatus.ERROR)) {
			if (fIsEditingMember)
				status.setError(PreferencesMessages.FavoriteStaticMemberInputDialog_error_invalidMemberName);
			else
				status.setError(PreferencesMessages.FavoriteStaticMemberInputDialog_error_invalidTypeName);
		} else {
			if (doesExist(newText)) {
				status.setError(PreferencesMessages.FavoriteStaticMemberInputDialog_error_entryExists);
			}
		}
	}
	updateStatus(status);
}
 
Example #11
Source File: NameConventionConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IStatus validateIdentifiers(String[] values, boolean prefix) {
	for (int i= 0; i < values.length; i++) {
		String val= values[i];
		if (val.length() == 0) {
			if (prefix) {
				return new StatusInfo(IStatus.ERROR, PreferencesMessages.NameConventionConfigurationBlock_error_emptyprefix);
			} else {
				return new StatusInfo(IStatus.ERROR, PreferencesMessages.NameConventionConfigurationBlock_error_emptysuffix);
			}
		}
		String name= prefix ? val + "x" : "x" + val; //$NON-NLS-2$ //$NON-NLS-1$
		IStatus status= JavaConventions.validateIdentifier(name, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
		if (status.matches(IStatus.ERROR)) {
			if (prefix) {
				return new StatusInfo(IStatus.ERROR, Messages.format(PreferencesMessages.NameConventionConfigurationBlock_error_invalidprefix, val));
			} else {
				return new StatusInfo(IStatus.ERROR, Messages.format(PreferencesMessages.NameConventionConfigurationBlock_error_invalidsuffix, val));
			}
		}
	}
	return new StatusInfo();
}
 
Example #12
Source File: TypeFilterInputDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void doValidation() {
	StatusInfo status= new StatusInfo();
	String newText= fNameDialogField.getText();
	if (newText.length() == 0) {
		status.setError(PreferencesMessages.TypeFilterInputDialog_error_enterName);
	} else {
		newText= newText.replace('*', 'X').replace('?', 'Y');
		IStatus val= JavaConventions.validatePackageName(newText, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
		if (val.matches(IStatus.ERROR)) {
			status.setError(Messages.format(PreferencesMessages.TypeFilterInputDialog_error_invalidName, val.getMessage()));
		} else {
			if (fExistingEntries.contains(newText)) {
				status.setError(PreferencesMessages.TypeFilterInputDialog_error_entryExists);
			}
		}
	}
	updateStatus(status);
}
 
Example #13
Source File: FilteredTypesSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public int open() {
	if (getInitialPattern() == null) {
		IWorkbenchWindow window= JavaPlugin.getActiveWorkbenchWindow();
		if (window != null) {
			ISelection selection= window.getSelectionService().getSelection();
			if (selection instanceof ITextSelection) {
				String text= ((ITextSelection) selection).getText();
				if (text != null) {
					text= text.trim();
					if (text.length() > 0 && JavaConventions.validateJavaTypeName(text, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3).isOK()) {
						setInitialPattern(text, FULL_SELECTION);
					}
				}
			}
		}
	}
	return super.open();
}
 
Example #14
Source File: JavaPackageValidator.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Check if a string is a legal Java package name.
 */
public static IStatus validate(String packageName) {
  if (packageName == null) {
    return new Status(IStatus.ERROR, PLUGIN_ID, 45, "null package name", null);
  } else if (packageName.isEmpty()) { // default package is allowed
    return Status.OK_STATUS;
  } else if (packageName.endsWith(".")) { //$NON-NLS-1$
    // todo or allow this and strip the period
    return new Status(IStatus.ERROR, PLUGIN_ID, 46, 
        Messages.getString("package.ends.with.period", packageName), null); //$NON-NLS-1$
  } else if (containsWhitespace(packageName)) {
    // very weird condition because validatePackageName allows internal white space
    return new Status(IStatus.ERROR, PLUGIN_ID, 46, 
        Messages.getString("package.contains.whitespace", packageName), null); //$NON-NLS-1$
  } else {
    return JavaConventions.validatePackageName(
        packageName, JavaCore.VERSION_1_4, JavaCore.VERSION_1_4);
  }
}
 
Example #15
Source File: ImportOrganizeConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private List<ImportOrderEntry> loadFromProperties(Properties properties) {
	ArrayList<ImportOrderEntry> res= new ArrayList<ImportOrderEntry>();
	int nEntries= properties.size();
	for (int i= 0 ; i < nEntries; i++) {
		String curr= properties.getProperty(String.valueOf(i));
		if (curr != null) {
			ImportOrderEntry entry= ImportOrderEntry.fromSerialized(curr);
			if (entry.name.length() == 0 || !JavaConventions.validatePackageName(entry.name, JavaCore.VERSION_1_3, JavaCore.VERSION_1_5).matches(IStatus.ERROR)) {
				res.add(entry);
			} else {
				return null;
			}
		} else {
			return res;
		}
	}
	return res;
}
 
Example #16
Source File: NewPackageWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IStatus validatePackageName(String text) {
	IJavaProject project= getJavaProject();
	if (project == null || !project.exists()) {
		return JavaConventions.validatePackageName(text, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
	}
	return JavaConventionsUtil.validatePackageName(text, project);
}
 
Example #17
Source File: Util.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isValidTypeName(String typeName) {
  String complianceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.compliance");
  String sourceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.source");

  return JavaConventions.validateJavaTypeName(typeName, sourceLevel,
      complianceLevel).isOK();
}
 
Example #18
Source File: Util.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public static IStatus validatePackageName(String packageName) {
  if (packageName.length() > 0) {

    String sourceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.compliance");
    String compliance = JavaCore.getOption("org.eclipse.jdt.core.compiler.source");

    return JavaConventions.validatePackageName(packageName, sourceLevel,
        compliance);
  }

  return newWarningStatus(NewWizardMessages.NewTypeWizardPage_warning_DefaultPackageDiscouraged);
}
 
Example #19
Source File: CreateImportOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Possible failures: <ul>
 *  <li>NO_ELEMENTS_TO_PROCESS - the compilation unit supplied to the operation is
 * 		<code>null</code>.
 *  <li>INVALID_NAME - not a valid import declaration name.
 * </ul>
 * @see IJavaModelStatus
 * @see JavaConventions
 */
public IJavaModelStatus verify() {
	IJavaModelStatus status = super.verify();
	if (!status.isOK()) {
		return status;
	}
	IJavaProject project = getParentElement().getJavaProject();
	if (JavaConventions.validateImportDeclaration(this.importName, project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)).getSeverity() == IStatus.ERROR) {
		return new JavaModelStatus(IJavaModelStatusConstants.INVALID_NAME, this.importName);
	}
	return JavaModelStatus.VERIFIED_OK;
}
 
Example #20
Source File: JenerateBasePreferencePage.java    From jenerate with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isFieldStringValueValid(String value) {
    IStatus status = JavaConventions.validateIdentifier(value);
    if (status.isOK()) {
        return true;
    }
    setErrorMessage(status.getMessage());
    setValid(false);
    return false;
}
 
Example #21
Source File: Util.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isValidMethodName(String methodName) {
  String complianceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.compliance");
  String sourceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.source");

  return JavaConventions.validateMethodName(methodName, sourceLevel,
      complianceLevel).isOK();
}
 
Example #22
Source File: CreatePackageDeclarationOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Possible failures: <ul>
 *  <li>NO_ELEMENTS_TO_PROCESS - no compilation unit was supplied to the operation
 *  <li>INVALID_NAME - a name supplied to the operation was not a valid
 * 		package declaration name.
 * </ul>
 * @see IJavaModelStatus
 * @see JavaConventions
 */
public IJavaModelStatus verify() {
	IJavaModelStatus status = super.verify();
	if (!status.isOK()) {
		return status;
	}
	IJavaProject project = getParentElement().getJavaProject();
	if (JavaConventions.validatePackageName(this.name, project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)).getSeverity() == IStatus.ERROR) {
		return new JavaModelStatus(IJavaModelStatusConstants.INVALID_NAME, this.name);
	}
	return JavaModelStatus.VERIFIED_OK;
}
 
Example #23
Source File: CreateCompilationUnitOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Possible failures: <ul>
 *  <li>NO_ELEMENTS_TO_PROCESS - the package fragment supplied to the operation is
 * 		<code>null</code>.
 *	<li>INVALID_NAME - the compilation unit name provided to the operation
 * 		is <code>null</code> or has an invalid syntax
 *  <li>INVALID_CONTENTS - the source specified for the compiliation unit is null
 * </ul>
 */
public IJavaModelStatus verify() {
	if (getParentElement() == null) {
		return new JavaModelStatus(IJavaModelStatusConstants.NO_ELEMENTS_TO_PROCESS);
	}
	IJavaProject project = getParentElement().getJavaProject();
	if (JavaConventions.validateCompilationUnitName(this.name, project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)).getSeverity() == IStatus.ERROR) {
		return new JavaModelStatus(IJavaModelStatusConstants.INVALID_NAME, this.name);
	}
	if (this.source == null) {
		return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CONTENTS);
	}
	return JavaModelStatus.VERIFIED_OK;
}
 
Example #24
Source File: ParameterEditDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IStatus validateName() {
	if (fName == null)
		return null;
	String text= fName.getText();
	if (text.length() == 0)
		return createErrorStatus(RefactoringMessages.ParameterEditDialog_name_error);
	IStatus status= fContext != null
			? JavaConventionsUtil.validateFieldName(text, fContext.getCuHandle().getJavaProject())
			: JavaConventions.validateFieldName(text, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
	if (status.matches(IStatus.ERROR))
		return status;
	if (! Checks.startsWithLowerCase(text))
		return createWarningStatus(RefactoringCoreMessages.ExtractTempRefactoring_convention);
	return Status.OK_STATUS;
}
 
Example #25
Source File: GroovyReferenceValidator.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public IStatus validate(final Object value) {
    if (checkEmptyField) {
        final IStatus s = new EmptyInputValidator(fieldName).validate(value);
        if (!s.isOK()) {
            return s;
        }
    } else {
        if (value == null || value.toString().isEmpty()) {
            return ValidationStatus.ok();
        }
    }
    if (forceLowerCaseFirst && !value.toString().isEmpty()) {
        final char firstChar = value.toString().charAt(0);
        if (Character.isUpperCase(firstChar)) {
            return ValidationStatus.error(Messages.bind(Messages.nameMustStartWithLowerCase, value.toString()));
        }
    }
    if (!value.toString().isEmpty()) {
        if (value.toString().contains(" ")) {
            return ValidationStatus.error(Messages.bind(Messages.nameCantHaveAWhitespace, value.toString()));
        } else if (Character.isDigit(value.toString().charAt(0))) {
            return ValidationStatus.error(Messages.bind(Messages.nameMustStartWithLowerCase, value.toString()));
        }
    }

    if (value.toString() != null && !value.toString().isEmpty() && Arrays.asList(KEYWORDS).contains(value.toString())) {
        return ValidationStatus.error(Messages.reservedKeyword);
    }

    final IStatus javaConventionNameStatus = JavaConventions.validateFieldName(value.toString(), JavaCore.VERSION_1_6, JavaCore.VERSION_1_6);
    if (!javaConventionNameStatus.isOK()) {
        return ValidationStatus.error(javaConventionNameStatus.getMessage());
    }
    return ValidationStatus.ok();
}
 
Example #26
Source File: GroupIdValidator.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected IStatus validateJavaPackageName(Object value) {
    try {
        return JavaConventions.validatePackageName(value.toString(), JavaCore.VERSION_1_8, JavaCore.VERSION_1_8);
    } catch (IllegalStateException e) {
        //avoid stacktrace in tests
        return Status.OK_STATUS;
    }
}
 
Example #27
Source File: ProblemSeveritiesConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IStatus validateNullnessAnnotation(String value, String errorMessage) {
	StatusInfo status= new StatusInfo();
	if (JavaConventions.validateJavaTypeName(value, JavaCore.VERSION_1_5, JavaCore.VERSION_1_5).matches(IStatus.ERROR)
			|| value.indexOf('.') == -1)
		status.setError(errorMessage);
	return status;
}
 
Example #28
Source File: NameConventionConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected final void updateModel(DialogField field) {
	if (field == fNameConventionList) {
		for (int i= 0; i < fNameConventionList.getSize(); i++) {
			NameConventionEntry entry= fNameConventionList.getElement(i);
			setValue(entry.suffixkey, entry.suffix);
			setValue(entry.prefixkey, entry.prefix);
		}
	} else if (field == fExceptionName) {
		String name= fExceptionName.getText();

		setValue(PREF_EXCEPTION_NAME, name);

		// validation
		IStatus status = JavaConventions.validateIdentifier(name, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
		if (!status.isOK()) {
			fContext.statusChanged(status);
		} else {
			fContext.statusChanged(new StatusInfo());
		}
	} else if (field == fUseKeywordThisBox) {
		setValue(PREF_KEYWORD_THIS, fUseKeywordThisBox.isSelected());
	} else if (field == fUseIsForBooleanGettersBox) {
		setValue(PREF_IS_FOR_GETTERS, fUseIsForBooleanGettersBox.isSelected());
	} else if (field == fUseOverrideAnnotation) {
		setValue(PREF_USE_OVERRIDE_ANNOT, fUseOverrideAnnotation.isSelected());
	}
}
 
Example #29
Source File: WizardNewXtextProjectCreationPage.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected boolean validatePage() {
	if (!super.validatePage())
		return false;
	IStatus status = validateProjectName();
	if (!status.isOK()) {
		setErrorMessage(status.getMessage());
		return false;
	}
	if (languageNameField == null) // See the comment in createControl
		return true;
	if (languageNameField.getText().length() == 0)
		return false;

	status = JavaConventions.validateJavaTypeName(languageNameField.getText(), JavaCore.VERSION_1_5, JavaCore.VERSION_1_5);
	if (!status.isOK()) {
		setErrorMessage(Messages.WizardNewXtextProjectCreationPage_ErrorMessageLanguageName + status.getMessage());
		return false;
	}

	if (!languageNameField.getText().contains(".")) { //$NON-NLS-1$
		setErrorMessage(Messages.WizardNewXtextProjectCreationPage_ErrorMessageLanguageNameWithoutPackage);
		return false;
	}

	if (extensionsField.getText().length() == 0)
		return false;
	if (!PATTERN_EXTENSIONS.matcher(extensionsField.getText()).matches()) {
		setErrorMessage(Messages.WizardNewXtextProjectCreationPage_ErrorMessageExtensions);
		return false;
	}
	JavaVersion javaVersion = JavaVersion.fromBree(breeCombo.getText());
	if (javaVersion != null && !javaVersion.isAtLeast(JavaVersion.JAVA8)) {
		setMessage(Messages.WizardNewXtextProjectCreationPage_MessageAtLeastJava8, IStatus.WARNING);
		return true;
	}
	if (!Sets.newHashSet(JREContainerProvider.getConfiguredBREEs()).contains(breeCombo.getText())) {
		setMessage(Messages.WizardNewXtextProjectCreationPage_eeInfo_0 + breeCombo.getText()
				+ Messages.WizardNewXtextProjectCreationPage_eeInfo_1, IMessageProvider.INFORMATION);
		return true;
	}
	setErrorMessage(null);
	setMessage(null);
	return true;
}
 
Example #30
Source File: QueryParameterNameValidator.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected IStatus validateJavaConvention(String name) {
    return JavaConventions.validateFieldName(name, JavaCore.VERSION_1_8, JavaCore.VERSION_1_8);
}