コード例 #1
1
 public void test_performOperation_whenException() throws Exception {
   Logger oldLogger = AnalysisEngine.getInstance().getLogger();
   try {
     Error myException = new Error();
     when(unit.accept(isA(AngularHtmlIndexContributor.class))).thenThrow(myException);
     // set mock Logger
     Logger logger = mock(Logger.class);
     AnalysisEngine.getInstance().setLogger(logger);
     // run operation
     operation.performOperation();
     // verify that "myException" was logged
     verify(logger).logError(anyString(), same(myException));
   } finally {
     AnalysisEngine.getInstance().setLogger(oldLogger);
   }
 }
コード例 #2
0
 /**
  * Ensure that the dart VM is executable. If it is not, make it executable and log that it was
  * necessary for us to do so.
  */
 @DartBlockBody({})
 private void ensureVmIsExecutable() {
   File dartVm = getVmExecutable();
   if (dartVm != null) {
     if (!dartVm.canExecute()) {
       FileUtilities.makeExecutable(dartVm);
       AnalysisEngine.getInstance().getLogger().logError(dartVm.getPath() + " was not executable");
     }
   }
 }
コード例 #3
0
 @Override
 public Source fromFileUri(URI uri) {
   File file = new File(uri);
   String filePath = file.getAbsolutePath();
   String libPath = getLibraryDirectory().getAbsolutePath();
   if (!filePath.startsWith(libPath + File.separator)) {
     return null;
   }
   filePath = filePath.substring(libPath.length() + 1);
   for (SdkLibrary library : libraryMap.getSdkLibraries()) {
     String libraryPath = library.getPath();
     if (filePath.replace('\\', '/').equals(libraryPath)) {
       String path = library.getShortName();
       try {
         return new FileBasedSource(new URI(path), file);
       } catch (URISyntaxException exception) {
         AnalysisEngine.getInstance()
             .getLogger()
             .logInformation("Failed to create URI: " + path, exception);
         return null;
       }
     }
     libraryPath = new File(libraryPath).getParent();
     if (filePath.startsWith(libraryPath + File.separator)) {
       String path = library.getShortName() + "/" + filePath.substring(libraryPath.length() + 1);
       try {
         return new FileBasedSource(new URI(path), file);
       } catch (URISyntaxException exception) {
         AnalysisEngine.getInstance()
             .getLogger()
             .logInformation("Failed to create URI: " + path, exception);
         return null;
       }
     }
   }
   return null;
 }
コード例 #4
0
  public void test_dartEngineAnalysis() throws AnalysisException {
    String svnRootName = System.getProperty("svnRoot");
    assertNotNull("Missing property value: set using -DsvnRoot=...", svnRootName);
    File svnRoot = new File(svnRootName);
    assertTrue("Invalid property value: svnRoot directory does not exist", svnRoot.exists());

    DartSdk sdk = DirectoryBasedDartSdk.getDefaultSdk();
    assertNotNull(
        "Missing or invalid property value: set using -Dcom.google.dart.sdk=...", svnRootName);
    SourceFactory sourceFactory =
        new SourceFactory(new DartUriResolver(sdk), new FileUriResolver());
    AnalysisContext context = AnalysisEngine.getInstance().createAnalysisContext();
    context.setSourceFactory(sourceFactory);

    FileBasedSource engineSource =
        new FileBasedSource(
            sourceFactory.getContentCache(),
            new File(svnRoot, "pkg/analyzer_experimental/lib/src/generated/engine.dart"));
    long startTime = System.currentTimeMillis();
    LibraryElement library = context.computeLibraryElement(engineSource);
    verify(library);
    long endTime = System.currentTimeMillis();
    //
    // Print out timing information.
    //
    System.out.print("Resolved Dart analysis engine in ");
    System.out.print(endTime - startTime);
    System.out.println(" ms");
    System.out.println();
    printStatistics();
    //
    // Print out memory usage information.
    //
    //    MemoryUsage usage = MemoryUtilities.measureMemoryUsage(library);
    //    PrintWriter writer = new PrintWriter(System.out);
    //    usage.writeSummary(writer);
    //    writer.flush();
    //
    // Validate that there were no errors.
    //
    assertValid();
  }
コード例 #5
0
  /**
   * Read all of the configuration files to initialize the library maps.
   *
   * @param useDart2jsPaths {@code true} if the dart2js path should be used when it is available
   * @return the initialized library map
   */
  protected LibraryMap initialLibraryMap(boolean useDart2jsPaths) {

    File librariesFile =
        new File(
            new File(
                new File(new File(getLibraryDirectory(), INTERNAL_DIR), SDK_LIB_METADATA_DIR),
                SDK_LIB_METADATA_LIB_DIR),
            LIBRARIES_FILE);
    if (!librariesFile.exists()) {
      // Fall back to pre SDK reorg location.
      librariesFile = getLegacyLibrariesFile();
    }
    try {
      String contents = FileUtilities.getContents(librariesFile);
      return new SdkLibrariesReader(useDart2jsPaths).readFromFile(librariesFile, contents);
    } catch (Exception exception) {
      AnalysisEngine.getInstance()
          .getLogger()
          .logError(
              "Could not initialize the library map from " + librariesFile.getAbsolutePath(),
              exception);
      return new LibraryMap();
    }
  }
コード例 #6
0
 public void validate() {
   StringBuilder builder = new StringBuilder();
   if (accessors != null) {
     builder.append(accessors.size());
     builder.append(" accessors");
   }
   if (constructors != null) {
     if (builder.length() > 0) {
       builder.append("; ");
     }
     builder.append(constructors.size());
     builder.append(" constructors");
   }
   if (fields != null) {
     if (builder.length() > 0) {
       builder.append("; ");
     }
     builder.append(fields.size());
     builder.append(" fields");
   }
   if (functions != null) {
     if (builder.length() > 0) {
       builder.append("; ");
     }
     builder.append(functions.size());
     builder.append(" functions");
   }
   if (labels != null) {
     if (builder.length() > 0) {
       builder.append("; ");
     }
     builder.append(labels.size());
     builder.append(" labels");
   }
   if (localVariables != null) {
     if (builder.length() > 0) {
       builder.append("; ");
     }
     builder.append(localVariables.size());
     builder.append(" local variables");
   }
   if (methods != null) {
     if (builder.length() > 0) {
       builder.append("; ");
     }
     builder.append(methods.size());
     builder.append(" methods");
   }
   if (parameters != null) {
     if (builder.length() > 0) {
       builder.append("; ");
     }
     builder.append(parameters.size());
     builder.append(" parameters");
   }
   if (topLevelVariables != null) {
     if (builder.length() > 0) {
       builder.append("; ");
     }
     builder.append(topLevelVariables.size());
     builder.append(" top-level variables");
   }
   if (types != null) {
     if (builder.length() > 0) {
       builder.append("; ");
     }
     builder.append(types.size());
     builder.append(" types");
   }
   if (typeAliases != null) {
     if (builder.length() > 0) {
       builder.append("; ");
     }
     builder.append(typeAliases.size());
     builder.append(" type aliases");
   }
   if (typeParameters != null) {
     if (builder.length() > 0) {
       builder.append("; ");
     }
     builder.append(typeParameters.size());
     builder.append(" type parameters");
   }
   if (builder.length() > 0) {
     AnalysisEngine.getInstance()
         .getLogger()
         .logError("Failed to capture elements: " + builder.toString());
   }
 }