com.sun.tools.javac.code.Symtab Java Examples

The following examples show how to use com.sun.tools.javac.code.Symtab. 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 File: TestInvokeDynamic.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void run() {
    int id = checkCount.incrementAndGet();
    JavaSource source = new JavaSource(id);
    JavacTaskImpl ct = (JavacTaskImpl)comp.getTask(null, fm.get(), dc,
            Arrays.asList("-g"), null, Arrays.asList(source));
    Context context = ct.getContext();
    Symtab syms = Symtab.instance(context);
    Names names = Names.instance(context);
    Types types = Types.instance(context);
    ct.addTaskListener(new Indifier(syms, names, types));
    try {
        ct.generate();
    } catch (Throwable t) {
        t.printStackTrace();
        throw new AssertionError(
                String.format("Error thrown when compiling following code\n%s",
                source.source));
    }
    if (dc.diagFound) {
        throw new AssertionError(
                String.format("Diags found when compiling following code\n%s\n\n%s",
                source.source, dc.printDiags()));
    }
    verifyBytecode(id);
}
 
Example #2
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 6 votes vote down vote up
private Symbol.MethodSymbol findFieldAccessReflectUtilMethod( JCTree tree, Type type, boolean isStatic, boolean setter )
{
  String name = (setter ? "set" : "get") + "Field" + (isStatic ? "Static" : "") + '_' + typeForReflect( type );

  Symtab symtab = _tp.getSymtab();
  List<Type> paramTypes;
  if( setter )
  {
    paramTypes = List.of( isStatic ? symtab.classType : symtab.objectType, symtab.stringType, type );
  }
  else
  {
    paramTypes = List.of( isStatic ? symtab.classType : symtab.objectType, symtab.stringType );
  }

  Names names = Names.instance( _tp.getContext() );
  Symbol.ClassSymbol reflectMethodClassSym =
    IDynamicJdk.instance().getTypeElement( _tp.getContext(), _tp.getCompilationUnit(), ReflectionRuntimeMethods.class.getName() );

  return resolveMethod( tree.pos(), names.fromString( name ), reflectMethodClassSym.type, paramTypes );
}
 
Example #3
Source File: ClassReader.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize classes and packages, optionally treating this as
 * the definitive classreader.
 */
private void init(Symtab syms, boolean definitive) {
    if (classes != null) return;

    if (definitive) {
        Assert.check(packages == null || packages == syms.packages);
        packages = syms.packages;
        Assert.check(classes == null || classes == syms.classes);
        classes = syms.classes;
    } else {
        packages = new HashMap<Name, PackageSymbol>();
        classes = new HashMap<Name, ClassSymbol>();
    }

    packages.put(names.empty, syms.rootPackage);
    syms.rootPackage.completer = this;
    syms.unnamedPackage.completer = this;
}
 
Example #4
Source File: StaticCompiler.java    From manifold with Apache License 2.0 6 votes vote down vote up
private Object pushModuleSymbol( Context ctx )
{
  /*Modules*/ Object modules = ReflectUtil.method( "com.sun.tools.javac.comp.Modules", "instance", Context.class )
  .invokeStatic( ctx );
  Set<?>/*<Symbol.ModuleSymbol>*/ rootModules = (Set<?>)ReflectUtil.method( modules, "getRootModules" ).invoke();
  /*Symbol.ModuleSymbol*/ Object moduleSym = null;
  if( rootModules.size() == 1 )
  {
    moduleSym = rootModules.iterator().next();
  }
  else
  {
    if( rootModules.size() > 1 )
    {
      // todo: compile warning/error (are multiple roots possible in a single javac invocation?)
    }

    moduleSym = ReflectUtil.field( Symtab.instance( ctx ), "unnamedModule" ).get();
  }
  ctx.get( ManifoldJavaFileManager.MODULE_CTX ).push( moduleSym );

  return moduleSym;
}
 
Example #5
Source File: TestInvokeDynamic.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
Object getValue(Symtab syms, Names names, Types types) {
    switch (this) {
        case STRING:
        case INTEGER:
        case LONG:
        case FLOAT:
        case DOUBLE:
            return value;
        case CLASS:
            return syms.stringType.tsym;
        case METHOD_HANDLE:
            return new Pool.MethodHandle(REF_invokeVirtual,
                    syms.arrayCloneMethod, types);
        case METHOD_TYPE:
            return syms.arrayCloneMethod.type;
        default:
            throw new AssertionError();
    }
}
 
