protected boolean canAssignToStandardType(StandardType target) { if (target.isJavaLangObject()) return true; return isSubType(target); } }
private boolean doIsSubType(HierarchyType other) { if (fSuperclass != null && (other.isTypeEquivalentTo(fSuperclass) || fSuperclass.doIsSubType(other))) return true; for (int i= 0; i < fInterfaces.length; i++) { if (other.isTypeEquivalentTo(fInterfaces[i]) || fInterfaces[i].doIsSubType(other)) return true; } return false; }
public boolean isSubType(HierarchyType other) { if (getEnvironment() == other.getEnvironment()) { Map<TypeTuple, Boolean> cache= getEnvironment().getSubTypeCache(); TypeTuple key= new TypeTuple(this, other); Boolean value= cache.get(key); if (value != null) return value.booleanValue(); boolean isSub= doIsSubType(other); value= Boolean.valueOf(isSub); cache.put(key, value); return isSub; } return doIsSubType(other); }
/** * @param rhs * @param lhs * @return <code>true</code> iff an expression of type 'rhs' can be assigned to a variable of type 'lhs'. * Type arguments of generic / raw / parameterized types are <b>not</b> considered. */ public static boolean canAssignTo(TType rhs, TType lhs) { if (rhs.isHierarchyType() && lhs.isHierarchyType()) { HierarchyType rhsGeneric= (HierarchyType) rhs.getTypeDeclaration(); HierarchyType lhsGeneric= (HierarchyType) lhs.getTypeDeclaration(); return lhs.isJavaLangObject() || rhsGeneric.equals(lhsGeneric) || rhsGeneric.isSubType(lhsGeneric); } else if (rhs.isTypeVariable()) { if (rhs.canAssignTo(lhs)) return true; TType[] bounds= ((TypeVariable) rhs).getBounds(); for (int i= 0; i < bounds.length; i++) { if (canAssignTo(bounds[i], lhs)) return true; } return lhs.isJavaLangObject(); } else { return rhs.canAssignTo(lhs); } }
protected void initialize(ITypeBinding binding, IType javaElementType) { Assert.isTrue(binding.isRawType()); super.initialize(binding, javaElementType); TypeEnvironment environment= getEnvironment(); fTypeDeclaration= (HierarchyType)environment.create(binding.getTypeDeclaration()); }
@Override protected boolean isTypeEquivalentTo(TType other) { int otherElementType= other.getKind(); if (otherElementType == RAW_TYPE || otherElementType == PARAMETERIZED_TYPE) return getErasure().isTypeEquivalentTo(other.getErasure()); return super.isTypeEquivalentTo(other); }
private static boolean isTaggingInterface(TType interf) { if (interf instanceof HierarchyType) { try { return ((HierarchyType) interf).getJavaElementType().getMethods().length == 0; } catch (JavaModelException e) { // assume it's not } } return false; }
protected void initialize(ITypeBinding binding, IType javaElementType) { super.initialize(binding); Assert.isNotNull(javaElementType); fJavaElementType= javaElementType; TypeEnvironment environment= getEnvironment(); ITypeBinding superclass= binding.getSuperclass(); if (superclass != null) { fSuperclass= (HierarchyType)environment.create(superclass); } ITypeBinding[] interfaces= binding.getInterfaces(); fInterfaces= new HierarchyType[interfaces.length]; for (int i= 0; i < interfaces.length; i++) { fInterfaces[i]= (HierarchyType)environment.create(interfaces[i]); } }
/** * @param rhs * @param lhs * @return <code>true</code> iff an expression of type 'rhs' can be assigned to a variable of type 'lhs'. * Type arguments of generic / raw / parameterized types are <b>not</b> considered. */ public static boolean canAssignTo(TType rhs, TType lhs) { if (rhs.isHierarchyType() && lhs.isHierarchyType()) { HierarchyType rhsGeneric= (HierarchyType) rhs.getTypeDeclaration(); HierarchyType lhsGeneric= (HierarchyType) lhs.getTypeDeclaration(); return lhs.isJavaLangObject() || rhsGeneric.equals(lhsGeneric) || rhsGeneric.isSubType(lhsGeneric); } else if (rhs.isTypeVariable()) { if (rhs.canAssignTo(lhs)) return true; TType[] bounds= ((TypeVariable) rhs).getBounds(); for (int i= 0; i < bounds.length; i++) { if (canAssignTo(bounds[i], lhs)) return true; } return lhs.isJavaLangObject(); } else { return rhs.canAssignTo(lhs); } }
protected void initialize(ITypeBinding binding, IType javaElementType) { Assert.isTrue(binding.isGenericType()); super.initialize(binding, javaElementType); TypeEnvironment environment= getEnvironment(); ITypeBinding[] typeParameters= binding.getTypeParameters(); fTypeParameters= new TypeVariable[typeParameters.length]; for (int i= 0; i < typeParameters.length; i++) { fTypeParameters[i]= (TypeVariable) environment.create(typeParameters[i]); } }
protected boolean isTypeEquivalentTo(TType other) { int otherElementType= other.getKind(); if (otherElementType == PARAMETERIZED_TYPE || otherElementType == GENERIC_TYPE) return getErasure().isTypeEquivalentTo(other.getErasure()); return super.isTypeEquivalentTo(other); }
private static boolean isTaggingInterface(TType interf) { if (interf instanceof HierarchyType) { try { return ((HierarchyType) interf).getJavaElementType().getMethods().length == 0; } catch (JavaModelException e) { // assume it's not } } return false; }
protected void initialize(ITypeBinding binding, IType javaElementType) { super.initialize(binding); Assert.isNotNull(javaElementType); fJavaElementType= javaElementType; TypeEnvironment environment= getEnvironment(); ITypeBinding superclass= binding.getSuperclass(); if (superclass != null) { fSuperclass= (HierarchyType)environment.create(superclass); } ITypeBinding[] interfaces= binding.getInterfaces(); fInterfaces= new HierarchyType[interfaces.length]; for (int i= 0; i < interfaces.length; i++) { fInterfaces[i]= (HierarchyType)environment.create(interfaces[i]); } }
/** * @param rhs * @param lhs * @return <code>true</code> iff an expression of type 'rhs' can be assigned to a variable of type 'lhs'. * Type arguments of generic / raw / parameterized types are <b>not</b> considered. */ public static boolean canAssignTo(TType rhs, TType lhs) { if (rhs.isHierarchyType() && lhs.isHierarchyType()) { HierarchyType rhsGeneric= (HierarchyType) rhs.getTypeDeclaration(); HierarchyType lhsGeneric= (HierarchyType) lhs.getTypeDeclaration(); return lhs.isJavaLangObject() || rhsGeneric.equals(lhsGeneric) || rhsGeneric.isSubType(lhsGeneric); } else if (rhs.isTypeVariable()) { if (rhs.canAssignTo(lhs)) return true; TType[] bounds= ((TypeVariable) rhs).getBounds(); for (int i= 0; i < bounds.length; i++) { if (canAssignTo(bounds[i], lhs)) return true; } return lhs.isJavaLangObject(); } else { return rhs.canAssignTo(lhs); } }
protected boolean canAssignToStandardType(StandardType target) { if (target.isJavaLangObject()) return true; return isSubType(target); } }
private boolean doIsSubType(HierarchyType other) { if (fSuperclass != null && (other.isTypeEquivalentTo(fSuperclass) || fSuperclass.doIsSubType(other))) return true; for (int i= 0; i < fInterfaces.length; i++) { if (other.isTypeEquivalentTo(fInterfaces[i]) || fInterfaces[i].doIsSubType(other)) return true; } return false; }
public boolean isSubType(HierarchyType other) { if (getEnvironment() == other.getEnvironment()) { Map cache= getEnvironment().getSubTypeCache(); TypeTuple key= new TypeTuple(this, other); Boolean value= (Boolean)cache.get(key); if (value != null) return value.booleanValue(); boolean isSub= doIsSubType(other); value= Boolean.valueOf(isSub); cache.put(key, value); return isSub; } return doIsSubType(other); }
@Override protected void initialize(ITypeBinding binding, IType javaElementType) { Assert.isTrue(binding.isRawType()); super.initialize(binding, javaElementType); TypeEnvironment environment= getEnvironment(); fTypeDeclaration= (HierarchyType)environment.create(binding.getTypeDeclaration()); }
protected boolean isTypeEquivalentTo(TType other) { int otherElementType= other.getKind(); if (otherElementType == RAW_TYPE || otherElementType == PARAMETERIZED_TYPE) return getErasure().isTypeEquivalentTo(other.getErasure()); return super.isTypeEquivalentTo(other); }
private ArrayList getNonTaggingInterfaces(ArrayList interfaceCandidates) { ArrayList unresolvedTypes= new ArrayList(); ArrayList nonTagging= new ArrayList(); for (int i= 0; i < interfaceCandidates.size(); i++) { TType interf= (TType) interfaceCandidates.get(i); Object isTagging= fInterfaceTaggingCache.get(interf); if (isTagging == null) unresolvedTypes.add(interf); else if (isTagging == Boolean.FALSE) nonTagging.add(interf); } if (unresolvedTypes.size() != 0) { TType[] interfaces= (TType[]) unresolvedTypes.toArray(new TType[unresolvedTypes.size()]); HierarchyType firstInterface= (HierarchyType) interfaces[0]; IJavaProject javaProject= firstInterface.getJavaElementType().getJavaProject(); ITypeBinding[] interfaceBindings= TypeEnvironment.createTypeBindings(interfaces, javaProject); //expensive... for (int i= 0; i < interfaceBindings.length; i++) { if (interfaceBindings[i].getDeclaredMethods().length == 0) { fInterfaceTaggingCache.put(interfaces[i], Boolean.TRUE); } else { fInterfaceTaggingCache.put(interfaces[i], Boolean.FALSE); nonTagging.add(interfaces[i]); } } } return nonTagging; }