Esempio n. 1
0
 @Override
 public LibrarySource getImportFor(String relPath) throws IOException {
   try {
     return wrappedSource.getImportFor(relPath);
   } catch (Exception exception) {
     DartCore.logInformation("Could not find import: '" + relPath + "'", exception);
     return null;
   }
 }
Esempio n. 2
0
 /**
  * Initialize this index from the given file.
  *
  * @param indexFile the file from which this index is to be initialized
  * @return <code>true</code> if the index was correctly initialized
  */
 private boolean initializeIndexFrom(File indexFile) {
   if (indexFile == null) {
     if (DartCoreDebug.TRACE_INDEX_STATISTICS) {
       DartCore.logInformation("Index file was null");
     }
     return false;
   } else if (!indexFile.exists()) {
     if (DartCoreDebug.TRACE_INDEX_STATISTICS) {
       DartCore.logInformation("Index file " + indexFile.getAbsolutePath() + " does not exist");
     }
     return false;
   }
   if (DartCoreDebug.TRACE_INDEX_STATISTICS) {
     DartCore.logInformation(
         "About to initialize the index from file "
             + indexFile.getAbsolutePath()
             + " (size = "
             + indexFile.getTotalSpace()
             + " bytes)");
   }
   try {
     boolean wasRead = readIndexFrom(indexFile);
     if (DartCoreDebug.TRACE_INDEX_STATISTICS) {
       logIndexStats("After initializing the index from file " + indexFile.getAbsolutePath());
     }
     synchronized (indexStore) {
       return wasRead && indexStore.getResourceCount() > 0;
     }
   } catch (Exception exception) {
     DartCore.logError("Could not read index file " + indexFile.getAbsolutePath(), exception);
   }
   if (DartCoreDebug.TRACE_INDEX_STATISTICS) {
     logIndexStats("Deleting corrupted index file " + indexFile.getAbsolutePath());
   }
   try {
     indexFile.delete();
   } catch (Exception exception) {
     DartCore.logError(
         "Could not delete corrupt index file " + indexFile.getAbsolutePath(), exception);
   }
   return false;
 }
Esempio n. 3
0
 /**
  * Report the number of milliseconds spent indexing since the last time this value was reported
  * and cleared, clearing the value after reporting it.
  */
 public void reportAndResetIndexingTime() {
   if (performanceRecorder != null) {
     DartCore.logInformation(
         "Indexed "
             + performanceRecorder.getResourceCount()
             + " resources in "
             + performanceRecorder.getTotalIndexTime()
             + " ms ["
             + performanceRecorder.getTotalBindingTime()
             + " ms in binding]");
     performanceRecorder.clear();
   }
 }
Esempio n. 4
0
 @Override
 public Void visitNode(DartNode node) {
   try {
     node.visitChildren(this);
   } catch (DartElementFoundException exception) {
     throw exception;
   } catch (Exception exception) {
     // Ignore the exception and proceed in order to visit the rest of the structure.
     DartCore.logInformation(
         "Exception caught while traversing an AST structure. Please report to the dartc team.",
         exception);
   }
   return null;
 }
 private void processType(DartIdentifier node, InterfaceType binding) {
   CompilationUnitElement element = getDartElement(binding.asRawType());
   if (element instanceof Type) {
     Type type = (Type) element;
     try {
       recordRelationship(
           peekTarget(new SourceRangeImpl(node)), new TypeLocation(type, type.getNameRange()));
     } catch (DartModelException exception) {
       DartCore.logInformation(
           "Could not get range for type "
               + type.getElementName()
               + " referenced from type "
               + peekTarget().getDartElement().getElementName(),
           exception);
     }
   }
 }
 /**
  * Projects do not allow a link to be created if there is another resource (linked or not) whose
  * name is the same as the new name with only case differences. Return <code>true</code> if the
  * project has a member whose name is the same when case is ignored.
  *
  * @param project the project containing the members
  * @param fileName the name being checked for
  * @return <code>true</code> if the project has a member whose name is the same when case is
  *     ignored
  * @throws
  */
 private static boolean hasSimilarChild(IProject project, String fileName) {
   try {
     IResource[] members = project.members();
     if (members == null) {
       return false;
     }
     for (IResource member : members) {
       if (member.getName().equalsIgnoreCase(fileName)) {
         return true;
       }
     }
   } catch (CoreException exception) {
     DartCore.logInformation(
         "Could not get members of project " + project.getLocation(), exception);
   }
   return false;
 }
Esempio n. 7
0
 /**
  * Search within the given AST node for an identifier representing a {@link DartElement Dart
  * element} in the specified source range. Return the element that was found, or <code>null</code>
  * if no element was found.
  *
  * @param node the AST node within which to search
  * @return the element that was found
  */
 public DartElement searchWithin(DartNode node) {
   try {
     node.accept(this);
   } catch (DartElementFoundException exception) {
     // A node with the right source position was found.
   } catch (Exception exception) {
     DartCore.logInformation(
         "Unable to locate element at offset ("
             + startOffset
             + " - "
             + endOffset
             + ") in "
             + compilationUnit.getElementName(),
         exception);
     return null;
   }
   return foundElement;
 }