Example #6
Source File: BadConstantValue.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static BadClassFile loadBadClass(String className) {
    // load the class, and save the thrown BadClassFile exception
    JavaCompiler c = ToolProvider.getSystemJavaCompiler();
    JavacTaskImpl task = (JavacTaskImpl) c.getTask(null, null, null,
            Arrays.asList("-classpath", classesdir.getPath()), null, null);
    Symtab syms = Symtab.instance(task.getContext());
    task.ensureEntered();
    BadClassFile badClassFile;
    try {
        com.sun.tools.javac.main.JavaCompiler.instance(task.getContext())
                .resolveIdent(syms.unnamedModule, className).complete();
    } catch (BadClassFile e) {
        return e;
    }
    return null;
}
 
Example #7
Source File: MakeLiteralTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
void run() throws Exception {
    Context context = new Context();
    JavacFileManager.preRegister(context);
    Symtab syms = Symtab.instance(context);
    maker = TreeMaker.instance(context);
    types = Types.instance(context);

    test("abc",                     CLASS,      syms.stringType,    "abc");
    test(Boolean.FALSE,             BOOLEAN,    syms.booleanType,   Integer.valueOf(0));
    test(Boolean.TRUE,              BOOLEAN,    syms.booleanType,   Integer.valueOf(1));
    test(Byte.valueOf((byte) 1),    BYTE,       syms.byteType,      Byte.valueOf((byte) 1));
    test(Character.valueOf('a'),    CHAR,       syms.charType,      Integer.valueOf('a'));
    test(Double.valueOf(1d),        DOUBLE,     syms.doubleType,    Double.valueOf(1d));
    test(Float.valueOf(1f),         FLOAT,      syms.floatType,     Float.valueOf(1f));
    test(Integer.valueOf(1),        INT,        syms.intType,       Integer.valueOf(1));
    test(Long.valueOf(1),           LONG,       syms.longType,      Long.valueOf(1));
    test(Short.valueOf((short) 1),  SHORT,      syms.shortType,     Short.valueOf((short) 1));

    if (errors > 0)
        throw new Exception(errors + " errors found");
}
 
Example #8
Source File: Enter.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
protected Enter(Context context) {
    context.put(enterKey, this);

    log = Log.instance(context);
    reader = ClassReader.instance(context);
    make = TreeMaker.instance(context);
    syms = Symtab.instance(context);
    chk = Check.instance(context);
    memberEnter = MemberEnter.instance(context);
    types = Types.instance(context);
    annotate = Annotate.instance(context);
    lint = Lint.instance(context);
    names = Names.instance(context);

    predefClassDef = make.ClassDef(
        make.Modifiers(PUBLIC),
        syms.predefClass.name, null, null, null, null);
    predefClassDef.sym = syms.predefClass;
    todo = Todo.instance(context);
    fileManager = context.get(JavaFileManager.class);

    Options options = Options.instance(context);
    pkginfoOpt = PkgInfo.get(options);
}
 
Example #9
Source File: MakeLiteralTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
void run() throws Exception {
    Context context = new Context();
    JavacFileManager.preRegister(context);
    Symtab syms = Symtab.instance(context);
    maker = TreeMaker.instance(context);
    types = Types.instance(context);

    test("abc",                     CLASS,      syms.stringType,    "abc");
    test(Boolean.FALSE,             BOOLEAN,    syms.booleanType,   Integer.valueOf(0));
    test(Boolean.TRUE,              BOOLEAN,    syms.booleanType,   Integer.valueOf(1));
    test(Byte.valueOf((byte) 1),    BYTE,       syms.byteType,      Byte.valueOf((byte) 1));
    test(Character.valueOf('a'),    CHAR,       syms.charType,      Integer.valueOf('a'));
    test(Double.valueOf(1d),        DOUBLE,     syms.doubleType,    Double.valueOf(1d));
    test(Float.valueOf(1f),         FLOAT,      syms.floatType,     Float.valueOf(1f));
    test(Integer.valueOf(1),        INT,        syms.intType,       Integer.valueOf(1));
    test(Long.valueOf(1),           LONG,       syms.longType,      Long.valueOf(1));
    test(Short.valueOf((short) 1),  SHORT,      syms.shortType,     Short.valueOf((short) 1));

    if (errors > 0)
        throw new Exception(errors + " errors found");
}
 
