List of usage examples for org.eclipse.jdt.core JavaConventions validateCompilationUnitName
public static IStatus validateCompilationUnitName(String name, String sourceLevel, String complianceLevel)
From source file:org.eclipse.jdt.internal.core.CompilationUnit.java
License:Open Source License
protected IStatus validateCompilationUnit(IResource resource) { IPackageFragmentRoot root = getPackageFragmentRoot(); // root never null as validation is not done for working copies try {//www . ja v a 2 s.c o m if (root.getKind() != IPackageFragmentRoot.K_SOURCE) return new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, root); } catch (JavaModelException e) { return e.getJavaModelStatus(); } if (resource != null) { char[][] inclusionPatterns = ((PackageFragmentRoot) root).fullInclusionPatternChars(); char[][] exclusionPatterns = ((PackageFragmentRoot) root).fullExclusionPatternChars(); if (Util.isExcluded(resource, inclusionPatterns, exclusionPatterns)) return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_NOT_ON_CLASSPATH, this); if (!resource.isAccessible()) return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this); } IJavaProject project = getJavaProject(); return JavaConventions.validateCompilationUnitName(getElementName(), project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)); }
From source file:org.gw4e.eclipse.facade.JDTManager.java
License:Open Source License
public static boolean validateClassName(String name) { String temp = name + ".java"; IStatus status = JavaConventions.validateCompilationUnitName(temp, JavaCore.VERSION_1_8, JavaCore.VERSION_1_8);// ww w.java 2 s.c o m boolean b = (status.getCode() == IStatus.OK); return b; }
From source file:org.objectstyle.wolips.refactoring.RenameWOComponentProcessor.java
License:Open Source License
@Override public RefactoringStatus validateNewElementName(String newName) { //TODO Return custom error message IProject project = _resource.getProject(); IJavaProject jProject = JavaCore.create(project); String sourceLevel = jProject.getOption(JavaCore.COMPILER_SOURCE, true); String compliance = jProject.getOption(JavaCore.COMPILER_COMPLIANCE, true); IStatus status = JavaConventions.validateCompilationUnitName(newName + ".java", sourceLevel, compliance); if (!status.isOK()) return RefactoringStatus.create(status); return super.validateNewElementName(newName); }
From source file:org.objectstyle.wolips.wizards.WOComponentCreationPage.java
License:Open Source License
@Override protected boolean validatePage() { IStatus status = JavaConventions.validateCompilationUnitName(this.getFileName() + ".java", CompilerOptions.VERSION_1_3, CompilerOptions.VERSION_1_3); if (!status.isOK()) { setErrorMessage(status.getMessage()); return false; }// www. j a v a2s . com IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(getContainerFullPath().segment(0)); // This may need to change depending on how we want to deal with localized components in future. LocatePlugin locatePlugin = LocatePlugin.getDefault(); try { LocalizedComponentsLocateResult result = locatePlugin.getLocalizedComponentsLocateResult(project, getFileName()); if (result.getResources().length > 0) { setErrorMessage("A component by that name already exists"); return false; } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } // Check that we aren't going to create a wocomponent inside another wocomponent IPath path = getContainerFullPath(); if (path.lastSegment().endsWith(".wo")) { setErrorMessage("Cannot create a component within another component"); return false; } return super.validatePage(); }