Esempio n. 8
0
 /**
  * Write the contents of this index to the given file.
  *
  * @param indexFile the file to which this index will be written
  * @throws IOException if the index could not be written to the given file
  */
 private void writeIndexTo(File indexFile) {
   boolean successfullyWritten = true;
   ObjectOutputStream output = null;
   try {
     output = new ObjectOutputStream(new FileOutputStream(indexFile));
     long startTime = System.currentTimeMillis();
     writeIndex(output);
     if (DartCoreDebug.PERF_INDEX) {
       long endTime = System.currentTimeMillis();
       DartCore.logInformation("Writing the index took " + (endTime - startTime) + " ms");
     }
   } catch (IOException exception) {
     successfullyWritten = false;
     DartCore.logError(
         "Could not write index file: \"" + indexFile.getAbsolutePath() + "\"", exception);
   } finally {
     if (output != null) {
       try {
         output.flush();
       } catch (IOException exception) {
         successfullyWritten = false;
         DartCore.logError(
             "Could not flush index file after write: \"" + indexFile.getAbsolutePath() + "\"",
             exception);
       }
       try {
         output.close();
       } catch (IOException exception) {
         successfullyWritten = false;
         DartCore.logError(
             "Could not close index file after write: \"" + indexFile.getAbsolutePath() + "\"",
             exception);
       }
     }
   }
   if (!successfullyWritten) {
     if (!indexFile.delete()) {
       DartCore.logError(
           "Could not delete corrupted index file: \"" + indexFile.getAbsolutePath() + "\"");
     }
   }
 }
Esempio n. 9
0
 /**
  * Read the contents of this index from the given file.
  *
  * @param indexFile the file from which this index will be read
  * @return {@code true} if the file was correctly read
  * @throws IOException if the index could not be read from the given file
  */
 private boolean readIndexFrom(File indexFile) throws IOException {
   ObjectInputStream input = null;
   try {
     input = new ObjectInputStream(new FileInputStream(indexFile));
     long startTime = System.currentTimeMillis();
     boolean wasRead = readIndex(input);
     if (DartCoreDebug.PERF_INDEX) {
       long endTime = System.currentTimeMillis();
       DartCore.logInformation("Reading the index took " + (endTime - startTime) + " ms");
     }
     return wasRead;
   } finally {
     if (input != null) {
       try {
         input.close();
       } catch (IOException exception) {
         DartCore.logError(
             "Could not close index file after read: \"" + indexFile.getAbsolutePath() + "\"",
             exception);
       }
     }
   }
 }
Esempio n. 10
0
 /** Write index statistics to the log. */
 public void logIndexStats(String message) {
   int relationshipCount;
   int attributeCount;
   int elementCount;
   int resourceCount;
   synchronized (indexStore) {
     relationshipCount = indexStore.getRelationshipCount();
     attributeCount = indexStore.getAttributeCount();
     elementCount = indexStore.getElementCount();
     resourceCount = indexStore.getResourceCount();
   }
   DartCore.logInformation(
       message
           + ": "
           + relationshipCount
           + " relationships and "
           + attributeCount
           + " attributes in "
           + elementCount
           + " elements in "
           + resourceCount
           + " resources");
 }
Esempio n. 11
0
 /**
  * Initialize this index with information from the bundled libraries.
  *
  * @return <code>true</code> if the bundled libraries were successfully indexed
  */
 private boolean indexBundledLibraries() {
   boolean librariesIndexed = true;
   long startTime = System.currentTimeMillis();
   PackageLibraryManager libraryManager = PackageLibraryManagerProvider.getPackageLibraryManager();
   ArrayList<String> librarySpecs = new ArrayList<String>(libraryManager.getAllLibrarySpecs());
   if (librarySpecs.remove("dart:html")) {
     librarySpecs.add("dart:html");
   }
   AnalysisServer analysisServer = PackageLibraryManagerProvider.getDefaultAnalysisServer();
   analysisServer.reanalyze();
   SavedContext savedContext = analysisServer.getSavedContext();
   for (String urlSpec : librarySpecs) {
     try {
       URI libraryUri = new URI(urlSpec);
       File libraryFile = new File(libraryManager.resolveDartUri(libraryUri));
       savedContext.resolve(libraryFile, null);
     } catch (URISyntaxException exception) {
       librariesIndexed = false;
       DartCore.logError(
           "Invalid URI returned from the system library manager: \"" + urlSpec + "\"", exception);
     } catch (Exception exception) {
       librariesIndexed = false;
       DartCore.logError("Could not index bundled libraries", exception);
     }
   }
   if (DartCoreDebug.PERF_INDEX) {
     long endTime = System.currentTimeMillis();
     DartCore.logInformation(
         "Initializing the index with information from bundled libraries took "
             + (endTime - startTime)
             + " ms ("
             + initIndexingTime
             + " ms indexing)");
   }
   return librariesIndexed;
 }
Esempio n. 12
0
 public void shutdown() {
   synchronized (indexStore) {
     if (DartCoreDebug.TRACE_INDEX_STATISTICS) {
       logIndexStats("In shutdown, before writing the index");
     }
     if (hasBeenInitialized) {
       if (hasPendingClear()) {
         try {
           if (DartCoreDebug.TRACE_INDEX_STATISTICS) {
             DartCore.logInformation("In shutdown, deleting the index file");
           }
           getIndexFile().delete();
         } catch (Exception exception) {
           DartCore.logError("Could not delete the index file", exception);
         }
       } else {
         writeIndexTo(getIndexFile());
         if (DartCoreDebug.TRACE_INDEX_STATISTICS) {
           logIndexStats("In shutdown, after writing the index");
         }
       }
     }
   }
 }