Java Code Examples for org.eclipse.jdt.core.dom.rewrite.ListRewrite#insertBefore()
The following examples show how to use
org.eclipse.jdt.core.dom.rewrite.ListRewrite#insertBefore() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MoveMethodRefactoring.java From JDeodorant with MIT License | 6 votes |
private void addParamTagElementToJavadoc(MethodDeclaration newMethodDeclaration, ASTRewrite targetRewriter, String parameterToBeAdded) { if(newMethodDeclaration.getJavadoc() != null) { AST ast = newMethodDeclaration.getAST(); Javadoc javadoc = newMethodDeclaration.getJavadoc(); List<TagElement> tags = javadoc.tags(); TagElement returnTagElement = null; for(TagElement tag : tags) { if(tag.getTagName() != null && tag.getTagName().equals(TagElement.TAG_RETURN)) { returnTagElement = tag; break; } } TagElement tagElement = ast.newTagElement(); targetRewriter.set(tagElement, TagElement.TAG_NAME_PROPERTY, TagElement.TAG_PARAM, null); ListRewrite fragmentsRewrite = targetRewriter.getListRewrite(tagElement, TagElement.FRAGMENTS_PROPERTY); SimpleName paramName = ast.newSimpleName(parameterToBeAdded); fragmentsRewrite.insertLast(paramName, null); ListRewrite tagsRewrite = targetRewriter.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY); if(returnTagElement != null) tagsRewrite.insertBefore(tagElement, returnTagElement, null); else tagsRewrite.insertLast(tagElement, null); } }
Example 2
Source File: LocalCorrectionsSubProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
public static void addCasesOmittedProposals(IInvocationContext context, IProblemLocationCore problem, Collection<ChangeCorrectionProposal> proposals) { ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot()); if (selectedNode instanceof Expression && selectedNode.getLocationInParent() == SwitchStatement.EXPRESSION_PROPERTY) { AST ast = selectedNode.getAST(); SwitchStatement parent = (SwitchStatement) selectedNode.getParent(); for (Statement statement : (List<Statement>) parent.statements()) { if (statement instanceof SwitchCase && ((SwitchCase) statement).isDefault()) { // insert //$CASES-OMITTED$: ASTRewrite rewrite = ASTRewrite.create(ast); rewrite.setTargetSourceRangeComputer(new NoCommentSourceRangeComputer()); ListRewrite listRewrite = rewrite.getListRewrite(parent, SwitchStatement.STATEMENTS_PROPERTY); ASTNode casesOmittedComment = rewrite.createStringPlaceholder("//$CASES-OMITTED$", ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$ listRewrite.insertBefore(casesOmittedComment, statement, null); String label = CorrectionMessages.LocalCorrectionsSubProcessor_insert_cases_omitted; ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label, CodeActionKind.QuickFix, context.getCompilationUnit(), rewrite, IProposalRelevance.INSERT_CASES_OMITTED); proposals.add(proposal); break; } } } }
Example 3
Source File: ASTUtil.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
private static void addImports(ListRewrite importRewrite, Comparator<? super ImportDeclaration> comparator, Iterator<ImportDeclaration> newImports) { try { ImportDeclaration newImport = newImports.next(); List<?> imports = importRewrite.getRewrittenList(); for (Object importObj : imports) { ImportDeclaration anImport = (ImportDeclaration) importObj; int comp = comparator.compare(newImport, anImport); if (comp > 0) { continue; } if (comp < 0) { importRewrite.insertBefore(newImport, anImport, null); } newImport = newImports.next(); } importRewrite.insertLast(newImport, null); while (newImports.hasNext()) { importRewrite.insertLast(newImports.next(), null); } } catch (NoSuchElementException e) { // do nothing } }
Example 4
Source File: ReplaceTypeCodeWithStateStrategy.java From JDeodorant with MIT License | 6 votes |
private void createStateField() { ASTRewrite sourceRewriter = ASTRewrite.create(sourceTypeDeclaration.getAST()); AST contextAST = sourceTypeDeclaration.getAST(); ListRewrite contextBodyRewrite = sourceRewriter.getListRewrite(sourceTypeDeclaration, TypeDeclaration.BODY_DECLARATIONS_PROPERTY); VariableDeclarationFragment typeFragment = createStateFieldVariableDeclarationFragment(sourceRewriter, contextAST); FieldDeclaration typeFieldDeclaration = contextAST.newFieldDeclaration(typeFragment); sourceRewriter.set(typeFieldDeclaration, FieldDeclaration.TYPE_PROPERTY, contextAST.newSimpleName(abstractClassName), null); ListRewrite typeFieldDeclarationModifiersRewrite = sourceRewriter.getListRewrite(typeFieldDeclaration, FieldDeclaration.MODIFIERS2_PROPERTY); typeFieldDeclarationModifiersRewrite.insertLast(contextAST.newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD), null); contextBodyRewrite.insertBefore(typeFieldDeclaration, typeCheckElimination.getTypeField().getParent(), null); try { TextEdit sourceEdit = sourceRewriter.rewriteAST(); ICompilationUnit sourceICompilationUnit = (ICompilationUnit)sourceCompilationUnit.getJavaElement(); CompilationUnitChange change = compilationUnitChanges.get(sourceICompilationUnit); change.getEdit().addChild(sourceEdit); change.addTextEditGroup(new TextEditGroup("Create field holding the current state", new TextEdit[] {sourceEdit})); } catch (JavaModelException e) { e.printStackTrace(); } }
Example 5
Source File: DelegateCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Performs the actual rewriting and adds an edit to the ASTRewrite set with * {@link #setSourceRewrite(CompilationUnitRewrite)}. * * @throws JavaModelException */ public void createEdit() throws JavaModelException { try { IDocument document= new Document(fDelegateRewrite.getCu().getBuffer().getContents()); TextEdit edit= fDelegateRewrite.getASTRewrite().rewriteAST(document, fDelegateRewrite.getCu().getJavaProject().getOptions(true)); edit.apply(document, TextEdit.UPDATE_REGIONS); String newSource= Strings.trimIndentation(document.get(fTrackedPosition.getStartPosition(), fTrackedPosition.getLength()), fPreferences.tabWidth, fPreferences.indentWidth, false); ASTNode placeholder= fOriginalRewrite.getASTRewrite().createStringPlaceholder(newSource, fDeclaration.getNodeType()); CategorizedTextEditGroup groupDescription= fOriginalRewrite.createCategorizedGroupDescription(getTextEditGroupLabel(), CATEGORY_DELEGATE); ListRewrite bodyDeclarationsListRewrite= fOriginalRewrite.getASTRewrite().getListRewrite(fDeclaration.getParent(), getTypeBodyDeclarationsProperty()); if (fCopy) if (fInsertBefore) bodyDeclarationsListRewrite.insertBefore(placeholder, fDeclaration, groupDescription); else bodyDeclarationsListRewrite.insertAfter(placeholder, fDeclaration, groupDescription); else bodyDeclarationsListRewrite.replace(fDeclaration, placeholder, groupDescription); } catch (BadLocationException e) { JavaPlugin.log(e); } }
Example 6
Source File: LocalCorrectionsSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static void addCasesOmittedProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot()); if (selectedNode instanceof Expression && selectedNode.getLocationInParent() == SwitchStatement.EXPRESSION_PROPERTY) { AST ast= selectedNode.getAST(); SwitchStatement parent= (SwitchStatement) selectedNode.getParent(); for (Statement statement : (List<Statement>) parent.statements()) { if (statement instanceof SwitchCase && ((SwitchCase) statement).isDefault()) { // insert //$CASES-OMITTED$: ASTRewrite rewrite= ASTRewrite.create(ast); rewrite.setTargetSourceRangeComputer(new NoCommentSourceRangeComputer()); ListRewrite listRewrite= rewrite.getListRewrite(parent, SwitchStatement.STATEMENTS_PROPERTY); ASTNode casesOmittedComment= rewrite.createStringPlaceholder("//$CASES-OMITTED$", ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$ listRewrite.insertBefore(casesOmittedComment, statement, null); String label= CorrectionMessages.LocalCorrectionsSubProcessor_insert_cases_omitted; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.INSERT_CASES_OMITTED, image); proposals.add(proposal); break; } } } }
Example 7
Source File: ReorgPolicyFactory.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private void insertRelative(ASTNode newNode, ASTNode relativeNode, ListRewrite listRewrite) { final List<?> list= listRewrite.getOriginalList(); final int index= list.indexOf(relativeNode); if (getLocation() == IReorgDestination.LOCATION_BEFORE) { listRewrite.insertBefore(newNode, (ASTNode) list.get(index), null); } else if (index + 1 < list.size()) { listRewrite.insertBefore(newNode, (ASTNode) list.get(index + 1), null); } else { listRewrite.insertLast(newNode, null); } }
Example 8
Source File: CreateElementInCUOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Inserts the given child into the given AST, * based on the position settings of this operation. * * @see #createAfter(IJavaElement) * @see #createBefore(IJavaElement) */ protected void insertASTNode(ASTRewrite rewriter, ASTNode parent, ASTNode child) throws JavaModelException { StructuralPropertyDescriptor propertyDescriptor = getChildPropertyDescriptor(parent); if (propertyDescriptor instanceof ChildListPropertyDescriptor) { ChildListPropertyDescriptor childListPropertyDescriptor = (ChildListPropertyDescriptor) propertyDescriptor; ListRewrite rewrite = rewriter.getListRewrite(parent, childListPropertyDescriptor); switch (this.insertionPolicy) { case INSERT_BEFORE: ASTNode element = ((JavaElement) this.anchorElement).findNode(this.cuAST); if (childListPropertyDescriptor.getElementType().isAssignableFrom(element.getClass())) rewrite.insertBefore(child, element, null); else // case of an empty import list: the anchor element is the top level type and cannot be used in insertBefore as it is not the same type rewrite.insertLast(child, null); break; case INSERT_AFTER: element = ((JavaElement) this.anchorElement).findNode(this.cuAST); if (childListPropertyDescriptor.getElementType().isAssignableFrom(element.getClass())) rewrite.insertAfter(child, element, null); else // case of an empty import list: the anchor element is the top level type and cannot be used in insertAfter as it is not the same type rewrite.insertLast(child, null); break; case INSERT_LAST: rewrite.insertLast(child, null); break; } } else { rewriter.set(parent, propertyDescriptor, child, null); } }
Example 9
Source File: LocalCorrectionsSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static void addFallThroughProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot()); if (selectedNode instanceof SwitchCase && selectedNode.getLocationInParent() == SwitchStatement.STATEMENTS_PROPERTY) { AST ast= selectedNode.getAST(); ASTNode parent= selectedNode.getParent(); // insert break: ASTRewrite rewrite= ASTRewrite.create(ast); ListRewrite listRewrite= rewrite.getListRewrite(parent, SwitchStatement.STATEMENTS_PROPERTY); listRewrite.insertBefore(ast.newBreakStatement(), selectedNode, null); String label= CorrectionMessages.LocalCorrectionsSubProcessor_insert_break_statement; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.INSERT_BREAK_STATEMENT, image); proposals.add(proposal); // insert //$FALL-THROUGH$: rewrite= ASTRewrite.create(ast); rewrite.setTargetSourceRangeComputer(new NoCommentSourceRangeComputer()); listRewrite= rewrite.getListRewrite(parent, SwitchStatement.STATEMENTS_PROPERTY); ASTNode fallThroughComment= rewrite.createStringPlaceholder("//$FALL-THROUGH$", ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$ listRewrite.insertBefore(fallThroughComment, selectedNode, null); label= CorrectionMessages.LocalCorrectionsSubProcessor_insert_fall_through; image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.INSERT_FALL_THROUGH, image); proposals.add(proposal); } }
Example 10
Source File: GenerateHashCodeEqualsOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void addMethod(ListRewrite rewriter, ASTNode insertion, MethodDeclaration stub, BodyDeclaration replace) { if (replace != null) { rewriter.replace(replace, stub, null); } else { if (insertion != null) rewriter.insertBefore(stub, insertion, null); else rewriter.insertLast(stub, null); } }
Example 11
Source File: GenerateToStringOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected void insertMethod(MethodDeclaration method, ListRewrite rewriter, BodyDeclaration replace) throws JavaModelException { if (replace != null) { rewriter.replace(replace, method, null); } else { ASTNode insertion= StubUtility2.getNodeToInsertBefore(rewriter, fInsert); if (insertion != null) rewriter.insertBefore(method, insertion, null); else rewriter.insertLast(method, null); } }
Example 12
Source File: ReorgPolicyFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void insertRelative(ASTNode newNode, ASTNode relativeNode, ListRewrite listRewrite) { final List<?> list= listRewrite.getOriginalList(); final int index= list.indexOf(relativeNode); if (getLocation() == IReorgDestination.LOCATION_BEFORE) { listRewrite.insertBefore(newNode, (ASTNode) list.get(index), null); } else if (index + 1 < list.size()) { listRewrite.insertBefore(newNode, (ASTNode) list.get(index + 1), null); } else { listRewrite.insertLast(newNode, null); } }
Example 13
Source File: ExtractTempRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void insertAt(ASTNode target, Statement declaration) { ASTRewrite rewrite= fCURewrite.getASTRewrite(); TextEditGroup groupDescription= fCURewrite.createGroupDescription(RefactoringCoreMessages.ExtractTempRefactoring_declare_local_variable); ASTNode parent= target.getParent(); StructuralPropertyDescriptor locationInParent= target.getLocationInParent(); while (locationInParent != Block.STATEMENTS_PROPERTY && locationInParent != SwitchStatement.STATEMENTS_PROPERTY) { if (locationInParent == IfStatement.THEN_STATEMENT_PROPERTY || locationInParent == IfStatement.ELSE_STATEMENT_PROPERTY || locationInParent == ForStatement.BODY_PROPERTY || locationInParent == EnhancedForStatement.BODY_PROPERTY || locationInParent == DoStatement.BODY_PROPERTY || locationInParent == WhileStatement.BODY_PROPERTY) { // create intermediate block if target was the body property of a control statement: Block replacement= rewrite.getAST().newBlock(); ListRewrite replacementRewrite= rewrite.getListRewrite(replacement, Block.STATEMENTS_PROPERTY); replacementRewrite.insertFirst(declaration, null); replacementRewrite.insertLast(rewrite.createMoveTarget(target), null); rewrite.replace(target, replacement, groupDescription); return; } target= parent; parent= parent.getParent(); locationInParent= target.getLocationInParent(); } ListRewrite listRewrite= rewrite.getListRewrite(parent, (ChildListPropertyDescriptor)locationInParent); listRewrite.insertBefore(declaration, target, groupDescription); }
Example 14
Source File: IntroduceParameterObjectProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void createParameterClass(MethodDeclaration methodDeclaration, CompilationUnitRewrite cuRewrite) throws CoreException { if (fCreateAsTopLevel) { IPackageFragmentRoot root= (IPackageFragmentRoot) cuRewrite.getCu().getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); fOtherChanges.addAll(fParameterObjectFactory.createTopLevelParameterObject(root)); } else { ASTRewrite rewriter= cuRewrite.getASTRewrite(); TypeDeclaration enclosingType= (TypeDeclaration) methodDeclaration.getParent(); ListRewrite bodyRewrite= rewriter.getListRewrite(enclosingType, TypeDeclaration.BODY_DECLARATIONS_PROPERTY); String fqn= enclosingType.getName().getFullyQualifiedName(); TypeDeclaration classDeclaration= fParameterObjectFactory.createClassDeclaration(fqn, cuRewrite, null); classDeclaration.modifiers().add(rewriter.getAST().newModifier(ModifierKeyword.PUBLIC_KEYWORD)); classDeclaration.modifiers().add(rewriter.getAST().newModifier(ModifierKeyword.STATIC_KEYWORD)); bodyRewrite.insertBefore(classDeclaration, methodDeclaration, null); } }
Example 15
Source File: DelegateCreator.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * Performs the actual rewriting and adds an edit to the ASTRewrite set with * {@link #setSourceRewrite(CompilationUnitRewrite)}. * * @throws JavaModelException */ public void createEdit() throws JavaModelException { try { IDocument document= new Document(fDelegateRewrite.getCu().getBuffer().getContents()); TextEdit edit= fDelegateRewrite.getASTRewrite().rewriteAST(document, fDelegateRewrite.getCu().getJavaProject().getOptions(true)); edit.apply(document, TextEdit.UPDATE_REGIONS); int tabWidth = CodeFormatterUtil.getTabWidth(fOriginalRewrite.getCu().getJavaProject()); int identWidth = CodeFormatterUtil.getIndentWidth(fOriginalRewrite.getCu().getJavaProject()); String newSource= Strings.trimIndentation(document.get(fTrackedPosition.getStartPosition(), fTrackedPosition.getLength()), tabWidth, identWidth, false); ASTNode placeholder= fOriginalRewrite.getASTRewrite().createStringPlaceholder(newSource, fDeclaration.getNodeType()); CategorizedTextEditGroup groupDescription= fOriginalRewrite.createCategorizedGroupDescription(getTextEditGroupLabel(), CATEGORY_DELEGATE); ListRewrite bodyDeclarationsListRewrite= fOriginalRewrite.getASTRewrite().getListRewrite(fDeclaration.getParent(), getTypeBodyDeclarationsProperty()); if (fCopy) { if (fInsertBefore) { bodyDeclarationsListRewrite.insertBefore(placeholder, fDeclaration, groupDescription); } else { bodyDeclarationsListRewrite.insertAfter(placeholder, fDeclaration, groupDescription); } } else { bodyDeclarationsListRewrite.replace(fDeclaration, placeholder, groupDescription); } } catch (BadLocationException e) { //JavaPlugin.log(e); } }
Example 16
Source File: GenerateHashCodeEqualsOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void addHelper(ListRewrite rewriter, ASTNode insertion, MethodDeclaration stub) { if (insertion != null) rewriter.insertBefore(stub, insertion, null); else rewriter.insertFirst(stub, null); }
Example 17
Source File: MoveInstanceMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Creates the method comment for the target method declaration. * * @param rewrite * the source ast rewrite * @param declaration * the source method declaration * @throws JavaModelException * if the argument references could not be generated */ protected void createMethodComment(final ASTRewrite rewrite, final MethodDeclaration declaration) throws JavaModelException { Assert.isNotNull(rewrite); Assert.isNotNull(declaration); final Javadoc comment= declaration.getJavadoc(); if (comment != null) { final List<TagElement> tags= new LinkedList<TagElement>(comment.tags()); final IVariableBinding[] bindings= getArgumentBindings(declaration); final Map<String, TagElement> elements= new HashMap<String, TagElement>(bindings.length); String name= null; List<? extends ASTNode> fragments= null; TagElement element= null; TagElement reference= null; IVariableBinding binding= null; for (int index= 0; index < bindings.length; index++) { binding= bindings[index]; for (final Iterator<TagElement> iterator= comment.tags().iterator(); iterator.hasNext();) { element= iterator.next(); name= element.getTagName(); fragments= element.fragments(); if (name != null) { if (name.equals(TagElement.TAG_PARAM) && !fragments.isEmpty() && fragments.get(0) instanceof SimpleName) { final SimpleName simple= (SimpleName) fragments.get(0); if (binding.getName().equals(simple.getIdentifier())) { elements.put(binding.getKey(), element); tags.remove(element); } } else if (reference == null) reference= element; } } } if (bindings.length == 0 && reference == null) { for (final Iterator<TagElement> iterator= comment.tags().iterator(); iterator.hasNext();) { element= iterator.next(); name= element.getTagName(); fragments= element.fragments(); if (name != null && !name.equals(TagElement.TAG_PARAM)) reference= element; } } final List<ASTNode> arguments= new ArrayList<ASTNode>(bindings.length + 1); createArgumentList(declaration, arguments, new IArgumentFactory() { public final ASTNode getArgumentNode(final IVariableBinding argument, final boolean last) throws JavaModelException { Assert.isNotNull(argument); if (elements.containsKey(argument.getKey())) return rewrite.createCopyTarget(elements.get(argument.getKey())); return JavadocUtil.createParamTag(argument.getName(), declaration.getAST(), fMethod.getJavaProject()); } public final ASTNode getTargetNode() throws JavaModelException { return JavadocUtil.createParamTag(fTargetName, declaration.getAST(), fMethod.getJavaProject()); } }); final ListRewrite rewriter= rewrite.getListRewrite(comment, Javadoc.TAGS_PROPERTY); ASTNode tag= null; for (final Iterator<TagElement> iterator= comment.tags().iterator(); iterator.hasNext();) { tag= iterator.next(); if (!tags.contains(tag)) rewriter.remove(tag, null); } for (final Iterator<ASTNode> iterator= arguments.iterator(); iterator.hasNext();) { tag= iterator.next(); if (reference != null) rewriter.insertBefore(tag, reference, null); else rewriter.insertLast(tag, null); } } }
Example 18
Source File: AddGetterSetterOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 3 votes |
/** * Adds a new accessor for the specified field. * * @param type the type * @param field the field * @param contents the contents of the accessor method * @param rewrite the list rewrite to use * @param insertion the insertion point * @throws JavaModelException if an error occurs */ private void addNewAccessor(final IType type, final IField field, final String contents, final ListRewrite rewrite, final ASTNode insertion) throws JavaModelException { final String delimiter= StubUtility.getLineDelimiterUsed(type); final MethodDeclaration declaration= (MethodDeclaration) rewrite.getASTRewrite().createStringPlaceholder(CodeFormatterUtil.format(CodeFormatter.K_CLASS_BODY_DECLARATIONS, contents, 0, delimiter, field.getJavaProject()), ASTNode.METHOD_DECLARATION); if (insertion != null) rewrite.insertBefore(declaration, insertion, null); else rewrite.insertLast(declaration, null); }