public void dispose() { try { RefactoringFileBuffers.release(fCUnit); } catch (CoreException exception) { JavaPlugin.log(exception); } }
public void dispose() { try { RefactoringFileBuffers.release(fCUnit); } catch (CoreException exception) { JavaPlugin.log(exception); } }
public void dispose() { try { RefactoringFileBuffers.release(fCUnit); } catch (CoreException exception) { JavaPlugin.log(exception); } }
public static StubTypeContext createStubTypeContext(ICompilationUnit cu, CompilationUnit root, int focalPosition) throws CoreException { IDocument document= RefactoringFileBuffers.acquire(cu).getDocument(); try { StringBuffer bufBefore= new StringBuffer(); StringBuffer bufAfter= new StringBuffer(); int introEnd= 0; PackageDeclaration pack= root.getPackage(); if (pack != null) introEnd= pack.getStartPosition() + pack.getLength(); List imports= root.imports(); if (imports.size() > 0) { ImportDeclaration lastImport= (ImportDeclaration) imports.get(imports.size() - 1); introEnd= lastImport.getStartPosition() + lastImport.getLength(); } try { bufBefore.append(document.get(0, introEnd)); } catch (BadLocationException e) { throw new RuntimeException(e); // doesn't happen } fillWithTypeStubs(bufBefore, bufAfter, focalPosition, root.types()); bufBefore.append(' '); bufAfter.insert(0, ' '); return new StubTypeContext(cu, bufBefore.toString(), bufAfter.toString()); } finally { RefactoringFileBuffers.release(cu); } }
private static TextChange addTextEditFromRewrite(TextChangeManager manager, ICompilationUnit cu, ASTRewrite rewrite) throws CoreException { try { ITextFileBuffer buffer= RefactoringFileBuffers.acquire(cu); TextEdit resultingEdits= rewrite.rewriteAST(buffer.getDocument(), cu.getJavaProject().getOptions(true)); TextChange textChange= manager.get(cu); if (textChange instanceof TextFileChange) { TextFileChange tfc= (TextFileChange) textChange; tfc.setSaveMode(TextFileChange.KEEP_SAVE_STATE); } String message= RefactoringCoreMessages.DeleteChangeCreator_1; TextChangeCompatibility.addTextEdit(textChange, message, resultingEdits); return textChange; } finally { RefactoringFileBuffers.release(cu); } }
private static TextChange addTextEditFromRewrite(TextChangeManager manager, ICompilationUnit cu, ASTRewrite rewrite) throws CoreException { try { ITextFileBuffer buffer= RefactoringFileBuffers.acquire(cu); TextEdit resultingEdits= rewrite.rewriteAST(buffer.getDocument(), cu.getJavaProject().getOptions(true)); TextChange textChange= manager.get(cu); if (textChange instanceof TextFileChange) { TextFileChange tfc= (TextFileChange) textChange; tfc.setSaveMode(TextFileChange.KEEP_SAVE_STATE); } String message= RefactoringCoreMessages.DeleteChangeCreator_1; TextChangeCompatibility.addTextEdit(textChange, message, resultingEdits); return textChange; } finally { RefactoringFileBuffers.release(cu); } }
private void removePackageDeclaration(final ICompilationUnit cu) throws JavaModelException, CoreException { IPackageDeclaration[] packageDeclarations= cu.getPackageDeclarations(); if (packageDeclarations.length != 0) { ITextFileBuffer buffer= null; try { buffer= RefactoringFileBuffers.acquire(cu); ISourceRange sourceRange= packageDeclarations[0].getSourceRange(); buffer.getDocument().replace(sourceRange.getOffset(), sourceRange.getLength(), ""); //$NON-NLS-1$ } catch (BadLocationException e) { JavaPlugin.log(e); } finally { if (buffer != null) RefactoringFileBuffers.release(cu); } } } };
private void removePackageDeclaration(final ICompilationUnit cu) throws JavaModelException, CoreException { IPackageDeclaration[] packageDeclarations= cu.getPackageDeclarations(); if (packageDeclarations.length != 0) { ITextFileBuffer buffer= null; try { buffer= RefactoringFileBuffers.acquire(cu); ISourceRange sourceRange= packageDeclarations[0].getSourceRange(); buffer.getDocument().replace(sourceRange.getOffset(), sourceRange.getLength(), ""); //$NON-NLS-1$ } catch (BadLocationException e) { JavaPlugin.log(e); } finally { if (buffer != null) RefactoringFileBuffers.release(cu); } } } };
private static TextChange addTextEditFromRewrite(TextChangeManager manager, ICompilationUnit cu, ASTRewrite rewrite) throws CoreException { try { ITextFileBuffer buffer= RefactoringFileBuffers.acquire(cu); TextEdit resultingEdits= rewrite.rewriteAST(buffer.getDocument(), cu.getJavaProject().getOptions(true)); TextChange textChange= manager.get(cu); if (textChange instanceof TextFileChange) { TextFileChange tfc= (TextFileChange) textChange; if (cu.isWorkingCopy()) tfc.setSaveMode(TextFileChange.LEAVE_DIRTY); } String message= RefactoringCoreMessages.DeleteChangeCreator_1; TextChangeCompatibility.addTextEdit(textChange, message, resultingEdits); return textChange; } finally { RefactoringFileBuffers.release(cu); } }
RefactoringFileBuffers.release(unit);
RefactoringFileBuffers.release(unit);
RefactoringFileBuffers.release(unit);
RefactoringFileBuffers.release(context.compilationUnit);
RefactoringFileBuffers.release(context.compilationUnit);
} finally { if (buffer != null) RefactoringFileBuffers.release(unit);
RefactoringFileBuffers.release(cu);
@Override public Change createChange(IProgressMonitor pm) throws CoreException { ASTParser p= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL); p.setSource(getDestinationCu()); CompilationUnit cuNode= (CompilationUnit) p.createAST(pm); ASTRewrite rewrite= ASTRewrite.create(cuNode.getAST()); TypedSource source= null; for (int i= fSources.length - 1; i >= 0; i--) { source= fSources[i]; final ASTNode destination= getDestinationNodeForSourceElement(fDestination, source.getType(), cuNode); if (destination != null) { if (destination instanceof CompilationUnit) insertToCu(rewrite, createNewNodeToInsertToCu(source, rewrite), (CompilationUnit) destination); else if (destination instanceof AbstractTypeDeclaration) insertToType(rewrite, createNewNodeToInsertToType(source, rewrite), (AbstractTypeDeclaration) destination); } } final CompilationUnitChange result= new CompilationUnitChange(ReorgMessages.PasteAction_change_name, getDestinationCu()); try { ITextFileBuffer buffer= RefactoringFileBuffers.acquire(getDestinationCu()); TextEdit rootEdit= rewrite.rewriteAST(buffer.getDocument(), fDestination.getJavaProject().getOptions(true)); if (getDestinationCu().isWorkingCopy()) result.setSaveMode(TextFileChange.LEAVE_DIRTY); TextChangeCompatibility.addTextEdit(result, ReorgMessages.PasteAction_edit_name, rootEdit); } finally { RefactoringFileBuffers.release(getDestinationCu()); } return result; }
RefactoringFileBuffers.release(cu);
public Change createChange(IProgressMonitor pm) throws CoreException { ASTParser p= ASTParser.newParser(AST.JLS3); p.setSource(getDestinationCu()); CompilationUnit cuNode= (CompilationUnit) p.createAST(pm); ASTRewrite rewrite= ASTRewrite.create(cuNode.getAST()); TypedSource source= null; for (int i= fSources.length - 1; i >= 0; i--) { source= fSources[i]; final ASTNode destination= getDestinationNodeForSourceElement(fDestination, source.getType(), cuNode); if (destination != null) { if (destination instanceof CompilationUnit) insertToCu(rewrite, createNewNodeToInsertToCu(source, rewrite), (CompilationUnit) destination); else if (destination instanceof AbstractTypeDeclaration) insertToType(rewrite, createNewNodeToInsertToType(source, rewrite), (AbstractTypeDeclaration) destination); } } final CompilationUnitChange result= new CompilationUnitChange(ReorgMessages.PasteAction_change_name, getDestinationCu()); try { ITextFileBuffer buffer= RefactoringFileBuffers.acquire(getDestinationCu()); TextEdit rootEdit= rewrite.rewriteAST(buffer.getDocument(), fDestination.getJavaProject().getOptions(true)); if (getDestinationCu().isWorkingCopy()) result.setSaveMode(TextFileChange.LEAVE_DIRTY); TextChangeCompatibility.addTextEdit(result, ReorgMessages.PasteAction_edit_name, rootEdit); } finally { RefactoringFileBuffers.release(getDestinationCu()); } return result; }
@Override public Change createChange(IProgressMonitor pm) throws CoreException { ASTParser p= ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL); p.setSource(getDestinationCu()); CompilationUnit cuNode= (CompilationUnit) p.createAST(pm); ASTRewrite rewrite= ASTRewrite.create(cuNode.getAST()); TypedSource source= null; for (int i= fSources.length - 1; i >= 0; i--) { source= fSources[i]; final ASTNode destination= getDestinationNodeForSourceElement(fDestination, source.getType(), cuNode); if (destination != null) { if (destination instanceof CompilationUnit) insertToCu(rewrite, createNewNodeToInsertToCu(source, rewrite), (CompilationUnit) destination); else if (destination instanceof AbstractTypeDeclaration) insertToType(rewrite, createNewNodeToInsertToType(source, rewrite), (AbstractTypeDeclaration) destination); } } final CompilationUnitChange result= new CompilationUnitChange(ReorgMessages.PasteAction_change_name, getDestinationCu()); try { ITextFileBuffer buffer= RefactoringFileBuffers.acquire(getDestinationCu()); TextEdit rootEdit= rewrite.rewriteAST(buffer.getDocument(), fDestination.getJavaProject().getOptions(true)); if (getDestinationCu().isWorkingCopy()) result.setSaveMode(TextFileChange.LEAVE_DIRTY); TextChangeCompatibility.addTextEdit(result, ReorgMessages.PasteAction_edit_name, rootEdit); } finally { RefactoringFileBuffers.release(getDestinationCu()); } return result; }