Example #10
Source File: ImplicitDependencyExtractor.java    From bazel with Apache License 2.0 6 votes vote down vote up
/**
 * Collects the implicit dependencies of the given set of ClassSymbol roots. As we're interested
 * in differentiating between symbols that were just resolved vs. symbols that were fully
 * completed by the compiler, we start the analysis by finding all the implicit dependencies
 * reachable from the given set of roots. For completeness, we then walk the symbol table
 * associated with the given context and collect the jar files of the remaining class symbols
 * found there.
 *
 * @param context compilation context
 * @param roots root classes in the implicit dependency collection
 */
public void accumulate(Context context, Set<ClassSymbol> roots) {
  Symtab symtab = Symtab.instance(context);

  // Collect transitive references for root types
  for (ClassSymbol root : roots) {
    root.type.accept(typeVisitor, null);
  }

  // Collect all other partially resolved types
  for (ClassSymbol cs : symtab.getAllClasses()) {
    // When recording we want to differentiate between jar references through completed symbols
    // and incomplete symbols
    boolean completed = cs.isCompleted();
    if (cs.classfile != null) {
      collectJarOf(cs.classfile, platformJars, completed);
    } else if (cs.sourcefile != null) {
      collectJarOf(cs.sourcefile, platformJars, completed);
    }
  }
}
 
Example #11
Source File: TestBootstrapMethodsCount.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void run(JavaCompiler comp) {
    JavaSource source = new JavaSource();
    JavacTaskImpl ct = (JavacTaskImpl)comp.getTask(null, null, dc,
            Arrays.asList("-g"), null, Arrays.asList(source));
    Context context = ct.getContext();
    Symtab syms = Symtab.instance(context);
    Names names = Names.instance(context);
    Types types = Types.instance(context);
    ct.addTaskListener(new Indifier(syms, names, types));
    try {
        ct.generate();
    } catch (Throwable t) {
        t.printStackTrace();
        throw new AssertionError(
                String.format("Error thrown when compiling following code\n%s",
                        source.source));
    }
    if (dc.diagFound) {
        throw new AssertionError(
                String.format("Diags found when compiling following code\n%s\n\n%s",
                        source.source, dc.printDiags()));
    }
    verifyBytecode();
}
 
Example #12
Source File: AsyncJavaSymbolDescriptor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@NonNull
private Map<?,?> getPackages(final Symtab cr) {
    Map<?,?> res = Collections.emptyMap();
    try {
        final Field fld = ClassReader.class.getDeclaredField("packages");    //NOI18N
        fld.setAccessible(true);
        final Map<?,?> pkgs = (Map<?,?>) fld.get(cr);
        if (pkgs != null) {
            res = pkgs;
        }
    } catch (ReflectiveOperationException e) {
        if (!pkgROELogged) {
            LOG.warning(e.getMessage());
            pkgROELogged = true;
        }
    }
    return res;
}
 
Example #13
Source File: MakeLiteralTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
void run() throws Exception {
    Context context = new Context();
    JavacFileManager.preRegister(context);
    Symtab syms = Symtab.instance(context);
    maker = TreeMaker.instance(context);
    types = Types.instance(context);

    test("abc",                     CLASS,      syms.stringType,    "abc");
    test(Boolean.FALSE,             BOOLEAN,    syms.booleanType,   Integer.valueOf(0));
    test(Boolean.TRUE,              BOOLEAN,    syms.booleanType,   Integer.valueOf(1));
    test(Byte.valueOf((byte) 1),    BYTE,       syms.byteType,      Byte.valueOf((byte) 1));
    test(Character.valueOf('a'),    CHAR,       syms.charType,      Integer.valueOf('a'));
    test(Double.valueOf(1d),        DOUBLE,     syms.doubleType,    Double.valueOf(1d));
    test(Float.valueOf(1f),         FLOAT,      syms.floatType,     Float.valueOf(1f));
    test(Integer.valueOf(1),        INT,        syms.intType,       Integer.valueOf(1));
    test(Long.valueOf(1),           LONG,       syms.longType,      Long.valueOf(1));
    test(Short.valueOf((short) 1),  SHORT,      syms.shortType,     Short.valueOf((short) 1));

    if (errors > 0)
        throw new Exception(errors + " errors found");
}
 
