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); } }
public CallInliner(ICompilationUnit unit, CompilationUnit targetAstRoot, SourceProvider provider) throws CoreException { super(); fCUnit= unit; fBuffer= RefactoringFileBuffers.acquire(fCUnit); fSourceProvider= provider; fImportRewrite= StubUtility.createImportRewrite(targetAstRoot, true); fLocals= new ArrayList<>(3); fRewrite= ASTRewrite.create(targetAstRoot.getAST()); fRewrite.setTargetSourceRangeComputer(new NoCommentSourceRangeComputer()); fTypeEnvironment= new TypeEnvironment(); }
public void dispose() { try { RefactoringFileBuffers.release(fCUnit); } catch (CoreException exception) { JavaPlugin.log(exception); } }
public CallInliner(ICompilationUnit unit, CompilationUnit targetAstRoot, SourceProvider provider) throws CoreException { super(); fCUnit= unit; fBuffer= RefactoringFileBuffers.acquire(fCUnit); fSourceProvider= provider; fImportRewrite= StubUtility.createImportRewrite(targetAstRoot, true); fLocals= new ArrayList(3); fRewrite= ASTRewrite.create(targetAstRoot.getAST()); fRewrite.setTargetSourceRangeComputer(new NoCommentSourceRangeComputer()); fTypeEnvironment= new TypeEnvironment(); }
public void dispose() { try { RefactoringFileBuffers.release(fCUnit); } catch (CoreException exception) { JavaPlugin.log(exception); } }
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); } }
public CallInliner(ICompilationUnit unit, CompilationUnit targetAstRoot, SourceProvider provider) throws CoreException { super(); fCUnit= unit; fBuffer= RefactoringFileBuffers.acquire(fCUnit); fSourceProvider= provider; fImportRewrite= StubUtility.createImportRewrite(targetAstRoot, true); fLocals= new ArrayList<>(3); fRewrite= ASTRewrite.create(targetAstRoot.getAST()); fRewrite.setTargetSourceRangeComputer(new NoCommentSourceRangeComputer()); fTypeEnvironment= new TypeEnvironment(); }
public void dispose() { try { RefactoringFileBuffers.release(fCUnit); } catch (CoreException exception) { JavaPlugin.log(exception); } }
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); } }
monitor.setTaskName(RefactoringCoreMessages.ExtractInterfaceProcessor_creating); final ICompilationUnit subUnit= getSharedWorkingCopy(fSubType.getCompilationUnit().getPrimary(), new SubProgressMonitor(monitor, 20)); final ITextFileBuffer buffer= RefactoringFileBuffers.acquire(fSubType.getCompilationUnit()); final ASTRewrite rewrite= sourceRewrite.getASTRewrite(); try { RefactoringFileBuffers.release(fSubType.getCompilationUnit());
monitor.setTaskName(RefactoringCoreMessages.ExtractInterfaceProcessor_creating); final ICompilationUnit subUnit= getSharedWorkingCopy(fSubType.getCompilationUnit().getPrimary(), new SubProgressMonitor(monitor, 20)); final ITextFileBuffer buffer= RefactoringFileBuffers.acquire(fSubType.getCompilationUnit()); final ASTRewrite rewrite= sourceRewrite.getASTRewrite(); try { RefactoringFileBuffers.release(fSubType.getCompilationUnit());
ModifierRewrite.create(rewrite, field).setModifiers(modifiers, null); final ICompilationUnit unit= sourceRewrite.getCu(); final ITextFileBuffer buffer= RefactoringFileBuffers.acquire(unit); try { final IDocument document= new Document(buffer.getDocument().get()); RefactoringFileBuffers.release(unit);
ModifierRewrite.create(rewrite, field).setModifiers(modifiers, null); final ICompilationUnit unit= sourceRewrite.getCu(); final ITextFileBuffer buffer= RefactoringFileBuffers.acquire(unit); try { final IDocument document= new Document(buffer.getDocument().get()); RefactoringFileBuffers.release(unit);
monitor.setTaskName(RefactoringCoreMessages.ExtractInterfaceProcessor_creating); final ICompilationUnit subUnit= getSharedWorkingCopy(fSubType.getCompilationUnit().getPrimary(), new SubProgressMonitor(monitor, 20)); final ITextFileBuffer buffer= RefactoringFileBuffers.acquire(fSubType.getCompilationUnit()); final ASTRewrite rewrite= sourceRewrite.getASTRewrite(); try { RefactoringFileBuffers.release(fSubType.getCompilationUnit());