List of usage examples for org.eclipse.jdt.core JavaConventions validateJavaTypeName
public static IStatus validateJavaTypeName(String name, String sourceLevel, String complianceLevel)
From source file:at.bestsolution.efxclipse.tooling.pde.e4.project.PluginContentPage.java
License:Open Source License
protected void validatePage() { String errorMessage = validateProperties(); if (errorMessage == null && fGenerateActivator.getSelection()) { IStatus status = JavaConventions.validateJavaTypeName(fClassText.getText().trim(), PDEJavaHelper.getJavaSourceLevel(null), PDEJavaHelper.getJavaComplianceLevel(null)); if (status.getSeverity() == IStatus.ERROR) { errorMessage = status.getMessage(); } else if (status.getSeverity() == IStatus.WARNING) { setMessage(status.getMessage(), IMessageProvider.WARNING); }//from w ww. j a v a2 s . c o m } if (errorMessage == null) { String eeid = fEEChoice.getText(); if (fEEChoice.isEnabled()) { IExecutionEnvironment ee = VMUtil.getExecutionEnvironment(eeid); if (ee != null && ee.getCompatibleVMs().length == 0) { errorMessage = PDEUIMessages.NewProjectCreationPage_invalidEE; } } } setErrorMessage(errorMessage); setPageComplete(errorMessage == null); }
From source file:com.android.ide.eclipse.adt.internal.wizards.newproject.ApplicationInfoPage.java
License:Open Source License
public static IStatus validateClass(String className) { if (className == null || className.length() == 0) { return new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, "Class name must be specified."); }/*from w ww . ja va 2 s . c o m*/ if (className.indexOf('.') != -1) { return new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, "Enter just a class name, not a full package name"); } return JavaConventions.validateJavaTypeName(className, JDK_15, JDK_15); }
From source file:com.ebmwebsourcing.petals.services.jsr181.v11.Jsr181ProvidePage11.java
License:Open Source License
@Override public boolean validate() { // Case: WSDL first String errorMsg = null;/*from w w w .j a va2 s . c o m*/ if (this.wsdlFirst) { if (StringUtils.isEmpty(this.wsdlUriAsString)) { errorMsg = "You must specify a WSDL URI."; } else { int errorCode = 0; try { // Check the URI URI uri = UriAndUrlHelper.urlToUri(this.wsdlUriAsString); errorCode = 1; // Validate the WSDL WsdlUtils.INSTANCE.parse(this.wsdlUriAsString); errorCode = 2; // Display its content InputStream stream = uri.toURL().openStream(); ByteArrayOutputStream os = new ByteArrayOutputStream(); IoUtils.copyStream(stream, os); this.styledText.setText(os.toString()); } catch (Exception e) { if (errorCode == 0) errorMsg = "The WSDL location is not a valid URI."; else if (errorCode == 1) errorMsg = "The WSDL cannot be parsed and appears to be invalid."; else { errorMsg = "An unexpected error occurred during the validation in the JSR-181 wizard. Check the logs for more details."; PetalsJsr181Plugin.log(e, IStatus.ERROR); } } } } // Case: new Java class else if (StringUtils.isEmpty(this.classToGenerate)) { errorMsg = "You must specify the name of the class to generate."; } else { IStatus status = JavaConventions.validateJavaTypeName(this.classToGenerate, JavaCore.getOption(JavaCore.COMPILER_SOURCE), JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE)); if (status.getSeverity() != IStatus.ERROR) { if (this.classToGenerate.indexOf('.') < 0) { errorMsg = "The use of the default package is now allowed."; } else if (!status.isOK()) { errorMsg = status.getMessage() + "."; } } else { errorMsg = status.getMessage() + "."; } } updateStatus(errorMsg); return errorMsg == null; }
From source file:com.google.gdt.eclipse.appengine.rpc.util.JavaUtils.java
License:Open Source License
public static IStatus validateJavaTypeName(String name) { return JavaConventions.validateJavaTypeName(name, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3); }
From source file:com.google.gwt.eclipse.core.modules.ModuleUtils.java
License:Open Source License
/** * 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 *//*from w w w .ja va 2 s. com*/ 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; }
From source file:com.google.gwt.eclipse.core.util.Util.java
License:Open Source License
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(); }
From source file:com.gwtplatform.plugin.wizard.NewPresenterWizardPage.java
License:Apache License
protected IStatus placeChanged() { StatusInfo status = new StatusInfo(); if (isPlace.isEnabled() && isPlace.getSelection()) { // Token/* ww w .j av a 2 s. co m*/ if (tokenName.getText().isEmpty()) { status.setError("Enter the token's name (fully.qualified.NameTokens#name)"); return status; } String parent = ""; String token = ""; if (!tokenName.getText().contains("#")) { parent = tokenName.getText(); } else { String[] split = tokenName.getText().split("#"); parent = split[0]; if (split.length > 1) { token = split[1]; } } try { IType type = getJavaProject().findType(parent); if (type == null || !type.exists()) { status.setError(parent + " doesn't exist"); return status; } if (type.isBinary()) { status.setError(parent + " is a Binary class"); return status; } if (token.isEmpty()) { status.setError("You must enter the token name (fully.qualified.NameTokens#name)"); return status; } char start = token.toCharArray()[0]; if (start >= 48 && start <= 57) { status.setError("Token name must not start by a number"); return status; } for (char c : token.toCharArray()) { // [a-z][0-9]! if (!((c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c == 33)) { status.setError("Token name must contain only lower-case letters, numbers and !"); return status; } } IField field = type.getField(token); if (field.exists()) { status.setError("The token " + token + " already exists."); return status; } } catch (JavaModelException e) { status.setError("An unexpected error has happened. Close the wizard and retry."); return status; } // Annotation if (!annotation.getText().isEmpty()) { try { IType type = getJavaProject().findType(annotation.getText()); if (type == null || !type.exists()) { // New type, we will try to create the annotation IStatus nameStatus = JavaConventions.validateJavaTypeName(annotation.getText(), JavaCore.VERSION_1_6, JavaCore.VERSION_1_7); if (nameStatus.getCode() != IStatus.OK && nameStatus.getCode() != IStatus.WARNING) { status.setError(annotation.getText() + " is not a valid type name."); return status; } } else { // Existing type, just reuse it if (!type.isAnnotation()) { status.setError(annotation.getText() + " isn't an Annotation"); return status; } } } catch (JavaModelException e) { status.setError("An unexpected error has happened. Close the wizard and retry."); return status; } } // Gatekeeper if (!gatekeeper.getText().isEmpty()) { try { IType type = getJavaProject().findType(gatekeeper.getText()); if (type == null || !type.exists()) { status.setError(gatekeeper.getText() + " doesn't exist"); return status; } ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor()); IType[] interfaces = hierarchy.getAllInterfaces(); boolean isGateKeeper = false; for (IType inter : interfaces) { if (inter.getFullyQualifiedName('.') .equals("com.gwtplatform.mvp.client.proxy.Gatekeeper")) { isGateKeeper = true; break; } } if (!isGateKeeper) { status.setError(gatekeeper.getText() + " doesn't implement GateKeeper"); return status; } } catch (JavaModelException e) { status.setError("An unexpected error has happened. Close the wizard and retry."); return status; } } } return status; }
From source file:com.liferay.ide.hook.ui.wizard.NewEventActionClassDialog.java
License:Open Source License
protected void updateQualifiedClassname() { int packageNameStatus = JavaConventions.validatePackageName(packageText.getText(), CompilerOptions.VERSION_1_7, CompilerOptions.VERSION_1_7).getSeverity(); int classNameStatus = JavaConventions .validateJavaTypeName(classText.getText(), CompilerOptions.VERSION_1_7, CompilerOptions.VERSION_1_7) .getSeverity();// w w w .ja v a2 s. c o m ; if (!CoreUtil.isNullOrEmpty(packageText.getText())) { this.qualifiedClassname = packageText.getText() + "." + classText.getText(); //$NON-NLS-1$ } else { this.qualifiedClassname = classText.getText(); packageNameStatus = IStatus.WARNING; } if (classText.getText().indexOf('.') != -1) { classNameStatus = IStatus.ERROR; } boolean isPackageNameAndClassNameValid = ((packageNameStatus != IStatus.ERROR) && (classNameStatus != IStatus.ERROR)); this.getButton(IDialogConstants.OK_ID).setEnabled(isPackageNameAndClassNameValid); if (classNameStatus == IStatus.ERROR && packageNameStatus == IStatus.ERROR) { this.errorMessageLabel.setText("Invalid package and class name"); } else if (classNameStatus == IStatus.ERROR) { this.errorMessageLabel.setText("Invalid class name"); } else if (packageNameStatus == IStatus.ERROR) { this.errorMessageLabel.setText("Invalid package name"); } this.errorMessageLabel.setVisible(!isPackageNameAndClassNameValid); }
From source file:com.liferay.ide.portlet.core.operation.NewPortletClassDataModelProvider.java
License:Open Source License
@Override public IStatus validate(String propertyName) { if (PORTLET_NAME.equals(propertyName)) { // must have a valid portlet name String portletName = getStringProperty(PORTLET_NAME); if (portletName == null || portletName.length() == 0) { return PortletCore.createErrorStatus(Msgs.portletNameEmpty); }//from w ww . j a v a2 s . c o m PortletDescriptorHelper portletDescriptorHelper = new PortletDescriptorHelper(getTargetProject()); String[] portletNames = portletDescriptorHelper.getAllPortletNames(); for (String name : portletNames) { if (name.equals(portletName)) { return PortletCore.createErrorStatus(Msgs.portletNameExists); } } } else if (CREATE_RESOURCE_BUNDLE_FILE_PATH.equals(propertyName)) { if (!getBooleanProperty(CREATE_RESOURCE_BUNDLE_FILE)) { return Status.OK_STATUS; } boolean validPath = false; boolean validFileName = false; String val = getStringProperty(propertyName); if (CoreUtil.isNullOrEmpty(val)) { return PortletCore.createErrorStatus(Msgs.resourceBundleFilePathValid); } try { IPath path = new Path(val); validPath = path.isValidPath(val); if ("properties".equals(path.getFileExtension())) //$NON-NLS-1$ { validFileName = true; } } catch (Exception e) { // eat errors } if (!validPath) { return PortletCore.createErrorStatus(Msgs.resourceBundleFilePathValid); } if (validFileName) { return super.validate(propertyName); } else { return PortletCore.createWarningStatus(Msgs.resourceBundleFilePathEndWithProperties); } } else if (CREATE_JSPS_FOLDER.equals(propertyName)) { if (!getBooleanProperty(CREATE_JSPS)) { return Status.OK_STATUS; } String folderValue = getStringProperty(propertyName); if (CoreUtil.isNullOrEmpty(folderValue)) { return PortletCore.createErrorStatus(Msgs.jspFolderNotEmpty); } IProject targetProject = getTargetProject(); if ((!CoreUtil.isNullOrEmpty(folderValue)) && targetProject != null) { final IWebProject webproject = LiferayCore.create(IWebProject.class, targetProject); if (webproject != null) { IFolder defaultDocroot = webproject.getDefaultDocrootFolder(); IStatus validation = validateFolder(defaultDocroot, folderValue); if (validation != null && !validation.isOK()) { return validation; } // make sure path first segment isn't the same as the portlet name String path = new Path(folderValue).segment(0); if (!CoreUtil.isNullOrEmpty(path) && path.equals(getStringProperty(PORTLET_NAME))) { return PortletCore.createErrorStatus(Msgs.jspFolderNotMatchPortletName); } } } } else if (SOURCE_FOLDER.equals(propertyName) && this.fragment) { return Status.OK_STATUS; } else if (SUPERCLASS.equals(propertyName)) { String superclass = getStringProperty(propertyName); if (CoreUtil.isNullOrEmpty(superclass)) { return PortletCore.createErrorStatus(Msgs.specifyPortletSuperclass); } if (this.fragment) { return JavaConventions.validateJavaTypeName(superclass, JavaCore.VERSION_1_5, JavaCore.VERSION_1_5); } if (!isValidPortletClass(superclass)) { return PortletCore.createErrorStatus(Msgs.portletSuperclassValid); } } else if (CATEGORY.equals(propertyName)) { String category = getStringProperty(propertyName); if (category.matches("\\s*")) { return PortletCore.createErrorStatus(Msgs.categoryNameEmpty); } } else if (ENTRY_WEIGHT.equals(propertyName)) { if (!getBooleanProperty(ADD_TO_CONTROL_PANEL)) { return Status.OK_STATUS; } String entryweight = getStringProperty(propertyName); if (!CoreUtil.isNumeric(entryweight)) { return PortletCore.createErrorStatus(Msgs.specifyValidDouble); } return Status.OK_STATUS; } else if (ENTRY_CLASS_NAME.equals(propertyName)) { if (!getBooleanProperty(ADD_TO_CONTROL_PANEL) || !getBooleanProperty(CREATE_ENTRY_CLASS)) { return Status.OK_STATUS; } String entryclasswrapper = getStringProperty(propertyName); if (validateJavaClassName(entryclasswrapper).getSeverity() != IStatus.ERROR) { IStatus existsStatus = canCreateTypeInClasspath(entryclasswrapper); if (existsStatus.matches(IStatus.ERROR | IStatus.WARNING)) { return existsStatus; } } return validateJavaClassName(entryclasswrapper); } else if ((CLASS_NAME.equals(propertyName))) { if (getBooleanProperty(USE_DEFAULT_PORTLET_CLASS)) { return Status.OK_STATUS; } } return super.validate(propertyName); }
From source file:com.liferay.ide.portlet.vaadin.core.operation.NewVaadinPortletClassDataModelProvider.java
License:Open Source License
@Override public IStatus validate(String propertyName) { // also accept the case where the superclass/portlet class does not exist (yet), perform basic java validation if (SUPERCLASS.equals(propertyName)) { String superclass = getStringProperty(propertyName); if (CoreUtil.isNullOrEmpty(superclass)) { return VaadinCore.createErrorStatus(Msgs.specifyPortletSuperclass); }// w w w. ja v a2s . co m return JavaConventions.validateJavaTypeName(superclass, JavaCore.VERSION_1_5, JavaCore.VERSION_1_5); } if (VAADIN_PORTLET_CLASS.equals(propertyName)) { String vaadinPortletClass = getStringProperty(propertyName); if (CoreUtil.isNullOrEmpty(vaadinPortletClass)) { return VaadinCore.createErrorStatus(Msgs.specifyVaadinPortletClass); } return JavaConventions.validateJavaTypeName(vaadinPortletClass, JavaCore.VERSION_1_5, JavaCore.VERSION_1_5); } return super.validate(propertyName); }