/**
  * @return {@code true} if two given {@link Element}s are {@link LocalElement}s and have
  *     intersecting with visibility ranges.
  */
 protected static boolean haveIntersectingRanges(LocalElement localElement, Element element) {
   if (!(element instanceof LocalElement)) {
     return false;
   }
   LocalElement localElement2 = (LocalElement) element;
   Source localSource = localElement.getSource();
   Source localSource2 = localElement2.getSource();
   SourceRange localRange = localElement.getVisibleRange();
   SourceRange localRange2 = localElement2.getVisibleRange();
   return Objects.equal(localSource2, localSource)
       && localRange != null
       && localRange2 != null
       && localRange2.intersects(localRange);
 }
 /**
  * @return if given unqualified {@link SearchMatch} intersects with visibility range of {@link
  *     LocalElement}.
  */
 protected static boolean isReferenceInLocalRange(
     LocalElement localElement, SearchMatch reference) {
   if (reference.isQualified()) {
     return false;
   }
   Source localSource = localElement.getSource();
   Source referenceSource = reference.getElement().getSource();
   SourceRange localRange = localElement.getVisibleRange();
   SourceRange referenceRange = reference.getSourceRange();
   return Objects.equal(referenceSource, localSource) && referenceRange.intersects(localRange);
 }
 private RefactoringStatus analyzePossibleConflicts(ProgressMonitor pm) {
   pm.beginTask("Analyze possible conflicts", 1);
   try {
     final RefactoringStatus result = new RefactoringStatus();
     // checks the resolved CompilationUnit(s)
     Source unitSource = element.getSource();
     Source[] librarySources = context.getLibrariesContaining(unitSource);
     for (Source librarySource : librarySources) {
       analyzePossibleConflicts_inLibrary(result, unitSource, librarySource);
     }
     pm.worked(1);
     // done
     return result;
   } finally {
     pm.done();
   }
 }
 @Override
 public Change createChange(ProgressMonitor pm) throws Exception {
   pm = checkProgressMonitor(pm);
   SourceChangeManager changeManager = new SourceChangeManager();
   // update declaration
   {
     Source source = element.getSource();
     SourceChange change = changeManager.get(source);
     addDeclarationEdit(change, element);
   }
   // update references
   List<SearchMatch> refMatches = searchEngine.searchReferences(element, null, null);
   List<SourceReference> references = getSourceReferences(refMatches);
   for (SourceReference reference : references) {
     SourceChange refChange = changeManager.get(reference.source);
     addReferenceEdit(refChange, reference);
   }
   // prepare change
   return new CompositeChange(getRefactoringName(), changeManager.getChanges());
 }
 @Override
 public boolean shouldReportUnsafeRefactoringSource(AnalysisContext context, Source source) {
   return element.getSource().equals(source);
 }