private void add(final Queue<RefactoringUnit> results, ICompilationUnit cu, JavaProjectOptions options) throws JavaModelException { if (!cu.isConsistent()) { cu.makeConsistent(null); } if (!cu.isReadOnly()) { results.add(new RefactoringUnit(cu, options)); } }
protected CompilationUnit parse(ICompilationUnit cu) throws JavaModelException { // ensure cu is consistent (noop if already consistent) cu.makeConsistent(this.progressMonitor); // create an AST for the compilation unit ASTParser parser = ASTParser.newParser(AST.JLS11); parser.setSource(cu); return (CompilationUnit) parser.createAST(this.progressMonitor); } /**
protected CompilationUnit parse(ICompilationUnit cu) throws JavaModelException { // ensure cu is consistent (noop if already consistent) cu.makeConsistent(this.progressMonitor); // create an AST for the compilation unit ASTParser parser = ASTParser.newParser(AST.JLS9); parser.setSource(cu); return (CompilationUnit) parser.createAST(this.progressMonitor); } /**
protected CompilationUnit parse(ICompilationUnit cu) throws JavaModelException { // ensure cu is consistent (noop if already consistent) cu.makeConsistent(this.progressMonitor); // create an AST for the compilation unit ASTParser parser = ASTParser.newParser(AST.JLS8); parser.setSource(cu); return (CompilationUnit) parser.createAST(this.progressMonitor); } /**
protected CompilationUnit parse(ICompilationUnit cu) throws JavaModelException { // ensure cu is consistent (noop if already consistent) cu.makeConsistent(this.progressMonitor); // create an AST for the compilation unit ASTParser parser = ASTParser.newParser(AST.JLS8); parser.setSource(cu); return (CompilationUnit) parser.createAST(this.progressMonitor); } /**
protected CompilationUnit parse(ICompilationUnit cu) throws JavaModelException { // ensure cu is consistent (noop if already consistent) cu.makeConsistent(this.progressMonitor); // create an AST for the compilation unit ASTParser parser = ASTParser.newParser(AST.JLS8); parser.setSource(cu); return (CompilationUnit) parser.createAST(this.progressMonitor); } /**
protected CompilationUnit parse(ICompilationUnit cu) throws JavaModelException { // ensure cu is consistent (noop if already consistent) cu.makeConsistent(this.progressMonitor); // create an AST for the compilation unit ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(cu); return (CompilationUnit) parser.createAST(this.progressMonitor); } /**
/** * {@inheritDoc} */ protected void releaseDocument(IDocument document, IProgressMonitor pm) throws CoreException { boolean isModified= isDocumentModified(); super.releaseDocument(document, pm); try { fCUnit.discardWorkingCopy(); } finally { if (isModified && !isDocumentAcquired()) { if (fCUnit.isWorkingCopy()) JavaModelUtil.reconcile(fCUnit); else fCUnit.makeConsistent(pm); } } }
/** * Reconciles the compilation unit for this JSPTranslation */ public void reconcileCompilationUnit() { ICompilationUnit cu = getCompilationUnit(); if (cu != null) { try { synchronized(cu) { cu.makeConsistent(getProgressMonitor()); cu.reconcile(ICompilationUnit.NO_AST, true, getWorkingCopyOwner(), getProgressMonitor()); } } catch (JavaModelException e) { Logger.logException(e); } } }
private void deleteElement(IJavaElement elementToRemove, ICompilationUnit cu) throws JavaModelException { // ensure cu is consistent (noop if already consistent) cu.makeConsistent(this.progressMonitor); this.parser.setSource(cu); CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor); ASTNode node = ((JavaElement) elementToRemove).findNode(astCU); if (node == null) Assert.isTrue(false, "Failed to locate " + elementToRemove.getElementName() + " in " + cu.getElementName()); //$NON-NLS-1$//$NON-NLS-2$ AST ast = astCU.getAST(); ASTRewrite rewriter = ASTRewrite.create(ast); rewriter.remove(node, null); TextEdit edits = rewriter.rewriteAST(); applyTextEdit(cu, edits); }
private void deleteElement(IJavaElement elementToRemove, ICompilationUnit cu) throws JavaModelException { // ensure cu is consistent (noop if already consistent) cu.makeConsistent(this.progressMonitor); this.parser.setSource(cu); CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor); ASTNode node = ((JavaElement) elementToRemove).findNode(astCU); if (node == null) Assert.isTrue(false, "Failed to locate " + elementToRemove.getElementName() + " in " + cu.getElementName()); //$NON-NLS-1$//$NON-NLS-2$ AST ast = astCU.getAST(); ASTRewrite rewriter = ASTRewrite.create(ast); rewriter.remove(node, null); TextEdit edits = rewriter.rewriteAST(); applyTextEdit(cu, edits); }
private void deleteElement(IJavaElement elementToRemove, ICompilationUnit cu) throws JavaModelException { // ensure cu is consistent (noop if already consistent) cu.makeConsistent(this.progressMonitor); this.parser.setSource(cu); CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor); ASTNode node = ((JavaElement) elementToRemove).findNode(astCU); if (node == null) Assert.isTrue(false, "Failed to locate " + elementToRemove.getElementName() + " in " + cu.getElementName()); //$NON-NLS-1$//$NON-NLS-2$ AST ast = astCU.getAST(); ASTRewrite rewriter = ASTRewrite.create(ast); rewriter.remove(node, null); TextEdit edits = rewriter.rewriteAST(); applyTextEdit(cu, edits); }
private void deleteElement(IJavaElement elementToRemove, ICompilationUnit cu) throws JavaModelException { // ensure cu is consistent (noop if already consistent) cu.makeConsistent(this.progressMonitor); this.parser.setSource(cu); CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor); ASTNode node = ((JavaElement) elementToRemove).findNode(astCU); if (node == null) Assert.isTrue(false, "Failed to locate " + elementToRemove.getElementName() + " in " + cu.getElementName()); //$NON-NLS-1$//$NON-NLS-2$ AST ast = astCU.getAST(); ASTRewrite rewriter = ASTRewrite.create(ast); rewriter.remove(node, null); TextEdit edits = rewriter.rewriteAST(); applyTextEdit(cu, edits); }
private void deleteElement(IJavaElement elementToRemove, ICompilationUnit cu) throws JavaModelException { // ensure cu is consistent (noop if already consistent) cu.makeConsistent(this.progressMonitor); this.parser.setSource(cu); CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor); ASTNode node = ((JavaElement) elementToRemove).findNode(astCU); if (node == null) Assert.isTrue(false, "Failed to locate " + elementToRemove.getElementName() + " in " + cu.getElementName()); //$NON-NLS-1$//$NON-NLS-2$ AST ast = astCU.getAST(); ASTRewrite rewriter = ASTRewrite.create(ast); rewriter.remove(node, null); TextEdit edits = rewriter.rewriteAST(); applyTextEdit(cu, edits); }
private void deleteElement(IJavaElement elementToRemove, ICompilationUnit cu) throws JavaModelException { // ensure cu is consistent (noop if already consistent) cu.makeConsistent(this.progressMonitor); this.parser.setSource(cu); CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor); ASTNode node = ((JavaElement) elementToRemove).findNode(astCU); if (node == null) Assert.isTrue(false, "Failed to locate " + elementToRemove.getElementName() + " in " + cu.getElementName()); //$NON-NLS-1$//$NON-NLS-2$ AST ast = astCU.getAST(); ASTRewrite rewriter = ASTRewrite.create(ast); rewriter.remove(node, null); TextEdit edits = rewriter.rewriteAST(); applyTextEdit(cu, edits); }
@Override protected void releaseDocument(IDocument document, IProgressMonitor pm) throws CoreException { boolean isModified= isDocumentModified(); SubMonitor subMonitor= SubMonitor.convert(pm, 2); super.releaseDocument(document, subMonitor.split(1)); try { fCUnit.discardWorkingCopy(); } finally { if (isModified && !isDocumentAcquired()) { if (fCUnit.isWorkingCopy()) fCUnit.reconcile( ICompilationUnit.NO_AST, false /* don't force problem detection */, null /* use primary owner */, subMonitor.split(1, SubMonitor.SUPPRESS_BEGINTASK | SubMonitor.SUPPRESS_ISCANCELED)); else fCUnit.makeConsistent(subMonitor.split(1, SubMonitor.SUPPRESS_BEGINTASK | SubMonitor.SUPPRESS_ISCANCELED)); } } }
/** * Updates the content of <code>cu</code>, modifying the type name and/or package * declaration as necessary. * * @return an AST rewrite or null if no rewrite needed */ private TextEdit updateContent(ICompilationUnit cu, PackageFragment dest, String newName) throws JavaModelException { String[] currPackageName = ((PackageFragment) cu.getParent()).names; String[] destPackageName = dest.names; if (Util.equalArraysOrNull(currPackageName, destPackageName) && newName == null) { return null; //nothing to change } else { // ensure cu is consistent (noop if already consistent) cu.makeConsistent(this.progressMonitor); this.parser.setSource(cu); CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor); AST ast = astCU.getAST(); ASTRewrite rewrite = ASTRewrite.create(ast); updateTypeName(cu, astCU, cu.getElementName(), newName, rewrite); updatePackageStatement(astCU, destPackageName, rewrite, cu); return rewrite.rewriteAST(); } } private void updatePackageStatement(CompilationUnit astCU, String[] pkgName, ASTRewrite rewriter, ICompilationUnit cu) throws JavaModelException {
/** * Updates the content of <code>cu</code>, modifying the type name and/or package * declaration as necessary. * * @return an AST rewrite or null if no rewrite needed */ private TextEdit updateContent(ICompilationUnit cu, PackageFragment dest, String newName) throws JavaModelException { String[] currPackageName = ((PackageFragment) cu.getParent()).names; String[] destPackageName = dest.names; if (Util.equalArraysOrNull(currPackageName, destPackageName) && newName == null) { return null; //nothing to change } else { // ensure cu is consistent (noop if already consistent) cu.makeConsistent(this.progressMonitor); this.parser.setSource(cu); CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor); AST ast = astCU.getAST(); ASTRewrite rewrite = ASTRewrite.create(ast); updateTypeName(cu, astCU, cu.getElementName(), newName, rewrite); updatePackageStatement(astCU, destPackageName, rewrite, cu); return rewrite.rewriteAST(); } } private void updatePackageStatement(CompilationUnit astCU, String[] pkgName, ASTRewrite rewriter, ICompilationUnit cu) throws JavaModelException {
/** * Updates the content of <code>cu</code>, modifying the type name and/or package * declaration as necessary. * * @return an AST rewrite or null if no rewrite needed */ private TextEdit updateContent(ICompilationUnit cu, PackageFragment dest, String newName) throws JavaModelException { String[] currPackageName = ((PackageFragment) cu.getParent()).names; String[] destPackageName = dest.names; if (Util.equalArraysOrNull(currPackageName, destPackageName) && newName == null) { return null; //nothing to change } else { // ensure cu is consistent (noop if already consistent) cu.makeConsistent(this.progressMonitor); this.parser.setSource(cu); CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor); AST ast = astCU.getAST(); ASTRewrite rewrite = ASTRewrite.create(ast); updateTypeName(cu, astCU, cu.getElementName(), newName, rewrite); updatePackageStatement(astCU, destPackageName, rewrite, cu); return rewrite.rewriteAST(); } } private void updatePackageStatement(CompilationUnit astCU, String[] pkgName, ASTRewrite rewriter, ICompilationUnit cu) throws JavaModelException {
/** * Updates the content of <code>cu</code>, modifying the type name and/or package * declaration as necessary. * * @return an AST rewrite or null if no rewrite needed */ private TextEdit updateContent(ICompilationUnit cu, PackageFragment dest, String newName) throws JavaModelException { String[] currPackageName = ((PackageFragment) cu.getParent()).names; String[] destPackageName = dest.names; if (Util.equalArraysOrNull(currPackageName, destPackageName) && newName == null) { return null; //nothing to change } else { // ensure cu is consistent (noop if already consistent) cu.makeConsistent(this.progressMonitor); this.parser.setSource(cu); CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor); AST ast = astCU.getAST(); ASTRewrite rewrite = ASTRewrite.create(ast); updateTypeName(cu, astCU, cu.getElementName(), newName, rewrite); updatePackageStatement(astCU, destPackageName, rewrite, cu); return rewrite.rewriteAST(); } } private void updatePackageStatement(CompilationUnit astCU, String[] pkgName, ASTRewrite rewriter, ICompilationUnit cu) throws JavaModelException {