private void computeSubstitutions(IType instantiatedType, IType instantiatingType, String[] typeArguments) throws JavaModelException { Substitutions s= new Substitutions(); fTypeVariableSubstitutions.put(instantiatedType, s); ITypeParameter curr= typeParameters[i]; s.addSubstitution(curr.getElementName(), '*' + curr.getElementName(), getTypeParameterErasure(curr, instantiatedType)); s.addSubstitution(curr.getElementName(), substString, erasure); ITypeParameter curr= typeParameters[i]; String erasure= getTypeParameterErasure(curr, instantiatedType); s.addSubstitution(curr.getElementName(), erasure, erasure);
private boolean hasCompatibleTypeParameters(IMethod overriding, IMethod overridden) throws JavaModelException { ITypeParameter[] overriddenTypeParameters= overridden.getTypeParameters(); ITypeParameter[] overridingTypeParameters= overriding.getTypeParameters(); int nOverridingTypeParameters= overridingTypeParameters.length; if (overriddenTypeParameters.length != nOverridingTypeParameters) { return nOverridingTypeParameters == 0; } Substitutions overriddenSubst= getMethodSubstitions(overridden); Substitutions overridingSubst= getMethodSubstitions(overriding); for (int i= 0; i < nOverridingTypeParameters; i++) { String erasure1= overriddenSubst.getErasure(overriddenTypeParameters[i].getElementName()); String erasure2= overridingSubst.getErasure(overridingTypeParameters[i].getElementName()); if (erasure1 == null || !erasure1.equals(erasure2)) { return false; } // comparing only the erasure is not really correct: Need to compare all bounds, that can be in different order int nBounds= overriddenTypeParameters[i].getBounds().length; if (nBounds > 1 && nBounds != overridingTypeParameters[i].getBounds().length) { return false; } } return true; }
private void computeSubstitutions(IType instantiatedType, IType instantiatingType, String[] typeArguments) throws JavaModelException { Substitutions s= new Substitutions(); fTypeVariableSubstitutions.put(instantiatedType, s); ITypeParameter curr= typeParameters[i]; s.addSubstitution(curr.getElementName(), '*' + curr.getElementName(), getTypeParameterErasure(curr, instantiatedType)); s.addSubstitution(curr.getElementName(), substString, erasure); ITypeParameter curr= typeParameters[i]; String erasure= getTypeParameterErasure(curr, instantiatedType); s.addSubstitution(curr.getElementName(), erasure, erasure);
private void computeSubstitutions(IType instantiatedType, IType instantiatingType, String[] typeArguments) throws JavaModelException { Substitutions s= new Substitutions(); fTypeVariableSubstitutions.put(instantiatedType, s); ITypeParameter curr= typeParameters[i]; s.addSubstitution(curr.getElementName(), '*' + curr.getElementName(), getTypeParameterErasure(curr, instantiatedType)); s.addSubstitution(curr.getElementName(), substString, erasure); ITypeParameter curr= typeParameters[i]; String erasure= getTypeParameterErasure(curr, instantiatedType); s.addSubstitution(curr.getElementName(), erasure, erasure);
private String getVariableSubstitution(IMember context, String variableName) throws JavaModelException { IType type; if (context instanceof IMethod) { String subst= getMethodSubstitions((IMethod) context).getSubstitution(variableName); if (subst != null) { return subst; } type= context.getDeclaringType(); } else { type= (IType) context; } String subst= getTypeSubstitions(type).getSubstitution(variableName); if (subst != null) { return subst; } IJavaElement parent= type.getParent(); if (parent instanceof IMethod) { return getVariableSubstitution((IMethod) parent, variableName); } else if (type.getDeclaringType() != null) { return getVariableSubstitution(type.getDeclaringType(), variableName); } return variableName; // not a type variable }
private String getVariableSubstitution(IMember context, String variableName) throws JavaModelException { IType type; if (context instanceof IMethod) { String subst= getMethodSubstitions((IMethod) context).getSubstitution(variableName); if (subst != null) { return subst; } type= context.getDeclaringType(); } else { type= (IType) context; } String subst= getTypeSubstitions(type).getSubstitution(variableName); if (subst != null) { return subst; } IJavaElement parent= type.getParent(); if (parent instanceof IMethod) { return getVariableSubstitution((IMethod) parent, variableName); } else if (type.getDeclaringType() != null) { return getVariableSubstitution(type.getDeclaringType(), variableName); } return variableName; // not a type variable }
private String getVariableErasure(IMember context, String variableName) throws JavaModelException { IType type; if (context instanceof IMethod) { String subst= getMethodSubstitions((IMethod) context).getErasure(variableName); if (subst != null) { return subst; } type= context.getDeclaringType(); } else { type= (IType) context; } String subst= getTypeSubstitions(type).getErasure(variableName); if (subst != null) { return subst; } IJavaElement parent= type.getParent(); if (parent instanceof IMethod) { return getVariableErasure((IMethod) parent, variableName); } else if (type.getDeclaringType() != null) { return getVariableErasure(type.getDeclaringType(), variableName); } return variableName; // not a type variable }
private boolean hasCompatibleTypeParameters(IMethod overriding, IMethod overridden) throws JavaModelException { ITypeParameter[] overriddenTypeParameters= overridden.getTypeParameters(); ITypeParameter[] overridingTypeParameters= overriding.getTypeParameters(); int nOverridingTypeParameters= overridingTypeParameters.length; if (overriddenTypeParameters.length != nOverridingTypeParameters) { return nOverridingTypeParameters == 0; } Substitutions overriddenSubst= getMethodSubstitions(overridden); Substitutions overridingSubst= getMethodSubstitions(overriding); for (int i= 0; i < nOverridingTypeParameters; i++) { String erasure1= overriddenSubst.getErasure(overriddenTypeParameters[i].getElementName()); String erasure2= overridingSubst.getErasure(overridingTypeParameters[i].getElementName()); if (erasure1 == null || !erasure1.equals(erasure2)) { return false; } // comparing only the erasure is not really correct: Need to compare all bounds, that can be in different order int nBounds= overriddenTypeParameters[i].getBounds().length; if (nBounds > 1 && nBounds != overridingTypeParameters[i].getBounds().length) { return false; } } return true; }
private Substitutions getMethodSubstitions(IMethod method) throws JavaModelException { if (fMethodSubstitutions == null) { fMethodSubstitutions= new LRUMap<>(3); } Substitutions s= fMethodSubstitutions.get(method); if (s == null) { ITypeParameter[] typeParameters= method.getTypeParameters(); if (typeParameters.length == 0) { s= Substitutions.EMPTY_SUBST; } else { IType instantiatedType= method.getDeclaringType(); s= new Substitutions(); for (int i= 0; i < typeParameters.length; i++) { ITypeParameter curr= typeParameters[i]; s.addSubstitution(curr.getElementName(), '+' + String.valueOf(i), getTypeParameterErasure(curr, instantiatedType)); } } fMethodSubstitutions.put(method, s); } return s; }
private String getVariableErasure(IMember context, String variableName) throws JavaModelException { IType type; if (context instanceof IMethod) { String subst= getMethodSubstitions((IMethod) context).getErasure(variableName); if (subst != null) { return subst; } type= context.getDeclaringType(); } else { type= (IType) context; } String subst= getTypeSubstitions(type).getErasure(variableName); if (subst != null) { return subst; } IJavaElement parent= type.getParent(); if (parent instanceof IMethod) { return getVariableErasure((IMethod) parent, variableName); } else if (type.getDeclaringType() != null) { return getVariableErasure(type.getDeclaringType(), variableName); } return variableName; // not a type variable }
private boolean hasCompatibleTypeParameters(IMethod overriding, IMethod overridden) throws JavaModelException { ITypeParameter[] overriddenTypeParameters= overridden.getTypeParameters(); ITypeParameter[] overridingTypeParameters= overriding.getTypeParameters(); int nOverridingTypeParameters= overridingTypeParameters.length; if (overriddenTypeParameters.length != nOverridingTypeParameters) { return nOverridingTypeParameters == 0; } Substitutions overriddenSubst= getMethodSubstitions(overridden); Substitutions overridingSubst= getMethodSubstitions(overriding); for (int i= 0; i < nOverridingTypeParameters; i++) { String erasure1= overriddenSubst.getErasure(overriddenTypeParameters[i].getElementName()); String erasure2= overridingSubst.getErasure(overridingTypeParameters[i].getElementName()); if (erasure1 == null || !erasure1.equals(erasure2)) { return false; } // comparing only the erasure is not really correct: Need to compare all bounds, that can be in different order int nBounds= overriddenTypeParameters[i].getBounds().length; if (nBounds > 1 && nBounds != overridingTypeParameters[i].getBounds().length) { return false; } } return true; }
private Substitutions getMethodSubstitions(IMethod method) throws JavaModelException { if (fMethodSubstitutions == null) { fMethodSubstitutions= new LRUMap<>(3); } Substitutions s= fMethodSubstitutions.get(method); if (s == null) { ITypeParameter[] typeParameters= method.getTypeParameters(); if (typeParameters.length == 0) { s= Substitutions.EMPTY_SUBST; } else { IType instantiatedType= method.getDeclaringType(); s= new Substitutions(); for (int i= 0; i < typeParameters.length; i++) { ITypeParameter curr= typeParameters[i]; s.addSubstitution(curr.getElementName(), '+' + String.valueOf(i), getTypeParameterErasure(curr, instantiatedType)); } } fMethodSubstitutions.put(method, s); } return s; }
private Substitutions getMethodSubstitions(IMethod method) throws JavaModelException { if (fMethodSubstitutions == null) { fMethodSubstitutions= new LRUMap(3); } Substitutions s= (Substitutions) fMethodSubstitutions.get(method); if (s == null) { ITypeParameter[] typeParameters= method.getTypeParameters(); if (typeParameters.length == 0) { s= Substitutions.EMPTY_SUBST; } else { IType instantiatedType= method.getDeclaringType(); s= new Substitutions(); for (int i= 0; i < typeParameters.length; i++) { ITypeParameter curr= typeParameters[i]; s.addSubstitution(curr.getElementName(), '+' + String.valueOf(i), getTypeParameterErasure(curr, instantiatedType)); } } fMethodSubstitutions.put(method, s); } return s; }
private String getVariableErasure(IMember context, String variableName) throws JavaModelException { IType type; if (context instanceof IMethod) { String subst= getMethodSubstitions((IMethod) context).getErasure(variableName); if (subst != null) { return subst; } type= context.getDeclaringType(); } else { type= (IType) context; } String subst= getTypeSubstitions(type).getErasure(variableName); if (subst != null) { return subst; } return variableName; // not a type variable }
private String getVariableSubstitution(IMember context, String variableName) throws JavaModelException { IType type; if (context instanceof IMethod) { String subst= getMethodSubstitions((IMethod) context).getSubstitution(variableName); if (subst != null) { return subst; } type= context.getDeclaringType(); } else { type= (IType) context; } String subst= getTypeSubstitions(type).getSubstitution(variableName); if (subst != null) { return subst; } return variableName; // not a type variable }
public String getSubstitution(String typeVariable) { String[] subst= getSubstArray(typeVariable); if (subst != null) { return subst[0]; } return null; }
public String getErasure(String typeVariable) { String[] subst= getSubstArray(typeVariable); if (subst != null) { return subst[1]; } return null; } }
public String getErasure(String typeVariable) { String[] subst= getSubstArray(typeVariable); if (subst != null) { return subst[1]; } return null; } }
public String getSubstitution(String typeVariable) { String[] subst= getSubstArray(typeVariable); if (subst != null) { return subst[0]; } return null; }
public String getSubstitution(String typeVariable) { String[] subst= getSubstArray(typeVariable); if (subst != null) { return subst[0]; } return null; }