List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeBinding isEquivalentTo
public boolean isEquivalentTo(TypeBinding otherType)
From source file:org.eclipse.jdt.internal.compiler.lookup.MethodVerifier15.java
License:Open Source License
boolean areTypesEqual(TypeBinding one, TypeBinding two) { if (one == two) return true; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=329584 switch (one.kind()) { case Binding.TYPE: switch (two.kind()) { case Binding.PARAMETERIZED_TYPE: case Binding.RAW_TYPE: if (one == two.erasure()) return true; }/*from w ww .j a v a 2s. c o m*/ break; case Binding.RAW_TYPE: case Binding.PARAMETERIZED_TYPE: switch (two.kind()) { case Binding.TYPE: if (one.erasure() == two) return true; } } // need to consider X<?> and X<? extends Object> as the same 'type' if (one.isParameterizedType() && two.isParameterizedType()) return one.isEquivalentTo(two) && two.isEquivalentTo(one); // Can skip this since we resolved each method before comparing it, see computeSubstituteMethod() // if (one instanceof UnresolvedReferenceBinding) // return ((UnresolvedReferenceBinding) one).resolvedType == two; // if (two instanceof UnresolvedReferenceBinding) // return ((UnresolvedReferenceBinding) two).resolvedType == one; return false; // all other type bindings are identical }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
private TypeBinding lowerUpperBound(TypeBinding[] types, List lubStack) { int typeLength = types.length; if (typeLength == 1) { TypeBinding type = types[0];//from w ww . j av a2 s.co m return type == null ? TypeBinding.VOID : type; } // cycle detection int stackLength = lubStack.size(); nextLubCheck: for (int i = 0; i < stackLength; i++) { TypeBinding[] lubTypes = (TypeBinding[]) lubStack.get(i); int lubTypeLength = lubTypes.length; if (lubTypeLength < typeLength) continue nextLubCheck; nextTypeCheck: for (int j = 0; j < typeLength; j++) { TypeBinding type = types[j]; if (type == null) continue nextTypeCheck; // ignore for (int k = 0; k < lubTypeLength; k++) { TypeBinding lubType = lubTypes[k]; if (lubType == null) continue; // ignore if (lubType == type || lubType.isEquivalentTo(type)) continue nextTypeCheck; // type found, jump to next one } continue nextLubCheck; // type not found in current lubTypes } // all types are included in some lub, cycle detected - stop recursion by answering special value (int) return TypeBinding.INT; } lubStack.add(types); Map invocations = new HashMap(1); TypeBinding[] mecs = minimalErasedCandidates(types, invocations); if (mecs == null) return null; int length = mecs.length; if (length == 0) return TypeBinding.VOID; int count = 0; TypeBinding firstBound = null; int commonDim = -1; for (int i = 0; i < length; i++) { TypeBinding mec = mecs[i]; if (mec == null) continue; mec = leastContainingInvocation(mec, invocations.get(mec), lubStack); if (mec == null) return null; int dim = mec.dimensions(); if (commonDim == -1) { commonDim = dim; } else if (dim != commonDim) { // not all types have same dimension return null; } if (firstBound == null && !mec.leafComponentType().isInterface()) firstBound = mec.leafComponentType(); mecs[count++] = mec; // recompact them to the front } switch (count) { case 0: return TypeBinding.VOID; case 1: return mecs[0]; case 2: if ((commonDim == 0 ? mecs[1].id : mecs[1].leafComponentType().id) == TypeIds.T_JavaLangObject) return mecs[0]; if ((commonDim == 0 ? mecs[0].id : mecs[0].leafComponentType().id) == TypeIds.T_JavaLangObject) return mecs[1]; } TypeBinding[] otherBounds = new TypeBinding[count - 1]; int rank = 0; for (int i = 0; i < count; i++) { TypeBinding mec = commonDim == 0 ? mecs[i] : mecs[i].leafComponentType(); if (mec.isInterface()) { otherBounds[rank++] = mec; } } TypeBinding intersectionType = environment().createWildcard(null, 0, firstBound, otherBounds, Wildcard.EXTENDS); return commonDim == 0 ? intersectionType : environment().createArrayType(intersectionType, commonDim); }