/** * 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); } }
@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(); } }
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; }
/** * 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; }
private void createLibraryNameControls(Composite parent, int cols) { Label libraryNameLbl = new Label(parent, SWT.NONE); libraryNameLbl.setText("Library Name:"); libraryNameLbl.setToolTipText("A class-name like identifier that will be used to generate the class file containing your functions"); libraryNameLbl.setLayoutData(new GridData(SWT.FILL,SWT.TOP,false,false)); libraryName = new Text(parent, SWT.BORDER); libraryName.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,false,cols-1,1)); libraryName.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { libraryNameStatus = JavaConventions.validateJavaTypeName( libraryName.getText(), JavaCore.VERSION_1_6, JavaCore.VERSION_1_6); doStatusUpdate(); } }); }
private void createCategoryClassControls(Composite parent, int cols) { Label categoryClassLbl = new Label(parent, SWT.NONE); categoryClassLbl.setText("Category Class:"); categoryClassLbl.setLayoutData(new GridData(SWT.FILL,SWT.TOP,false,false)); categoryClassLbl.setToolTipText("The class that will represent the category. Usually automatically suggested"); categoryClass = new Text(parent, SWT.BORDER); categoryClass.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,false,cols-1,1)); categoryClass.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { categoryClassStatus = JavaConventions.validateJavaTypeName( categoryClass.getText(), JavaCore.VERSION_1_6, JavaCore.VERSION_1_6); if(categoryClassStatus.isOK()){ // Ensure Library Class is different from Category Class String libraryNameTxt = libraryName.getText(); String categoryClassTxt = categoryClass.getText(); if(categoryClassTxt.endsWith("."+libraryNameTxt) || categoryClassTxt.equals(libraryNameTxt)) { categoryClassStatus = new Status(IStatus.ERROR, JaspersoftStudioPlugin.PLUGIN_ID, -1, "Category class can not be the same one of the Library itself", null); } } doStatusUpdate(); } }); AutoCompletionHelper.enableAutoCompletion(categoryClass, getExistingCategories()); }
@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; }
@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(); } }
public static void commitClassPath(List<CPListElement> newEntries, IJavaProject project, IProgressMonitor monitor) throws JavaModelException { if (monitor == null) monitor= new NullProgressMonitor(); monitor.beginTask("", 2); //$NON-NLS-1$ try { IClasspathEntry[] entries= convert(newEntries); IPath outputLocation= project.getOutputLocation(); IJavaModelStatus status= JavaConventions.validateClasspath(project, entries, outputLocation); if (!status.isOK()) throw new JavaModelException(status); BuildPathSupport.setEEComplianceOptions(project, newEntries); project.setRawClasspath(entries, outputLocation, new SubProgressMonitor(monitor, 2)); } finally { monitor.done(); } }
public static void commitClassPath(CPJavaProject cpProject, IProgressMonitor monitor) throws JavaModelException { if (monitor == null) monitor= new NullProgressMonitor(); monitor.beginTask("", 2); //$NON-NLS-1$ try { List<CPListElement> cpListElements= cpProject.getCPListElements(); IClasspathEntry[] entries= convert(cpListElements); IPath outputLocation= cpProject.getDefaultOutputLocation(); IJavaProject javaProject= cpProject.getJavaProject(); IJavaModelStatus status= JavaConventions.validateClasspath(javaProject, entries, outputLocation); if (!status.isOK()) throw new JavaModelException(status); BuildPathSupport.setEEComplianceOptions(javaProject, cpListElements); javaProject.setRawClasspath(entries, outputLocation, new SubProgressMonitor(monitor, 2)); } finally { monitor.done(); } }
/** * 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); }
@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(); }
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); }
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(); }
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); }
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); }
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; }
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(); }
/** * 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; }
private void validate() { if (projectData.packageName.trim().isEmpty()) { setErrorMessage("Package name must not be empty"); setPageComplete(false); return; } IStatus validPackageName = JavaConventions.validatePackageName(projectData.packageName, "1.5", "1.5"); if (!validPackageName.isOK()) { setErrorMessage("Package name is invalid"); setPageComplete(false); return; } if (projectData.androidSelected) { String androidValidation = validateAndroidPackageName(projectData.packageName); if (androidValidation != null) { setErrorMessage(androidValidation); setPageComplete(false); return; } } if (projectData.mainClassName.trim().isEmpty()) { setErrorMessage("Main class name must not be empty"); setPageComplete(false); return; } IStatus validClassName = JavaConventions.validateJavaTypeName(projectData.mainClassName, "1.5", "1.5"); if (!validClassName.isOK()) { setErrorMessage("Main class name is invalid"); setPageComplete(false); return; } setErrorMessage(null); setPageComplete(true); }
private void validate() { if (projectData.packageName.trim().isEmpty()) { setErrorMessage("Package name must not be empty"); setPageComplete(false); return; } IStatus validPackageName = JavaConventions.validatePackageName(projectData.packageName, "1.5", "1.5"); if (!validPackageName.isOK()) { setErrorMessage("Package name is invalid"); setPageComplete(false); return; } if (projectData.mainClassName.trim().isEmpty()) { setErrorMessage("Main class name must not be empty"); setPageComplete(false); return; } IStatus validClassName = JavaConventions.validateJavaTypeName(projectData.mainClassName, "1.5", "1.5"); if (!validClassName.isOK()) { setErrorMessage("Main class name is invalid"); setPageComplete(false); return; } setErrorMessage(null); setPageComplete(true); }
public static void getWrongTypeNameProposals(IInvocationContext context, IProblemLocation problem, Collection<CUCorrectionProposal> proposals) { ICompilationUnit cu= context.getCompilationUnit(); IJavaProject javaProject= cu.getJavaProject(); String sourceLevel= javaProject.getOption(JavaCore.COMPILER_SOURCE, true); String compliance= javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true); CompilationUnit root= context.getASTRoot(); ASTNode coveredNode= problem.getCoveredNode(root); if (!(coveredNode instanceof SimpleName)) { return; } ASTNode parentType= coveredNode.getParent(); if (!(parentType instanceof AbstractTypeDeclaration)) { return; } String currTypeName= ((SimpleName) coveredNode).getIdentifier(); String newTypeName= JavaCore.removeJavaLikeExtension(cu.getElementName()); List<AbstractTypeDeclaration> types= root.types(); for (int i= 0; i < types.size(); i++) { AbstractTypeDeclaration curr= types.get(i); if (parentType != curr) { if (newTypeName.equals(curr.getName().getIdentifier())) { return; } } } if (!JavaConventions.validateJavaTypeName(newTypeName, sourceLevel, compliance).matches(IStatus.ERROR)) { proposals.add(new CorrectMainTypeNameProposal(cu, context, currTypeName, newTypeName, IProposalRelevance.RENAME_TYPE)); } }
public static ClasspathChange newChange( IJavaProject project, IClasspathEntry[] newClasspath, IPath outputLocation) { if (!JavaConventions.validateClasspath(project, newClasspath, outputLocation) .matches(IStatus.ERROR)) { return new ClasspathChange(project, newClasspath, outputLocation); } return null; }
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(); }
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(); }
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); }
private boolean isFieldStringValueValid(String value) { IStatus status = JavaConventions.validateIdentifier(value); if (status.isOK()) { return true; } setErrorMessage(status.getMessage()); setValid(false); return false; }
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; }
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); }