11/*******************************************************************************
2- * Copyright (c) 2000, 2005 IBM Corporation and others.
2+ * Copyright (c) 2000, 2006 IBM Corporation and others.
33 * All rights reserved. This program and the accompanying materials
44 * are made available under the terms of the Eclipse Public License v1.0
55 * which accompanies this distribution, and is available at
3030import org .eclipse .jdt .core .dom .AbstractTypeDeclaration ;
3131import org .eclipse .jdt .core .dom .AnonymousClassDeclaration ;
3232import org .eclipse .jdt .core .dom .Assignment ;
33+ import org .eclipse .jdt .core .dom .EnumDeclaration ;
3334import org .eclipse .jdt .core .dom .Expression ;
3435import org .eclipse .jdt .core .dom .FieldAccess ;
3536import org .eclipse .jdt .core .dom .IBinding ;
@@ -147,10 +148,10 @@ public static int hashCode(IBinding binding){
147148 return key .hashCode ();
148149 }
149150
150- /*
151+ /**
151152 * Note: this method is for debugging and testing purposes only.
152- * There are tests whose precomputed test results rely on the returned String's format.
153- * @see org.eclipse.jdt.internal.ui.viewsupport.BindingLabels
153+ * There are tests whose pre-computed test results rely on the returned String's format.
154+ * @see org.eclipse.jdt.internal.ui.viewsupport.BindingLabelProvider
154155 */
155156 public static String asString (IBinding binding ) {
156157 if (binding instanceof IMethodBinding )
@@ -221,16 +222,37 @@ public static String getTypeQualifiedName(ITypeBinding type) {
221222 * @return the fully qualified name
222223 */
223224 public static String getFullyQualifiedName (ITypeBinding type ) {
224-
225- // TW: replace by call to type.getJavaElement().getFullyQualifiedName (see 78087)
226-
227225 String name = type .getQualifiedName ();
228226 final int index = name .indexOf ('<' );
229227 if (index > 0 )
230228 name = name .substring (0 , index );
231229 return name ;
232230 }
233231
232+ // public static String getImportName(IBinding binding) {
233+ // ITypeBinding declaring= null;
234+ // switch (binding.getKind()) {
235+ // case IBinding.TYPE:
236+ // return getRawQualifiedName((ITypeBinding) binding);
237+ // case IBinding.PACKAGE:
238+ // return binding.getName() + ".*"; //$NON-NLS-1$
239+ // case IBinding.METHOD:
240+ // declaring= ((IMethodBinding) binding).getDeclaringClass();
241+ // break;
242+ // case IBinding.VARIABLE:
243+ // declaring= ((IVariableBinding) binding).getDeclaringClass();
244+ // if (declaring == null) {
245+ // return binding.getName(); // array.length
246+ // }
247+ //
248+ // break;
249+ // default:
250+ // return binding.getName();
251+ // }
252+ // return JavaModelUtil.concatenateName(getRawQualifiedName(declaring), binding.getName());
253+ // }
254+
255+
234256 private static void createName (ITypeBinding type , boolean includePackage , List list ) {
235257 ITypeBinding baseType = type ;
236258 if (type .isArray ()) {
@@ -525,7 +547,7 @@ public static IMethodBinding findMethodInHierarchy(ITypeBinding typeObject, ITyp
525547 * Returns <code>null</code> if no such method exists. If the method is defined in more than one super type only the first match is
526548 * returned. First the super class is examined and than the implemented interfaces.
527549 * @param type The type to search the method in
528- * @param binding The method that overrrides
550+ * @param binding The method that overrides
529551 * @return the method binding overridden the method
530552 */
531553 public static IMethodBinding findOverriddenMethodInHierarchy (ITypeBinding type , IMethodBinding binding ) {
@@ -780,25 +802,25 @@ public static boolean isEqualMethod(IMethodBinding method, String methodName, IT
780802 }
781803
782804 /**
783- * @param m1 overriding method
784- * @param m2 overridden method
805+ * @param overriding overriding method (m1)
806+ * @param overridden overridden method (m2)
785807 * @return <code>true</code> iff the method <code>m1</code> is a subsignature of the method <code>m2</code>.
786808 * This is one of the requirements for m1 to override m2.
787809 * Accessibility and return types are not taken into account.
788810 * Note that subsignature is <em>not</em> symmetric!
789811 */
790- public static boolean isSubsignature (IMethodBinding m1 , IMethodBinding m2 ) {
812+ public static boolean isSubsignature (IMethodBinding overriding , IMethodBinding overridden ) {
791813 //TODO: use IMethodBinding#isSubsignature(..) once it is tested and fixed (only erasure of m1's parameter types, considering type variable counts, doing type variable substitution
792- if (! m1 .getName ().equals (m2 .getName ()))
814+ if (!overriding .getName ().equals (overridden .getName ()))
793815 return false ;
794816
795- ITypeBinding [] m1Params = m1 .getParameterTypes ();
796- ITypeBinding [] m2Params = m2 .getParameterTypes ();
817+ ITypeBinding [] m1Params = overriding .getParameterTypes ();
818+ ITypeBinding [] m2Params = overridden .getParameterTypes ();
797819 if (m1Params .length != m2Params .length )
798820 return false ;
799821
800- ITypeBinding [] m1TypeParams = m1 .getTypeParameters ();
801- ITypeBinding [] m2TypeParams = m2 .getTypeParameters ();
822+ ITypeBinding [] m1TypeParams = overriding .getTypeParameters ();
823+ ITypeBinding [] m2TypeParams = overridden .getTypeParameters ();
802824 if (m1TypeParams .length != m2TypeParams .length
803825 && m1TypeParams .length != 0 ) //non-generic m1 can override a generic m2
804826 return false ;
@@ -976,36 +998,52 @@ public static IVariableBinding getAssignedVariable(Assignment assignment) {
976998 /**
977999 * Returns <code>true</code> if the given type is a super type of a candidate.
9781000 * <code>true</code> is returned if the two type bindings are identical (TODO)
979- * @param type the type to inspect
980- * @param candidate the candidates
981- * @return <code>true</code> is a super type of one of the candidates; otherwise
982- * <code>false </code>
1001+ * @param possibleSuperType the type to inspect
1002+ * @param type the type whose super types are looked at
1003+ * @return <code>true</code> iff <code>possibleSuperType</code> is
1004+ * a super type of <code>type </code> or is equal to it
9831005 */
984- public static boolean isSuperType (ITypeBinding type , ITypeBinding candidate ) {
985- if (candidate .isArray () || candidate .isPrimitive ()) {
1006+ public static boolean isSuperType (ITypeBinding possibleSuperType , ITypeBinding type ) {
1007+ if (type .isArray () || type .isPrimitive ()) {
9861008 return false ;
9871009 }
988- if (Bindings .equals (candidate , type )) {
1010+ if (Bindings .equals (type , possibleSuperType )) {
9891011 return true ;
9901012 }
991- ITypeBinding superClass = candidate .getSuperclass ();
1013+ ITypeBinding superClass = type .getSuperclass ();
9921014 if (superClass != null ) {
993- if (isSuperType (type , superClass )) {
1015+ if (isSuperType (possibleSuperType , superClass )) {
9941016 return true ;
9951017 }
9961018 }
9971019
998- if (type .isInterface ()) {
999- ITypeBinding [] superInterfaces = candidate .getInterfaces ();
1020+ if (possibleSuperType .isInterface ()) {
1021+ ITypeBinding [] superInterfaces = type .getInterfaces ();
10001022 for (int i = 0 ; i < superInterfaces .length ; i ++) {
1001- if (isSuperType (type , superInterfaces [i ])) {
1023+ if (isSuperType (possibleSuperType , superInterfaces [i ])) {
10021024 return true ;
10031025 }
10041026 }
10051027 }
10061028 return false ;
10071029 }
10081030
1031+ /**
1032+ * Finds the compilation unit where the type of the given <code>ITypeBinding</code> is defined,
1033+ * using the class path defined by the given Java project. Returns <code>null</code>
1034+ * if no compilation unit is found (e.g. type binding is from a binary type)
1035+ * @param typeBinding the type binding to search for
1036+ * @param project the project used as a scope
1037+ * @return the compilation unit containing the type
1038+ * @throws JavaModelException if an errors occurs in the Java model
1039+ */
1040+ // public static ICompilationUnit findCompilationUnit(ITypeBinding typeBinding, IJavaProject project) throws JavaModelException {
1041+ // IJavaElement type= typeBinding.getJavaElement();
1042+ // if (type instanceof IType)
1043+ // return ((IType) type).getCompilationUnit();
1044+ // else
1045+ // return null;
1046+ // }
10091047
10101048
10111049 /**
@@ -1015,6 +1053,7 @@ public static boolean isSuperType(ITypeBinding type, ITypeBinding candidate) {
10151053 * @param type the type to look in
10161054 * @return the corresponding IMethod or <code>null</code>
10171055 * @throws JavaModelException if an error occurs in the Java model
1056+ * @deprecated Use {@link #findMethodInHierarchy(ITypeBinding, String, String[])} or {@link JavaModelUtil}
10181057 */
10191058 public static IMethod findMethod (IMethodBinding method , IType type ) throws JavaModelException {
10201059 method = method .getMethodDeclaration ();
@@ -1056,7 +1095,7 @@ private static boolean sameParameter(ITypeBinding type, String candidate, IType
10561095 type = type .getElementType ();
10571096 candidate = Signature .getElementType (candidate );
10581097
1059- if (isPrimitiveType ( candidate ) != type .isPrimitive ()) {
1098+ if (( Signature . getTypeSignatureKind ( candidate ) == Signature . BASE_TYPE_SIGNATURE ) != type .isPrimitive ()) {
10601099 return false ;
10611100 }
10621101
@@ -1067,7 +1106,7 @@ private static boolean sameParameter(ITypeBinding type, String candidate, IType
10671106 candidate = Signature .getTypeErasure (candidate );
10681107 type = type .getErasure ();
10691108
1070- if (isResolvedType ( candidate )) {
1109+ if (candidate . charAt ( Signature . getArrayCount ( candidate )) == Signature . C_RESOLVED ) {
10711110 return Signature .toString (candidate ).equals (Bindings .getFullyQualifiedName (type ));
10721111 } else {
10731112 String [][] qualifiedCandidates = scope .resolveType (Signature .toString (candidate ));
@@ -1128,6 +1167,8 @@ public static boolean isVoidType(ITypeBinding binding) {
11281167 * Normalizes the binding so that it can be used as a type inside a declaration
11291168 * (e.g. variable declaration, method return type, parameter type, ...). For
11301169 * null bindings Object is returned.
1170+ * @param binding binding to normalize
1171+ * @param ast current ast
11311172 *
11321173 * @return the normalized type to be used in declarations
11331174 */
@@ -1147,9 +1188,9 @@ public static ITypeBinding normalizeForDeclarationUse(ITypeBinding binding, AST
11471188 }
11481189
11491190 /**
1150- * Returns the type binding of the node's parent type declaration
1191+ * Returns the type binding of the node's parent type declaration.
11511192 * @param node
1152- * @return CompilationUnit
1193+ * @return the type binding of the node's parent type declaration
11531194 */
11541195 public static ITypeBinding getBindingOfParentType (ASTNode node ) {
11551196 while (node != null ) {
@@ -1180,7 +1221,7 @@ public static String getRawQualifiedName(ITypeBinding binding) {
11801221 final String EMPTY = "" ; //$NON-NLS-1$
11811222
11821223 if (binding .isAnonymous () || binding .isLocal ()) {
1183- return EMPTY ; //$NON-NLS-1$
1224+ return EMPTY ;
11841225 }
11851226
11861227 if (binding .isPrimitive () || binding .isNullType () || binding .isTypeVariable ()) {
@@ -1269,6 +1310,12 @@ public static boolean containsOverridingMethod(IMethodBinding[] candidates, IMet
12691310 return false ;
12701311 }
12711312
1313+
1314+ /**
1315+ * @deprecated Need to review: Use {@link #isSubsignature(IMethodBinding, IMethodBinding)} if the two bindings
1316+ * are in the same hierarchy (directly overrides each other), or {@link #findMethodInHierarchy(ITypeBinding, String, ITypeBinding[])}
1317+ * else.
1318+ */
12721319 public static boolean containsSignatureEquivalentConstructor (IMethodBinding [] candidates , IMethodBinding overridable ) {
12731320 for (int index = 0 ; index < candidates .length ; index ++) {
12741321 if (isSignatureEquivalentConstructor (candidates [index ], overridable ))
@@ -1288,6 +1335,11 @@ public static boolean isSignatureEquivalentConstructor(IMethodBinding overridden
12881335 return areSubTypeCompatible (overridden , overridable );
12891336 }
12901337
1338+ /**
1339+ * @deprecated Need to review: Use {@link #isSubsignature(IMethodBinding, IMethodBinding)} if the two bindings
1340+ * are in the same hierarchy (directly overrides each other), or {@link #findMethodInHierarchy(ITypeBinding, String, ITypeBinding[])}
1341+ * else.
1342+ */
12911343 public static boolean areOverriddenMethods (IMethodBinding overridden , IMethodBinding overridable ) {
12921344
12931345 if (!overridden .getName ().equals (overridable .getName ()))
0 commit comments