/** Checks if created method will shadow or will be shadowed by other elements. */
 private RefactoringStatus checkPossibleConflicts(IProgressMonitor pm) throws CoreException {
   List<SearchMatch> references = Lists.newArrayList();
   // top-level function
   if (parentMember.getParent() instanceof DartUnit) {
     RefactoringStatus conflictsStatus =
         RenameTopLevelProcessor.analyzePossibleConflicts(
             unit.getLibrary(), DartElement.FUNCTION, false, references, methodName);
     if (!conflictsStatus.isOK()) {
       return convertRenameToCreateStatus(conflictsStatus);
     }
   }
   // method of class
   if (parentMember.getParent() instanceof DartClass) {
     ClassElement enclosingClassElement = (ClassElement) parentMember.getParent().getElement();
     Type enclosingType = (Type) BindingUtils.getDartElement(enclosingClassElement);
     RefactoringStatus conflictsStatus =
         RenameTypeMemberProcessor.analyzePossibleConflicts(
             DartElement.FUNCTION, enclosingType, methodName, references, methodName, pm);
     if (!conflictsStatus.isOK()) {
       return convertRenameToCreateStatus(conflictsStatus);
     }
   }
   // OK
   return new RefactoringStatus();
 }
Beispiel #2
0
 @Override
 public Void visitIdentifier(DartIdentifier node) {
   if (foundElement == null) {
     int start = node.getSourceInfo().getOffset();
     int length = node.getSourceInfo().getLength();
     int end = start + length;
     if (start <= startOffset && endOffset <= end) {
       wordRegion = new Region(start, length);
       Element targetElement = DartAstUtilities.getElement(node, includeDeclarations);
       if (targetElement == null) {
         foundElement = null;
       } else {
         if (targetElement instanceof VariableElement) {
           VariableElement variableElement = (VariableElement) targetElement;
           resolvedElement = variableElement;
           if (variableElement.getKind() == ElementKind.PARAMETER
               || variableElement.getKind() == ElementKind.VARIABLE) {
             foundElement =
                 BindingUtils.getDartElement(compilationUnit.getLibrary(), variableElement);
             candidateRegion =
                 new Region(
                     variableElement.getNameLocation().getOffset(),
                     variableElement.getNameLocation().getLength());
           } else {
             foundElement = null;
           }
         } else {
           findElementFor(targetElement);
           // Import prefix is resolved into LibraryElement, so it is correct that corresponding
           // DartElement is DartLibrary, but this is not what we (and user) wants, because
           // it looses information. We want DartImport, it gives both DartLibrary and name.
           if (foundElement instanceof DartLibrary) {
             try {
               DartImport[] imports = compilationUnit.getLibrary().getImports();
               for (DartImport imprt : imports) {
                 if (Objects.equal(imprt.getLibrary(), foundElement)
                     && Objects.equal(imprt.getPrefix(), node.getName())) {
                   foundElement = imprt;
                   SourceRange range = imprt.getNameRange();
                   candidateRegion = new Region(range.getOffset(), range.getLength());
                 }
               }
             } catch (DartModelException e) {
               DartCore.logError("Cannot resolve import " + foundElement.getElementName(), e);
             }
           }
         }
       }
       throw new DartElementFoundException();
     }
   }
   return null;
 }
Beispiel #3
0
 /**
  * Given a compiler element representing some portion of the code base, set {@link #foundElement}
  * to the editor model element that corresponds to it.
  *
  * @param targetSymbol the compiler element representing some portion of the code base
  */
 private void findElementFor(Element targetSymbol) {
   if (targetSymbol == null) {
     return;
   }
   LibraryElement definingLibraryElement = BindingUtils.getLibrary(targetSymbol);
   DartLibrary definingLibrary = null;
   if (definingLibraryElement != null) {
     definingLibrary =
         BindingUtils.getDartElement(compilationUnit.getLibrary(), definingLibraryElement);
   }
   if (definingLibrary == null) {
     definingLibrary = compilationUnit.getLibrary();
   }
   resolvedElement = targetSymbol;
   foundElement = BindingUtils.getDartElement(definingLibrary, targetSymbol);
   if (foundElement instanceof SourceReference) {
     try {
       SourceRange range = ((SourceReference) foundElement).getNameRange();
       candidateRegion = new Region(range.getOffset(), range.getLength());
     } catch (DartModelException exception) {
       // Ignored
     }
   }
 }