| Index: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/editor/DartEditor.java
|
| diff --git a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/editor/DartEditor.java b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/editor/DartEditor.java
|
| index c81ff4dc065ec89c5ecd025a33af774a676eab96..e29dbdbf30d9fefe9c49347217234613db65553e 100644
|
| --- a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/editor/DartEditor.java
|
| +++ b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/editor/DartEditor.java
|
| @@ -17,19 +17,9 @@ import com.google.dart.compiler.ast.DartNode;
|
| import com.google.dart.compiler.ast.DartUnit;
|
| import com.google.dart.compiler.ast.DartVariable;
|
| import com.google.dart.compiler.resolver.Element;
|
| -import com.google.dart.engine.context.AnalysisException;
|
| -import com.google.dart.engine.element.CompilationUnitElement;
|
| -import com.google.dart.engine.error.AnalysisError;
|
| -import com.google.dart.engine.error.AnalysisErrorListener;
|
| -import com.google.dart.engine.internal.builder.CompilationUnitBuilder;
|
| -import com.google.dart.engine.internal.context.AnalysisContextImpl;
|
| -import com.google.dart.engine.parser.Parser;
|
| -import com.google.dart.engine.scanner.StringScanner;
|
| -import com.google.dart.engine.scanner.Token;
|
| -import com.google.dart.engine.source.FileBasedSource;
|
| +import com.google.dart.engine.context.AnalysisContext;
|
| +import com.google.dart.engine.element.LibraryElement;
|
| import com.google.dart.engine.source.Source;
|
| -import com.google.dart.engine.source.SourceFactory;
|
| -import com.google.dart.engine.utilities.io.FileUtilities;
|
| import com.google.dart.tools.core.DartCore;
|
| import com.google.dart.tools.core.DartCoreDebug;
|
| import com.google.dart.tools.core.formatter.DefaultCodeFormatterConstants;
|
| @@ -95,6 +85,7 @@ import com.ibm.icu.text.BreakIterator;
|
|
|
| import org.eclipse.core.commands.operations.IOperationApprover;
|
| import org.eclipse.core.commands.operations.IUndoContext;
|
| +import org.eclipse.core.resources.IFile;
|
| import org.eclipse.core.resources.IResource;
|
| import org.eclipse.core.resources.ProjectScope;
|
| import org.eclipse.core.runtime.CoreException;
|
| @@ -210,7 +201,6 @@ import org.eclipse.ui.views.contentoutline.ContentOutline;
|
| import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
|
| import org.osgi.service.prefs.BackingStoreException;
|
|
|
| -import java.io.IOException;
|
| import java.lang.ref.SoftReference;
|
| import java.lang.reflect.InvocationTargetException;
|
| import java.text.CharacterIterator;
|
| @@ -2102,59 +2092,74 @@ public abstract class DartEditor extends AbstractDecoratedTextEditor implements
|
| * Alternative to {@link #getInputDartElement()} that returns the Analysis engine
|
| * {@link com.google.dart.engine.element.Element} instead of a {@link DartElement}.
|
| */
|
| - public com.google.dart.engine.element.Element getInputElement() {
|
| + public com.google.dart.engine.element.CompilationUnitElement getInputElement() {
|
| com.google.dart.engine.ast.CompilationUnit unit = getInputUnit();
|
| return unit == null ? null : unit.getElement();
|
| }
|
|
|
| public com.google.dart.engine.ast.CompilationUnit getInputUnit() {
|
| - // TODO(jwren) the Element should not be computed every time, instead, after the AnalysisContext
|
| - // API has been decided on, this method should get the information from a shared cache
|
| - java.io.File file = null;
|
| - if (getEditorInput() instanceof IFileEditorInput) {
|
| - IFileEditorInput input = (IFileEditorInput) getEditorInput();
|
| - if (input.getFile().getLocation() != null) {
|
| - file = input.getFile().getLocation().toFile();
|
| - }
|
| - }
|
| -
|
| - if (file == null) {
|
| - return null;
|
| - }
|
| -
|
| - AnalysisErrorListener ael = new AnalysisErrorListener() {
|
| - @Override
|
| - public void onError(AnalysisError error) {
|
| - // do nothing
|
| - }
|
| - };
|
| -
|
| - // Scanner
|
| - Source source = new FileBasedSource(new SourceFactory(), file);
|
| - StringScanner scanner = null;
|
| + // TODO(scheglov) updated to use most recent API
|
| try {
|
| - scanner = new StringScanner(source, FileUtilities.getContents(file), ael);
|
| - } catch (IOException e) {
|
| - e.printStackTrace();
|
| - }
|
| - if (scanner == null) {
|
| - return null;
|
| - }
|
| - Token token = scanner.tokenize();
|
| -
|
| - // Parser
|
| - Parser parser = new Parser(source, ael);
|
| - final com.google.dart.engine.ast.CompilationUnit unit = parser.parseCompilationUnit(token);
|
| -
|
| - // Element Builder
|
| - CompilationUnitBuilder builder = new CompilationUnitBuilder(new AnalysisContextImpl(), ael);
|
| - CompilationUnitElement element = null;
|
| - try {
|
| - element = builder.buildCompilationUnit(source, unit);
|
| - } catch (AnalysisException e) {
|
| - e.printStackTrace();
|
| - }
|
| - return unit;
|
| + IFile file = getInputFile();
|
| + if (file == null) {
|
| + return null;
|
| + }
|
| + com.google.dart.tools.core.analysis.model.Project project = DartCore.getProjectManager().getProject(
|
| + file.getProject());
|
| + AnalysisContext context = project.getContext(file);
|
| + Source source = project.getSource(file);
|
| + LibraryElement libraryElement = context.getLibraryElement(source);
|
| + return context.resolve(source, libraryElement);
|
| + } catch (Throwable e) {
|
| + throw new Error(e);
|
| + }
|
| +
|
| +// // TODO(jwren) the Element should not be computed every time, instead, after the AnalysisContext
|
| +// // API has been decided on, this method should get the information from a shared cache
|
| +// java.io.File file = null;
|
| +// if (getEditorInput() instanceof IFileEditorInput) {
|
| +// IFileEditorInput input = (IFileEditorInput) getEditorInput();
|
| +// if (input.getFile().getLocation() != null) {
|
| +// file = input.getFile().getLocation().toFile();
|
| +// }
|
| +// }
|
| +//
|
| +// if (file == null) {
|
| +// return null;
|
| +// }
|
| +//
|
| +// AnalysisErrorListener ael = new AnalysisErrorListener() {
|
| +// @Override
|
| +// public void onError(AnalysisError error) {
|
| +// // do nothing
|
| +// }
|
| +// };
|
| +// // Scanner
|
| +// Source source = new FileBasedSource(new SourceFactory(), file);
|
| +// StringScanner scanner = null;
|
| +// try {
|
| +// scanner = new StringScanner(source, FileUtilities.getContents(file), ael);
|
| +// } catch (IOException e) {
|
| +// e.printStackTrace();
|
| +// }
|
| +// if (scanner == null) {
|
| +// return null;
|
| +// }
|
| +// Token token = scanner.tokenize();
|
| +//
|
| +// // Parser
|
| +// Parser parser = new Parser(source, ael);
|
| +// final com.google.dart.engine.ast.CompilationUnit unit = parser.parseCompilationUnit(token);
|
| +//
|
| +// // Element Builder
|
| +// CompilationUnitBuilder builder = new CompilationUnitBuilder(new AnalysisContextImpl(), ael);
|
| +// CompilationUnitElement element = null;
|
| +// try {
|
| +// element = builder.buildCompilationUnit(source, unit);
|
| +// } catch (AnalysisException e) {
|
| +// e.printStackTrace();
|
| +// }
|
| +// return unit;
|
| }
|
|
|
| @Override
|
| @@ -3137,11 +3142,19 @@ public abstract class DartEditor extends AbstractDecoratedTextEditor implements
|
| protected IOperationApprover getUndoRedoOperationApprover(IUndoContext undoContext) {
|
| // since IResource is a more general way to compare dart elements, we
|
| // use this as the preferred class for comparing objects.
|
| - return new NonLocalUndoUserApprover(
|
| - undoContext,
|
| - this,
|
| - new Object[] {getInputDartElement()},
|
| - IResource.class);
|
| + if (DartCoreDebug.ENABLE_NEW_ANALYSIS) {
|
| + return new NonLocalUndoUserApprover(
|
| + undoContext,
|
| + this,
|
| + new Object[] {getInputFile()},
|
| + IResource.class);
|
| + } else {
|
| + return new NonLocalUndoUserApprover(
|
| + undoContext,
|
| + this,
|
| + new Object[] {getInputDartElement()},
|
| + IResource.class);
|
| + }
|
| }
|
|
|
| @Override
|
| @@ -4049,6 +4062,15 @@ public abstract class DartEditor extends AbstractDecoratedTextEditor implements
|
| return key != null && store.getBoolean(key);
|
| }
|
|
|
| + private IFile getInputFile() {
|
| + IFile file = null;
|
| + if (getEditorInput() instanceof IFileEditorInput) {
|
| + IFileEditorInput input = (IFileEditorInput) getEditorInput();
|
| + file = input.getFile();
|
| + }
|
| + return file;
|
| + }
|
| +
|
| /**
|
| * Returns the lock object for the given annotation model.
|
| *
|
|
|