Java Code Examples for org.eclipse.jdt.core.JavaConventions#validateIdentifier()

The following examples show how to use org.eclipse.jdt.core.JavaConventions#validateIdentifier() . 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: 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 2
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 3
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 4
Source File: IntroduceParameterObjectWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
protected void validateRefactoring() {
	List<String> names= new ArrayList<String>();
	boolean oneChecked= false;
	setMessage(null);
	setErrorMessage(null);
	setPageComplete(true);
	IJavaProject project= fProcessor.getMethod().getJavaProject();
	String sourceLevel= project.getOption(JavaCore.COMPILER_SOURCE, true);
	String compliance= project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
	List<ParameterInfo> parameterInfos= fProcessor.getParameterInfos();
	for (Iterator<ParameterInfo> iter= parameterInfos.iterator(); iter.hasNext();) {
		ParameterInfo pi= iter.next();
		if (names.contains(pi.getNewName())) {
			setErrorMessage(Messages.format(RefactoringMessages.IntroduceParameterObjectWizard_parametername_check_notunique, BasicElementLabels.getJavaElementName(pi.getNewName())));
			setPageComplete(false);
			return;
		}
		names.add(pi.getNewName());
		IStatus validateIdentifier= JavaConventions.validateIdentifier(pi.getNewName(), sourceLevel, compliance);
		if (isErrorMessage(validateIdentifier))
			return;
		if (pi.isCreateField())
			oneChecked= true;
	}
	if (!oneChecked) {
		setErrorMessage(RefactoringMessages.IntroduceParameterObjectWizard_parametername_check_atleastoneparameter);
		setPageComplete(false);
		return;
	}
	IStatus validateJavaTypeName= JavaConventions.validateJavaTypeName(fProcessor.getClassName(), sourceLevel, compliance);
	if (isErrorMessage(validateJavaTypeName))
		return;
	if (fProcessor.getClassName().indexOf('.') != -1) {
		setErrorMessage(RefactoringMessages.IntroduceParameterObjectWizard_dot_not_allowed_error);
		setPageComplete(false);
	}
	if (!"".equals(fProcessor.getPackage())) { //$NON-NLS-1$
		IStatus validatePackageName= JavaConventions.validatePackageName(fProcessor.getPackage(), sourceLevel, compliance);
		if (isErrorMessage(validatePackageName))
			return;
	}
	try {
		IType type= project.findType(fProcessor.getNewTypeName());
		if (type != null) {
			String packageLabel= JavaElementLabels.getElementLabel(type.getPackageFragment(), JavaElementLabels.ALL_DEFAULT);
			if (fProcessor.isCreateAsTopLevel()) {
				setErrorMessage(Messages.format(RefactoringMessages.IntroduceParameterObjectWizard_type_already_exists_in_package_info,
						new Object[] { BasicElementLabels.getJavaElementName(fProcessor.getClassName()), packageLabel }));
				setPageComplete(false);
				return;
			} else {
				setErrorMessage(Messages.format(RefactoringMessages.IntroduceParameterObjectWizard_parametername_check_alreadyexists,
						new Object[] { BasicElementLabels.getJavaElementName(fProcessor.getClassName()), BasicElementLabels.getFileName(type.getCompilationUnit()) }));
				setPageComplete(false);
				return;
			}
		}
	} catch (JavaModelException e) {
		// Don't care. The error will popup later anyway..
	}
}
 
Example 5
Source File: JavaConventionsUtil.java    From eclipse.jdt.ls with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * @param name
 *            the name to validate
 * @param context
 *            an {@link IJavaElement} or <code>null</code>
 * @return validation status in <code>context</code>'s project or in the
 *         workspace
 *
 * @see JavaConventions#validateIdentifier(String, String, String)
 */
public static IStatus validateIdentifier(String name, IJavaElement context) {
	String[] sourceComplianceLevels = getSourceComplianceLevels(context);
	return JavaConventions.validateIdentifier(name, sourceComplianceLevels[0], sourceComplianceLevels[1]);
}
 
Example 6
Source File: JavaConventionsUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * @param name the name to validate
 * @param context an {@link IJavaElement} or <code>null</code>
 * @return validation status in <code>context</code>'s project or in the workspace
 *
 * @see JavaConventions#validateIdentifier(String, String, String)
 */
public static IStatus validateIdentifier(String name, IJavaElement context) {
	String[] sourceComplianceLevels= getSourceComplianceLevels(context);
	return JavaConventions.validateIdentifier(name, sourceComplianceLevels[0], sourceComplianceLevels[1]);
}