Java Code Examples for org.eclipse.jdt.core.JavaConventions#validatePackageName()
The following examples show how to use
org.eclipse.jdt.core.JavaConventions#validatePackageName() .
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: JavaPackageValidator.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
/** * 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 2
Source File: NewTxtUMLProjectWizardPage.java From txtUML with Eclipse Public License 1.0 | 6 votes |
@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 3
Source File: TypeFilterInputDialog.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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 4
Source File: NewOrEditDependencyDialog.java From tesb-studio-se with Apache License 2.0 | 6 votes |
/** * 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 5
Source File: Util.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
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 6
Source File: NewPackageWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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 7
Source File: GroupIdValidator.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
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 8
Source File: NewWebAppProjectWizardPage.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 4 votes |
private void validatePageAndSetCompletionStatus() { IStatus status; boolean pageComplete = false; try { // Project name cannot be blank if (getProjectName().length() == 0) { setMessage("Enter a name for the project"); return; } // Verify that project name is valid status = ResourcesPlugin.getWorkspace().validateName(getProjectName(), IResource.PROJECT); if (!validateFromStatus(status)) { return; } // Make sure project doesn't already exist in workspace if (existingProjectNames.contains(getProjectName())) { setMessage("A project with this name already exists.", ERROR); return; } // Output directory cannot be blank if (getOutputDirectory().length() == 0) { setMessage("Enter the output directory"); return; } // If the user wants to use a custom output directory, // verify that the directory exists if (outDirCustomButton.getSelection()) { File outDir = new Path(getOutputDirectory()).toFile(); if (!outDir.isDirectory()) { setMessage("The output directory does not exist", ERROR); return; } } // Make sure resource with project's name doesn't already exist in output // directory IPath outPath = new Path(getOutputDirectory()); if (outDirWorkspaceButton.getSelection()) { if (outPath.toFile().exists()) { setMessage("A resource with the project name already exists in the workspace root", ERROR); return; } } // Make sure output directory doesn't already contain an Eclipse project if (outDirCustomButton.getSelection()) { outPath = outPath.append(IProjectDescription.DESCRIPTION_FILE_NAME); if (outPath.toFile().exists()) { setMessage("The output directory already contains a project file", ERROR); return; } } // Package name cannot be blank if (getPackage().length() == 0) { setMessage("Enter a package name"); return; } String complianceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.compliance"); String sourceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.source"); // Verify that package name is valid status = JavaConventions.validatePackageName(getPackage(), complianceLevel, sourceLevel); if (!validateFromStatus(status)) { return; } // If we are using GWT then an SDK must be selected if (useGwtCheckbox.getSelection()) { IStatus gwtRuntimeValidationStatus; GwtSdk selectedGwtRuntime = getSelectedGwtSdk(); if (selectedGwtRuntime == null) { setMessage("Please configure a GWT SDK.", ERROR); return; } else if (!(gwtRuntimeValidationStatus = selectedGwtRuntime.validate()).isOK()) { setMessage("The selected GWT SDK is not valid: " + gwtRuntimeValidationStatus.getMessage(), ERROR); return; } } pageComplete = true; setMessage(null); } finally { setPageComplete(pageComplete); } }
Example 9
Source File: IntroduceParameterObjectWizard.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
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 10
Source File: NewTypeWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static IStatus validatePackageName(String text, IJavaProject project) { if (project == null || !project.exists()) { return JavaConventions.validatePackageName(text, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3); } return JavaConventionsUtil.validatePackageName(text, project); }
Example 11
Source File: PackageNameValidator.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
protected IStatus javaPackageValidation(String value) { return JavaConventions.validatePackageName(value, JavaCore.VERSION_1_8, JavaCore.VERSION_1_8); }
Example 12
Source File: JavaConventionsUtil.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 2 votes |
/** * @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#validatePackageName(String, String, String) */ public static IStatus validatePackageName(String name, IJavaElement context) { String[] sourceComplianceLevels = getSourceComplianceLevels(context); return JavaConventions.validatePackageName(name, sourceComplianceLevels[0], sourceComplianceLevels[1]); }
Example 13
Source File: JavaConventionsUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 2 votes |
/** * @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#validatePackageName(String, String, String) */ public static IStatus validatePackageName(String name, IJavaElement context) { String[] sourceComplianceLevels= getSourceComplianceLevels(context); return JavaConventions.validatePackageName(name, sourceComplianceLevels[0], sourceComplianceLevels[1]); }