Esempio 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;
 }
Esempio n. 2
0
 public void test_DartModelManager_getLibraryName_directive() throws Exception {
   String libraryName = "library";
   DartUnit unit =
       new DartUnit(new TestDartSource("test.dart", "#library('" + libraryName + "')"));
   unit.addDirective(new DartLibraryDirective(DartStringLiteral.get(libraryName)));
   String result = getLibraryName(unit);
   assertEquals(libraryName, result);
 }
Esempio n. 3
0
 /**
  * Create a new node with the given type.
  *
  * @param nodeClass the class of the node to be created
  * @return the node that was created
  */
 @SuppressWarnings("unchecked")
 public <N extends DartNode> N createInstance(Class<N> nodeClass) {
   if (nodeClass == DartArrayAccess.class) {
     return (N) new DartArrayAccess(null, null);
   } else if (nodeClass == DartArrayLiteral.class) {
     return (N) new DartArrayLiteral(false, null, new ArrayList<DartExpression>());
   } else if (nodeClass == DartBinaryExpression.class) {
     return (N) new DartBinaryExpression(null, 0, null, null);
   } else if (nodeClass == DartBlock.class) {
     return (N) new DartBlock(new ArrayList<DartStatement>());
   } else if (nodeClass == DartBooleanLiteral.class) {
     return (N) DartBooleanLiteral.get(false);
   } else if (nodeClass == DartBreakStatement.class) {
     return (N) new DartBreakStatement(null);
   } else if (nodeClass == DartCase.class) {
     return (N) new DartCase(null, new ArrayList<DartLabel>(), new ArrayList<DartStatement>());
   } else if (nodeClass == DartCatchBlock.class) {
     return (N) new DartCatchBlock(null, null, null);
   } else if (nodeClass == DartClass.class) {
     return (N)
         new DartClass(
             null,
             null,
             null,
             new ArrayList<DartTypeNode>(),
             new ArrayList<DartNode>(),
             new ArrayList<DartTypeParameter>(),
             null,
             false,
             Modifiers.NONE);
   } else if (nodeClass == DartComment.class) {
     return (N) new DartComment(null, 0, 0, null);
   } else if (nodeClass == DartConditional.class) {
     return (N) new DartConditional(null, null, null);
   } else if (nodeClass == DartContinueStatement.class) {
     return (N) new DartContinueStatement(null);
   } else if (nodeClass == DartDefault.class) {
     return (N) new DartDefault(new ArrayList<DartLabel>(), new ArrayList<DartStatement>());
   } else if (nodeClass == DartDoubleLiteral.class) {
     return (N) DartDoubleLiteral.get(0.0);
   } else if (nodeClass == DartDoWhileStatement.class) {
     return (N) new DartDoWhileStatement(null, null);
   } else if (nodeClass == DartEmptyStatement.class) {
     return (N) new DartEmptyStatement();
   } else if (nodeClass == DartExprStmt.class) {
     return (N) new DartExprStmt(null);
   } else if (nodeClass == DartField.class) {
     return (N) new DartField(null, null, null, null);
   } else if (nodeClass == DartFieldDefinition.class) {
     return (N) new DartFieldDefinition(null, new ArrayList<DartField>());
   } else if (nodeClass == DartForStatement.class) {
     return (N) new DartForStatement(null, null, null, null);
   } else if (nodeClass == DartFunction.class) {
     return (N) new DartFunction(new ArrayList<DartParameter>(), null, null);
   } else if (nodeClass == DartFunctionExpression.class) {
     return (N) new DartFunctionExpression(null, null, false);
   } else if (nodeClass == DartFunctionObjectInvocation.class) {
     return (N) new DartFunctionObjectInvocation(null, new ArrayList<DartExpression>());
   } else if (nodeClass == DartFunctionTypeAlias.class) {
     return (N)
         new DartFunctionTypeAlias(
             null, null, new ArrayList<DartParameter>(), new ArrayList<DartTypeParameter>());
   } else if (nodeClass == DartIdentifier.class) {
     return (N) new DartIdentifier("");
   } else if (nodeClass == DartIfStatement.class) {
     return (N) new DartIfStatement(null, 0, null, 0, null);
   } else if (nodeClass == DartInitializer.class) {
     return (N) new DartInitializer(null, null);
   } else if (nodeClass == DartLabel.class) {
     return (N) new DartLabel(null, null);
   } else if (nodeClass == DartMapLiteral.class) {
     return (N) new DartMapLiteral(false, null, new ArrayList<DartMapLiteralEntry>());
   } else if (nodeClass == DartMapLiteralEntry.class) {
     return (N) new DartMapLiteralEntry(null, null);
   } else if (nodeClass == DartMethodDefinition.class) {
     return (N) DartMethodDefinition.create(null, null, null, null);
   } else if (nodeClass == DartMethodInvocation.class) {
     return (N) new DartMethodInvocation(null, false, null, new ArrayList<DartExpression>());
   } else if (nodeClass == DartNativeBlock.class) {
     return (N) new DartNativeBlock();
   } else if (nodeClass == DartNewExpression.class) {
     return (N) new DartNewExpression(null, new ArrayList<DartExpression>(), false);
   } else if (nodeClass == DartNullLiteral.class) {
     return (N) DartNullLiteral.get();
   } else if (nodeClass == DartParameter.class) {
     return (N)
         new DartParameter(null, null, new ArrayList<DartParameter>(), null, Modifiers.NONE);
   } else if (nodeClass == DartParenthesizedExpression.class) {
     return (N) new DartParenthesizedExpression(null);
   } else if (nodeClass == DartPropertyAccess.class) {
     return (N) new DartPropertyAccess(null, null);
   } else if (nodeClass == DartReturnStatement.class) {
     return (N) new DartReturnStatement(null);
   } else if (nodeClass == DartStringInterpolation.class) {
     return (N)
         new DartStringInterpolation(
             new ArrayList<DartStringLiteral>(), new ArrayList<DartExpression>());
   } else if (nodeClass == DartStringLiteral.class) {
     return (N) DartStringLiteral.get("");
   } else if (nodeClass == DartSuperConstructorInvocation.class) {
     return (N) new DartSuperConstructorInvocation(null, new ArrayList<DartExpression>());
   } else if (nodeClass == DartSuperExpression.class) {
     return (N) DartSuperExpression.get();
   } else if (nodeClass == DartSwitchStatement.class) {
     return (N) new DartSwitchStatement(null, new ArrayList<DartSwitchMember>());
   } else if (nodeClass == DartThisExpression.class) {
     return (N) DartThisExpression.get();
   } else if (nodeClass == DartThrowStatement.class) {
     return (N) new DartThrowStatement(null);
   } else if (nodeClass == DartTryStatement.class) {
     return (N) new DartTryStatement(null, new ArrayList<DartCatchBlock>(), null);
   } else if (nodeClass == DartTypeExpression.class) {
     return (N) new DartTypeExpression(null);
   } else if (nodeClass == DartTypeNode.class) {
     return (N) new DartTypeNode(null, new ArrayList<DartTypeNode>());
   } else if (nodeClass == DartTypeParameter.class) {
     return (N) new DartTypeParameter(null, null);
   } else if (nodeClass == DartUnaryExpression.class) {
     return (N) new DartUnaryExpression(null, 0, null, true);
   } else if (nodeClass == DartUnit.class) {
     return (N) new DartUnit(null, false);
   } else if (nodeClass == DartUnqualifiedInvocation.class) {
     return (N) new DartUnqualifiedInvocation(null, new ArrayList<DartExpression>());
   } else if (nodeClass == DartVariable.class) {
     return (N) new DartVariable(null, null);
   } else if (nodeClass == DartVariableStatement.class) {
     return (N) new DartVariableStatement(new ArrayList<DartVariable>(), null);
   } else if (nodeClass == DartWhileStatement.class) {
     return (N) new DartWhileStatement(null, null);
   }
   return null;
 }