Java Code Examples for org.eclipse.ltk.core.refactoring.TextChange#getPreviewContent()
The following examples show how to use
org.eclipse.ltk.core.refactoring.TextChange#getPreviewContent() .
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: RenameAnalyzeUtil.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * This method analyzes a set of local variable renames inside one cu. It checks whether * any new compile errors have been introduced by the rename(s) and whether the correct * node(s) has/have been renamed. * * @param analyzePackages the LocalAnalyzePackages containing the information about the local renames * @param cuChange the TextChange containing all local variable changes to be applied. * @param oldCUNode the fully (incl. bindings) resolved AST node of the original compilation unit * @param recovery whether statements and bindings recovery should be performed when parsing the changed CU * @return a RefactoringStatus containing errors if compile errors or wrongly renamed nodes are found * @throws CoreException thrown if there was an error greating the preview content of the change */ public static RefactoringStatus analyzeLocalRenames(LocalAnalyzePackage[] analyzePackages, TextChange cuChange, CompilationUnit oldCUNode, boolean recovery) throws CoreException { RefactoringStatus result= new RefactoringStatus(); ICompilationUnit compilationUnit= (ICompilationUnit) oldCUNode.getJavaElement(); String newCuSource= cuChange.getPreviewContent(new NullProgressMonitor()); CompilationUnit newCUNode= new RefactoringASTParser(IASTSharedValues.SHARED_AST_LEVEL).parse(newCuSource, compilationUnit, true, recovery, null); result.merge(analyzeCompileErrors(newCuSource, newCUNode, oldCUNode)); if (result.hasError()) { return result; } for (int i= 0; i < analyzePackages.length; i++) { ASTNode enclosing= getEnclosingBlockOrMethodOrLambda(analyzePackages[i].fDeclarationEdit, cuChange, newCUNode); // get new declaration IRegion newRegion= RefactoringAnalyzeUtil.getNewTextRange(analyzePackages[i].fDeclarationEdit, cuChange); ASTNode newDeclaration= NodeFinder.perform(newCUNode, newRegion.getOffset(), newRegion.getLength()); Assert.isTrue(newDeclaration instanceof Name); VariableDeclaration declaration= getVariableDeclaration((Name) newDeclaration); Assert.isNotNull(declaration); SimpleName[] problemNodes= ProblemNodeFinder.getProblemNodes(enclosing, declaration, analyzePackages[i].fOccurenceEdits, cuChange); result.merge(RefactoringAnalyzeUtil.reportProblemNodes(newCuSource, problemNodes)); } return result; }
Example 2
Source File: ChangeSignatureProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private RefactoringStatus checkCompilationofDeclaringCu() throws CoreException { ICompilationUnit cu= getCu(); TextChange change= fChangeManager.get(cu); String newCuSource= change.getPreviewContent(new NullProgressMonitor()); CompilationUnit newCUNode= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(newCuSource, cu, true, false, null); IProblem[] problems= RefactoringAnalyzeUtil.getIntroducedCompileProblems(newCUNode, fBaseCuRewrite.getRoot()); RefactoringStatus result= new RefactoringStatus(); for (int i= 0; i < problems.length; i++) { IProblem problem= problems[i]; if (shouldReport(problem, newCUNode)) result.addEntry(new RefactoringStatusEntry((problem.isError() ? RefactoringStatus.ERROR : RefactoringStatus.WARNING), problem.getMessage(), new JavaStringStatusContext(newCuSource, SourceRangeFactory.create(problem)))); } return result; }
Example 3
Source File: RenameAnalyzeUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * This method analyzes a set of local variable renames inside one cu. It checks whether * any new compile errors have been introduced by the rename(s) and whether the correct * node(s) has/have been renamed. * * @param analyzePackages the LocalAnalyzePackages containing the information about the local renames * @param cuChange the TextChange containing all local variable changes to be applied. * @param oldCUNode the fully (incl. bindings) resolved AST node of the original compilation unit * @param recovery whether statements and bindings recovery should be performed when parsing the changed CU * @return a RefactoringStatus containing errors if compile errors or wrongly renamed nodes are found * @throws CoreException thrown if there was an error greating the preview content of the change */ public static RefactoringStatus analyzeLocalRenames(LocalAnalyzePackage[] analyzePackages, TextChange cuChange, CompilationUnit oldCUNode, boolean recovery) throws CoreException { RefactoringStatus result= new RefactoringStatus(); ICompilationUnit compilationUnit= (ICompilationUnit) oldCUNode.getJavaElement(); String newCuSource= cuChange.getPreviewContent(new NullProgressMonitor()); CompilationUnit newCUNode= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(newCuSource, compilationUnit, true, recovery, null); result.merge(analyzeCompileErrors(newCuSource, newCUNode, oldCUNode)); if (result.hasError()) return result; for (int i= 0; i < analyzePackages.length; i++) { ASTNode enclosing= getEnclosingBlockOrMethodOrLambda(analyzePackages[i].fDeclarationEdit, cuChange, newCUNode); // get new declaration IRegion newRegion= RefactoringAnalyzeUtil.getNewTextRange(analyzePackages[i].fDeclarationEdit, cuChange); ASTNode newDeclaration= NodeFinder.perform(newCUNode, newRegion.getOffset(), newRegion.getLength()); Assert.isTrue(newDeclaration instanceof Name); VariableDeclaration declaration= getVariableDeclaration((Name) newDeclaration); Assert.isNotNull(declaration); SimpleName[] problemNodes= ProblemNodeFinder.getProblemNodes(enclosing, declaration, analyzePackages[i].fOccurenceEdits, cuChange); result.merge(RefactoringAnalyzeUtil.reportProblemNodes(newCuSource, problemNodes)); } return result; }