Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Unified Diff: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/AssistContext.java

Issue 9834028: Initial implementation of "Rename Local Variable" refactoring. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: LInked/inline mode for rename Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/AssistContext.java
diff --git a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/AssistContext.java b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/AssistContext.java
new file mode 100644
index 0000000000000000000000000000000000000000..e42d769313a6e69efbc4b2de9d609308373b8537
--- /dev/null
+++ b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/AssistContext.java
@@ -0,0 +1,129 @@
+package com.google.dart.tools.ui.internal.text.correction;
+
+import com.google.dart.compiler.ast.DartNode;
+import com.google.dart.compiler.ast.DartUnit;
+import com.google.dart.tools.core.dom.NodeFinder;
+import com.google.dart.tools.core.model.CompilationUnit;
+import com.google.dart.tools.ui.internal.text.editor.ASTProvider;
+import com.google.dart.tools.ui.text.dart.IInvocationContext;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.TextInvocationContext;
+import org.eclipse.ui.IEditorPart;
+
+public class AssistContext extends TextInvocationContext implements IInvocationContext {
+
+ private final CompilationUnit fCompilationUnit;
+ private final IEditorPart fEditor;
+
+ private DartUnit fASTRoot;
+// private final SharedASTProvider.WAIT_FLAG fWaitFlag;
+ private final ASTProvider.WAIT_FLAG fWaitFlag;
+ /**
+ * The cached node finder, can be null.
+ */
+ private NodeFinder fNodeFinder;
+
+ /*
+ * Constructor for CorrectionContext.
+ */
+ public AssistContext(CompilationUnit cu, int offset, int length) {
+ this(cu, null, offset, length);
+ }
+
+ public AssistContext(CompilationUnit cu, ISourceViewer sourceViewer, IEditorPart editor,
+ int offset, int length) {
+ this(cu, sourceViewer, editor, offset, length, ASTProvider.WAIT_YES);
+ }
+
+ public AssistContext(CompilationUnit cu, ISourceViewer sourceViewer, int offset, int length) {
+ this(cu, sourceViewer, null, offset, length);
+ }
+
+ public AssistContext(CompilationUnit cu, ISourceViewer sourceViewer, int offset, int length,
+ ASTProvider.WAIT_FLAG waitFlag) {
+ this(cu, sourceViewer, null, offset, length, waitFlag);
+ }
+
+ private AssistContext(CompilationUnit cu, ISourceViewer sourceViewer, IEditorPart editor,
+ int offset, int length, ASTProvider.WAIT_FLAG waitFlag) {
+ super(sourceViewer, offset, length);
+ Assert.isLegal(cu != null);
+ Assert.isLegal(waitFlag != null);
+ fCompilationUnit = cu;
+ fEditor = editor;
+ fWaitFlag = waitFlag;
+ }
+
+ @Override
+ public DartUnit getASTRoot() {
+ if (fASTRoot == null) {
+// fASTRoot = SharedASTProvider.getAST(fCompilationUnit, fWaitFlag, null);
+ fASTRoot = ASTProvider.getASTProvider().getAST(fCompilationUnit, fWaitFlag, null);
+ // TODO(scheglov) don't know if needed
+// if (fASTRoot == null) {
+// // see bug 63554
+// fASTRoot = ASTResolving.createQuickFixAST(fCompilationUnit, null);
+// }
+ }
+ return fASTRoot;
+ }
+
+ /**
+ * Returns the compilation unit.
+ *
+ * @return an <code>CompilationUnit</code>
+ */
+ @Override
+ public CompilationUnit getCompilationUnit() {
+ return fCompilationUnit;
+ }
+
+ @Override
+ public DartNode getCoveredNode() {
+ if (fNodeFinder == null) {
+ fNodeFinder = NodeFinder.find(getASTRoot(), getOffset(), getLength());
+ }
+ return fNodeFinder.getCoveredNode();
+ }
+
+ @Override
+ public DartNode getCoveringNode() {
+ if (fNodeFinder == null) {
+ fNodeFinder = NodeFinder.find(getASTRoot(), getOffset(), getLength());
+ }
+ return fNodeFinder.getCoveringNode();
+ }
+
+ /**
+ * Returns the editor or <code>null</code> if none.
+ *
+ * @return an <code>IEditorPart</code> or <code>null</code> if none
+ * @since 3.5
+ */
+ public IEditorPart getEditor() {
+ return fEditor;
+ }
+
+ /**
+ * Returns the length.
+ */
+ @Override
+ public int getSelectionLength() {
+ return Math.max(getLength(), 0);
+ }
+
+ /**
+ * Returns the offset.
+ */
+ @Override
+ public int getSelectionOffset() {
+ return getOffset();
+ }
+
+ public void setASTRoot(DartUnit root) {
+ fASTRoot = root;
+ }
+
+}

Powered by Google App Engine
This is Rietveld 408576698