if (modifier instanceof org.eclipse.jdt.core.dom.Annotation) { org.eclipse.jdt.core.dom.Annotation annotation = (org.eclipse.jdt.core.dom.Annotation)modifier; String qualifiedAnnotationName = annotation.resolveTypeBinding().getQualifiedName(); if (!"java.lang.Override".equals(qualifiedAnnotationName) && !"java.lang.SuppressWarnings".equals(qualifiedAnnotationName)) annotations.add(annotation); .append(" ").append(declaration.getName().getFullyQualifiedName()) .append("(");
protected SimpleName getNewName(ASTRewrite rewrite) { ASTNode invocationNode= getInvocationNode(); String name; if (invocationNode instanceof MethodInvocation) { name= ((MethodInvocation)invocationNode).getName().getIdentifier(); } else if (invocationNode instanceof SuperMethodInvocation) { name= ((SuperMethodInvocation)invocationNode).getName().getIdentifier(); } else { name= getSenderBinding().getName(); // name of the class } AST ast= rewrite.getAST(); SimpleName newNameNode= ast.newSimpleName(name); addLinkedPosition(rewrite.track(newNameNode), false, KEY_NAME); ASTNode invocationName= getInvocationNameNode(); if (invocationName != null && invocationName.getAST() == ast) { // in the same CU addLinkedPosition(rewrite.track(invocationName), true, KEY_NAME); } return newNameNode; }
protected void rewrite(SimpleName node, ITypeBinding type) { AST ast= node.getAST(); Type result= fCuRewrite.getImportRewrite().addImport(type, fCuRewrite.getAST()); fCuRewrite.getImportRemover().registerAddedImport(type.getQualifiedName()); Name dummy= ASTNodeFactory.newName(fCuRewrite.getAST(), ASTFlattener.asString(result)); QualifiedName name= ast.newQualifiedName(dummy, ast.newSimpleName(node.getIdentifier())); fCuRewrite.getASTRewrite().replace(node, name, fCuRewrite.createGroupDescription(REFERENCE_UPDATE)); fCuRewrite.getImportRemover().registerRemovedNode(node); fProcessed.add(node); fNeedsImport= true; }
public 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.isWildcardType() && type.getBound() != null) return containsTypeVariables(type.getBound()); return false; }
private void setSuperType(TypeDeclaration declaration) throws JavaModelException { ClassInstanceCreation classInstanceCreation= (ClassInstanceCreation) fAnonymousInnerClassNode.getParent(); ITypeBinding binding= classInstanceCreation.resolveTypeBinding(); if (binding == null) return; Type newType= (Type) ASTNode.copySubtree(fAnonymousInnerClassNode.getAST(), classInstanceCreation.getType()); if (binding.getSuperclass().getQualifiedName().equals("java.lang.Object")) { //$NON-NLS-1$ Assert.isTrue(binding.getInterfaces().length <= 1); if (binding.getInterfaces().length == 0) return; declaration.superInterfaceTypes().add(0, newType); } else { declaration.setSuperclassType(newType); } }
private boolean updateParameterizedTypeReference(ITypeBinding[] parameters, ParameterizedType type, CompilationUnitRewrite targetRewrite, TextEditGroup group) { if (!(type.getParent() instanceof ClassInstanceCreation)) { final ListRewrite rewrite= targetRewrite.getASTRewrite().getListRewrite(type, ParameterizedType.TYPE_ARGUMENTS_PROPERTY); final AST ast= targetRewrite.getRoot().getAST(); Type simpleType= null; for (int index= type.typeArguments().size(); index < parameters.length; index++) { simpleType= ast.newSimpleType(ast.newSimpleName(parameters[index].getName())); rewrite.insertLast(simpleType, group); } } return true; }
public static void getInvalidQualificationProposals(IInvocationContext context, IProblemLocationCore problem, Collection<CUCorrectionProposal> proposals) { ASTNode node= problem.getCoveringNode(context.getASTRoot()); if (!(node instanceof Name)) { return; } Name name= (Name) node; IBinding binding= name.resolveBinding(); if (!(binding instanceof ITypeBinding)) { return; } ITypeBinding typeBinding= (ITypeBinding)binding; AST ast= node.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); rewrite.replace(name, ast.newName(typeBinding.getQualifiedName()), null); String label= CorrectionMessages.JavadocTagsSubProcessor_qualifylinktoinner_description; ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label, CodeActionKind.QuickFix, context.getCompilationUnit(), rewrite, IProposalRelevance.QUALIFY_INNER_TYPE_NAME); proposals.add(proposal); } }
private static String getQualifiedName(ITypeBinding typeBinding) { if (typeBinding.isAnonymous()) return getQualifiedName(typeBinding.getSuperclass()); if (! typeBinding.isArray()) return typeBinding.getQualifiedName(); else return typeBinding.getElementType().getQualifiedName(); }
private void updateConstructorReference(ITypeBinding[] parameters, ParameterizedType type, CompilationUnitRewrite targetRewrite, ICompilationUnit cu, TextEditGroup group) throws CoreException { final ListRewrite rewrite= targetRewrite.getASTRewrite().getListRewrite(type, ParameterizedType.TYPE_ARGUMENTS_PROPERTY); TypeParameter parameter= null; for (int index= type.typeArguments().size(); index < parameters.length; index++) { parameter= targetRewrite.getRoot().getAST().newTypeParameter(); parameter.setName(targetRewrite.getRoot().getAST().newSimpleName(parameters[index].getName())); rewrite.insertLast(parameter, group); } if (type.getParent() instanceof ClassInstanceCreation) updateConstructorReference((ClassInstanceCreation) type.getParent(), targetRewrite, cu, group); }
@Override public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModelCore linkedModel) throws CoreException { ASTRewrite rewrite= cuRewrite.getASTRewrite(); IBinding binding= fUnusedName.resolveBinding(); CompilationUnit root= (CompilationUnit) fUnusedName.getRoot(); String displayString= FixMessages.UnusedCodeFix_RemoveUnusedTypeParameter_description; TextEditGroup group= createTextEditGroup(displayString, cuRewrite); if (binding.getKind() == IBinding.TYPE) { ITypeBinding decl= ((ITypeBinding) binding).getTypeDeclaration(); ASTNode declaration= root.findDeclaringNode(decl); if (declaration.getParent() instanceof TypeDeclarationStatement) { declaration= declaration.getParent(); } rewrite.remove(declaration, group); } } }
private boolean hasAddedStaticImport(SimpleName name) { IBinding binding= name.resolveBinding(); if (binding instanceof IVariableBinding) { IVariableBinding variable= (IVariableBinding) binding; return hasAddedStaticImport(variable.getDeclaringClass().getQualifiedName(), variable.getName(), true); } else if (binding instanceof IMethodBinding) { IMethodBinding method= (IMethodBinding) binding; return hasAddedStaticImport(method.getDeclaringClass().getQualifiedName(), method.getName(), false); } return false; }
private static boolean isInterfaceOrAnnotationMember(IBinding binding) { ITypeBinding declaringType= null; if (binding instanceof IVariableBinding) { declaringType= ((IVariableBinding) binding).getDeclaringClass(); } else if (binding instanceof IMethodBinding) { declaringType= ((IMethodBinding) binding).getDeclaringClass(); } else if (binding instanceof ITypeBinding) { declaringType= ((ITypeBinding) binding).getDeclaringClass(); } return declaringType != null && (declaringType.isInterface() || declaringType.isAnnotation()); }
private Type evaluateParameterType(AST ast, Expression elem, String key, ImportRewriteContext context) { ITypeBinding binding= Bindings.normalizeTypeBinding(elem.resolveTypeBinding()); if (binding != null && binding.isWildcardType()) { binding= ASTResolving.normalizeWildcardType(binding, true, ast); } if (binding != null) { return getImportRewrite().addImport(binding, ast, context, TypeLocation.PARAMETER); } return ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$ }
private void collectSuperTypes(ITypeBinding curr, List<ITypeBinding> list) { if (list.add(curr.getTypeDeclaration())) { ITypeBinding[] interfaces= curr.getInterfaces(); for (int i= 0; i < interfaces.length; i++) { collectSuperTypes(interfaces[i], list); } ITypeBinding superClass= curr.getSuperclass(); if (superClass != null) { collectSuperTypes(superClass, list); } } }
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); } }
public ITypeBinding anonymousBaseType() { ITypeBinding binding = nestedTypeBinding(); return binding.getInterfaces().length > 0 ? binding.getInterfaces()[0] : binding.getSuperclass(); }
private static ITypeBinding getDeclaringClassBinding(SimpleName memberName) { IBinding binding= memberName.resolveBinding(); if (binding instanceof IMethodBinding) return ((IMethodBinding) binding).getDeclaringClass(); if (binding instanceof IVariableBinding) return ((IVariableBinding) binding).getDeclaringClass(); if (binding instanceof ITypeBinding) return ((ITypeBinding) binding).getDeclaringClass(); Assert.isTrue(false); return null; }
private boolean needsNoSuperCall(ITypeBinding typeBinding, String name, ITypeBinding[] parameters) { Assert.isNotNull(typeBinding); IMethodBinding binding= Bindings.findMethodInHierarchy(typeBinding.getSuperclass(), name, parameters); if (binding != null && !Modifier.isAbstract(binding.getModifiers())) { ITypeBinding declaring= binding.getDeclaringClass(); return declaring.getQualifiedName().equals(JAVA_LANG_OBJECT); } return true; }
public static ITypeBinding replaceWildcardsAndCaptures(ITypeBinding type) { while (type.isWildcardType() || type.isCapture() || (type.isArray() && type.getElementType().isCapture())) { ITypeBinding bound = type.getBound(); type = (bound != null) ? bound : type.getErasure(); } return type; }
protected void initialize(ITypeBinding binding, IType javaElementType) { Assert.isTrue(binding.isParameterizedType()); super.initialize(binding, javaElementType); TypeEnvironment environment= getEnvironment(); fTypeDeclaration= (GenericType)environment.create(binding.getTypeDeclaration()); ITypeBinding[] typeArguments= binding.getTypeArguments(); fTypeArguments= new TType[typeArguments.length]; for (int i= 0; i < typeArguments.length; i++) { fTypeArguments[i]= environment.create(typeArguments[i]); } }