Example #14
Source File: ClassReader.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/** Initialize classes and packages, optionally treating this as
 *  the definitive classreader.
 */
private void init(Symtab syms, boolean definitive) {
    if (classes != null) return;

    if (definitive) {
        Assert.check(packages == null || packages == syms.packages);
        packages = syms.packages;
        Assert.check(classes == null || classes == syms.classes);
        classes = syms.classes;
    } else {
        packages = new HashMap<Name, PackageSymbol>();
        classes = new HashMap<Name, ClassSymbol>();
    }

    packages.put(names.empty, syms.rootPackage);
    syms.rootPackage.completer = thisCompleter;
    syms.unnamedPackage.completer = thisCompleter;
}
 
Example #15
Source File: ClassReader.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/** Initialize classes and packages, optionally treating this as
 *  the definitive classreader.
 */
private void init(Symtab syms, boolean definitive) {
    if (classes != null) return;

    if (definitive) {
        Assert.check(packages == null || packages == syms.packages);
        packages = syms.packages;
        Assert.check(classes == null || classes == syms.classes);
        classes = syms.classes;
    } else {
        packages = new HashMap<Name, PackageSymbol>();
        classes = new HashMap<Name, ClassSymbol>();
    }

    packages.put(names.empty, syms.rootPackage);
    syms.rootPackage.completer = thisCompleter;
    syms.unnamedPackage.completer = thisCompleter;
}
 
Example #16
Source File: ToolEnvironment.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor
 *
 * @param context      Context for this javadoc instance.
 */
protected ToolEnvironment(Context context) {
    context.put(ToolEnvKey, this);
    this.context = context;

    messager = Messager.instance0(context);
    syms = Symtab.instance(context);
    finder = JavadocClassFinder.instance(context);
    enter = JavadocEnter.instance(context);
    names = Names.instance(context);
    externalizableSym = syms.enterClass(syms.java_base, names.fromString("java.io.Externalizable"));
    chk = Check.instance(context);
    types = com.sun.tools.javac.code.Types.instance(context);
    fileManager = context.get(JavaFileManager.class);
    if (fileManager instanceof JavacFileManager) {
        ((JavacFileManager)fileManager).setSymbolFileEnabled(false);
    }
    docTrees = JavacTrees.instance(context);
    source = Source.instance(context);
    elements =  JavacElements.instance(context);
    typeutils = JavacTypes.instance(context);
    elementToTreePath = new HashMap<>();
}
 
Example #17
Source File: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected Flow(Context context) {
    context.put(flowKey, this);
    names = Names.instance(context);
    log = Log.instance(context);
    syms = Symtab.instance(context);
    types = Types.instance(context);
    chk = Check.instance(context);
    lint = Lint.instance(context);
    rs = Resolve.instance(context);
    diags = JCDiagnostic.Factory.instance(context);
    Source source = Source.instance(context);
    allowImprovedRethrowAnalysis = source.allowImprovedRethrowAnalysis();
    allowImprovedCatchAnalysis = source.allowImprovedCatchAnalysis();
    allowEffectivelyFinalInInnerClasses = source.allowEffectivelyFinalInInnerClasses();
    enforceThisDotInit = source.enforceThisDotInit();
}
 
Example #18
Source File: Infer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected Infer(Context context) {
    context.put(inferKey, this);

    rs = Resolve.instance(context);
    chk = Check.instance(context);
    syms = Symtab.instance(context);
    types = Types.instance(context);
    diags = JCDiagnostic.Factory.instance(context);
    log = Log.instance(context);
    inferenceException = new InferenceException(diags);
    Options options = Options.instance(context);
    allowGraphInference = Source.instance(context).allowGraphInference()
            && options.isUnset("useLegacyInference");
    dependenciesFolder = options.get("debug.dumpInferenceGraphsTo");
    pendingGraphs = List.nil();

    emptyContext = new InferenceContext(this, List.nil());
}
 
