| Index: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/QuickFixProcessor.java
|
| diff --git a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/QuickFixProcessor.java b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/QuickFixProcessor.java
|
| index 0f4a5643dbf7bfd93797a7eb36aa73bb81fbfd48..b20a91046e4d8126bfe490b2df5d6f6f2830e06f 100644
|
| --- a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/QuickFixProcessor.java
|
| +++ b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/QuickFixProcessor.java
|
| @@ -26,6 +26,7 @@ import com.google.dart.compiler.ErrorCode;
|
| import com.google.dart.compiler.PackageLibraryManager;
|
| import com.google.dart.compiler.Source;
|
| import com.google.dart.compiler.ast.ASTNodes;
|
| +import com.google.dart.compiler.ast.DartClass;
|
| import com.google.dart.compiler.ast.DartClassMember;
|
| import com.google.dart.compiler.ast.DartDirective;
|
| import com.google.dart.compiler.ast.DartExpression;
|
| @@ -45,6 +46,8 @@ import com.google.dart.compiler.common.SourceInfo;
|
| import com.google.dart.compiler.resolver.ClassElement;
|
| import com.google.dart.compiler.resolver.Element;
|
| import com.google.dart.compiler.resolver.ElementKind;
|
| +import com.google.dart.compiler.resolver.Elements;
|
| +import com.google.dart.compiler.resolver.LibraryElement;
|
| import com.google.dart.compiler.resolver.MethodElement;
|
| import com.google.dart.compiler.resolver.ResolverErrorCode;
|
| import com.google.dart.compiler.resolver.TypeErrorCode;
|
| @@ -112,14 +115,42 @@ import java.util.Set;
|
| * @coverage dart.editor.ui.correction
|
| */
|
| public class QuickFixProcessor implements IQuickFixProcessor {
|
| - private static final int DEFAULT_RELEVANCE = 50;
|
| + /**
|
| + * Helper for finding {@link Element} with name closest to the given.
|
| + */
|
| + private static class ClosestElementFinder {
|
| + private final Class<?> targetClass;
|
| + private final String targetName;
|
| + Element element = null;
|
| + int distance = Integer.MAX_VALUE;
|
| +
|
| + public ClosestElementFinder(Class<?> targetClass, String targetName) {
|
| + this.targetClass = targetClass;
|
| + this.targetName = targetName;
|
| + }
|
| +
|
| + void update(Element member) {
|
| + if (targetClass.isInstance(member)) {
|
| + int memberDistance = StringUtils.getLevenshteinDistance(member.getName(), targetName);
|
| + if (memberDistance < distance) {
|
| + element = member;
|
| + distance = memberDistance;
|
| + }
|
| + }
|
| + }
|
|
|
| + void update(Iterable<? extends Element> members) {
|
| + for (Element member : members) {
|
| + update(member);
|
| + }
|
| + }
|
| + }
|
| +
|
| + private static final int DEFAULT_RELEVANCE = 50;
|
| private static final DartElementImageDescriptor OBJ_CONSTRUCTOR_DESC = new DartElementImageDescriptor(
|
| DartPluginImages.DESC_MISC_PUBLIC,
|
| DartElementImageDescriptor.CONSTRUCTOR,
|
| DartElementImageProvider.SMALL_SIZE);
|
| - private static final Image OBJ_CONSTRUCTOR_IMG = DartToolsPlugin.getImageDescriptorRegistry().get(
|
| - OBJ_CONSTRUCTOR_DESC);
|
|
|
| // private static ReplaceEdit createInsertEdit(int offset, String text) {
|
| // return new ReplaceEdit(offset, 0, text);
|
| @@ -129,6 +160,9 @@ public class QuickFixProcessor implements IQuickFixProcessor {
|
| // return createReplaceEdit(range, "");
|
| // }
|
|
|
| + private static final Image OBJ_CONSTRUCTOR_IMG = DartToolsPlugin.getImageDescriptorRegistry().get(
|
| + OBJ_CONSTRUCTOR_DESC);
|
| +
|
| private static void addSuperTypeProposals(SourceBuilder sb, Set<Type> alreadyAdded, Type type) {
|
| if (type != null && !alreadyAdded.contains(type) && type.getElement() instanceof ClassElement) {
|
| alreadyAdded.add(type);
|
| @@ -183,12 +217,13 @@ public class QuickFixProcessor implements IQuickFixProcessor {
|
|
|
| private CompilationUnit unit;
|
| private ExtractUtils utils;
|
| - private DartNode node;
|
|
|
| + private DartNode node;
|
| private final List<ICommandAccess> proposals = Lists.newArrayList();
|
| private int proposalRelevance = DEFAULT_RELEVANCE;
|
| private final List<TextEdit> textEdits = Lists.newArrayList();
|
| private final Map<String, List<TrackedNodePosition>> linkedPositions = Maps.newHashMap();
|
| +
|
| private final Map<String, List<TrackedNodeProposal>> linkedPositionProposals = Maps.newHashMap();
|
|
|
| private LinkedCorrectionProposal proposal;
|
| @@ -210,7 +245,8 @@ public class QuickFixProcessor implements IQuickFixProcessor {
|
| if (errorCode == ResolverErrorCode.CANNOT_RESOLVE_METHOD
|
| || errorCode == ResolverErrorCode.CANNOT_RESOLVE_METHOD_IN_CLASS
|
| || errorCode == TypeErrorCode.INTERFACE_HAS_NO_METHOD_NAMED) {
|
| - addFix_createUnresolvedMethod(location);
|
| + addFix_unresolvedMethodSimilar(location);
|
| + addFix_unresolvedMethodCreate(location);
|
| }
|
| if (errorCode == TypeErrorCode.IS_STATIC_METHOD_IN) {
|
| addFix_useStaticAccess_method(location);
|
| @@ -218,7 +254,8 @@ public class QuickFixProcessor implements IQuickFixProcessor {
|
| if (errorCode == TypeErrorCode.NO_SUCH_TYPE
|
| || errorCode == TypeErrorCode.CANNOT_BE_RESOLVED) {
|
| addFix_importLibrary_withType(location);
|
| - addFix_createClass(location);
|
| + addFix_unresolvedClass_useSimilar(location);
|
| + addFix_unresolvedClass_create(location);
|
| }
|
| if (errorCode == ResolverErrorCode.CANNOT_RESOLVE_METHOD) {
|
| addFix_importLibrary_withFunction(location);
|
| @@ -248,46 +285,6 @@ public class QuickFixProcessor implements IQuickFixProcessor {
|
| || errorCode == ResolverErrorCode.NEW_EXPRESSION_NOT_CONSTRUCTOR;
|
| }
|
|
|
| - private void addFix_createClass(IProblemLocation location) {
|
| - if (mayBeTypeIdentifier(node)) {
|
| - String name = ((DartIdentifier) node).getName();
|
| - // prepare environment
|
| - String eol = utils.getEndOfLine();
|
| - DartClassMember<?> enclosingMember = ASTNodes.getAncestor(node, DartClassMember.class);
|
| - String prefix = utils.getNodePrefix(enclosingMember);
|
| - SourceRange range = SourceRangeFactory.forEndLength(enclosingMember, 0);
|
| - //
|
| - SourceBuilder sb = new SourceBuilder(range);
|
| - {
|
| - sb.append(eol + eol);
|
| - sb.append(prefix);
|
| - // "class"
|
| - sb.append("class ");
|
| - // append name
|
| - {
|
| - sb.startPosition("NAME");
|
| - sb.append(name);
|
| - sb.endPosition();
|
| - }
|
| - // no members
|
| - sb.append(" {");
|
| - sb.append(eol);
|
| - sb.append("}");
|
| - }
|
| - // insert source
|
| - addReplaceEdit(range, sb.toString());
|
| - // add linked positions
|
| - addLinkedPosition("NAME", TrackedPositions.forNode(node));
|
| - addLinkedPositions(sb);
|
| - // add proposal
|
| - addUnitCorrectionProposal(
|
| - unit,
|
| - TextFileChange.FORCE_SAVE,
|
| - Messages.format(CorrectionMessages.QuickFixProcessor_createClass, name),
|
| - DartPluginImages.get(DartPluginImages.IMG_OBJS_CLASS));
|
| - }
|
| - }
|
| -
|
| private void addFix_createConstructor() {
|
| DartNewExpression newExpression = null;
|
| DartNode nameNode = null;
|
| @@ -340,7 +337,7 @@ public class QuickFixProcessor implements IQuickFixProcessor {
|
| sb.endPosition();
|
| }
|
| }
|
| - addFix_createUnresolvedMethod_parameters(sb, newExpression);
|
| + addFix_unresolvedMethodCreate_parameters(sb, newExpression);
|
| sb.append(") {" + eol + prefix + "}");
|
| sb.append(eol);
|
| }
|
| @@ -360,7 +357,189 @@ public class QuickFixProcessor implements IQuickFixProcessor {
|
| }
|
| }
|
|
|
| - private void addFix_createUnresolvedMethod(IProblemLocation location) throws Exception {
|
| + private void addFix_importLibrary(String importPath) throws Exception {
|
| + CompilationUnit libraryUnit = unit.getLibrary().getDefiningCompilationUnit();
|
| + // prepare new import location
|
| + SourceRange range;
|
| + String prefix;
|
| + String suffix;
|
| + {
|
| + String eol = utils.getEndOfLine();
|
| + // if no directives
|
| + range = SourceRangeFactory.forStartEnd(0, 0);
|
| + prefix = "";
|
| + suffix = eol;
|
| + // after last directive in library
|
| + {
|
| + DartUnit libraryUnitNode = DartCompilerUtilities.parseUnit(libraryUnit);
|
| + for (DartDirective directive : libraryUnitNode.getDirectives()) {
|
| + if (directive instanceof DartLibraryDirective || directive instanceof DartImportDirective) {
|
| + range = SourceRangeFactory.forEndLength(directive, 0);
|
| + prefix = eol;
|
| + suffix = "";
|
| + }
|
| + }
|
| + }
|
| + }
|
| + // insert new import
|
| + String importSource = prefix + "import '" + importPath + "';" + suffix;
|
| + addReplaceEdit(range, importSource);
|
| + // add proposal
|
| + proposalRelevance += 1;
|
| + addUnitCorrectionProposal(
|
| + libraryUnit,
|
| + TextFileChange.FORCE_SAVE,
|
| + Messages.format(CorrectionMessages.QuickFixProcessor_importLibrary, importPath),
|
| + DartPluginImages.get(DartPluginImages.IMG_CORRECTION_CHANGE));
|
| + }
|
| +
|
| + private void addFix_importLibrary_withElement(String name) throws Exception {
|
| + // ignore if private
|
| + if (name.startsWith("_")) {
|
| + return;
|
| + }
|
| + // prepare base URI
|
| + CompilationUnit libraryUnit = unit.getLibrary().getDefiningCompilationUnit();
|
| + URI unitNormalizedUri;
|
| + {
|
| + URI unitUri = libraryUnit.getUnderlyingResource().getLocationURI();
|
| + unitNormalizedUri = unitUri.resolve(".").normalize();
|
| + }
|
| + // may be there is existing import, but it is with prefix and we don't use this prefix
|
| + for (DartImport imp : unit.getLibrary().getImports()) {
|
| + String prefix = imp.getPrefix();
|
| + if (!StringUtils.isEmpty(prefix) && imp.getLibrary().findTopLevelElement(name) != null) {
|
| + SourceRange range = SourceRangeFactory.forStartLength(node, 0);
|
| + addReplaceEdit(range, prefix + ".");
|
| + // add proposal
|
| + proposalRelevance += 2;
|
| + addUnitCorrectionProposal(
|
| + libraryUnit,
|
| + TextFileChange.FORCE_SAVE,
|
| + Messages.format(
|
| + CorrectionMessages.QuickFixProcessor_importLibrary_addPrefix,
|
| + new Object[] {getSource(imp.getUriRange()), prefix}),
|
| + DartPluginImages.get(DartPluginImages.IMG_CORRECTION_CHANGE));
|
| + }
|
| + }
|
| + // prepare Dart model
|
| + DartModel model = DartCore.create(ResourcesPlugin.getWorkspace().getRoot());
|
| + // check workspace libraries
|
| + for (DartProject project : model.getDartProjects()) {
|
| + for (DartLibrary library : project.getDartLibraries()) {
|
| + if (library.findTopLevelElement(name) != null) {
|
| + URI libraryUri = library.getUri();
|
| + URI libraryRelativeUri = unitNormalizedUri.relativize(libraryUri);
|
| + if (StringUtils.isEmpty(libraryRelativeUri.getScheme())) {
|
| + String importPath = libraryRelativeUri.toString();
|
| + addFix_importLibrary(importPath);
|
| + }
|
| + }
|
| + }
|
| + }
|
| + // check SDK libraries
|
| + PackageLibraryManager libraryManager = PackageLibraryManagerProvider.getPackageLibraryManager();
|
| + for (DartLibrary library : model.getBundledLibraries()) {
|
| + if (library.findTopLevelElement(name) != null) {
|
| + URI libraryUri = library.getUri();
|
| + URI libraryShortUri = libraryManager.getShortUri(libraryUri);
|
| + if (libraryShortUri != null) {
|
| + String importPath = libraryShortUri.toString();
|
| + addFix_importLibrary(importPath);
|
| + }
|
| + }
|
| + }
|
| + }
|
| +
|
| + private void addFix_importLibrary_withField(IProblemLocation location) throws Exception {
|
| + if (node instanceof DartIdentifier) {
|
| + String name = ((DartIdentifier) node).getName();
|
| + addFix_importLibrary_withElement(name);
|
| + }
|
| + }
|
| +
|
| + private void addFix_importLibrary_withFunction(IProblemLocation location) throws Exception {
|
| + if (node instanceof DartIdentifier
|
| + && getLocationInParent(node) == DART_METHOD_INVOCATION_TARGET) {
|
| + String name = ((DartIdentifier) node).getName();
|
| + addFix_importLibrary_withElement(name);
|
| + }
|
| + }
|
| +
|
| + private void addFix_importLibrary_withType(IProblemLocation location) throws Exception {
|
| + if (mayBeTypeIdentifier(node)) {
|
| + String typeName = ((DartIdentifier) node).getName();
|
| + addFix_importLibrary_withElement(typeName);
|
| + }
|
| + }
|
| +
|
| + private void addFix_unresolvedClass_create(IProblemLocation location) {
|
| + if (mayBeTypeIdentifier(node)) {
|
| + String name = ((DartIdentifier) node).getName();
|
| + // prepare environment
|
| + String eol = utils.getEndOfLine();
|
| + DartClassMember<?> enclosingMember = ASTNodes.getAncestor(node, DartClassMember.class);
|
| + String prefix = utils.getNodePrefix(enclosingMember);
|
| + SourceRange range = SourceRangeFactory.forEndLength(enclosingMember, 0);
|
| + //
|
| + SourceBuilder sb = new SourceBuilder(range);
|
| + {
|
| + sb.append(eol + eol);
|
| + sb.append(prefix);
|
| + // "class"
|
| + sb.append("class ");
|
| + // append name
|
| + {
|
| + sb.startPosition("NAME");
|
| + sb.append(name);
|
| + sb.endPosition();
|
| + }
|
| + // no members
|
| + sb.append(" {");
|
| + sb.append(eol);
|
| + sb.append("}");
|
| + }
|
| + // insert source
|
| + addReplaceEdit(range, sb.toString());
|
| + // add linked positions
|
| + addLinkedPosition("NAME", TrackedPositions.forNode(node));
|
| + addLinkedPositions(sb);
|
| + // add proposal
|
| + addUnitCorrectionProposal(
|
| + unit,
|
| + TextFileChange.FORCE_SAVE,
|
| + Messages.format(CorrectionMessages.QuickFixProcessor_createClass, name),
|
| + DartPluginImages.get(DartPluginImages.IMG_OBJS_CLASS));
|
| + }
|
| + }
|
| +
|
| + private void addFix_unresolvedClass_useSimilar(IProblemLocation location) {
|
| + if (mayBeTypeIdentifier(node)) {
|
| + String name = ((DartIdentifier) node).getName();
|
| + ClosestElementFinder finder = new ClosestElementFinder(ClassElement.class, name);
|
| + // find closest element
|
| + {
|
| + DartUnit enclosingUnit = ASTNodes.getAncestor(node, DartUnit.class);
|
| + LibraryElement enclosingLibrary = enclosingUnit.getLibrary().getElement();
|
| + finder.update(enclosingLibrary.getImportScope().getElements().values());
|
| + finder.update(enclosingLibrary.getScope().getElements().values());
|
| + }
|
| + // if we have close enough element, suggest to use it
|
| + if (finder != null && finder.distance < 5) {
|
| + String closestName = finder.element.getName();
|
| + addReplaceEdit(SourceRangeFactory.create(node), closestName);
|
| + // add proposal
|
| + if (closestName != null) {
|
| + proposalRelevance += 1;
|
| + addUnitCorrectionProposal(
|
| + Messages.format(CorrectionMessages.QuickFixProcessor_changeTo, closestName),
|
| + DartPluginImages.get(DartPluginImages.IMG_CORRECTION_CHANGE));
|
| + }
|
| + }
|
| + }
|
| + }
|
| +
|
| + private void addFix_unresolvedMethodCreate(IProblemLocation location) throws Exception {
|
| if (node instanceof DartIdentifier && node.getParent() instanceof DartInvocation) {
|
| String name = ((DartIdentifier) node).getName();
|
| DartInvocation invocation = (DartInvocation) node.getParent();
|
| @@ -407,7 +586,7 @@ public class QuickFixProcessor implements IQuickFixProcessor {
|
| }
|
| // may be return type
|
| {
|
| - Type type = addFix_createUnresolvedMethod_getReturnType(invocation);
|
| + Type type = addFix_unresolvedMethodCreate_getReturnType(invocation);
|
| if (type != null) {
|
| sb.startPosition("RETURN_TYPE");
|
| sb.append(ExtractUtils.getTypeSource(type));
|
| @@ -421,7 +600,7 @@ public class QuickFixProcessor implements IQuickFixProcessor {
|
| sb.append(name);
|
| sb.endPosition();
|
| }
|
| - addFix_createUnresolvedMethod_parameters(sb, invocation);
|
| + addFix_unresolvedMethodCreate_parameters(sb, invocation);
|
| sb.append(") {" + eol + prefix + "}");
|
| sb.append(sourceSuffix);
|
| }
|
| @@ -445,7 +624,7 @@ public class QuickFixProcessor implements IQuickFixProcessor {
|
| * @return the possible return {@link Type}, may be <code>null</code> if can not be identified.
|
| * {@link TypeKind#DYNAMIC} also returned as <code>null</code>.
|
| */
|
| - private Type addFix_createUnresolvedMethod_getReturnType(DartInvocation invocation) {
|
| + private Type addFix_unresolvedMethodCreate_getReturnType(DartInvocation invocation) {
|
| Type type = null;
|
| StructuralPropertyDescriptor invocationLocation = getLocationInParent(invocation);
|
| if (invocationLocation == DART_VARIABLE_VALUE) {
|
| @@ -458,7 +637,7 @@ public class QuickFixProcessor implements IQuickFixProcessor {
|
| return type;
|
| }
|
|
|
| - private void addFix_createUnresolvedMethod_parameters(SourceBuilder sb, DartInvocation invocation) {
|
| + private void addFix_unresolvedMethodCreate_parameters(SourceBuilder sb, DartInvocation invocation) {
|
| // append parameters
|
| sb.append("(");
|
| Set<String> excluded = Sets.newHashSet();
|
| @@ -494,119 +673,54 @@ public class QuickFixProcessor implements IQuickFixProcessor {
|
| }
|
| }
|
|
|
| - private void addFix_importLibrary(String importPath) throws Exception {
|
| - CompilationUnit libraryUnit = unit.getLibrary().getDefiningCompilationUnit();
|
| - // prepare new import location
|
| - SourceRange range;
|
| - String prefix;
|
| - String suffix;
|
| - {
|
| - String eol = utils.getEndOfLine();
|
| - // if no directives
|
| - range = SourceRangeFactory.forStartEnd(0, 0);
|
| - prefix = "";
|
| - suffix = eol;
|
| - // after last directive in library
|
| - {
|
| - DartUnit libraryUnitNode = DartCompilerUtilities.parseUnit(libraryUnit);
|
| - for (DartDirective directive : libraryUnitNode.getDirectives()) {
|
| - if (directive instanceof DartLibraryDirective || directive instanceof DartImportDirective) {
|
| - range = SourceRangeFactory.forEndLength(directive, 0);
|
| - prefix = eol;
|
| - suffix = "";
|
| + private void addFix_unresolvedMethodSimilar(IProblemLocation location) throws Exception {
|
| + if (node instanceof DartIdentifier && node.getParent() instanceof DartInvocation) {
|
| + DartInvocation invocation = (DartInvocation) node.getParent();
|
| + String name = ((DartIdentifier) node).getName();
|
| + String closestName = null;
|
| + ClosestElementFinder finder = new ClosestElementFinder(MethodElement.class, name);
|
| + // unqualified invocation
|
| + if (invocation instanceof DartUnqualifiedInvocation
|
| + && ((DartUnqualifiedInvocation) invocation).getTarget() == node) {
|
| + // may be invocation of method
|
| + {
|
| + DartClass enclosingClass = ASTNodes.getAncestor(invocation, DartClass.class);
|
| + if (enclosingClass != null) {
|
| + List<Element> allMembers = Elements.getAllMembers(enclosingClass.getElement());
|
| + finder.update(allMembers);
|
| }
|
| }
|
| - }
|
| - }
|
| - // insert new import
|
| - String importSource = prefix + "import '" + importPath + "';" + suffix;
|
| - addReplaceEdit(range, importSource);
|
| - // add proposal
|
| - proposalRelevance += 1;
|
| - addUnitCorrectionProposal(
|
| - libraryUnit,
|
| - TextFileChange.FORCE_SAVE,
|
| - Messages.format(CorrectionMessages.QuickFixProcessor_importLibrary, importPath),
|
| - DartPluginImages.get(DartPluginImages.IMG_CORRECTION_CHANGE));
|
| - }
|
| -
|
| - private void addFix_importLibrary_withElement(String name) throws Exception {
|
| - // ignore if private
|
| - if (name.startsWith("_")) {
|
| - return;
|
| - }
|
| - // prepare base URI
|
| - CompilationUnit libraryUnit = unit.getLibrary().getDefiningCompilationUnit();
|
| - URI unitNormalizedUri;
|
| - {
|
| - URI unitUri = libraryUnit.getUnderlyingResource().getLocationURI();
|
| - unitNormalizedUri = unitUri.resolve(".").normalize();
|
| - }
|
| - // may be there is existing import, but it is with prefix and we don't use this prefix
|
| - for (DartImport imp : unit.getLibrary().getImports()) {
|
| - String prefix = imp.getPrefix();
|
| - if (!StringUtils.isEmpty(prefix) && imp.getLibrary().findTopLevelElement(name) != null) {
|
| - SourceRange range = SourceRangeFactory.forStartLength(node, 0);
|
| - addReplaceEdit(range, prefix + ".");
|
| - // add proposal
|
| - proposalRelevance += 2;
|
| - addUnitCorrectionProposal(
|
| - libraryUnit,
|
| - TextFileChange.FORCE_SAVE,
|
| - Messages.format(
|
| - CorrectionMessages.QuickFixProcessor_importLibrary_addPrefix,
|
| - new Object[] {getSource(imp.getUriRange()), prefix}),
|
| - DartPluginImages.get(DartPluginImages.IMG_CORRECTION_CHANGE));
|
| - }
|
| - }
|
| - // prepare Dart model
|
| - DartModel model = DartCore.create(ResourcesPlugin.getWorkspace().getRoot());
|
| - // check workspace libraries
|
| - for (DartProject project : model.getDartProjects()) {
|
| - for (DartLibrary library : project.getDartLibraries()) {
|
| - if (library.findTopLevelElement(name) != null) {
|
| - URI libraryUri = library.getUri();
|
| - URI libraryRelativeUri = unitNormalizedUri.relativize(libraryUri);
|
| - if (StringUtils.isEmpty(libraryRelativeUri.getScheme())) {
|
| - String importPath = libraryRelativeUri.toString();
|
| - addFix_importLibrary(importPath);
|
| - }
|
| + // may be invocation of top-level function
|
| + {
|
| + DartUnit enclosingUnit = ASTNodes.getAncestor(invocation, DartUnit.class);
|
| + LibraryElement enclosingLibrary = enclosingUnit.getLibrary().getElement();
|
| + finder.update(enclosingLibrary.getImportScope().getElements().values());
|
| + finder.update(enclosingLibrary.getScope().getElements().values());
|
| }
|
| }
|
| - }
|
| - // check SDK libraries
|
| - PackageLibraryManager libraryManager = PackageLibraryManagerProvider.getPackageLibraryManager();
|
| - for (DartLibrary library : model.getBundledLibraries()) {
|
| - if (library.findTopLevelElement(name) != null) {
|
| - URI libraryUri = library.getUri();
|
| - URI libraryShortUri = libraryManager.getShortUri(libraryUri);
|
| - if (libraryShortUri != null) {
|
| - String importPath = libraryShortUri.toString();
|
| - addFix_importLibrary(importPath);
|
| + // qualified invocation
|
| + if (invocation instanceof DartMethodInvocation
|
| + && ((DartMethodInvocation) invocation).getFunctionName() == node) {
|
| + DartExpression targetExpression = ((DartMethodInvocation) invocation).getRealTarget();
|
| + Element targetElement = getTypeElement(targetExpression);
|
| + if (targetElement instanceof ClassElement) {
|
| + ClassElement targetClassElement = (ClassElement) targetElement;
|
| + List<Element> allMembers = Elements.getAllMembers(targetClassElement);
|
| + finder.update(allMembers);
|
| }
|
| }
|
| - }
|
| - }
|
| -
|
| - private void addFix_importLibrary_withField(IProblemLocation location) throws Exception {
|
| - if (node instanceof DartIdentifier) {
|
| - String name = ((DartIdentifier) node).getName();
|
| - addFix_importLibrary_withElement(name);
|
| - }
|
| - }
|
| -
|
| - private void addFix_importLibrary_withFunction(IProblemLocation location) throws Exception {
|
| - if (node instanceof DartIdentifier
|
| - && getLocationInParent(node) == DART_METHOD_INVOCATION_TARGET) {
|
| - String name = ((DartIdentifier) node).getName();
|
| - addFix_importLibrary_withElement(name);
|
| - }
|
| - }
|
| -
|
| - private void addFix_importLibrary_withType(IProblemLocation location) throws Exception {
|
| - if (mayBeTypeIdentifier(node)) {
|
| - String typeName = ((DartIdentifier) node).getName();
|
| - addFix_importLibrary_withElement(typeName);
|
| + // if we have close enough element, suggest to use it
|
| + if (finder != null && finder.distance < 5) {
|
| + closestName = finder.element.getName();
|
| + addReplaceEdit(SourceRangeFactory.create(node), closestName);
|
| + }
|
| + // add proposal
|
| + if (closestName != null) {
|
| + proposalRelevance += 1;
|
| + addUnitCorrectionProposal(
|
| + Messages.format(CorrectionMessages.QuickFixProcessor_changeTo, closestName),
|
| + DartPluginImages.get(DartPluginImages.IMG_CORRECTION_CHANGE));
|
| + }
|
| }
|
| }
|
|
|
|
|