public static ITypeBinding getTypesVariablesBase(ITypeBinding returnType, AST ast) { assert returnType.isTypeVariable() || returnType.isCapture(); if (returnType.getTypeBounds().length > 0) return returnType.getTypeBounds()[0]; // TODO: why is there more than one bound? else return ast.resolveWellKnownType("java.lang.Object"); }
private static Set<ITypeBinding> getTypeBoundsForSubsignature(ITypeBinding typeParameter) { ITypeBinding[] typeBounds= typeParameter.getTypeBounds(); int count= typeBounds.length; if (count == 0) return Collections.emptySet(); Set<ITypeBinding> result= new HashSet<>(typeBounds.length); for (int i= 0; i < typeBounds.length; i++) { ITypeBinding bound= typeBounds[i]; if ("java.lang.Object".equals(typeBounds[0].getQualifiedName())) //$NON-NLS-1$ continue; else if (containsTypeVariables(bound)) result.add(bound.getErasure()); // try to achieve effect of "rename type variables" else if (bound.isRawType()) result.add(bound.getTypeDeclaration()); else result.add(bound); } return result; }
private static Set getTypeBoundsForSubsignature(ITypeBinding typeParameter) { ITypeBinding[] typeBounds= typeParameter.getTypeBounds(); int count= typeBounds.length; if (count == 0) return Collections.EMPTY_SET; Set result= new HashSet(typeBounds.length); for (int i= 0; i < typeBounds.length; i++) { ITypeBinding bound= typeBounds[i]; if ("java.lang.Object".equals(typeBounds[0].getQualifiedName())) //$NON-NLS-1$ continue; else if (containsTypeVariables(bound)) result.add(bound.getErasure()); // try to achieve effect of "rename type variables" else if (bound.isRawType()) result.add(bound.getTypeDeclaration()); else result.add(bound); } return result; }
private static IType getType(ITypeBinding typeBinding) { if (typeBinding == null) { return null; } if (typeBinding.isTypeVariable()) { ITypeBinding[] typeBounds= typeBinding.getTypeBounds(); if (typeBounds.length > 0) { typeBinding= typeBounds[0].getTypeDeclaration(); } else { return null; } } return (IType) typeBinding.getJavaElement(); }
private static IType getType(ITypeBinding typeBinding) { if (typeBinding == null) { return null; } if (typeBinding.isTypeVariable()) { ITypeBinding[] typeBounds= typeBinding.getTypeBounds(); if (typeBounds.length > 0) { typeBinding= typeBounds[0].getTypeDeclaration(); } else { return null; } } return (IType) typeBinding.getJavaElement(); }
private static void createTypeParameters(ImportRewrite imports, ImportRewriteContext context, AST ast, IMethodBinding binding, MethodDeclaration decl) { ITypeBinding[] typeParams= binding.getTypeParameters(); List<TypeParameter> typeParameters= decl.typeParameters(); for (int i= 0; i < typeParams.length; i++) { ITypeBinding curr= typeParams[i]; TypeParameter newTypeParam= ast.newTypeParameter(); newTypeParam.setName(ast.newSimpleName(curr.getName())); ITypeBinding[] typeBounds= curr.getTypeBounds(); if (typeBounds.length != 1 || !"java.lang.Object".equals(typeBounds[0].getQualifiedName())) {//$NON-NLS-1$ List<Type> newTypeBounds= newTypeParam.typeBounds(); for (int k= 0; k < typeBounds.length; k++) { newTypeBounds.add(imports.addImport(typeBounds[k], ast, context)); } } typeParameters.add(newTypeParam); } }
public static void createTypeParameters(ImportRewrite imports, ImportRewriteContext context, AST ast, IMethodBinding binding, MethodDeclaration decl) { ITypeBinding[] typeParams= binding.getTypeParameters(); List<TypeParameter> typeParameters= decl.typeParameters(); for (int i= 0; i < typeParams.length; i++) { ITypeBinding curr= typeParams[i]; TypeParameter newTypeParam= ast.newTypeParameter(); newTypeParam.setName(ast.newSimpleName(curr.getName())); ITypeBinding[] typeBounds= curr.getTypeBounds(); if (typeBounds.length != 1 || !"java.lang.Object".equals(typeBounds[0].getQualifiedName())) {//$NON-NLS-1$ List<Type> newTypeBounds= newTypeParam.typeBounds(); for (int k= 0; k < typeBounds.length; k++) { newTypeBounds.add(imports.addImport(typeBounds[k], ast, context, TypeLocation.TYPE_BOUND)); } } typeParameters.add(newTypeParam); } }
private void copyTypeParameters(MethodDeclaration intermediary, CompilationUnitRewrite rew, ImportRewriteContext context) { ITypeBinding[] typeParameters= fTargetMethodBinding.getTypeParameters(); for (int i= 0; i < typeParameters.length; i++) { ITypeBinding current= typeParameters[i]; TypeParameter parameter= rew.getAST().newTypeParameter(); parameter.setName(rew.getAST().newSimpleName(current.getName())); ITypeBinding[] bounds= current.getTypeBounds(); for (int j= 0; j < bounds.length; j++) if (!"java.lang.Object".equals(bounds[j].getQualifiedName())) //$NON-NLS-1$ parameter.typeBounds().add(rew.getImportRewrite().addImport(bounds[j], rew.getAST(), context)); intermediary.typeParameters().add(parameter); } }
private void copyTypeParameters(MethodDeclaration intermediary, CompilationUnitRewrite rew) { ITypeBinding[] typeParameters= fTargetMethodBinding.getTypeParameters(); for (int i= 0; i < typeParameters.length; i++) { ITypeBinding current= typeParameters[i]; TypeParameter parameter= rew.getAST().newTypeParameter(); parameter.setName(rew.getAST().newSimpleName(current.getName())); ITypeBinding[] bounds= current.getTypeBounds(); for (int j= 0; j < bounds.length; j++) if (!"java.lang.Object".equals(bounds[j].getQualifiedName())) //$NON-NLS-1$ parameter.typeBounds().add(rew.getImportRewrite().addImport(bounds[j], rew.getAST())); intermediary.typeParameters().add(parameter); } }
private void copyTypeParameters(MethodDeclaration intermediary, CompilationUnitRewrite rew, ImportRewriteContext context) { ITypeBinding[] typeParameters= fTargetMethodBinding.getTypeParameters(); for (int i= 0; i < typeParameters.length; i++) { ITypeBinding current= typeParameters[i]; TypeParameter parameter= rew.getAST().newTypeParameter(); parameter.setName(rew.getAST().newSimpleName(current.getName())); ITypeBinding[] bounds= current.getTypeBounds(); for (int j= 0; j < bounds.length; j++) if (!"java.lang.Object".equals(bounds[j].getQualifiedName())) //$NON-NLS-1$ parameter.typeBounds().add(rew.getImportRewrite().addImport(bounds[j], rew.getAST(), context, TypeLocation.TYPE_BOUND)); intermediary.typeParameters().add(parameter); } }
private void addTypeParameters(CompilationUnitRewrite imRewrite, List newTypeParameters, ITypeBinding parent) { ITypeBinding enclosing= parent.getDeclaringClass(); if (enclosing != null) addTypeParameters(imRewrite, newTypeParameters, enclosing); ITypeBinding[] typeParameters= parent.getTypeParameters(); for (int i= 0; i < typeParameters.length; i++) { TypeParameter ntp= imRewrite.getAST().newTypeParameter(); ntp.setName(imRewrite.getAST().newSimpleName(typeParameters[i].getName())); ITypeBinding[] bounds= typeParameters[i].getTypeBounds(); for (int j= 0; j < bounds.length; j++) if (!"java.lang.Object".equals(bounds[j].getQualifiedName())) //$NON-NLS-1$ ntp.typeBounds().add(imRewrite.getImportRewrite().addImport(bounds[j], imRewrite.getAST())); newTypeParameters.add(ntp); } }
private void addTypeParameters(CompilationUnitRewrite imRewrite, List<TypeParameter> list, ITypeBinding parent, ImportRewriteContext context) { ITypeBinding enclosing= parent.getDeclaringClass(); if (enclosing != null) addTypeParameters(imRewrite, list, enclosing, context); ITypeBinding[] typeParameters= parent.getTypeParameters(); for (int i= 0; i < typeParameters.length; i++) { TypeParameter ntp= imRewrite.getAST().newTypeParameter(); ntp.setName(imRewrite.getAST().newSimpleName(typeParameters[i].getName())); ITypeBinding[] bounds= typeParameters[i].getTypeBounds(); for (int j= 0; j < bounds.length; j++) if (!"java.lang.Object".equals(bounds[j].getQualifiedName())) //$NON-NLS-1$ ntp.typeBounds().add(imRewrite.getImportRewrite().addImport(bounds[j], imRewrite.getAST(), context)); list.add(ntp); } }
private void addTypeParameters(CompilationUnitRewrite imRewrite, List<TypeParameter> list, ITypeBinding parent, ImportRewriteContext context) { ITypeBinding enclosing= parent.getDeclaringClass(); if (enclosing != null) addTypeParameters(imRewrite, list, enclosing, context); ITypeBinding[] typeParameters= parent.getTypeParameters(); for (int i= 0; i < typeParameters.length; i++) { TypeParameter ntp= imRewrite.getAST().newTypeParameter(); ntp.setName(imRewrite.getAST().newSimpleName(typeParameters[i].getName())); ITypeBinding[] bounds= typeParameters[i].getTypeBounds(); for (int j= 0; j < bounds.length; j++) if (!"java.lang.Object".equals(bounds[j].getQualifiedName())) //$NON-NLS-1$ ntp.typeBounds().add(imRewrite.getImportRewrite().addImport(bounds[j], imRewrite.getAST(), context, TypeLocation.TYPE_BOUND)); list.add(ntp); } }
protected void initialize(ITypeBinding binding) { super.initialize(binding); ITypeBinding[] bounds= binding.getTypeBounds(); if (bounds.length == 0) { fBounds= EMPTY_TYPE_ARRAY; if (getEnvironment().getJavaLangObject() == null) { getEnvironment().initializeJavaLangObject(binding.getErasure()); } } else { fBounds= new TType[bounds.length]; for (int i= 0; i < bounds.length; i++) { fBounds[i]= getEnvironment().create(bounds[i]); } } }
private void collectTypeVariables(ITypeBinding typeBinding, Set<ITypeBinding> typeVariablesCollector) { if (typeBinding.isTypeVariable()) { typeVariablesCollector.add(typeBinding); ITypeBinding[] typeBounds= typeBinding.getTypeBounds(); for (int i= 0; i < typeBounds.length; i++) collectTypeVariables(typeBounds[i], typeVariablesCollector); } else if (typeBinding.isArray()) { collectTypeVariables(typeBinding.getElementType(), typeVariablesCollector); } else if (typeBinding.isParameterizedType()) { ITypeBinding[] typeArguments= typeBinding.getTypeArguments(); for (int i= 0; i < typeArguments.length; i++) collectTypeVariables(typeArguments[i], typeVariablesCollector); } else if (typeBinding.isWildcardType()) { ITypeBinding bound= typeBinding.getBound(); if (bound != null) { collectTypeVariables(bound, typeVariablesCollector); } } }
private void collectTypeVariables(ITypeBinding typeBinding, Set typeVariablesCollector) { if (typeBinding.isTypeVariable()) { typeVariablesCollector.add(typeBinding); ITypeBinding[] typeBounds= typeBinding.getTypeBounds(); for (int i= 0; i < typeBounds.length; i++) collectTypeVariables(typeBounds[i], typeVariablesCollector); } else if (typeBinding.isArray()) { collectTypeVariables(typeBinding.getElementType(), typeVariablesCollector); } else if (typeBinding.isParameterizedType()) { ITypeBinding[] typeArguments= typeBinding.getTypeArguments(); for (int i= 0; i < typeArguments.length; i++) collectTypeVariables(typeArguments[i], typeVariablesCollector); } else if (typeBinding.isWildcardType()) { ITypeBinding bound= typeBinding.getBound(); if (bound != null) { collectTypeVariables(bound, typeVariablesCollector); } } }
@Override protected void initialize(ITypeBinding binding) { super.initialize(binding); ITypeBinding[] bounds= binding.getTypeBounds(); if (bounds.length == 0) { fBounds= EMPTY_TYPE_ARRAY; if (getEnvironment().getJavaLangObject() == null) { getEnvironment().initializeJavaLangObject(binding.getErasure()); } } else { fBounds= new TType[bounds.length]; for (int i= 0; i < bounds.length; i++) { fBounds[i]= getEnvironment().create(bounds[i]); } } }
@Override protected void initialize(ITypeBinding binding) { super.initialize(binding); ITypeBinding[] bounds= binding.getTypeBounds(); if (bounds.length == 0) { fBounds= EMPTY_TYPE_ARRAY; if (getEnvironment().getJavaLangObject() == null) { getEnvironment().initializeJavaLangObject(binding.getErasure()); } } else { fBounds= new TType[bounds.length]; for (int i= 0; i < bounds.length; i++) { fBounds[i]= getEnvironment().create(bounds[i]); } } }
private void collectTypeVariables(ITypeBinding typeBinding, Set<ITypeBinding> typeVariablesCollector) { if (typeBinding.isTypeVariable()) { typeVariablesCollector.add(typeBinding); ITypeBinding[] typeBounds= typeBinding.getTypeBounds(); for (int i= 0; i < typeBounds.length; i++) collectTypeVariables(typeBounds[i], typeVariablesCollector); } else if (typeBinding.isArray()) { collectTypeVariables(typeBinding.getElementType(), typeVariablesCollector); } else if (typeBinding.isParameterizedType()) { ITypeBinding[] typeArguments= typeBinding.getTypeArguments(); for (int i= 0; i < typeArguments.length; i++) collectTypeVariables(typeArguments[i], typeVariablesCollector); } else if (typeBinding.isWildcardType()) { ITypeBinding bound= typeBinding.getBound(); if (bound != null) { collectTypeVariables(bound, typeVariablesCollector); } } }
private static boolean containsTypeVariables(ITypeBinding type) { if (type.isTypeVariable()) return true; if (type.isArray()) return containsTypeVariables(type.getElementType()); if (type.isCapture()) return containsTypeVariables(type.getWildcard()); if (type.isParameterizedType()) return containsTypeVariables(type.getTypeArguments()); if (type.isTypeVariable()) return containsTypeVariables(type.getTypeBounds()); if (type.isWildcardType() && type.getBound() != null) return containsTypeVariables(type.getBound()); return false; }