Example #19
Source File: LambdaToMethod.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private LambdaToMethod(Context context) {
    context.put(unlambdaKey, this);
    diags = JCDiagnostic.Factory.instance(context);
    log = Log.instance(context);
    lower = Lower.instance(context);
    names = Names.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    make = TreeMaker.instance(context);
    types = Types.instance(context);
    transTypes = TransTypes.instance(context);
    analyzer = new LambdaAnalyzerPreprocessor();
    Options options = Options.instance(context);
    dumpLambdaToMethodStats = options.isSet("dumpLambdaToMethodStats");
    attr = Attr.instance(context);
}
 
Example #20
Source File: JavacTrees.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void init(Context context) {
    modules = Modules.instance(context);
    attr = Attr.instance(context);
    enter = Enter.instance(context);
    elements = JavacElements.instance(context);
    log = Log.instance(context);
    resolve = Resolve.instance(context);
    treeMaker = TreeMaker.instance(context);
    memberEnter = MemberEnter.instance(context);
    names = Names.instance(context);
    types = Types.instance(context);
    docTreeMaker = DocTreeMaker.instance(context);
    parser = ParserFactory.instance(context);
    syms = Symtab.instance(context);
    fileManager = context.get(JavaFileManager.class);
    JavacTask t = context.get(JavacTask.class);
    if (t instanceof JavacTaskImpl)
        javacTaskImpl = (JavacTaskImpl) t;
}
 
Example #21
Source File: TestInvokeDynamic.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
Object getValue(Symtab syms, Names names, Types types) {
    switch (this) {
        case STRING:
        case INTEGER:
        case LONG:
        case FLOAT:
        case DOUBLE:
            return value;
        case CLASS:
            return syms.stringType.tsym;
        case METHOD_HANDLE:
            return new Pool.MethodHandle(REF_invokeVirtual,
                    syms.arrayCloneMethod, types);
        case METHOD_TYPE:
            return syms.arrayCloneMethod.type;
        default:
            throw new AssertionError();
    }
}
 
Example #22
Source File: MakeLiteralTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
void run() throws Exception {
    Context context = new Context();
    JavacFileManager.preRegister(context);
    Symtab syms = Symtab.instance(context);
    maker = TreeMaker.instance(context);
    types = Types.instance(context);

    test("abc",                     CLASS,      syms.stringType,    "abc");
    test(Boolean.FALSE,             BOOLEAN,    syms.booleanType,   Integer.valueOf(0));
    test(Boolean.TRUE,              BOOLEAN,    syms.booleanType,   Integer.valueOf(1));
    test(Byte.valueOf((byte) 1),    BYTE,       syms.byteType,      Byte.valueOf((byte) 1));
    test(Character.valueOf('a'),    CHAR,       syms.charType,      Integer.valueOf('a'));
    test(Double.valueOf(1d),        DOUBLE,     syms.doubleType,    Double.valueOf(1d));
    test(Float.valueOf(1f),         FLOAT,      syms.floatType,     Float.valueOf(1f));
    test(Integer.valueOf(1),        INT,        syms.intType,       Integer.valueOf(1));
    test(Long.valueOf(1),           LONG,       syms.longType,      Long.valueOf(1));
    test(Short.valueOf((short) 1),  SHORT,      syms.shortType,     Short.valueOf((short) 1));

    if (errors > 0)
        throw new Exception(errors + " errors found");
}
 
Example #23
Source File: TestInvokeDynamic.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
Object getValue(Symtab syms, Names names, Types types) {
    switch (this) {
        case STRING:
        case INTEGER:
        case LONG:
        case FLOAT:
        case DOUBLE:
            return value;
        case CLASS:
            return syms.stringType.tsym;
        case METHOD_HANDLE:
            return new Pool.MethodHandle(REF_invokeVirtual,
                    syms.arrayCloneMethod, types);
        case METHOD_TYPE:
            return syms.arrayCloneMethod.type;
        default:
            throw new AssertionError();
    }
}
 
Example #24
Source File: ClassReader.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/** Initialize classes and packages, optionally treating this as
 *  the definitive classreader.
 */
private void init(Symtab syms, boolean definitive) {
    if (classes != null) return;

    if (definitive) {
        Assert.check(packages == null || packages == syms.packages);
        packages = syms.packages;
        Assert.check(classes == null || classes == syms.classes);
        classes = syms.classes;
    } else {
        packages = new HashMap<Name, PackageSymbol>();
        classes = new HashMap<Name, ClassSymbol>();
    }

    packages.put(names.empty, syms.rootPackage);
    syms.rootPackage.completer = thisCompleter;
    syms.unnamedPackage.completer = thisCompleter;
}
 
