Ejemplo n.º 1
0
 @Override
 public Void visitStringLiteral(DartStringLiteral node) {
   if (foundElement == null) {
     int start = node.getSourceInfo().getOffset();
     int length = node.getSourceInfo().getLength();
     int end = start + length;
     if (end == 0) {
       return null;
     }
     if (start <= startOffset && end >= endOffset) {
       wordRegion = computeInternalStringRegion(start, length);
       DartNode parent = node.getParent();
       if (parent instanceof DartSourceDirective
           && ((DartSourceDirective) parent).getSourceUri() == node) {
         // resolvedElement = ((DartSourceDirective) parent).getElement();
         DartLibrary library = compilationUnit.getLibrary();
         String fileName = getFileName(library, node.getValue());
         CompilationUnit sourcedUnit = library.getCompilationUnit(fileName);
         if (sourcedUnit != null && sourcedUnit.exists()) {
           foundElement = sourcedUnit;
         }
       } else if (parent instanceof DartResourceDirective
           && ((DartResourceDirective) parent).getResourceUri() == node) {
         // resolvedElement = ((DartResourceDirective) parent).getElement();
         DartLibrary library = compilationUnit.getLibrary();
         try {
           DartSource unitSource = compilationUnit.getSourceRef();
           if (unitSource != null) {
             LibrarySource librarySource = unitSource.getLibrary();
             if (librarySource != null) {
               DartSource resourceSource = librarySource.getSourceFor(node.getValue());
               if (resourceSource != null) {
                 URI resourceUri = resourceSource.getUri();
                 DartResource resource = library.getResource(resourceUri);
                 if (resource != null && resource.exists()) {
                   foundElement = resource;
                 }
               }
             }
           }
         } catch (DartModelException exception) {
           foundElement = null;
         }
       }
       throw new DartElementFoundException();
     }
   }
   return null;
 }