@Override public CompilationUnit getASTRoot() { if (fASTRoot == null) { fASTRoot= SharedASTProvider.getAST(fCompilationUnit, fWaitFlag, null); if (fASTRoot == null) { // see bug 63554 fASTRoot= ASTResolving.createQuickFixAST(fCompilationUnit, null); } } return fASTRoot; }
private static CompilationUnit getASTRoot(ICompilationUnit compilationUnit, IProgressMonitor monitor) { CompilationUnit result= ASTProvider.getASTProvider().getAST(compilationUnit, ASTProvider.WAIT_YES, monitor); if (result == null) { // see bug 63554 result= ASTResolving.createQuickFixAST(compilationUnit, monitor); } return result; } }
public CompilationUnit getASTRoot() { if (fASTRoot == null) { fASTRoot= ASTProvider.getASTProvider().getAST(fCompilationUnit, ASTProvider.WAIT_YES, null); if (fASTRoot == null) { // see bug 63554 fASTRoot= ASTResolving.createQuickFixAST(fCompilationUnit, null); } } return fASTRoot; }
private static CompilationUnit findCUForMethod(CompilationUnit compilationUnit, ICompilationUnit cu, IMethodBinding methodBinding) { ASTNode methodDecl= compilationUnit.findDeclaringNode(methodBinding.getMethodDeclaration()); if (methodDecl == null) { // is methodDecl defined in another CU? ITypeBinding declaringTypeDecl= methodBinding.getDeclaringClass().getTypeDeclaration(); if (declaringTypeDecl.isFromSource()) { ICompilationUnit targetCU= null; try { targetCU= ASTResolving.findCompilationUnitForBinding(cu, compilationUnit, declaringTypeDecl); } catch (JavaModelException e) { /* can't do better */ } if (targetCU != null) { return ASTResolving.createQuickFixAST(targetCU, null); } } return null; } return compilationUnit; }
@Override protected ASTRewrite getRewrite() throws CoreException { CompilationUnit astRoot= ASTResolving.findParentCompilationUnit(fInvocationNode); ASTNode typeDecl= astRoot.findDeclaringNode(fSenderBinding); ASTNode newTypeDecl= null; if (typeDecl != null) { newTypeDecl= typeDecl; } else { astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey()); } createImportRewrite(astRoot); if (newTypeDecl instanceof AnnotationTypeDeclaration) { AnnotationTypeDeclaration newAnnotationTypeDecl= (AnnotationTypeDeclaration) newTypeDecl; ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST()); AnnotationTypeMemberDeclaration newStub= getStub(rewrite, newAnnotationTypeDecl); List<BodyDeclaration> members= newAnnotationTypeDecl.bodyDeclarations(); int insertIndex= members.size(); ListRewrite listRewriter= rewrite.getListRewrite(newAnnotationTypeDecl, AnnotationTypeDeclaration.BODY_DECLARATIONS_PROPERTY); listRewriter.insertAt(newStub, insertIndex, null); return rewrite; } return null; }
protected ASTRewrite getRewrite() throws CoreException { CompilationUnit astRoot= ASTResolving.findParentCompilationUnit(fInvocationNode); ASTNode typeDecl= astRoot.findDeclaringNode(fSenderBinding); ASTNode newTypeDecl= null; if (typeDecl != null) { newTypeDecl= typeDecl; } else { astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey()); } createImportRewrite(astRoot); if (newTypeDecl instanceof AnnotationTypeDeclaration) { ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST()); AnnotationTypeMemberDeclaration newStub= getStub(rewrite, (AnnotationTypeDeclaration) newTypeDecl); ChildListPropertyDescriptor property= ASTNodes.getBodyDeclarationsProperty(newTypeDecl); List members= (List) newTypeDecl.getStructuralProperty(property); int insertIndex= members.size(); ListRewrite listRewriter= rewrite.getListRewrite(newTypeDecl, property); listRewriter.insertAt(newStub, insertIndex, null); return rewrite; } return null; }
protected ASTRewrite getRewrite() throws CoreException { CompilationUnit astRoot= (CompilationUnit) fInvocationNode.getRoot(); ASTNode methodDecl= astRoot.findDeclaringNode(fSenderBinding); ASTNode newMethodDecl= null; boolean isInDifferentCU; if (methodDecl != null) { isInDifferentCU= false; newMethodDecl= methodDecl; } else { isInDifferentCU= true; astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); newMethodDecl= astRoot.findDeclaringNode(fSenderBinding.getKey()); } createImportRewrite(astRoot); if (newMethodDecl instanceof MethodDeclaration) { MethodDeclaration decl= (MethodDeclaration) newMethodDecl; ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST()); if (fParameterChanges != null) { modifyParameters(rewrite, decl, isInDifferentCU); } if (fExceptionChanges != null) { modifyExceptions(rewrite, decl); } return rewrite; } return null; }
@Override protected ASTRewrite getRewrite() throws CoreException { CompilationUnit astRoot= (CompilationUnit) fInvocationNode.getRoot(); ASTNode methodDecl= astRoot.findDeclaringNode(fSenderBinding); ASTNode newMethodDecl= null; if (methodDecl != null) { newMethodDecl= methodDecl; } else { astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); newMethodDecl= astRoot.findDeclaringNode(fSenderBinding.getKey()); } createImportRewrite(astRoot); if (newMethodDecl instanceof MethodDeclaration) { MethodDeclaration decl= (MethodDeclaration) newMethodDecl; ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST()); if (fParameterChanges != null) { modifyParameters(rewrite, decl); } if (fExceptionChanges != null) { modifyExceptions(rewrite, decl); } return rewrite; } return null; }
selectionDescription= new TextEditGroup("selection"); // in different CU, needs selection //$NON-NLS-1$ CompilationUnit newRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); declNode= newRoot.findDeclaringNode(fBinding.getKey());
protected ASTRewrite getRewrite() throws CoreException { ASTNode boundNode= fAstRoot.findDeclaringNode(fBinding); ASTNode declNode= null; CompilationUnit newRoot= fAstRoot; if (boundNode != null) { declNode= boundNode; // is same CU } else { newRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); declNode= newRoot.findDeclaringNode(fBinding.getKey()); } ImportRewrite imports= createImportRewrite(newRoot); if (declNode instanceof TypeDeclaration) { AST ast= declNode.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); Type newInterface= imports.addImport(fNewInterface, ast); ListRewrite listRewrite= rewrite.getListRewrite(declNode, TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY); listRewrite.insertLast(newInterface, null); // set up linked mode final String KEY_TYPE= "type"; //$NON-NLS-1$ addLinkedPosition(rewrite.track(newInterface), true, KEY_TYPE); return rewrite; } return null; }
@Override protected ASTRewrite getRewrite() throws CoreException { ASTNode boundNode= fAstRoot.findDeclaringNode(fBinding); ASTNode declNode= null; CompilationUnit newRoot= fAstRoot; if (boundNode != null) { declNode= boundNode; // is same CU } else { newRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); declNode= newRoot.findDeclaringNode(fBinding.getKey()); } ImportRewrite imports= createImportRewrite(newRoot); if (declNode instanceof TypeDeclaration) { AST ast= declNode.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(declNode, imports); Type newInterface= imports.addImport(fNewInterface, ast, importRewriteContext); ListRewrite listRewrite= rewrite.getListRewrite(declNode, TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY); listRewrite.insertLast(newInterface, null); // set up linked mode final String KEY_TYPE= "type"; //$NON-NLS-1$ addLinkedPosition(rewrite.track(newInterface), true, KEY_TYPE); return rewrite; } return null; }
@Override protected ASTRewrite getRewrite() throws CoreException { if (fMethodDeclaration == null) { CompilationUnit astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); fMethodDeclaration= (MethodDeclaration) astRoot.findDeclaringNode(fMethodBinding.getKey()); } AST ast= fMethodDeclaration.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); ListRewrite listRewrite= rewrite.getListRewrite(fMethodDeclaration, MethodDeclaration.MODIFIERS2_PROPERTY); MarkerAnnotation annotation= ast.newMarkerAnnotation(); String importString= createImportRewrite((CompilationUnit) fMethodDeclaration.getRoot()).addImport("java.lang.SafeVarargs"); //$NON-NLS-1$ annotation.setTypeName(ast.newName(importString)); listRewrite.insertFirst(annotation, null); // set up linked mode addLinkedPosition(rewrite.track(annotation), true, "annotation"); //$NON-NLS-1$ return rewrite; }
} else { isInDifferentCU= true; astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey());
private ASTRewrite doAddEnumConst(CompilationUnit astRoot) throws CoreException { SimpleName node= fOriginalNode; ASTNode newTypeDecl= astRoot.findDeclaringNode(fSenderBinding); if (newTypeDecl == null) { astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey()); } if (newTypeDecl != null) { AST ast= newTypeDecl.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); EnumConstantDeclaration constDecl= ast.newEnumConstantDeclaration(); constDecl.setName(ast.newSimpleName(node.getIdentifier())); ListRewrite listRewriter= rewrite.getListRewrite(newTypeDecl, EnumDeclaration.ENUM_CONSTANTS_PROPERTY); listRewriter.insertLast(constDecl, null); addLinkedPosition(rewrite.track(constDecl.getName()), false, KEY_NAME); return rewrite; } return null; }
} else { isInDifferentCU= true; astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey());
private ASTRewrite doAddEnumConst(CompilationUnit astRoot) { SimpleName node= fOriginalNode; ASTNode newTypeDecl= astRoot.findDeclaringNode(fSenderBinding); if (newTypeDecl == null) { astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey()); } if (newTypeDecl != null) { AST ast= newTypeDecl.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); EnumConstantDeclaration constDecl= ast.newEnumConstantDeclaration(); constDecl.setName(ast.newSimpleName(node.getIdentifier())); ListRewrite listRewriter= rewrite.getListRewrite(newTypeDecl, EnumDeclaration.ENUM_CONSTANTS_PROPERTY); listRewriter.insertLast(constDecl, null); addLinkedPosition(rewrite.track(constDecl.getName()), false, KEY_NAME); return rewrite; } return null; }
CompilationUnit newRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); declNode= newRoot.findDeclaringNode(fBinding.getKey()); createImportRewrite(newRoot);
CompilationUnit newRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); declNode= newRoot.findDeclaringNode(fBinding.getKey()); createImportRewrite(newRoot);
astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey()); isInDifferentCU= true;
astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null); newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey()); isInDifferentCU= true;