Esempio n. 1
0
    @Override
    public void run() throws Exception {
      final PackageLibraryManager libraryManager =
          PackageLibraryManagerProvider.getPackageLibraryManager();
      final LibraryElement enclosingLibrary =
          cachedLibraries.get(librarySource.wrappedSource).getElement();

      // Try to find the core library in the enclosing set of libraries, otherwise the typeAnalyzer
      // will be void of core types.
      LibraryUnit coreUnit;
      // All calls to DartC must be synchronized
      synchronized (compilerLock) {
        coreUnit = DartCompiler.getCoreLib(enclosingLibrary.getLibraryUnit());
      }
      if (coreUnit == null) {
        throw new RuntimeException("Unable to locate core library");
      }
      LibraryElement coreLibrary = coreUnit.getElement();

      SourceDelta delta =
          new SourceDelta() {

            @Override
            public DartSource getSourceAfter() {
              return source;
            }

            @Override
            public Source getSourceBefore() {
              for (DartUnit u : enclosingLibrary.getLibraryUnit().getUnits()) {
                Source unitSource = u.getSourceInfo().getSource();
                if (unitSource.getUri().equals(unitUri)) {
                  return unitSource;
                }
              }
              return null;
            }

            @Override
            public DartUnit getUnitAfter() {
              return parsedUnit;
            }
          };
      final CompilerConfiguration config =
          new DefaultCompilerConfiguration(DartCompilerUtilities.COMPILER_OPTIONS, libraryManager) {

            @Override
            public boolean incremental() {
              return true;
            }

            @Override
            public boolean resolveDespiteParseErrors() {
              return true;
            }

            @Override
            public boolean typeErrorsAreFatal() {
              return false;
            }

            @Override
            public boolean warningsAreFatal() {
              return false;
            }
          };
      // All calls to DartC must be synchronized
      synchronized (compilerLock) {
        analyzedNode =
            DartCompiler.analyzeDelta(
                delta,
                enclosingLibrary,
                coreLibrary,
                completionNode,
                completionLocation,
                0,
                config,
                this);
      }
    }