Package com.google.dart.engine.source

Examples of com.google.dart.engine.source.Source


   * @param task the task that was performed
   * @return an entry containing the computed results
   * @throws AnalysisException if the results could not be recorded
   */
  private HtmlEntry recordResolveHtmlTaskResults(ResolveHtmlTask task) throws AnalysisException {
    Source source = task.getSource();
    AnalysisException thrownException = task.getException();
    HtmlEntry htmlEntry = null;
    synchronized (cacheLock) {
      SourceEntry sourceEntry = cache.get(source);
      if (sourceEntry == null) {
        throw new ObsoleteSourceAnalysisException(source);
      } else if (!(sourceEntry instanceof HtmlEntry)) {
        // This shouldn't be possible because we should never have performed the task if the source
        // didn't represent an HTML file, but check to be safe.
        throw new AnalysisException(
            "Internal error: attempting to resolve non-HTML file as an HTML file: "
                + source.getFullName());
      }
      htmlEntry = (HtmlEntry) sourceEntry;
      long sourceTime = getModificationStamp(source);
      long resultTime = task.getModificationTime();
      if (sourceTime == resultTime) {
        if (htmlEntry.getModificationTime() != sourceTime) {
          // The source has changed without the context being notified. Simulate notification.
          sourceChanged(source);
          htmlEntry = getReadableHtmlEntry(source);
          if (htmlEntry == null) {
            throw new AnalysisException("An HTML file became a non-HTML file: "
                + source.getFullName());
          }
        }
        HtmlEntryImpl htmlCopy = htmlEntry.getWritableCopy();
        if (thrownException == null) {
          htmlCopy.setState(HtmlEntry.PARSED_UNIT, CacheState.FLUSHED);
View Full Code Here


   * @param task the task that was performed
   * @return an entry containing the computed results
   * @throws AnalysisException if the results could not be recorded
   */
  private DartEntry recordScanDartTaskResults(ScanDartTask task) throws AnalysisException {
    Source source = task.getSource();
    AnalysisException thrownException = task.getException();
    DartEntry dartEntry = null;
    synchronized (cacheLock) {
      SourceEntry sourceEntry = cache.get(source);
      if (sourceEntry == null) {
        throw new ObsoleteSourceAnalysisException(source);
      } else if (!(sourceEntry instanceof DartEntry)) {
        // This shouldn't be possible because we should never have performed the task if the source
        // didn't represent a Dart file, but check to be safe.
        throw new AnalysisException(
            "Internal error: attempting to parse non-Dart file as a Dart file: "
                + source.getFullName());
      }
      dartEntry = (DartEntry) sourceEntry;
      long sourceTime = getModificationStamp(source);
      long resultTime = task.getModificationTime();
      if (sourceTime == resultTime) {
        if (dartEntry.getModificationTime() != sourceTime) {
          // The source has changed without the context being notified. Simulate notification.
          sourceChanged(source);
          dartEntry = getReadableDartEntry(source);
          if (dartEntry == null) {
            throw new AnalysisException("A Dart file became a non-Dart file: "
                + source.getFullName());
          }
        }
        DartEntryImpl dartCopy = dartEntry.getWritableCopy();
        if (thrownException == null) {
          LineInfo lineInfo = task.getLineInfo();
View Full Code Here

   * @param dartEntry the entry containing the list of included parts
   */
  private void removeFromParts(Source librarySource, DartEntry dartEntry) {
    Source[] oldParts = dartEntry.getValue(DartEntry.INCLUDED_PARTS);
    for (int i = 0; i < oldParts.length; i++) {
      Source partSource = oldParts[i];
      DartEntry partEntry = getReadableDartEntry(partSource);
      if (partEntry != null && partEntry != dartEntry) {
        DartEntryImpl partCopy = partEntry.getWritableCopy();
        partCopy.removeContainingLibrary(librarySource);
        if (partCopy.getContainingLibraries().size() == 0 && !exists(partSource)) {
View Full Code Here

   *
   * @param oldPartMap the table containing the parts associated with each library
   */
  private void removeFromPartsUsingMap(HashMap<Source, Source[]> oldPartMap) {
    for (Map.Entry<Source, Source[]> entry : oldPartMap.entrySet()) {
      Source librarySource = entry.getKey();
      Source[] oldParts = entry.getValue();
      for (int i = 0; i < oldParts.length; i++) {
        Source partSource = oldParts[i];
        if (!partSource.equals(librarySource)) {
          DartEntry partEntry = getReadableDartEntry(partSource);
          if (partEntry != null) {
            DartEntryImpl partCopy = partEntry.getWritableCopy();
            partCopy.removeContainingLibrary(librarySource);
            if (partCopy.getContainingLibraries().size() == 0 && !exists(partSource)) {
View Full Code Here

   *
   * @return the type "Future" from the dart:async library
   */
  private Type getLoadLibraryReturnType() {
    try {
      Source asyncSource = context.getSourceFactory().forUri(DartSdk.DART_ASYNC);
      if (asyncSource == null) {
        AnalysisEngine.getInstance().getLogger().logError(
            "Could not create a source for dart:async");
        return VoidTypeImpl.getInstance();
      }
View Full Code Here

   *
   * @return {@code true} if the receiver directly or indirectly imports the dart:html libraries
   */
  private boolean isOrImportsBrowserLibrary() {
    List<LibraryElement> visited = new ArrayList<LibraryElement>(10);
    Source htmlLibSource = context.getSourceFactory().forUri(DartSdk.DART_HTML);
    visited.add(this);
    for (int index = 0; index < visited.size(); index++) {
      LibraryElement library = visited.get(index);
      Source source = library.getDefiningCompilationUnit().getSource();
      if (source.equals(htmlLibSource)) {
        return true;
      }
      for (LibraryElement importedLibrary : library.getImportedLibraries()) {
        if (!visited.contains(importedLibrary)) {
          visited.add(importedLibrary);
View Full Code Here

   * @return {@code true} if and only if an error code is generated on the passed node
   * @see PubSuggestionCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE
   */
  private boolean checkForFileImportInsideLibReferencesFileOutside(StringLiteral uriLiteral,
      String path) {
    Source source = getSource(uriLiteral);
    String fullName = getSourceFullName(source);
    if (fullName != null) {
      int pathIndex = 0;
      int fullNameIndex = fullName.length();
      while (pathIndex < path.length()
          && StringUtilities.startsWith3(path, pathIndex, '.', '.', '/')) {
        fullNameIndex = fullName.lastIndexOf('/', fullNameIndex);
        if (fullNameIndex < 4) {
          return false;
        }
        // Check for "/lib" at a specified place in the fullName
        if (StringUtilities.startsWith4(fullName, fullNameIndex - 4, '/', 'l', 'i', 'b')) {
          String relativePubspecPath = path.substring(0, pathIndex + 3).concat(PUBSPEC_YAML);
          Source pubspecSource = context.getSourceFactory().resolveUri(source, relativePubspecPath);
          if (context.exists(pubspecSource)) {
            // Files inside the lib directory hierarchy should not reference files outside
            errorReporter.reportErrorForNode(
                PubSuggestionCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE,
                uriLiteral);
View Full Code Here

    return false;
  }

  private boolean checkForFileImportOutsideLibReferencesFileInsideAtIndex(StringLiteral uriLiteral,
      String path, int pathIndex) {
    Source source = getSource(uriLiteral);
    String relativePubspecPath = path.substring(0, pathIndex).concat(PUBSPEC_YAML);
    Source pubspecSource = context.getSourceFactory().resolveUri(source, relativePubspecPath);
    if (!context.exists(pubspecSource)) {
      return false;
    }
    String fullName = getSourceFullName(source);
    if (fullName != null) {
View Full Code Here

   *
   * @param node the node (not {@code null})
   * @return the source or {@code null} if it could not be determined
   */
  private Source getSource(AstNode node) {
    Source source = null;
    CompilationUnit unit = node.getAncestor(CompilationUnit.class);
    if (unit != null) {
      CompilationUnitElement element = unit.getElement();
      if (element != null) {
        source = element.getSource();
View Full Code Here

  @Override
  public String getExtendedDisplayName(String shortName) {
    if (shortName == null) {
      shortName = getDisplayName();
    }
    Source source = getSource();
    if (source != null) {
      return shortName + " (" + source.getFullName() + ")";
    }
    return shortName;
  }
View Full Code Here

TOP

Related Classes of com.google.dart.engine.source.Source

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.