X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/util/JavaModelUtil.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/util/JavaModelUtil.java index 6359918..0e9eab3 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/util/JavaModelUtil.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/util/JavaModelUtil.java @@ -12,25 +12,25 @@ package net.sourceforge.phpdt.internal.corext.util; import java.util.StringTokenizer; -import net.sourceforge.phpdt.core.Flags; +//import net.sourceforge.phpdt.core.Flags; import net.sourceforge.phpdt.core.ICompilationUnit; import net.sourceforge.phpdt.core.IField; import net.sourceforge.phpdt.core.IJavaElement; import net.sourceforge.phpdt.core.IMember; import net.sourceforge.phpdt.core.IMethod; -import net.sourceforge.phpdt.core.IPackageFragment; +//import net.sourceforge.phpdt.core.IPackageFragment; import net.sourceforge.phpdt.core.IPackageFragmentRoot; import net.sourceforge.phpdt.core.IType; import net.sourceforge.phpdt.core.JavaModelException; import net.sourceforge.phpdt.core.Signature; -import net.sourceforge.phpdt.core.compiler.CharOperation; +//import net.sourceforge.phpdt.core.compiler.CharOperation; //import net.sourceforge.phpdt.ui.JavaUI; import net.sourceforge.phpeclipse.PHPeclipsePlugin; //import net.sourceforge.phpeclipse.phpeditor.EditorUtility; import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; +//import org.eclipse.core.runtime.CoreException; +//import org.eclipse.core.runtime.IPath; /** * Utility methods for the Java Model. @@ -173,17 +173,17 @@ public class JavaModelUtil { * (separated by dots)) * @return the type found, or null if not existing */ - public static IType findTypeInCompilationUnit(ICompilationUnit cu, - String typeQualifiedName) throws JavaModelException { - IType[] types = cu.getAllTypes(); - for (int i = 0; i < types.length; i++) { - String currName = getTypeQualifiedName(types[i]); - if (typeQualifiedName.equals(currName)) { - return types[i]; - } - } - return null; - } +// public static IType findTypeInCompilationUnit(ICompilationUnit cu, +// String typeQualifiedName) throws JavaModelException { +// IType[] types = cu.getAllTypes(); +// for (int i = 0; i < types.length; i++) { +// String currName = getTypeQualifiedName(types[i]); +// if (typeQualifiedName.equals(currName)) { +// return types[i]; +// } +// } +// return null; +// } /** * Finds a a member in a compilation unit. Typical usage is to find the @@ -195,14 +195,14 @@ public class JavaModelUtil { * the member (eg. from the original) * @return the member found, or null if not existing */ - public static IMember findMemberInCompilationUnit(ICompilationUnit cu, - IMember member) throws JavaModelException { - IJavaElement[] elements = cu.findElements(member); - if (elements != null && elements.length > 0) { - return (IMember) elements[0]; - } - return null; - } +// public static IMember findMemberInCompilationUnit(ICompilationUnit cu, +// IMember member) throws JavaModelException { +// IJavaElement[] elements = cu.findElements(member); +// if (elements != null && elements.length > 0) { +// return (IMember) elements[0]; +// } +// return null; +// } /** * Returns the element of the given compilation unit which is "equal" to the @@ -249,58 +249,58 @@ public class JavaModelUtil { * uses '$' as separators. As '$' is also a valid character in an id this is * ambiguous. JavaCore PR: 1GCFUNT */ - public static String getFullyQualifiedName(IType type) { - return type.getFullyQualifiedName('.'); - } +// public static String getFullyQualifiedName(IType type) { +// return type.getFullyQualifiedName('.'); +// } /** * Returns the fully qualified name of a type's container. (package name or * enclosing type name) */ - public static String getTypeContainerName(IType type) { - IType outerType = type.getDeclaringType(); - if (outerType != null) { - return outerType.getFullyQualifiedName('.'); - } else { - return type.getPackageFragment().getElementName(); - } - } +// public static String getTypeContainerName(IType type) { +// IType outerType = type.getDeclaringType(); +// if (outerType != null) { +// return outerType.getFullyQualifiedName('.'); +// } else { +// return type.getPackageFragment().getElementName(); +// } +// } /** * Concatenates two names. Uses a dot for separation. Both strings can be * empty or null. */ - public static String concatenateName(String name1, String name2) { - StringBuffer buf = new StringBuffer(); - if (name1 != null && name1.length() > 0) { - buf.append(name1); - } - if (name2 != null && name2.length() > 0) { - if (buf.length() > 0) { - buf.append('.'); - } - buf.append(name2); - } - return buf.toString(); - } +// public static String concatenateName(String name1, String name2) { +// StringBuffer buf = new StringBuffer(); +// if (name1 != null && name1.length() > 0) { +// buf.append(name1); +// } +// if (name2 != null && name2.length() > 0) { +// if (buf.length() > 0) { +// buf.append('.'); +// } +// buf.append(name2); +// } +// return buf.toString(); +// } /** * Concatenates two names. Uses a dot for separation. Both strings can be * empty or null. */ - public static String concatenateName(char[] name1, char[] name2) { - StringBuffer buf = new StringBuffer(); - if (name1 != null && name1.length > 0) { - buf.append(name1); - } - if (name2 != null && name2.length > 0) { - if (buf.length() > 0) { - buf.append('.'); - } - buf.append(name2); - } - return buf.toString(); - } +// public static String concatenateName(char[] name1, char[] name2) { +// StringBuffer buf = new StringBuffer(); +// if (name1 != null && name1.length > 0) { +// buf.append(name1); +// } +// if (name2 != null && name2.length > 0) { +// if (buf.length() > 0) { +// buf.append('.'); +// } +// buf.append(name2); +// } +// return buf.toString(); +// } /** * Evaluates if a member (possible from another package) is visible from @@ -311,20 +311,20 @@ public class JavaModelUtil { * @param pack * The package in focus */ - public static boolean isVisible(IMember member, IPackageFragment pack) - throws JavaModelException { - int otherflags = member.getFlags(); - - if (Flags.isPublic(otherflags)) { - return true; - } else if (Flags.isPrivate(otherflags)) { - return false; - } - - IPackageFragment otherpack = (IPackageFragment) findParentOfKind( - member, IJavaElement.PACKAGE_FRAGMENT); - return (pack != null && pack.equals(otherpack)); - } +// public static boolean isVisible(IMember member, IPackageFragment pack) +// throws JavaModelException { +// int otherflags = member.getFlags(); +// +// if (Flags.isPublic(otherflags)) { +// return true; +// } else if (Flags.isPrivate(otherflags)) { +// return false; +// } +// +// IPackageFragment otherpack = (IPackageFragment) findParentOfKind( +// member, IJavaElement.PACKAGE_FRAGMENT); +// return (pack != null && pack.equals(otherpack)); +// } /** * Returns the package fragment root of IJavaElement. If the @@ -343,12 +343,12 @@ public class JavaModelUtil { * * @deprecated Use element.getParent().getAncestor(kind); */ - public static IJavaElement findParentOfKind(IJavaElement element, int kind) { - if (element != null && element.getParent() != null) { - return element.getParent().getAncestor(kind); - } - return null; - } +// public static IJavaElement findParentOfKind(IJavaElement element, int kind) { +// if (element != null && element.getParent() != null) { +// return element.getParent().getAncestor(kind); +// } +// return null; +// } /** * Finds a method in a type. This searches for a method with the same name @@ -365,10 +365,10 @@ public class JavaModelUtil { * If the method is a constructor * @return The first found method or null, if nothing found */ - public static IMethod findMethod(String name, String[] paramTypes, - boolean isConstructor, IType type) throws JavaModelException { - return findMethod(name, paramTypes, isConstructor, type.getMethods()); - } +// public static IMethod findMethod(String name, String[] paramTypes, +// boolean isConstructor, IType type) throws JavaModelException { +// return findMethod(name, paramTypes, isConstructor, type.getMethods()); +// } /** * Finds a method by name. This searches for a method with a name and @@ -387,16 +387,16 @@ public class JavaModelUtil { * The methods to search in * @return The found method or null, if nothing found */ - public static IMethod findMethod(String name, String[] paramTypes, - boolean isConstructor, IMethod[] methods) throws JavaModelException { - for (int i = methods.length - 1; i >= 0; i--) { - if (isSameMethodSignature(name, paramTypes, isConstructor, - methods[i])) { - return methods[i]; - } - } - return null; - } +// public static IMethod findMethod(String name, String[] paramTypes, +// boolean isConstructor, IMethod[] methods) throws JavaModelException { +// for (int i = methods.length - 1; i >= 0; i--) { +// if (isSameMethodSignature(name, paramTypes, isConstructor, +// methods[i])) { +// return methods[i]; +// } +// } +// return null; +// } /** * Finds a method declararion in a type's hierarchy. The search is top down, @@ -487,41 +487,41 @@ public class JavaModelUtil { * @return Returns true if the method has the given name and * parameter types and constructor state. */ - public static boolean isSameMethodSignature(String name, - String[] paramTypes, boolean isConstructor, IMethod curr) - throws JavaModelException { - if (isConstructor || name.equals(curr.getElementName())) { - if (isConstructor == curr.isConstructor()) { - String[] currParamTypes = curr.getParameterTypes(); - if (paramTypes.length == currParamTypes.length) { - for (int i = 0; i < paramTypes.length; i++) { - String t1 = Signature.getSimpleName(Signature - .toString(paramTypes[i])); - String t2 = Signature.getSimpleName(Signature - .toString(currParamTypes[i])); - if (!t1.equals(t2)) { - return false; - } - } - return true; - } - } - } - return false; - } +// public static boolean isSameMethodSignature(String name, +// String[] paramTypes, boolean isConstructor, IMethod curr) +// throws JavaModelException { +// if (isConstructor || name.equals(curr.getElementName())) { +// if (isConstructor == curr.isConstructor()) { +// String[] currParamTypes = curr.getParameterTypes(); +// if (paramTypes.length == currParamTypes.length) { +// for (int i = 0; i < paramTypes.length; i++) { +// String t1 = Signature.getSimpleName(Signature +// .toString(paramTypes[i])); +// String t2 = Signature.getSimpleName(Signature +// .toString(currParamTypes[i])); +// if (!t1.equals(t2)) { +// return false; +// } +// } +// return true; +// } +// } +// } +// return false; +// } /** * Checks whether the given type has a valid main method or not. */ - public static boolean hasMainMethod(IType type) throws JavaModelException { - IMethod[] methods = type.getMethods(); - for (int i = 0; i < methods.length; i++) { - if (methods[i].isMainMethod()) { - return true; - } - } - return false; - } +// public static boolean hasMainMethod(IType type) throws JavaModelException { +// IMethod[] methods = type.getMethods(); +// for (int i = 0; i < methods.length; i++) { +// if (methods[i].isMainMethod()) { +// return true; +// } +// } +// return false; +// } /** * Checks if the field is boolean. @@ -671,19 +671,19 @@ public class JavaModelUtil { * a working copy or the member does not exist in the working copy the input * is returned. */ - public static IMember toWorkingCopy(IMember member) { - ICompilationUnit cu = member.getCompilationUnit(); - if (cu != null && !cu.isWorkingCopy()) { - ICompilationUnit workingCopy = /*EditorUtility.*/getWorkingCopy(cu); - if (workingCopy != null) { - IJavaElement[] members = workingCopy.findElements(member); - if (members != null && members.length > 0) { - return (IMember) members[0]; - } - } - } - return member; - } +// public static IMember toWorkingCopy(IMember member) { +// ICompilationUnit cu = member.getCompilationUnit(); +// if (cu != null && !cu.isWorkingCopy()) { +// ICompilationUnit workingCopy = /*EditorUtility.*/getWorkingCopy(cu); +// if (workingCopy != null) { +// IJavaElement[] members = workingCopy.findElements(member); +// if (members != null && members.length > 0) { +// return (IMember) members[0]; +// } +// } +// } +// return member; +// } /** * Returns the working copy CU of the given CU. If the CU is already a @@ -707,24 +707,24 @@ public class JavaModelUtil { * So we should not log not present exceptions when they happen in working * copies. */ - public static boolean filterNotPresentException(CoreException exception) { - if (!(exception instanceof JavaModelException)) - return true; - JavaModelException je = (JavaModelException) exception; - if (!je.isDoesNotExist()) - return true; - IJavaElement[] elements = je.getJavaModelStatus().getElements(); - for (int i = 0; i < elements.length; i++) { - IJavaElement element = elements[i]; - ICompilationUnit unit = (ICompilationUnit) element - .getAncestor(IJavaElement.COMPILATION_UNIT); - if (unit == null) - return true; - if (!unit.isWorkingCopy()) - return true; - } - return false; - } +// public static boolean filterNotPresentException(CoreException exception) { +// if (!(exception instanceof JavaModelException)) +// return true; +// JavaModelException je = (JavaModelException) exception; +// if (!je.isDoesNotExist()) +// return true; +// IJavaElement[] elements = je.getJavaModelStatus().getElements(); +// for (int i = 0; i < elements.length; i++) { +// IJavaElement element = elements[i]; +// ICompilationUnit unit = (ICompilationUnit) element +// .getAncestor(IJavaElement.COMPILATION_UNIT); +// if (unit == null) +// return true; +// if (!unit.isWorkingCopy()) +// return true; +// } +// return false; +// } // public static IType[] getAllSuperTypes(IType type, IProgressMonitor pm) // throws JavaModelException { @@ -752,17 +752,17 @@ public class JavaModelUtil { // } // } - public static boolean isExcludedPath(IPath resourcePath, - IPath[] exclusionPatterns) { - char[] path = resourcePath.toString().toCharArray(); - for (int i = 0, length = exclusionPatterns.length; i < length; i++) { - char[] pattern = exclusionPatterns[i].toString().toCharArray(); - if (CharOperation.pathMatch(pattern, path, true, '/')) { - return true; - } - } - return false; - } +// public static boolean isExcludedPath(IPath resourcePath, +// IPath[] exclusionPatterns) { +// char[] path = resourcePath.toString().toCharArray(); +// for (int i = 0, length = exclusionPatterns.length; i < length; i++) { +// char[] pattern = exclusionPatterns[i].toString().toCharArray(); +// if (CharOperation.pathMatch(pattern, path, true, '/')) { +// return true; +// } +// } +// return false; +// } /* * Returns whether the given resource path matches one of the exclusion @@ -770,16 +770,16 @@ public class JavaModelUtil { * * @see IClasspathEntry#getExclusionPatterns */ - public final static boolean isExcluded(IPath resourcePath, - char[][] exclusionPatterns) { - if (exclusionPatterns == null) - return false; - char[] path = resourcePath.toString().toCharArray(); - for (int i = 0, length = exclusionPatterns.length; i < length; i++) - if (CharOperation.pathMatch(exclusionPatterns[i], path, true, '/')) - return true; - return false; - } +// public final static boolean isExcluded(IPath resourcePath, +// char[][] exclusionPatterns) { +// if (exclusionPatterns == null) +// return false; +// char[] path = resourcePath.toString().toCharArray(); +// for (int i = 0, length = exclusionPatterns.length; i < length; i++) +// if (CharOperation.pathMatch(exclusionPatterns[i], path, true, '/')) +// return true; +// return false; +// } private static final String ARGUMENTS_DELIMITER = "#"; //$NON-NLS-1$ @@ -852,16 +852,16 @@ public class JavaModelUtil { * @return the corresponding member in the shared working copy or * null if not found */ - public static IMember getWorkingCopy(IMember member) - throws JavaModelException { - ICompilationUnit cu = member.getCompilationUnit(); - if (cu != null) { - ICompilationUnit workingCopy = getWorkingCopy(cu); - if (workingCopy != null) { - return JavaModelUtil.findMemberInCompilationUnit(workingCopy, - member); - } - } - return null; - } +// public static IMember getWorkingCopy(IMember member) +// throws JavaModelException { +// ICompilationUnit cu = member.getCompilationUnit(); +// if (cu != null) { +// ICompilationUnit workingCopy = getWorkingCopy(cu); +// if (workingCopy != null) { +// return JavaModelUtil.findMemberInCompilationUnit(workingCopy, +// member); +// } +// } +// return null; +// } }