X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/JavaConventions.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/JavaConventions.java index a8c48f2..e7ec0d5 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/JavaConventions.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/JavaConventions.java @@ -10,20 +10,21 @@ *******************************************************************************/ package net.sourceforge.phpdt.core; -import java.util.StringTokenizer; +//import java.util.StringTokenizer; -import net.sourceforge.phpdt.core.compiler.CharOperation; +//import net.sourceforge.phpdt.core.compiler.CharOperation; import net.sourceforge.phpdt.core.compiler.ITerminalSymbols; +import net.sourceforge.phpdt.core.compiler.ITerminalSymbols.TokenName; import net.sourceforge.phpdt.core.compiler.InvalidInputException; import net.sourceforge.phpdt.internal.compiler.parser.Scanner; -import net.sourceforge.phpdt.internal.core.ClasspathEntry; +//import net.sourceforge.phpdt.internal.core.ClasspathEntry; import net.sourceforge.phpdt.internal.core.JavaModelStatus; import net.sourceforge.phpdt.internal.core.util.Util; import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspace; +//import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; +//import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -36,7 +37,7 @@ import org.eclipse.core.runtime.Status; */ public final class JavaConventions { - private final static char DOT = '.'; + //private final static char DOT = '.'; private final static Scanner SCANNER = new Scanner(); @@ -59,25 +60,25 @@ public final class JavaConventions { * overlap, false otherwise * @deprecated Overlapping roots are allowed in 2.1 */ - public static boolean isOverlappingRoots(IPath rootPath1, IPath rootPath2) { - if (rootPath1 == null || rootPath2 == null) { - return false; - } - // String extension1 = rootPath1.getFileExtension(); - // String extension2 = rootPath2.getFileExtension(); - // if (extension1 != null && - // (extension1.equalsIgnoreCase(SuffixConstants.EXTENSION_JAR) || - // extension1.equalsIgnoreCase(SuffixConstants.EXTENSION_ZIP))) { - // return false; - // } - // if (extension2 != null && - // (extension2.equalsIgnoreCase(SuffixConstants.EXTENSION_JAR) || - // extension2.equalsIgnoreCase(SuffixConstants.EXTENSION_ZIP))) { - // return false; - // } - return rootPath1.isPrefixOf(rootPath2) - || rootPath2.isPrefixOf(rootPath1); - } +// public static boolean isOverlappingRoots(IPath rootPath1, IPath rootPath2) { +// if (rootPath1 == null || rootPath2 == null) { +// return false; +// } +// // String extension1 = rootPath1.getFileExtension(); +// // String extension2 = rootPath2.getFileExtension(); +// // if (extension1 != null && +// // (extension1.equalsIgnoreCase(SuffixConstants.EXTENSION_JAR) || +// // extension1.equalsIgnoreCase(SuffixConstants.EXTENSION_ZIP))) { +// // return false; +// // } +// // if (extension2 != null && +// // (extension2.equalsIgnoreCase(SuffixConstants.EXTENSION_JAR) || +// // extension2.equalsIgnoreCase(SuffixConstants.EXTENSION_ZIP))) { +// // return false; +// // } +// return rootPath1.isPrefixOf(rootPath2) +// || rootPath2.isPrefixOf(rootPath1); +// } /* * Returns the current identifier extracted by the scanner (without unicode @@ -94,16 +95,16 @@ public final class JavaConventions { } try { SCANNER.setSource(id.toCharArray()); - int token = SCANNER.getNextToken(); + TokenName token = SCANNER.getNextToken(); char[] currentIdentifier; try { currentIdentifier = SCANNER.getCurrentIdentifierSource(); } catch (ArrayIndexOutOfBoundsException e) { return null; } - int nextToken = SCANNER.getNextToken(); - if (token == ITerminalSymbols.TokenNameIdentifier - && nextToken == ITerminalSymbols.TokenNameEOF + TokenName nextToken = SCANNER.getNextToken(); + if (token == ITerminalSymbols.TokenName.IDENTIFIER + && nextToken == ITerminalSymbols.TokenName.EOF && SCANNER.startPosition == SCANNER.source.length) { // to // handle // case @@ -277,21 +278,21 @@ public final class JavaConventions { * name is valid as an import declaration, otherwise a status object * indicating what is wrong with the name */ - public static IStatus validateImportDeclaration(String name) { - if (name == null || name.length() == 0) { - return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util - .bind("convention.import.nullImport"), null); //$NON-NLS-1$ - } - if (name.charAt(name.length() - 1) == '*') { - if (name.charAt(name.length() - 2) == '.') { - return validatePackageName(name.substring(0, name.length() - 2)); - } else { - return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util - .bind("convention.import.unqualifiedImport"), null); //$NON-NLS-1$ - } - } - return validatePackageName(name); - } +// public static IStatus validateImportDeclaration(String name) { +// if (name == null || name.length() == 0) { +// return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util +// .bind("convention.import.nullImport"), null); //$NON-NLS-1$ +// } +// if (name.charAt(name.length() - 1) == '*') { +// if (name.charAt(name.length() - 2) == '.') { +// return validatePackageName(name.substring(0, name.length() - 2)); +// } else { +// return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util +// .bind("convention.import.unqualifiedImport"), null); //$NON-NLS-1$ +// } +// } +// return validatePackageName(name); +// } /** * Validate the given Java type name, either simple or qualified. For @@ -306,52 +307,52 @@ public final class JavaConventions { * discouraged, otherwise a status object indicating what is wrong * with the name */ - public static IStatus validateJavaTypeName(String name) { - if (name == null) { - return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util - .bind("convention.type.nullName"), null); //$NON-NLS-1$ - } - String trimmed = name.trim(); - if (!name.equals(trimmed)) { - return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util - .bind("convention.type.nameWithBlanks"), null); //$NON-NLS-1$ - } - int index = name.lastIndexOf('.'); - char[] scannedID; - if (index == -1) { - // simple name - scannedID = scannedIdentifier(name); - } else { - // qualified name - String pkg = name.substring(0, index).trim(); - IStatus status = validatePackageName(pkg); - if (!status.isOK()) { - return status; - } - String type = name.substring(index + 1).trim(); - scannedID = scannedIdentifier(type); - } - - if (scannedID != null) { - IStatus status = ResourcesPlugin.getWorkspace().validateName( - new String(scannedID), IResource.FILE); - if (!status.isOK()) { - return status; - } - if (CharOperation.contains('$', scannedID)) { - return new Status(IStatus.WARNING, JavaCore.PLUGIN_ID, -1, Util - .bind("convention.type.dollarName"), null); //$NON-NLS-1$ - } - if ((scannedID.length > 0 && Character.isLowerCase(scannedID[0]))) { - return new Status(IStatus.WARNING, JavaCore.PLUGIN_ID, -1, Util - .bind("convention.type.lowercaseName"), null); //$NON-NLS-1$ - } - return JavaModelStatus.VERIFIED_OK; - } else { - return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util.bind( - "convention.type.invalidName", name), null); //$NON-NLS-1$ - } - } +// public static IStatus validateJavaTypeName(String name) { +// if (name == null) { +// return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util +// .bind("convention.type.nullName"), null); //$NON-NLS-1$ +// } +// String trimmed = name.trim(); +// if (!name.equals(trimmed)) { +// return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util +// .bind("convention.type.nameWithBlanks"), null); //$NON-NLS-1$ +// } +// int index = name.lastIndexOf('.'); +// char[] scannedID; +// if (index == -1) { +// // simple name +// scannedID = scannedIdentifier(name); +// } else { +// // qualified name +// String pkg = name.substring(0, index).trim(); +// IStatus status = validatePackageName(pkg); +// if (!status.isOK()) { +// return status; +// } +// String type = name.substring(index + 1).trim(); +// scannedID = scannedIdentifier(type); +// } +// +// if (scannedID != null) { +// IStatus status = ResourcesPlugin.getWorkspace().validateName( +// new String(scannedID), IResource.FILE); +// if (!status.isOK()) { +// return status; +// } +// if (CharOperation.contains('$', scannedID)) { +// return new Status(IStatus.WARNING, JavaCore.PLUGIN_ID, -1, Util +// .bind("convention.type.dollarName"), null); //$NON-NLS-1$ +// } +// if ((scannedID.length > 0 && Character.isLowerCase(scannedID[0]))) { +// return new Status(IStatus.WARNING, JavaCore.PLUGIN_ID, -1, Util +// .bind("convention.type.lowercaseName"), null); //$NON-NLS-1$ +// } +// return JavaModelStatus.VERIFIED_OK; +// } else { +// return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util.bind( +// "convention.type.invalidName", name), null); //$NON-NLS-1$ +// } +// } /** * Validate the given method name. The special names "<init>" and @@ -366,10 +367,10 @@ public final class JavaConventions { * name is valid as a method name, otherwise a status object * indicating what is wrong with the name */ - public static IStatus validateMethodName(String name) { - - return validateIdentifier(name); - } +// public static IStatus validateMethodName(String name) { +// +// return validateIdentifier(name); +// } /** * Validate the given package name. @@ -388,67 +389,67 @@ public final class JavaConventions { * name is valid as a package name, otherwise a status object * indicating what is wrong with the name */ - public static IStatus validatePackageName(String name) { - - if (name == null) { - return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util - .bind("convention.package.nullName"), null); //$NON-NLS-1$ - } - int length; - if ((length = name.length()) == 0) { - return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util - .bind("convention.package.emptyName"), null); //$NON-NLS-1$ - } - if (name.charAt(0) == DOT || name.charAt(length - 1) == DOT) { - return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util - .bind("convention.package.dotName"), null); //$NON-NLS-1$ - } - if (CharOperation.isWhitespace(name.charAt(0)) - || CharOperation.isWhitespace(name.charAt(name.length() - 1))) { - return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util - .bind("convention.package.nameWithBlanks"), null); //$NON-NLS-1$ - } - int dot = 0; - while (dot != -1 && dot < length - 1) { - if ((dot = name.indexOf(DOT, dot + 1)) != -1 && dot < length - 1 - && name.charAt(dot + 1) == DOT) { - return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util - .bind("convention.package.consecutiveDotsName"), null); //$NON-NLS-1$ - } - } - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - StringTokenizer st = new StringTokenizer(name, new String( - new char[] { DOT })); - boolean firstToken = true; - IStatus warningStatus = null; - while (st.hasMoreTokens()) { - String typeName = st.nextToken(); - typeName = typeName.trim(); // grammar allows spaces - char[] scannedID = scannedIdentifier(typeName); - if (scannedID == null) { - return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util - .bind("convention.illegalIdentifier", typeName), null); //$NON-NLS-1$ - } - IStatus status = workspace.validateName(new String(scannedID), - IResource.FOLDER); - if (!status.isOK()) { - return status; - } - if (firstToken && scannedID.length > 0 - && Character.isUpperCase(scannedID[0])) { - if (warningStatus == null) { - warningStatus = new Status(IStatus.WARNING, - JavaCore.PLUGIN_ID, -1, - Util.bind("convention.package.uppercaseName"), null); //$NON-NLS-1$ - } - } - firstToken = false; - } - if (warningStatus != null) { - return warningStatus; - } - return JavaModelStatus.VERIFIED_OK; - } +// public static IStatus validatePackageName(String name) { +// +// if (name == null) { +// return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util +// .bind("convention.package.nullName"), null); //$NON-NLS-1$ +// } +// int length; +// if ((length = name.length()) == 0) { +// return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util +// .bind("convention.package.emptyName"), null); //$NON-NLS-1$ +// } +// if (name.charAt(0) == DOT || name.charAt(length - 1) == DOT) { +// return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util +// .bind("convention.package.dotName"), null); //$NON-NLS-1$ +// } +// if (CharOperation.isWhitespace(name.charAt(0)) +// || CharOperation.isWhitespace(name.charAt(name.length() - 1))) { +// return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util +// .bind("convention.package.nameWithBlanks"), null); //$NON-NLS-1$ +// } +// int dot = 0; +// while (dot != -1 && dot < length - 1) { +// if ((dot = name.indexOf(DOT, dot + 1)) != -1 && dot < length - 1 +// && name.charAt(dot + 1) == DOT) { +// return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util +// .bind("convention.package.consecutiveDotsName"), null); //$NON-NLS-1$ +// } +// } +// IWorkspace workspace = ResourcesPlugin.getWorkspace(); +// StringTokenizer st = new StringTokenizer(name, new String( +// new char[] { DOT })); +// boolean firstToken = true; +// IStatus warningStatus = null; +// while (st.hasMoreTokens()) { +// String typeName = st.nextToken(); +// typeName = typeName.trim(); // grammar allows spaces +// char[] scannedID = scannedIdentifier(typeName); +// if (scannedID == null) { +// return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Util +// .bind("convention.illegalIdentifier", typeName), null); //$NON-NLS-1$ +// } +// IStatus status = workspace.validateName(new String(scannedID), +// IResource.FOLDER); +// if (!status.isOK()) { +// return status; +// } +// if (firstToken && scannedID.length > 0 +// && Character.isUpperCase(scannedID[0])) { +// if (warningStatus == null) { +// warningStatus = new Status(IStatus.WARNING, +// JavaCore.PLUGIN_ID, -1, +// Util.bind("convention.package.uppercaseName"), null); //$NON-NLS-1$ +// } +// } +// firstToken = false; +// } +// if (warningStatus != null) { +// return warningStatus; +// } +// return JavaModelStatus.VERIFIED_OK; +// } /** * Validate a given classpath and output location for a project, using the @@ -500,12 +501,12 @@ public final class JavaConventions { * location * @since 2.0 */ - public static IJavaModelStatus validateClasspath(IJavaProject javaProject, - IClasspathEntry[] rawClasspath, IPath projectOutputLocation) { - - return ClasspathEntry.validateClasspath(javaProject, rawClasspath, - projectOutputLocation); - } +// public static IJavaModelStatus validateClasspath(IJavaProject javaProject, +// IClasspathEntry[] rawClasspath, IPath projectOutputLocation) { +// +// return ClasspathEntry.validateClasspath(javaProject, rawClasspath, +// projectOutputLocation); +// } /** * Returns a Java model status describing the problem related to this @@ -524,9 +525,9 @@ public final class JavaConventions { * IStatus.OK if the entry is fine * @since 2.0 */ - public static IJavaModelStatus validateClasspathEntry(IJavaProject project, - IClasspathEntry entry, boolean checkSourceAttachment) { - return ClasspathEntry.validateClasspathEntry(project, entry, - checkSourceAttachment, true/* recurse in container */); - } +// public static IJavaModelStatus validateClasspathEntry(IJavaProject project, +// IClasspathEntry entry, boolean checkSourceAttachment) { +// return ClasspathEntry.validateClasspathEntry(project, entry, +// checkSourceAttachment, true/* recurse in container */); +// } }