Example #25
Source File: TestInvokeDynamic.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void run() {
    int id = checkCount.incrementAndGet();
    JavaSource source = new JavaSource(id);
    JavacTaskImpl ct = (JavacTaskImpl)comp.getTask(null, fm.get(), dc,
            Arrays.asList("-g"), null, Arrays.asList(source));
    Context context = ct.getContext();
    Symtab syms = Symtab.instance(context);
    Names names = Names.instance(context);
    Types types = Types.instance(context);
    ct.addTaskListener(new Indifier(syms, names, types));
    try {
        ct.generate();
    } catch (Throwable t) {
        t.printStackTrace();
        throw new AssertionError(
                String.format("Error thrown when compiling following code\n%s",
                source.source));
    }
    if (dc.diagFound) {
        throw new AssertionError(
                String.format("Diags found when compiling following code\n%s\n\n%s",
                source.source, dc.printDiags()));
    }
    verifyBytecode(id);
}
 
Example #26
Source File: MakeQualIdent.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws Exception {
    JavacTool tool = JavacTool.create();
    JavacTask task = tool.getTask(null, null, null, new ArrayList<String>(), null, null);
    Context ctx = ((JavacTaskImpl)task).getContext();
    TreeMaker treeMaker = TreeMaker.instance(ctx);
    Symtab syms = Symtab.instance(ctx);

    String stringTree = printTree(treeMaker.QualIdent(syms.stringType.tsym));

    if (!"java.lang.String".equals(stringTree)) {
        throw new IllegalStateException(stringTree);
    }
}
 
Example #27
Source File: T6400303.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) {
    javax.tools.JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, null, null, null, null, null);
    Symtab syms = Symtab.instance(task.getContext());
    task.ensureEntered();
    JavaCompiler compiler = JavaCompiler.instance(task.getContext());
    try {
        compiler.resolveIdent(syms.unnamedModule, "Test$1").complete();
    } catch (CompletionFailure ex) {
        System.err.println("Got expected completion failure: " + ex.getLocalizedMessage());
        return;
    }
    throw new AssertionError("No error reported");
}
 
Example #28
Source File: MakeQualIdent.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws Exception {
    JavacTool tool = JavacTool.create();
    JavacTask task = tool.getTask(null, null, null, new ArrayList<String>(), null, null);
    Context ctx = ((JavacTaskImpl)task).getContext();
    TreeMaker treeMaker = TreeMaker.instance(ctx);
    Symtab syms = Symtab.instance(ctx);

    String stringTree = printTree(treeMaker.QualIdent(syms.stringType.tsym));

    if (!"java.lang.String".equals(stringTree)) {
        throw new IllegalStateException(stringTree);
    }
}
 
Example #29
Source File: RichDiagnosticFormatter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
protected RichDiagnosticFormatter(Context context) {
    super((AbstractDiagnosticFormatter)Log.instance(context).getDiagnosticFormatter());
    setRichPrinter(new RichPrinter());
    this.syms = Symtab.instance(context);
    this.diags = JCDiagnostic.Factory.instance(context);
    this.types = Types.instance(context);
    this.messages = JavacMessages.instance(context);
    whereClauses = new EnumMap<WhereClauseKind, Map<Type, JCDiagnostic>>(WhereClauseKind.class);
    configuration = new RichConfiguration(Options.instance(context), formatter);
    for (WhereClauseKind kind : WhereClauseKind.values())
        whereClauses.put(kind, new LinkedHashMap<Type, JCDiagnostic>());
}
 
Example #30
Source File: Infer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean accepts(UndetVar t, InferenceContext inferenceContext) {
    if (!t.isThrows()) {
        //not a throws undet var
        return false;
    }
    Types types = inferenceContext.types;
    Symtab syms = inferenceContext.infer.syms;
    return StreamSupport.stream(t.getBounds(InferenceBound.UPPER))
            .filter(b -> !inferenceContext.free(b))
            .allMatch(u -> types.isSubtype(syms.runtimeExceptionType, u));
}