private boolean relevantPropertiesHaveChanged(RuleGenerateWith generatorRule) {
      // Gather binding and configuration property values that have been changed in the part of
      // the library dependency tree on which this generator has not yet run.
      Multimap<String, String> newConfigurationPropertyValues =
          compilerContext.gatherNewConfigurationPropertyValuesForGenerator(generatorRule.getName());
      Multimap<String, String> newBindingPropertyValues =
          compilerContext.gatherNewBindingPropertyValuesForGenerator(generatorRule.getName());

      return generatorRule.caresAboutProperties(newConfigurationPropertyValues.keySet())
          || generatorRule.caresAboutProperties(newBindingPropertyValues.keySet());
    }
Beispiel #2
0
 static Multimap<String, JRunAsync> computeRunAsyncsByName(
     Collection<JRunAsync> runAsyncs, boolean onlyExplicitNames) {
   Multimap<String, JRunAsync> runAsyncsByName = LinkedListMultimap.create();
   for (JRunAsync runAsync : runAsyncs) {
     String name = runAsync.getName();
     if (name == null || (onlyExplicitNames && !runAsync.hasExplicitClassLiteral())) {
       continue;
     }
     runAsyncsByName.put(name, runAsync);
   }
   return runAsyncsByName;
 }
Beispiel #3
0
  public void addCompilationUnit(CompilationUnit compilationUnit) {
    String compilationUnitTypeSourceName = compilationUnit.getTypeName();
    compilationUnitsByTypeName.put(compilationUnitTypeSourceName, compilationUnit);
    compilationUnitTypeNames.add(compilationUnitTypeSourceName);

    Collection<CompiledClass> compiledClasses = compilationUnit.getCompiledClasses();
    for (CompiledClass compiledClass : compiledClasses) {
      String sourceName = compiledClass.getSourceName();
      String binaryName = InternalName.toBinaryName(compiledClass.getInternalName());
      nestedSourceNamesByCompilationUnitName.put(compilationUnitTypeSourceName, sourceName);
      nestedBinaryNamesByCompilationUnitName.put(compilationUnitTypeSourceName, binaryName);
      compilationUnitNamesByNestedSourceName.put(sourceName, compilationUnitTypeSourceName);
      compilationUnitNamesByNestedBinaryName.put(binaryName, compilationUnitTypeSourceName);
    }
  }
Beispiel #4
0
 @Override
 public CompilationUnit getCompilationUnitByTypeBinaryName(String typeBinaryName) {
   // Convert nested binary name to enclosing type source name.
   String typeSourceName =
       compilationUnitNamesByNestedBinaryName.get(typeBinaryName).iterator().next();
   return compilationUnitsByTypeName.get(typeSourceName);
 }
Beispiel #5
0
  private void onNewDirectory(Path directory) throws IOException {
    String relativePath = getRelativePath(directory);
    if (!relativePath.isEmpty() && !getPathPrefixSet().includesDirectory(relativePath)) {
      return;
    }

    if (watchService != null) {
      // Start watching the directory.
      directory.register(watchService, ENTRY_CREATE, ENTRY_DELETE);
    }

    try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory)) {
      for (Path child : stream) {
        childPathsByParentPath.put(directory, child);
        onNewPath(child);
      }
    }
  }
Beispiel #6
0
 private void onRemovedPath(Path path) {
   resolutionsByResource.remove(toFileResource(path));
   for (Path child : childPathsByParentPath.get(path)) {
     onRemovedPath(child);
   }
 }
Beispiel #7
0
  /**
   * Find a split point as designated in the {@link #PROP_INITIAL_SEQUENCE} configuration property.
   */
  public static JRunAsync findRunAsync(String refString, JProgram program, TreeLogger branch)
      throws UnableToCompleteException {
    SpeedTracerLogger.Event codeSplitterEvent =
        SpeedTracerLogger.start(CompilerEventType.CODE_SPLITTER, "phase", "findRunAsync");
    Multimap<String, JRunAsync> splitPointsByRunAsyncName =
        computeRunAsyncsByName(program.getRunAsyncs(), false);

    if (refString.startsWith("@")) {
      JsniRef jsniRef = JsniRef.parse(refString);
      if (jsniRef == null) {
        branch.log(
            TreeLogger.ERROR,
            "Badly formatted JSNI reference in " + PROP_INITIAL_SEQUENCE + ": " + refString);
        throw new UnableToCompleteException();
      }
      final String lookupErrorHolder[] = new String[1];
      JNode referent =
          JsniRefLookup.findJsniRefTarget(
              jsniRef,
              program,
              new JsniRefLookup.ErrorReporter() {
                @Override
                public void reportError(String error) {
                  lookupErrorHolder[0] = error;
                }
              });
      if (referent == null) {
        TreeLogger resolveLogger =
            branch.branch(TreeLogger.ERROR, "Could not resolve JSNI reference: " + jsniRef);
        resolveLogger.log(TreeLogger.ERROR, lookupErrorHolder[0]);
        throw new UnableToCompleteException();
      }

      if (!(referent instanceof JMethod)) {
        branch.log(TreeLogger.ERROR, "Not a method: " + referent);
        throw new UnableToCompleteException();
      }

      JMethod method = (JMethod) referent;
      String canonicalName = ReplaceRunAsyncs.getImplicitName(method);
      Collection<JRunAsync> splitPoints = splitPointsByRunAsyncName.get(canonicalName);
      if (splitPoints == null) {
        branch.log(TreeLogger.ERROR, "Method does not enclose a runAsync call: " + jsniRef);
        throw new UnableToCompleteException();
      }
      if (splitPoints.size() > 1) {
        branch.log(
            TreeLogger.ERROR,
            "Method includes multiple runAsync calls, "
                + "so it's ambiguous which one is meant: "
                + jsniRef);
        throw new UnableToCompleteException();
      }

      assert splitPoints.size() == 1;
      return splitPoints.iterator().next();
    }

    // Assume it's a raw class name
    Collection<JRunAsync> splitPoints = splitPointsByRunAsyncName.get(refString);
    if (splitPoints == null || splitPoints.size() == 0) {
      branch.log(TreeLogger.ERROR, "No runAsync call is labelled with class " + refString);
      throw new UnableToCompleteException();
    }
    if (splitPoints.size() > 1) {
      branch.log(
          TreeLogger.ERROR, "More than one runAsync call is labelled with class " + refString);
      throw new UnableToCompleteException();
    }
    assert splitPoints.size() == 1;
    JRunAsync result = splitPoints.iterator().next();
    codeSplitterEvent.end();

    return result;
  }
 @Override
 public void addNewConfigurationPropertyValuesByName(
     String propertyName, Iterable<String> propertyValues) {
   newConfigurationPropertyValuesByName.putAll(propertyName, propertyValues);
 }
 @Override
 public void addNewBindingPropertyValuesByName(
     String propertyName, Iterable<String> propertyValues) {
   newBindingPropertyValuesByName.putAll(propertyName, propertyValues);
 }