1 11 package org.eclipse.jdt.internal.ui.text.correction; 12 13 import org.eclipse.jdt.core.ICompilationUnit; 14 import org.eclipse.jdt.core.dom.ASTNode; 15 import org.eclipse.jdt.core.dom.CompilationUnit; 16 17 import org.eclipse.jdt.internal.corext.dom.NodeFinder; 18 19 import org.eclipse.jdt.ui.text.java.IInvocationContext; 20 21 import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider; 22 23 25 public class AssistContext implements IInvocationContext { 26 27 private ICompilationUnit fCompilationUnit; 28 private int fOffset; 29 private int fLength; 30 31 private CompilationUnit fASTRoot; 32 33 36 public AssistContext(ICompilationUnit cu, int offset, int length) { 37 fCompilationUnit= cu; 38 fOffset= offset; 39 fLength= length; 40 41 fASTRoot= null; 42 } 43 44 48 public ICompilationUnit getCompilationUnit() { 49 return fCompilationUnit; 50 } 51 52 56 public int getSelectionLength() { 57 return fLength; 58 } 59 60 64 public int getSelectionOffset() { 65 return fOffset; 66 } 67 68 public CompilationUnit getASTRoot() { 69 if (fASTRoot == null) { 70 fASTRoot= ASTProvider.getASTProvider().getAST(fCompilationUnit, ASTProvider.WAIT_YES, null); 71 if (fASTRoot == null) { 72 fASTRoot= ASTResolving.createQuickFixAST(fCompilationUnit, null); 74 } 75 } 76 return fASTRoot; 77 } 78 79 80 83 public void setASTRoot(CompilationUnit root) { 84 fASTRoot= root; 85 } 86 87 90 public ASTNode getCoveringNode() { 91 NodeFinder finder= new NodeFinder(fOffset, fLength); 92 getASTRoot().accept(finder); 93 return finder.getCoveringNode(); 94 } 95 96 99 public ASTNode getCoveredNode() { 100 NodeFinder finder= new NodeFinder(fOffset, fLength); 101 getASTRoot().accept(finder); 102 return finder.getCoveredNode(); 103 } 104 105 } 106 | Popular Tags |