コード例 #1
0
ファイル: DependencyChecker.java プロジェクト: sba1/teavm
  public void submitMethod(MethodReference methodRef, Program program) {
    if (!completing) {
      ClassHolder cls = classSource.get(methodRef.getClassName());

      if (cls == null) {
        throw new IllegalArgumentException("Class not found: " + methodRef.getClassName());
      }
      if (cls.getMethod(methodRef.getDescriptor()) != null) {
        throw new IllegalArgumentException("Method already exists: " + methodRef.getClassName());
      }
      MethodHolder method = new MethodHolder(methodRef.getDescriptor());
      method.getModifiers().add(ElementModifier.STATIC);
      method.setProgram(ProgramUtils.copy(program));
      new UnreachableBasicBlockEliminator().optimize(program);
      cls.addMethod(method);
    } else {
      MethodDependency dep = getMethod(methodRef);
      if (dep == null) {
        throw new IllegalArgumentException("Method was not reached: " + methodRef);
      }
      MethodHolder method = dep.method;

      if (!method.hasModifier(ElementModifier.NATIVE)) {
        throw new IllegalArgumentException("Method is not native: " + methodRef);
      }
      if (!dep.used) {
        return;
      }
      method.getModifiers().remove(ElementModifier.NATIVE);
      method.setProgram(ProgramUtils.copy(program));
      new UnreachableBasicBlockEliminator().optimize(method.getProgram());

      dep.used = false;
      lock(dep, false);
      tasks.add(
          () -> {
            DependencyGraphBuilder graphBuilder =
                new DependencyGraphBuilder(DependencyChecker.this);
            graphBuilder.buildGraph(dep);
            dep.used = true;
          });

      processQueue();
    }
  }
コード例 #2
0
 @Override
 public void transformClass(
     ClassHolder cls, ClassReaderSource innerSource, Diagnostics diagnostics) {
   for (MethodHolder method : cls.getMethods()) {
     if (method.getAnnotations().get(JavaScriptBody.class.getName()) != null) {
       AnnotationHolder genAnnot = new AnnotationHolder(GeneratedBy.class.getName());
       genAnnot
           .getValues()
           .put(
               "value",
               new AnnotationValue(ValueType.object(JavaScriptBodyGenerator.class.getName())));
       method.getAnnotations().add(genAnnot);
       method.setProgram(null);
       method.getModifiers().add(ElementModifier.NATIVE);
     }
   }
 }