com.sun.tools.javac.api.BasicJavacTask Java Examples

The following examples show how to use com.sun.tools.javac.api.BasicJavacTask. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: TencentKona-8   Author: Tencent   File: TestClose.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void add(ProcessingEnvironment env, Runnable r) {
    try {
        JavacTask task = JavacTask.instance(env);
        TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next();
        // The TaskListener is an instanceof TestClose, but when using the
        // default class loaders. the taskListener uses a different
        // instance of Class<TestClose> than the anno processor.
        // If you try to evaluate
        //      TestClose tc = (TestClose) (l).
        // you get the following somewhat confusing error:
        //   java.lang.ClassCastException: TestClose cannot be cast to TestClose
        // The workaround is to access the fields of TestClose with reflection.
        Field f = l.getClass().getField("runnables");
        @SuppressWarnings("unchecked")
        List<Runnable> runnables = (List<Runnable>) f.get(l);
        runnables.add(r);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
Example #2
Source Project: jdk8u60   Author: chenghanpeng   File: TestClose.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void add(ProcessingEnvironment env, Runnable r) {
    try {
        JavacTask task = JavacTask.instance(env);
        TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next();
        // The TaskListener is an instanceof TestClose, but when using the
        // default class loaders. the taskListener uses a different
        // instance of Class<TestClose> than the anno processor.
        // If you try to evaluate
        //      TestClose tc = (TestClose) (l).
        // you get the following somewhat confusing error:
        //   java.lang.ClassCastException: TestClose cannot be cast to TestClose
        // The workaround is to access the fields of TestClose with reflection.
        Field f = l.getClass().getField("runnables");
        @SuppressWarnings("unchecked")
        List<Runnable> runnables = (List<Runnable>) f.get(l);
        runnables.add(r);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
Example #3
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: TestClose.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void add(ProcessingEnvironment env, Runnable r) {
    try {
        JavacTask task = JavacTask.instance(env);
        TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next();
        // The TaskListener is an instanceof TestClose, but when using the
        // default class loaders. the taskListener uses a different
        // instance of Class<TestClose> than the anno processor.
        // If you try to evaluate
        //      TestClose tc = (TestClose) (l).
        // you get the following somewhat confusing error:
        //   java.lang.ClassCastException: TestClose cannot be cast to TestClose
        // The workaround is to access the fields of TestClose with reflection.
        Field f = l.getClass().getField("runnables");
        @SuppressWarnings("unchecked")
        List<Runnable> runnables = (List<Runnable>) f.get(l);
        runnables.add(r);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
Example #4
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: TestClose.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void add(ProcessingEnvironment env, Runnable r) {
    try {
        JavacTask task = JavacTask.instance(env);
        TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next();
        // The TaskListener is an instanceof TestClose, but when using the
        // default class loaders. the taskListener uses a different
        // instance of Class<TestClose> than the anno processor.
        // If you try to evaluate
        //      TestClose tc = (TestClose) (l).
        // you get the following somewhat confusing error:
        //   java.lang.ClassCastException: TestClose cannot be cast to TestClose
        // The workaround is to access the fields of TestClose with reflection.
        Field f = l.getClass().getField("runnables");
        @SuppressWarnings("unchecked")
        List<Runnable> runnables = (List<Runnable>) f.get(l);
        runnables.add(r);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
Example #5
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: TestClose.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void add(ProcessingEnvironment env, Runnable r) {
    // ensure this class in this class loader can access javac internals
    try {
        JavacTask task = JavacTask.instance(env);
        TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next();
        // The TaskListener is an instanceof TestClose, but when using the
        // default class loaders. the taskListener uses a different
        // instance of Class<TestClose> than the anno processor.
        // If you try to evaluate
        //      TestClose tc = (TestClose) (l).
        // you get the following somewhat confusing error:
        //   java.lang.ClassCastException: TestClose cannot be cast to TestClose
        // The workaround is to access the fields of TestClose with reflection.
        Field f = l.getClass().getField("runnables");
        @SuppressWarnings("unchecked")
        List<Runnable> runnables = (List<Runnable>) f.get(l);
        runnables.add(r);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
Example #6
Source Project: manifold   Author: manifold-systems   File: ExtensionTransformer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void visitAssignop( JCTree.JCAssignOp tree )
{
  super.visitAssignop( tree );

  if( _tp.isGenerate() && !shouldProcessForGeneration() )
  {
    // Don't process tree during GENERATE, unless the tree was generated e.g., a bridge method
    return;
  }

  if( isJailbreakReceiver( tree ) )
  {
    // +=, -=, etc. operators not supported with jailbreak, only direct assignment
    _tp.report( tree, Diagnostic.Kind.ERROR, ExtIssueMsg.MSG_COMPOUND_OP_NOT_ALLOWED_REFLECTION.get() );
    Types types = Types.instance( ((BasicJavacTask)_tp.getJavacTask()).getContext() );
    tree.type = types.createErrorType( tree.type );

    result = tree;
  }
  else
  {
    result = tree;
  }
}
 
Example #7
Source Project: manifold   Author: manifold-systems   File: ExtensionTransformer.java    License: Apache License 2.0 6 votes vote down vote up
private JCExpression makeClassExpr( JCTree tree, Type type )
{
  BasicJavacTask javacTask = (BasicJavacTask)_tp.getJavacTask();
  Types types = Types.instance( javacTask.getContext() );
  type = types.erasure( type );

  JCExpression classExpr;
  if( isPrimitiveOrPrimitiveArray( type ) ||
      (JreUtil.isJava8() && type.tsym.getModifiers().contains( javax.lang.model.element.Modifier.PUBLIC )) )
  {
    // class is publicly accessible, assume we can use class literal
    classExpr = _tp.getTreeMaker().ClassLiteral( type );
    classExpr.pos = tree.pos;
  }
  else
  {
    // generate `ReflectUtil.type( typeName )`
    classExpr = classForNameCall( type, tree );
  }
  return classExpr;
}
 
Example #8
Source Project: manifold   Author: manifold-systems   File: DynamicProxyFactory.java    License: Apache License 2.0 6 votes vote down vote up
private static boolean hasCallHandlerFromExtension( Class rootClass )
{
  Boolean isCallHandler = ICALL_HANDLER_MAP.get( rootClass );
  if( isCallHandler != null )
  {
    return isCallHandler;
  }

  String fqn = rootClass.getCanonicalName();
  BasicJavacTask javacTask = RuntimeManifoldHost.get().getJavaParser().getJavacTask();
  Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> classSymbol = ClassSymbols.instance( RuntimeManifoldHost.get().getSingleModule() ).getClassSymbol( javacTask, fqn );
  Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> callHandlerSymbol = ClassSymbols.instance( RuntimeManifoldHost.get().getSingleModule() ).getClassSymbol( javacTask, ICallHandler.class.getCanonicalName() );
  if( Types.instance( javacTask.getContext() ).isAssignable( classSymbol.getFirst().asType(), callHandlerSymbol.getFirst().asType() ) )
  {
    // Nominally implements ICallHandler
    isCallHandler = true;
  }
  else
  {
    // Structurally implements ICallHandler
    isCallHandler = hasCallMethod( javacTask, classSymbol.getFirst() );
  }
  ICALL_HANDLER_MAP.put( rootClass, isCallHandler );
  return isCallHandler;
}
 
Example #9
Source Project: manifold   Author: manifold-systems   File: JavacPlugin.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void init( JavacTask task, String... args )
{
  INSTANCE = this;

  // calling this here because the line below this references the type `BasicJavacTask`, which is in a jdk module needing exposure
  NecessaryEvilUtil.bypassJava9Security();

  _javacTask = (BasicJavacTask)task;

  JavacProcessingEnvironment jpe = JavacProcessingEnvironment.instance( _javacTask.getContext() );
  IS_JAVA_8 = jpe.getSourceVersion() == SourceVersion.RELEASE_8;

  processArgs( jpe, args );

  _host = new JavacManifoldHost();
  _fileFragmentResources = new ArrayList<>();
  _javaSourcePath = Collections.emptySet();
  assignBootclasspath();
  hijackJavacFileManager();
  task.addTaskListener( this );
}
 
Example #10
Source Project: manifold   Author: manifold-systems   File: JavaParser.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Compiles fresh, no caching.  Intended for use with parser feedback tooling e.g., a Java editor.
 */
public InMemoryClassJavaFileObject compile( JavaFileObject jfo, String fqn, Iterable<String> options, DiagnosticCollector<JavaFileObject> errorHandler )
{
  init();


  int check = _mfm.pushRuntimeMode();
  try
  {
    StringWriter errors = new StringWriter();
    BasicJavacTask javacTask = (BasicJavacTask)_javac.getTask(
      errors, _mfm, errorHandler, options, null, Collections.singletonList( jfo ) );
    initTypeProcessing( javacTask, Collections.singleton( fqn ) );
    javacTask.call();
    return _mfm.findCompiledFile( fqn );
  }
  finally
  {
    _mfm.popRuntimeMode( check );
  }
}
 
Example #11
Source Project: manifold   Author: manifold-systems   File: JavaParser.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Compiles a collection of java source files, intended for use a command line compiler.
 */
public Collection<InMemoryClassJavaFileObject> compile( Collection<JavaFileObject> files, Iterable<String> options, DiagnosticCollector<JavaFileObject> errorHandler )
{
  init();

  int check = _mfm.pushRuntimeMode();
  try
  {
    StringWriter errors = new StringWriter();
    BasicJavacTask javacTask = (BasicJavacTask)_javac.getTask( errors, _mfm, errorHandler, options, null, files );
    initTypeProcessing( javacTask, files.stream().map( this::getTypeForFile ).collect( Collectors.toSet() ) );
    javacTask.call();
    return _mfm.getCompiledFiles();
  }
  finally
  {
    _mfm.popRuntimeMode( check );
  }
}
 
Example #12
Source Project: manifold   Author: manifold-systems   File: SrcClassUtil.java    License: Apache License 2.0 6 votes vote down vote up
private String genSuperCtorCall( IModule module, SrcClass srcClass, BasicJavacTask javacTask )
{
  String bodyStmt;
  SrcType superClass = srcClass.getSuperClass();
  if( superClass == null )
  {
    bodyStmt = "";
  }
  else
  {
    Symbol.MethodSymbol superCtor = findConstructor( module, superClass.getFqName(), javacTask );
    if( superCtor == null )
    {
      bodyStmt = "";
    }
    else
    {
      bodyStmt = genSuperCtorCall( superCtor );
    }
  }
  return bodyStmt;
}
 
Example #13
Source Project: manifold   Author: manifold-systems   File: SrcClassUtil.java    License: Apache License 2.0 6 votes vote down vote up
private Symbol.MethodSymbol findConstructor( IModule module, String fqn, BasicJavacTask javacTask )
{
  manifold.rt.api.util.Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> classSymbol = ClassSymbols.instance( module ).getClassSymbol( javacTask, fqn );
  Symbol.ClassSymbol cs = classSymbol.getFirst();
  Symbol.MethodSymbol ctor = null;
  for( Symbol sym: cs.getEnclosedElements() )
  {
    if( sym instanceof Symbol.MethodSymbol && sym.flatName().toString().equals( "<init>" ) )
    {
      if( ctor == null )
      {
        ctor = (Symbol.MethodSymbol)sym;
      }
      else
      {
        ctor = mostAccessible( ctor, (Symbol.MethodSymbol)sym );
      }
      if( Modifier.isPublic( (int)ctor.flags() ) )
      {
        return ctor;
      }
    }
  }
  return ctor;
}
 
Example #14
Source Project: manifold   Author: manifold-systems   File: ClassSymbols.java    License: Apache License 2.0 6 votes vote down vote up
public SrcClass makeSrcClassStub( String fqn, JavaFileManager.Location location, DiagnosticListener<JavaFileObject> errorHandler )
  {
    BasicJavacTask javacTask = /*location != null && JavacPlugin.instance() != null ? JavacPlugin.instance().getJavacTask() :*/ getJavacTask_PlainFileMgr();
    Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> pair = getClassSymbol( javacTask, (JavaFileManager.Location)null /*location*/, fqn );
    if( pair == null )
    {
      //## todo: revisit this, but for now we need to return null to handle inner class extensions
      return null;
//      throw new IllegalStateException( "Failed to find class, '" + fqn + "'" );
    }
    Symbol.ClassSymbol classSymbol = pair.getFirst();
    if( classSymbol == null )
    {
      // For the case where the class is generated from a type manifold esp. from a IExtensionClassProducer
      return makeSrcClassStubFromProducedClass( fqn, location, errorHandler );
    }

    return SrcClassUtil.instance().makeStub( fqn, classSymbol, pair.getSecond(), getJavacTask_PlainFileMgr(), _module, location, errorHandler );
  }
 
Example #15
Source Project: hottub   Author: dsrg-uoft   File: TestClose.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void add(ProcessingEnvironment env, Runnable r) {
    try {
        JavacTask task = JavacTask.instance(env);
        TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next();
        // The TaskListener is an instanceof TestClose, but when using the
        // default class loaders. the taskListener uses a different
        // instance of Class<TestClose> than the anno processor.
        // If you try to evaluate
        //      TestClose tc = (TestClose) (l).
        // you get the following somewhat confusing error:
        //   java.lang.ClassCastException: TestClose cannot be cast to TestClose
        // The workaround is to access the fields of TestClose with reflection.
        Field f = l.getClass().getField("runnables");
        @SuppressWarnings("unchecked")
        List<Runnable> runnables = (List<Runnable>) f.get(l);
        runnables.add(r);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
Example #16
Source Project: openjdk-8-source   Author: keerath   File: TestClose.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void add(ProcessingEnvironment env, Runnable r) {
    try {
        JavacTask task = JavacTask.instance(env);
        TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next();
        // The TaskListener is an instanceof TestClose, but when using the
        // default class loaders. the taskListener uses a different
        // instance of Class<TestClose> than the anno processor.
        // If you try to evaluate
        //      TestClose tc = (TestClose) (l).
        // you get the following somewhat confusing error:
        //   java.lang.ClassCastException: TestClose cannot be cast to TestClose
        // The workaround is to access the fields of TestClose with reflection.
        Field f = l.getClass().getField("runnables");
        @SuppressWarnings("unchecked")
        List<Runnable> runnables = (List<Runnable>) f.get(l);
        runnables.add(r);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
Example #17
Source Project: openjdk-8   Author: bpupadhyaya   File: TestClose.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void add(ProcessingEnvironment env, Runnable r) {
    try {
        JavacTask task = JavacTask.instance(env);
        TaskListener l = ((BasicJavacTask) task).getTaskListeners().iterator().next();
        // The TaskListener is an instanceof TestClose, but when using the
        // default class loaders. the taskListener uses a different
        // instance of Class<TestClose> than the anno processor.
        // If you try to evaluate
        //      TestClose tc = (TestClose) (l).
        // you get the following somewhat confusing error:
        //   java.lang.ClassCastException: TestClose cannot be cast to TestClose
        // The workaround is to access the fields of TestClose with reflection.
        Field f = l.getClass().getField("runnables");
        @SuppressWarnings("unchecked")
        List<Runnable> runnables = (List<Runnable>) f.get(l);
        runnables.add(r);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
Example #18
Source Project: TencentKona-8   Author: Tencent   File: AbstractCodingRulesAnalyzer.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void init(JavacTask task, String... args) {
    BasicJavacTask impl = (BasicJavacTask)task;
    Context context = impl.getContext();
    log = Log.instance(context);
    trees = Trees.instance(task);
    messages = new Messages();
    task.addTaskListener(new PostAnalyzeTaskListener());
}
 
Example #19
Source Project: TencentKona-8   Author: Tencent   File: DocEnv.java    License: GNU General Public License v2.0 5 votes vote down vote up
void initDoclint(Collection<String> opts, Collection<String> customTagNames) {
    ArrayList<String> doclintOpts = new ArrayList<String>();

    for (String opt: opts) {
        doclintOpts.add(opt == null ? DocLint.XMSGS_OPTION : DocLint.XMSGS_CUSTOM_PREFIX + opt);
    }

    if (doclintOpts.isEmpty()) {
        doclintOpts.add(DocLint.XMSGS_OPTION);
    } else if (doclintOpts.size() == 1
            && doclintOpts.get(0).equals(DocLint.XMSGS_CUSTOM_PREFIX + "none")) {
        return;
    }

    String sep = "";
    StringBuilder customTags = new StringBuilder();
    for (String customTag : customTagNames) {
        customTags.append(sep);
        customTags.append(customTag);
        sep = DocLint.TAGS_SEPARATOR;
    }
    doclintOpts.add(DocLint.XCUSTOM_TAGS_PREFIX + customTags.toString());

    JavacTask t = BasicJavacTask.instance(context);
    doclint = new DocLint();
    // standard doclet normally generates H1, H2
    doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2");
    doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false);
}
 
Example #20
Source Project: jdk8u60   Author: chenghanpeng   File: AbstractCodingRulesAnalyzer.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void init(JavacTask task, String... args) {
    BasicJavacTask impl = (BasicJavacTask)task;
    Context context = impl.getContext();
    log = Log.instance(context);
    trees = Trees.instance(task);
    messages = new Messages();
    task.addTaskListener(new PostAnalyzeTaskListener());
}
 
Example #21
Source Project: jdk8u60   Author: chenghanpeng   File: DocEnv.java    License: GNU General Public License v2.0 5 votes vote down vote up
void initDoclint(Collection<String> opts, Collection<String> customTagNames) {
    ArrayList<String> doclintOpts = new ArrayList<String>();

    for (String opt: opts) {
        doclintOpts.add(opt == null ? DocLint.XMSGS_OPTION : DocLint.XMSGS_CUSTOM_PREFIX + opt);
    }

    if (doclintOpts.isEmpty()) {
        doclintOpts.add(DocLint.XMSGS_OPTION);
    } else if (doclintOpts.size() == 1
            && doclintOpts.get(0).equals(DocLint.XMSGS_CUSTOM_PREFIX + "none")) {
        return;
    }

    String sep = "";
    StringBuilder customTags = new StringBuilder();
    for (String customTag : customTagNames) {
        customTags.append(sep);
        customTags.append(customTag);
        sep = DocLint.TAGS_SEPARATOR;
    }
    doclintOpts.add(DocLint.XCUSTOM_TAGS_PREFIX + customTags.toString());

    JavacTask t = BasicJavacTask.instance(context);
    doclint = new DocLint();
    // standard doclet normally generates H1, H2
    doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2");
    doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false);
}
 
Example #22
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: AbstractCodingRulesAnalyzer.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void init(JavacTask task, String... args) {
    BasicJavacTask impl = (BasicJavacTask)task;
    Context context = impl.getContext();
    log = Log.instance(context);
    trees = Trees.instance(task);
    messages = new Messages();
    task.addTaskListener(new PostAnalyzeTaskListener());
}
 
Example #23
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: DocEnv.java    License: GNU General Public License v2.0 5 votes vote down vote up
void initDoclint(Collection<String> opts, Collection<String> customTagNames) {
    ArrayList<String> doclintOpts = new ArrayList<String>();

    for (String opt: opts) {
        doclintOpts.add(opt == null ? DocLint.XMSGS_OPTION : DocLint.XMSGS_CUSTOM_PREFIX + opt);
    }

    if (doclintOpts.isEmpty()) {
        doclintOpts.add(DocLint.XMSGS_OPTION);
    } else if (doclintOpts.size() == 1
            && doclintOpts.get(0).equals(DocLint.XMSGS_CUSTOM_PREFIX + "none")) {
        return;
    }

    String sep = "";
    StringBuilder customTags = new StringBuilder();
    for (String customTag : customTagNames) {
        customTags.append(sep);
        customTags.append(customTag);
        sep = DocLint.TAGS_SEPARATOR;
    }
    doclintOpts.add(DocLint.XCUSTOM_TAGS_PREFIX + customTags.toString());

    JavacTask t = BasicJavacTask.instance(context);
    doclint = new DocLint();
    // standard doclet normally generates H1, H2
    doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2");
    doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false);
}
 
Example #24
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: AbstractCodingRulesAnalyzer.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void init(JavacTask task, String... args) {
    BasicJavacTask impl = (BasicJavacTask)task;
    Context context = impl.getContext();
    log = Log.instance(context);
    trees = Trees.instance(task);
    messages = new Messages();
    task.addTaskListener(new PostAnalyzeTaskListener());
}
 
Example #25
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: DocEnv.java    License: GNU General Public License v2.0 5 votes vote down vote up
void initDoclint(Collection<String> opts, Collection<String> customTagNames) {
    ArrayList<String> doclintOpts = new ArrayList<String>();

    for (String opt: opts) {
        doclintOpts.add(opt == null ? DocLint.XMSGS_OPTION : DocLint.XMSGS_CUSTOM_PREFIX + opt);
    }

    if (doclintOpts.isEmpty()) {
        doclintOpts.add(DocLint.XMSGS_OPTION);
    } else if (doclintOpts.size() == 1
            && doclintOpts.get(0).equals(DocLint.XMSGS_CUSTOM_PREFIX + "none")) {
        return;
    }

    String sep = "";
    StringBuilder customTags = new StringBuilder();
    for (String customTag : customTagNames) {
        customTags.append(sep);
        customTags.append(customTag);
        sep = DocLint.TAGS_SEPARATOR;
    }
    doclintOpts.add(DocLint.XCUSTOM_TAGS_PREFIX + customTags.toString());

    JavacTask t = BasicJavacTask.instance(context);
    doclint = new DocLint();
    // standard doclet normally generates H1, H2
    doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2");
    doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false);
}
 
Example #26
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: AbstractCodingRulesAnalyzer.java    License: GNU General Public License v2.0 5 votes vote down vote up
public AbstractCodingRulesAnalyzer(JavacTask task) {
    BasicJavacTask impl = (BasicJavacTask)task;
    Context context = impl.getContext();
    log = Log.instance(context);
    options = Options.instance(context);
    rawDiagnostics = options.isSet("rawDiagnostics");
    diags = JCDiagnostic.Factory.instance(context);
    messages = new Messages();
    syms = Symtab.instance(context);
    elements = JavacElements.instance(context);
    types = JavacTypes.instance(context);
}
 
Example #27
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: CodingRulesAnalyzerPlugin.java    License: GNU General Public License v2.0 5 votes vote down vote up
@DefinedBy(Api.COMPILER_TREE)
public void init(JavacTask task, String... args) {
    BasicJavacTask impl = (BasicJavacTask)task;
    Context context = impl.getContext();
    log = Log.instance(context);
    trees = Trees.instance(task);
    task.addTaskListener(new PostAnalyzeTaskListener(
            new MutableFieldsAnalyzer(task),
            new AssertCheckAnalyzer(task),
            new DefinedByAnalyzer(task)
    ));
}
 
Example #28
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: WorkArounds.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void initDocLint(Collection<String> opts, Collection<String> customTagNames, String htmlVersion) {
    ArrayList<String> doclintOpts = new ArrayList<>();
    boolean msgOptionSeen = false;

    for (String opt : opts) {
        if (opt.startsWith(DocLint.XMSGS_OPTION)) {
            if (opt.equals(DocLint.XMSGS_CUSTOM_PREFIX + "none"))
                return;
            msgOptionSeen = true;
        }
        doclintOpts.add(opt);
    }

    if (!msgOptionSeen) {
        doclintOpts.add(DocLint.XMSGS_OPTION);
    }

    String sep = "";
    StringBuilder customTags = new StringBuilder();
    for (String customTag : customTagNames) {
        customTags.append(sep);
        customTags.append(customTag);
        sep = DocLint.SEPARATOR;
    }
    doclintOpts.add(DocLint.XCUSTOM_TAGS_PREFIX + customTags.toString());
    doclintOpts.add(DocLint.XHTML_VERSION_PREFIX + htmlVersion);

    JavacTask t = BasicJavacTask.instance(toolEnv.context);
    doclint = new DocLint();
    // standard doclet normally generates H1, H2
    doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2");
    doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false);
}
 
Example #29
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: DocEnv.java    License: GNU General Public License v2.0 5 votes vote down vote up
void initDoclint(Collection<String> opts, Collection<String> customTagNames, String htmlVersion) {
    ArrayList<String> doclintOpts = new ArrayList<>();
    boolean msgOptionSeen = false;

    for (String opt : opts) {
        if (opt.startsWith(DocLint.XMSGS_OPTION)) {
            if (opt.equals(DocLint.XMSGS_CUSTOM_PREFIX + "none"))
                return;
            msgOptionSeen = true;
        }
        doclintOpts.add(opt);
    }

    if (!msgOptionSeen) {
        doclintOpts.add(DocLint.XMSGS_OPTION);
    }

    String sep = "";
    StringBuilder customTags = new StringBuilder();
    for (String customTag : customTagNames) {
        customTags.append(sep);
        customTags.append(customTag);
        sep = DocLint.SEPARATOR;
    }
    doclintOpts.add(DocLint.XCUSTOM_TAGS_PREFIX + customTags.toString());
    doclintOpts.add(DocLint.XHTML_VERSION_PREFIX + htmlVersion);

    JavacTask t = BasicJavacTask.instance(context);
    doclint = new DocLint();
    // standard doclet normally generates H1, H2
    doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2");
    doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false);
}
 
Example #30
Source Project: manifold   Author: manifold-systems   File: StringLiteralTemplateProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void init( BasicJavacTask javacTask, TypeProcessor typeProcessor )
{
  _tp = typeProcessor;
  _javacTask = javacTask;
  _disabled = new Stack<>();
  _disabled.push( false );

  javacTask.addTaskListener( this );

  loadTemplateProcessorGates();
}