Beispiel #1
0
  private boolean isValidSelectedFile() {
    if (selectedFile == null) {
      return false;
    }

    if (!DartCore.isDartLikeFileName(selectedFile.getName())) {
      return false;
    }

    DartElement element = DartCore.create(selectedFile);

    if (element instanceof CompilationUnit) {
      CompilationUnit cu = (CompilationUnit) element;

      DartLibrary lib = cu.getLibrary();

      if (lib instanceof DartLibraryImpl) {
        DartLibraryImpl impl = (DartLibraryImpl) lib;

        return impl.hasMain() && !impl.isBrowserApplication();
      }
    }

    return false;
  }
Beispiel #2
0
  /**
   * Parse the source for the specified compilation unit and resolve any elements found in it. Any
   * exceptions thrown by the {@link DartParser} will be added to the given collection.
   *
   * @param compilationUnit the compilation unit (not <code>null</code>)
   * @param parseErrors a collection to which parse errors are added or <code>null</code> if parse
   *     errors should be ignored
   * @return the parse result
   */
  public static DartUnit resolveUnit(
      CompilationUnit compilationUnit, Collection<DartCompilationError> parseErrors)
      throws DartModelException {

    long start = System.currentTimeMillis();

    DartLibraryImpl library = (DartLibraryImpl) compilationUnit.getLibrary();
    if (library == null) {
      // If we cannot get the library, we cannot resolve any elements so we
      // revert to simply parsing the compilation unit.
      DartUnit ret = parseUnit(compilationUnit, parseErrors);

      long elapsed = System.currentTimeMillis() - start;
      Instrumentation.metric("DartCompilerUtils-resolveUnit", elapsed)
          .with("ParseOnlyFallback", "true")
          .log();

      Instrumentation.operation("DartCompilerUtils-resolveUnit", elapsed)
          .with("ParseOnlyFallback", "true")
          .with("CompilaitonUnit-ElementName", compilationUnit.getElementName())
          .log();

      return ret;
    }
    IResource resource = compilationUnit.getResource();
    URI unitUri = null;
    if (resource != null) {
      unitUri = resource.getLocationURI();
    }
    if (unitUri == null && compilationUnit instanceof ExternalCompilationUnitImpl) {
      unitUri = ((ExternalCompilationUnitImpl) compilationUnit).getUri();
    }
    if (unitUri == null) {
      unitUri = ((CompilationUnitImpl) compilationUnit).getSourceRef().getUri();
    }
    String unitSource = compilationUnit.getSource();
    Map<URI, String> suppliedSources = new HashMap<URI, String>();
    if (unitSource != null) {
      suppliedSources.put(unitUri, unitSource);
    }
    DartUnit ret =
        resolveUnit(library.getLibrarySourceFile(), unitUri, suppliedSources, parseErrors);

    long elapsed = System.currentTimeMillis() - start;
    Instrumentation.metric("DartCompilerUtils-resolveUnit", elapsed)
        .with("ParseOnlyFallback", "false")
        .log();

    Instrumentation.operation("DartCompilerUtils-resolveUnit", elapsed)
        .with("ParseOnlyFallback", "false")
        .with("CompilaitonUnit-ElementName", compilationUnit.getElementName())
        .with("compilationUnit.LastModified", compilationUnit.getModificationStamp())
        .log();

    return ret;
  }
Beispiel #3
0
  /** Map from the source language to the target language (Dart to Javascript). */
  public SourceLocation mapDartToJavascript(IFile file, int line) {
    // given the file, find the dart element
    DartElement dartElement = DartCore.create(file);

    if (dartElement == null) {
      return SourceLocation.UNKNOWN_LOCATION;
    }

    // given that, find the dart application / library
    DartLibraryImpl dartLibrary = (DartLibraryImpl) dartElement.getAncestor(DartLibrary.class);

    if (dartLibrary == null) {
      return SourceLocation.UNKNOWN_LOCATION;
    }

    try {
      // [out/DartAppFileName.app.js.map]

      IPath outputLocation = getMainDartProject().getOutputLocation();

      List<LibraryConfigurationFileImpl> libraryConfigurationFiles =
          dartLibrary.getChildrenOfType(LibraryConfigurationFileImpl.class);

      //      if (libraryConfigurationFiles.size() > 0) {
      //        String libraryName = libraryConfigurationFiles.get(0).getFile().getName();
      //
      //        IPath sourceMapPath = outputLocation.append(libraryName + ".js.map");
      //
      //        SourceMapping mapping = getCachedSourceMappingPath(sourceMapPath);
      //
      //        if (mapping != null && mapping instanceof SourceMappingReversable) {
      //          SourceMappingReversable revMapping = (SourceMappingReversable) mapping;
      //
      //          String sourcePath = findMatchingSourcePath(file, revMapping);
      //
      //          if (sourcePath != null) {
      //            Collection<OriginalMapping> mappings = revMapping.getReverseMapping(sourcePath,
      // line, 1);
      //
      //            // TODO(devoncarew): We need to handle the case where there are more then one
      // mappings
      //            // returned; this will probably involve setting one breakpoint per mapping. More
      // then
      //            // one mapping ==> something like a function that's been inlined into multiple
      // places.
      //            if (mappings.size() > 0) {
      //              OriginalMapping map = mappings.iterator().next();
      //
      //              String fileName = map.getOriginalFile();
      //              int lineNumber = map.getLineNumber();
      //
      //              return new SourceLocation(new Path(fileName), lineNumber);
      //            }
      //          }
      //        }
      //      }
    } catch (DartModelException exception) {
      DartCore.logError(exception);
    }

    return SourceLocation.UNKNOWN_LOCATION;
  }