/** * Add the specified annotation to the specified array initializer, * padding it with 'null' literals as necessary */ private void addInnerToExpressions(Annotation inner, List<Expression> expressions) { if (expressions.size() > this.index) { throw new IllegalStateException("expressions size is greater than index - size: " + expressions.size() + " - index: " + this.index); } while (expressions.size() < this.index) { expressions.add(inner.getAST().newNullLiteral()); } expressions.add(inner); }
/** * Build a new array initializer to hold the specified annotation, * padding it with 'null' literals as necessary */ private ArrayInitializer buildNewInnerArrayInitializer(Annotation inner) { ArrayInitializer ai = inner.getAST().newArrayInitializer(); this.addInnerToExpressions(inner, this.expressions(ai)); return ai; }
iter.add((MemberValuePair) ASTNode.copySubtree(annotation.getAST(), mvp));
iter.add((MemberValuePair) ASTNode.copySubtree(annotation.getAST(), mvp));
MemberValuePair mvpCopy = (MemberValuePair) ASTNode.copySubtree(annotation.getAST(), mvp); mvpCopy.setValue((Expression) result.getInternal()); iter.add(mvpCopy);
MemberValuePair mvpCopy = (MemberValuePair) ASTNode.copySubtree(annotation.getAST(), mvp); mvpCopy.setValue((Expression) result.getInternal()); iter.add(mvpCopy);
/** * Move the annotation to the specified index, leaving its original * position cleared out. */ public void moveAnnotation(int newIndex, ModifiedDeclaration declaration) { int oldIndex = this.index; if (newIndex == oldIndex) { return; } Annotation original = this.getAnnotation(declaration); if (original == null) { this.index = newIndex; this.removeAnnotation(declaration); // clear out the new location (?) } else { Annotation copy = (Annotation) ASTNode.copySubtree(original.getAST(), original); this.index = newIndex; this.addAnnotation(declaration, copy); // install the copy in the new location this.index = oldIndex; this.removeAnnotation(declaration); // go back and clear out the original location (AFTER the move) this.index = newIndex; } }
/** * Manipulate the specified expression appropriately. * If it is an array initializer, add the specified annotation to it. * If it is not, replace the expression or convert it into an array * initializer. */ private void modifyExpression(ASTNode node, ExpressionProvider expProvider, Annotation inner) { Expression value = expProvider.getExpression(node); if (value.getNodeType() == ASTNode.ARRAY_INITIALIZER) { // ignore the other entries in the array initializer(?) - they may not be matching Annotations... List<Expression> expressions = this.expressions((ArrayInitializer) value); if (this.index >= expressions.size()) { this.addInnerToExpressions(inner, expressions); } else { expressions.set(this.index, inner); } } else { if (this.index == 0) { // replace whatever was there before expProvider.setExpression(node, inner); } else { // convert to an array ArrayInitializer ai = inner.getAST().newArrayInitializer(); List<Expression> expressions = this.expressions(ai); expressions.add((Expression) ASTNode.copySubtree(value.getAST(), value)); this.addInnerToExpressions(inner, expressions); expProvider.setExpression(node, ai); } } }
na.values().add(ASTNode.copySubtree(annotation.getAST(), mvp));
public static void removeOverrideAnnotationProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException { ICompilationUnit cu= context.getCompilationUnit(); ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot()); if (!(selectedNode instanceof MethodDeclaration)) { return; } MethodDeclaration methodDecl= (MethodDeclaration) selectedNode; Annotation annot= StubUtility2.findAnnotation("java.lang.Override", methodDecl.modifiers()); //$NON-NLS-1$ if (annot != null) { ASTRewrite rewrite= ASTRewrite.create(annot.getAST()); rewrite.remove(annot, null); String label= CorrectionMessages.ModifierCorrectionSubProcessor_remove_override; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, rewrite, IProposalRelevance.REMOVE_OVERRIDE, image); proposals.add(proposal); QuickAssistProcessor.getCreateInSuperClassProposals(context, methodDecl.getName(), proposals); } }
public static void removeOverrideAnnotationProposal(IInvocationContext context, IProblemLocation problem, Collection proposals) throws CoreException { ICompilationUnit cu= context.getCompilationUnit(); ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot()); if (!(selectedNode instanceof MethodDeclaration)) { return; } MethodDeclaration methodDecl= (MethodDeclaration) selectedNode; Annotation annot= findAnnotation("java.lang.Override", methodDecl.modifiers()); //$NON-NLS-1$ if (annot != null) { ASTRewrite rewrite= ASTRewrite.create(annot.getAST()); rewrite.remove(annot, null); String label= CorrectionMessages.ModifierCorrectionSubProcessor_remove_override; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, rewrite, 6, image); proposals.add(proposal); QuickAssistProcessor.getCreateInSuperClassProposals(context, methodDecl.getName(), proposals); } }
public static void removeOverrideAnnotationProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException { ICompilationUnit cu= context.getCompilationUnit(); ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot()); if (!(selectedNode instanceof MethodDeclaration)) { return; } MethodDeclaration methodDecl= (MethodDeclaration) selectedNode; Annotation annot= StubUtility2Core.findAnnotation("java.lang.Override", methodDecl.modifiers()); //$NON-NLS-1$ if (annot != null) { ASTRewrite rewrite= ASTRewrite.create(annot.getAST()); rewrite.remove(annot, null); String label= CorrectionMessages.ModifierCorrectionSubProcessor_remove_override; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, rewrite, IProposalRelevance.REMOVE_OVERRIDE, image); proposals.add(proposal); QuickAssistProcessor.getCreateInSuperClassProposals(context, methodDecl.getName(), proposals); } }
protected ASTRewrite getRewrite() throws CoreException { AST ast= fAnnotation.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); createImportRewrite((CompilationUnit) fAnnotation.getRoot()); ListRewrite listRewrite; if (fAnnotation instanceof NormalAnnotation) { listRewrite= rewrite.getListRewrite(fAnnotation, NormalAnnotation.VALUES_PROPERTY); } else { NormalAnnotation newAnnotation= ast.newNormalAnnotation(); newAnnotation.setTypeName((Name) rewrite.createMoveTarget(fAnnotation.getTypeName())); rewrite.replace(fAnnotation, newAnnotation, null); listRewrite= rewrite.getListRewrite(newAnnotation, NormalAnnotation.VALUES_PROPERTY); } addMissingAtributes(fAnnotation.resolveTypeBinding(), listRewrite); return rewrite; }
@Override protected ASTRewrite getRewrite() throws CoreException { AST ast= fAnnotation.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); createImportRewrite((CompilationUnit) fAnnotation.getRoot()); ListRewrite listRewrite; if (fAnnotation instanceof NormalAnnotation) { listRewrite= rewrite.getListRewrite(fAnnotation, NormalAnnotation.VALUES_PROPERTY); } else { NormalAnnotation newAnnotation= ast.newNormalAnnotation(); newAnnotation.setTypeName((Name) rewrite.createMoveTarget(fAnnotation.getTypeName())); rewrite.replace(fAnnotation, newAnnotation, null); listRewrite= rewrite.getListRewrite(newAnnotation, NormalAnnotation.VALUES_PROPERTY); } addMissingAtributes(fAnnotation.resolveTypeBinding(), listRewrite); return rewrite; }
@Override protected ASTRewrite getRewrite() throws CoreException { AST ast= fAnnotation.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); createImportRewrite((CompilationUnit) fAnnotation.getRoot()); ListRewrite listRewrite; if (fAnnotation instanceof NormalAnnotation) { listRewrite= rewrite.getListRewrite(fAnnotation, NormalAnnotation.VALUES_PROPERTY); } else { NormalAnnotation newAnnotation= ast.newNormalAnnotation(); newAnnotation.setTypeName((Name) rewrite.createMoveTarget(fAnnotation.getTypeName())); rewrite.replace(fAnnotation, newAnnotation, null); listRewrite= rewrite.getListRewrite(newAnnotation, NormalAnnotation.VALUES_PROPERTY); } addMissingAtributes(fAnnotation.resolveTypeBinding(), listRewrite); return rewrite; }