com.sun.tools.javac.util.Names Java Examples

The following examples show how to use com.sun.tools.javac.util.Names. 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: WorkArounds.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private VarSymbol getDefinedSerializableFields(ClassSymbol def) {
    Names names = def.name.table.names;

    /* SERIALIZABLE_FIELDS can be private,
     */
    for (Symbol sym : def.members().getSymbolsByName(names.fromString(SERIALIZABLE_FIELDS))) {
        if (sym.kind == VAR) {
            VarSymbol f = (VarSymbol) sym;
            if ((f.flags() & Flags.STATIC) != 0
                    && (f.flags() & Flags.PRIVATE) != 0) {
                return f;
            }
        }
    }
    return null;
}
 
Example #2
Source File: SerializedForm.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private VarSymbol getDefinedSerializableFields(ClassSymbol def) {
    Names names = def.name.table.names;

    /* SERIALIZABLE_FIELDS can be private,
     * so must lookup by ClassSymbol, not by ClassDocImpl.
     */
    for (Scope.Entry e = def.members().lookup(names.fromString(SERIALIZABLE_FIELDS)); e.scope != null; e = e.next()) {
        if (e.sym.kind == Kinds.VAR) {
            VarSymbol f = (VarSymbol)e.sym;
            if ((f.flags() & Flags.STATIC) != 0 &&
                (f.flags() & Flags.PRIVATE) != 0) {
                return f;
            }
        }
    }
    return null;
}
 
Example #3
Source File: ClassDocImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Find constructor in this class.
 *
 * @param constrName the unqualified name to search for.
 * @param paramTypes the array of Strings for constructor parameters.
 * @return the first ConstructorDocImpl which matches, null if not found.
 */
public ConstructorDoc findConstructor(String constrName,
                                      String[] paramTypes) {
    Names names = tsym.name.table.names;
    for (Scope.Entry e = tsym.members().lookup(names.fromString("<init>")); e.scope != null; e = e.next()) {
        if (e.sym.kind == Kinds.MTH) {
            if (hasParameterTypes((MethodSymbol)e.sym, paramTypes)) {
                return env.getConstructorDoc((MethodSymbol)e.sym);
            }
        }
    }

    //###(gj) As a temporary measure until type variables are better
    //### handled, try again without the parameter types.
    //### This will often find the right constructor, and occassionally
    //### find the wrong one.
    //if (paramTypes != null) {
    //    return findConstructor(constrName, null);
    //}

    return null;
}
 
Example #4
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 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);
    operators = Operators.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("debug.dumpLambdaToMethodStats");
    attr = Attr.instance(context);
    forceSerializable = options.isSet("forceSerializable");
}
 
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: TestInvokeDynamic.java    From TencentKona-8 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 #7
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 #8
Source File: SerializedForm.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private VarSymbol getDefinedSerializableFields(ClassSymbol def) {
    Names names = def.name.table.names;

    /* SERIALIZABLE_FIELDS can be private,
     * so must lookup by ClassSymbol, not by ClassDocImpl.
     */
    for (Scope.Entry e = def.members().lookup(names.fromString(SERIALIZABLE_FIELDS)); e.scope != null; e = e.next()) {
        if (e.sym.kind == Kinds.VAR) {
            VarSymbol f = (VarSymbol)e.sym;
            if ((f.flags() & Flags.STATIC) != 0 &&
                (f.flags() & Flags.PRIVATE) != 0) {
                return f;
            }
        }
    }
    return null;
}
 
Example #9
Source File: ClassDocImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Find constructor in this class.
 *
 * @param constrName the unqualified name to search for.
 * @param paramTypes the array of Strings for constructor parameters.
 * @return the first ConstructorDocImpl which matches, null if not found.
 */
public ConstructorDoc findConstructor(String constrName,
                                      String[] paramTypes) {
    Names names = tsym.name.table.names;
    for (Scope.Entry e = tsym.members().lookup(names.fromString("<init>")); e.scope != null; e = e.next()) {
        if (e.sym.kind == Kinds.MTH) {
            if (hasParameterTypes((MethodSymbol)e.sym, paramTypes)) {
                return env.getConstructorDoc((MethodSymbol)e.sym);
            }
        }
    }

    //###(gj) As a temporary measure until type variables are better
    //### handled, try again without the parameter types.
    //### This will often find the right constructor, and occassionally
    //### find the wrong one.
    //if (paramTypes != null) {
    //    return findConstructor(constrName, null);
    //}

    return null;
}
 
Example #10
Source File: JavacProcessingEnvironment.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/** Enter a set of generated class files. */
private List<ClassSymbol> enterClassFiles(Map<String, JavaFileObject> classFiles) {
    ClassReader reader = ClassReader.instance(context);
    Names names = Names.instance(context);
    List<ClassSymbol> list = List.nil();

    for (Map.Entry<String,JavaFileObject> entry : classFiles.entrySet()) {
        Name name = names.fromString(entry.getKey());
        JavaFileObject file = entry.getValue();
        if (file.getKind() != JavaFileObject.Kind.CLASS)
            throw new AssertionError(file);
        ClassSymbol cs;
        if (isPkgInfo(file, JavaFileObject.Kind.CLASS)) {
            Name packageName = Convert.packagePart(name);
            PackageSymbol p = reader.enterPackage(packageName);
            if (p.package_info == null)
                p.package_info = reader.enterClass(Convert.shortName(name), p);
            cs = p.package_info;
            if (cs.classfile == null)
                cs.classfile = file;
        } else
            cs = reader.enterClass(name, file);
        list = list.prepend(cs);
    }
    return list.reverse();
}
 
Example #11
Source File: SerializedForm.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private VarSymbol getDefinedSerializableFields(ClassSymbol def) {
    Names names = def.name.table.names;

    /* SERIALIZABLE_FIELDS can be private,
     * so must lookup by ClassSymbol, not by ClassDocImpl.
     */
    for (Scope.Entry e = def.members().lookup(names.fromString(SERIALIZABLE_FIELDS)); e.scope != null; e = e.next()) {
        if (e.sym.kind == Kinds.VAR) {
            VarSymbol f = (VarSymbol)e.sym;
            if ((f.flags() & Flags.STATIC) != 0 &&
                (f.flags() & Flags.PRIVATE) != 0) {
                return f;
            }
        }
    }
    return null;
}
 
Example #12
Source File: ClassDocImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Find constructor in this class.
 *
 * @param constrName the unqualified name to search for.
 * @param paramTypes the array of Strings for constructor parameters.
 * @return the first ConstructorDocImpl which matches, null if not found.
 */
public ConstructorDoc findConstructor(String constrName,
                                      String[] paramTypes) {
    Names names = tsym.name.table.names;
    for (Scope.Entry e = tsym.members().lookup(names.fromString("<init>")); e.scope != null; e = e.next()) {
        if (e.sym.kind == Kinds.MTH) {
            if (hasParameterTypes((MethodSymbol)e.sym, paramTypes)) {
                return env.getConstructorDoc((MethodSymbol)e.sym);
            }
        }
    }

    //###(gj) As a temporary measure until type variables are better
    //### handled, try again without the parameter types.
    //### This will often find the right constructor, and occassionally
    //### find the wrong one.
    //if (paramTypes != null) {
    //    return findConstructor(constrName, null);
    //}

    return null;
}
 
Example #13
Source File: SerializedForm.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private VarSymbol getDefinedSerializableFields(ClassSymbol def) {
    Names names = def.name.table.names;

    /* SERIALIZABLE_FIELDS can be private,
     * so must lookup by ClassSymbol, not by ClassDocImpl.
     */
    for (Scope.Entry e = def.members().lookup(names.fromString(SERIALIZABLE_FIELDS)); e.scope != null; e = e.next()) {
        if (e.sym.kind == Kinds.VAR) {
            VarSymbol f = (VarSymbol)e.sym;
            if ((f.flags() & Flags.STATIC) != 0 &&
                (f.flags() & Flags.PRIVATE) != 0) {
                return f;
            }
        }
    }
    return null;
}
 
Example #14
Source File: DocEnv.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor
 *
 * @param context      Context for this javadoc instance.
 */
protected DocEnv(Context context) {
    context.put(docEnvKey, this);
    this.context = context;

    messager = Messager.instance0(context);
    syms = Symtab.instance(context);
    reader = JavadocClassReader.instance0(context);
    enter = JavadocEnter.instance0(context);
    names = Names.instance(context);
    externalizableSym = reader.enterClass(names.fromString("java.io.Externalizable"));
    chk = Check.instance(context);
    types = Types.instance(context);
    fileManager = context.get(JavaFileManager.class);
    if (fileManager instanceof JavacFileManager) {
        ((JavacFileManager)fileManager).setSymbolFileEnabled(false);
    }

    // Default.  Should normally be reset with setLocale.
    this.doclocale = new DocLocale(this, "", breakiterator);
    source = Source.instance(context);
}
 
Example #15
Source File: JavacProcessingEnvironment.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/** Enter a set of generated class files. */
private List<ClassSymbol> enterClassFiles(Map<String, JavaFileObject> classFiles) {
    ClassReader reader = ClassReader.instance(context);
    Names names = Names.instance(context);
    List<ClassSymbol> list = List.nil();

    for (Map.Entry<String,JavaFileObject> entry : classFiles.entrySet()) {
        Name name = names.fromString(entry.getKey());
        JavaFileObject file = entry.getValue();
        if (file.getKind() != JavaFileObject.Kind.CLASS)
            throw new AssertionError(file);
        ClassSymbol cs;
        if (isPkgInfo(file, JavaFileObject.Kind.CLASS)) {
            Name packageName = Convert.packagePart(name);
            PackageSymbol p = reader.enterPackage(packageName);
            if (p.package_info == null)
                p.package_info = reader.enterClass(Convert.shortName(name), p);
            cs = p.package_info;
            if (cs.classfile == null)
                cs.classfile = file;
        } else
            cs = reader.enterClass(name, file);
        list = list.prepend(cs);
    }
    return list.reverse();
}
 
Example #16
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 6 votes vote down vote up
private JCTree[] tempify( JCTree.JCBinary tree, TreeMaker make, JCExpression expr, Context ctx, Symbol owner, String varName )
{
  switch( expr.getTag() )
  {
    case LITERAL:
    case IDENT:
      return null;

    default:
      JCTree.JCVariableDecl tempVar = make.VarDef( make.Modifiers( FINAL | SYNTHETIC ),
        Names.instance( ctx ).fromString( varName + tempVarIndex ), make.Type( expr.type ), expr );
      tempVar.sym = new Symbol.VarSymbol( FINAL | SYNTHETIC, tempVar.name, expr.type, owner );
      tempVar.type = tempVar.sym.type;
      tempVar.pos = tree.pos;
      JCExpression ident = make.Ident( tempVar );
      ident.type = expr.type;
      ident.pos = tree.pos;
      return new JCTree[] {tempVar, ident};
  }
}
 
Example #17
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 #18
Source File: JavacProcessingEnvironment.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/** Enter a set of generated class files. */
private List<ClassSymbol> enterClassFiles(Map<String, JavaFileObject> classFiles) {
    ClassReader reader = ClassReader.instance(context);
    Names names = Names.instance(context);
    List<ClassSymbol> list = List.nil();

    for (Map.Entry<String,JavaFileObject> entry : classFiles.entrySet()) {
        Name name = names.fromString(entry.getKey());
        JavaFileObject file = entry.getValue();
        if (file.getKind() != JavaFileObject.Kind.CLASS)
            throw new AssertionError(file);
        ClassSymbol cs;
        if (isPkgInfo(file, JavaFileObject.Kind.CLASS)) {
            Name packageName = Convert.packagePart(name);
            PackageSymbol p = reader.enterPackage(packageName);
            if (p.package_info == null)
                p.package_info = reader.enterClass(Convert.shortName(name), p);
            cs = p.package_info;
            if (cs.classfile == null)
                cs.classfile = file;
        } else
            cs = reader.enterClass(name, file);
        list = list.prepend(cs);
    }
    return list.reverse();
}
 
Example #19
Source File: JavacProcessingEnvironment.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/** Enter a set of generated class files. */
private List<ClassSymbol> enterClassFiles(Map<String, JavaFileObject> classFiles) {
    ClassReader reader = ClassReader.instance(context);
    Names names = Names.instance(context);
    List<ClassSymbol> list = List.nil();

    for (Map.Entry<String,JavaFileObject> entry : classFiles.entrySet()) {
        Name name = names.fromString(entry.getKey());
        JavaFileObject file = entry.getValue();
        if (file.getKind() != JavaFileObject.Kind.CLASS)
            throw new AssertionError(file);
        ClassSymbol cs;
        if (isPkgInfo(file, JavaFileObject.Kind.CLASS)) {
            Name packageName = Convert.packagePart(name);
            PackageSymbol p = reader.enterPackage(packageName);
            if (p.package_info == null)
                p.package_info = reader.enterClass(Convert.shortName(name), p);
            cs = p.package_info;
            if (cs.classfile == null)
                cs.classfile = file;
        } else
            cs = reader.enterClass(name, file);
        list = list.prepend(cs);
    }
    return list.reverse();
}
 
Example #20
Source File: TestInvokeDynamic.java    From openjdk-8-source 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 #21
Source File: NBClassReader.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public NBClassReader(Context context) {
    super(context);

    names = Names.instance(context);
    nbNames = NBNames.instance(context);

    NBAttributeReader[] readers = {
        new NBAttributeReader(nbNames._org_netbeans_EnclosingMethod, Version.V45_3, CLASS_OR_MEMBER_ATTRIBUTE) {
            public void read(Symbol sym, int attrLen) {
                int newbp = bp + attrLen;
                readEnclosingMethodAttr(sym);
                bp = newbp;
            }
        },
    };

    for (NBAttributeReader r: readers)
        attributeReaders.put(r.getName(), r);
}
 
Example #22
Source File: JavacProcessingEnvironment.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/** Enter a set of generated class files. */
private List<ClassSymbol> enterClassFiles(Map<String, JavaFileObject> classFiles) {
    ClassReader reader = ClassReader.instance(context);
    Names names = Names.instance(context);
    List<ClassSymbol> list = List.nil();

    for (Map.Entry<String,JavaFileObject> entry : classFiles.entrySet()) {
        Name name = names.fromString(entry.getKey());
        JavaFileObject file = entry.getValue();
        if (file.getKind() != JavaFileObject.Kind.CLASS)
            throw new AssertionError(file);
        ClassSymbol cs;
        if (isPkgInfo(file, JavaFileObject.Kind.CLASS)) {
            Name packageName = Convert.packagePart(name);
            PackageSymbol p = reader.enterPackage(packageName);
            if (p.package_info == null)
                p.package_info = reader.enterClass(Convert.shortName(name), p);
            cs = p.package_info;
            if (cs.classfile == null)
                cs.classfile = file;
        } else
            cs = reader.enterClass(name, file);
        list = list.prepend(cs);
    }
    return list.reverse();
}
 
Example #23
Source File: ClassDocImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Find constructor in this class.
 *
 * @param constrName the unqualified name to search for.
 * @param paramTypes the array of Strings for constructor parameters.
 * @return the first ConstructorDocImpl which matches, null if not found.
 */
public ConstructorDoc findConstructor(String constrName,
                                      String[] paramTypes) {
    Names names = tsym.name.table.names;
    for (Scope.Entry e = tsym.members().lookup(names.fromString("<init>")); e.scope != null; e = e.next()) {
        if (e.sym.kind == Kinds.MTH) {
            if (hasParameterTypes((MethodSymbol)e.sym, paramTypes)) {
                return env.getConstructorDoc((MethodSymbol)e.sym);
            }
        }
    }

    //###(gj) As a temporary measure until type variables are better
    //### handled, try again without the parameter types.
    //### This will often find the right constructor, and occassionally
    //### find the wrong one.
    //if (paramTypes != null) {
    //    return findConstructor(constrName, null);
    //}

    return null;
}
 
Example #24
Source File: DocEnv.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor
 *
 * @param context      Context for this javadoc instance.
 */
protected DocEnv(Context context) {
    context.put(docEnvKey, this);
    this.context = context;

    messager = Messager.instance0(context);
    syms = Symtab.instance(context);
    reader = JavadocClassReader.instance0(context);
    enter = JavadocEnter.instance0(context);
    names = Names.instance(context);
    externalizableSym = reader.enterClass(names.fromString("java.io.Externalizable"));
    chk = Check.instance(context);
    types = Types.instance(context);
    fileManager = context.get(JavaFileManager.class);
    if (fileManager instanceof JavacFileManager) {
        ((JavacFileManager)fileManager).setSymbolFileEnabled(false);
    }

    // Default.  Should normally be reset with setLocale.
    this.doclocale = new DocLocale(this, "", breakiterator);
    source = Source.instance(context);
}
 
Example #25
Source File: DocEnv.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor
 *
 * @param context      Context for this javadoc instance.
 */
protected DocEnv(Context context) {
    context.put(docEnvKey, this);
    this.context = context;

    messager = Messager.instance0(context);
    syms = Symtab.instance(context);
    reader = JavadocClassReader.instance0(context);
    enter = JavadocEnter.instance0(context);
    names = Names.instance(context);
    externalizableSym = reader.enterClass(names.fromString("java.io.Externalizable"));
    chk = Check.instance(context);
    types = Types.instance(context);
    fileManager = context.get(JavaFileManager.class);
    if (fileManager instanceof JavacFileManager) {
        ((JavacFileManager)fileManager).setSymbolFileEnabled(false);
    }

    // Default.  Should normally be reset with setLocale.
    this.doclocale = new DocLocale(this, "", breakiterator);
    source = Source.instance(context);
}
 
Example #26
Source File: JavacProcessingEnvironment.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/** Enter a set of generated class files. */
private List<ClassSymbol> enterClassFiles(Map<String, JavaFileObject> classFiles) {
    ClassReader reader = ClassReader.instance(context);
    Names names = Names.instance(context);
    List<ClassSymbol> list = List.nil();

    for (Map.Entry<String,JavaFileObject> entry : classFiles.entrySet()) {
        Name name = names.fromString(entry.getKey());
        JavaFileObject file = entry.getValue();
        if (file.getKind() != JavaFileObject.Kind.CLASS)
            throw new AssertionError(file);
        ClassSymbol cs;
        if (isPkgInfo(file, JavaFileObject.Kind.CLASS)) {
            Name packageName = Convert.packagePart(name);
            PackageSymbol p = reader.enterPackage(packageName);
            if (p.package_info == null)
                p.package_info = reader.enterClass(Convert.shortName(name), p);
            cs = p.package_info;
            if (cs.classfile == null)
                cs.classfile = file;
        } else
            cs = reader.enterClass(name, file);
        list = list.prepend(cs);
    }
    return list.reverse();
}
 
Example #27
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 6 votes vote down vote up
private JCExpression replaceStringLiteral( Symbol.ClassSymbol fragSym, JCTree tree, String methodName, String type )
{
  TreeMaker make = _tp.getTreeMaker();
  Names names = Names.instance( _tp.getContext() );

  Symbol.MethodSymbol fragmentValueMethod = resolveMethod( tree.pos(), names.fromString( methodName ),
    fragSym.type, List.nil() );

  JCTree.JCMethodInvocation fragmentValueCall = make.Apply( List.nil(),
    memberAccess( make, _tp.getElementUtil(), fragSym.getQualifiedName() + "." + methodName ), List.nil() );
  fragmentValueCall.type = fragmentValueMethod.getReturnType(); // type
  fragmentValueCall.setPos( tree.pos );
  JCTree.JCFieldAccess newMethodSelect = (JCTree.JCFieldAccess)fragmentValueCall.getMethodSelect();
  newMethodSelect.sym = fragmentValueMethod;
  newMethodSelect.type = fragmentValueMethod.type;
  assignTypes( newMethodSelect.selected, fragSym );

  return fragmentValueCall;
}
 
Example #28
Source File: ElementUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static TypeElement getTypeElementByBinaryName(JavacTask task, ModuleElement mod, String name) {
    Context ctx = ((JavacTaskImpl) task).getContext();
    Names names = Names.instance(ctx);
    Symtab syms = Symtab.instance(ctx);
    Check chk = Check.instance(ctx);
    final Name wrappedName = names.fromString(name);
    ClassSymbol clazz = chk.getCompiled((ModuleSymbol) mod, wrappedName);
    if (clazz != null) {
        return clazz;
    }
    clazz = syms.enterClass((ModuleSymbol) mod, wrappedName);
    
    try {
        clazz.complete();
        
        if (clazz.kind == Kind.TYP &&
            clazz.flatName() == wrappedName) {
            return clazz;
        }
    } catch (CompletionFailure cf) {
    }

    return null;
}
 
Example #29
Source File: ClassDocImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Find constructor in this class.
 *
 * @param constrName the unqualified name to search for.
 * @param paramTypes the array of Strings for constructor parameters.
 * @return the first ConstructorDocImpl which matches, null if not found.
 */
public ConstructorDoc findConstructor(String constrName,
                                      String[] paramTypes) {
    Names names = tsym.name.table.names;
    for (Scope.Entry e = tsym.members().lookup(names.fromString("<init>")); e.scope != null; e = e.next()) {
        if (e.sym.kind == Kinds.MTH) {
            if (hasParameterTypes((MethodSymbol)e.sym, paramTypes)) {
                return env.getConstructorDoc((MethodSymbol)e.sym);
            }
        }
    }

    //###(gj) As a temporary measure until type variables are better
    //### handled, try again without the parameter types.
    //### This will often find the right constructor, and occassionally
    //### find the wrong one.
    //if (paramTypes != null) {
    //    return findConstructor(constrName, null);
    //}

    return null;
}
 
Example #30
Source File: TestInvokeDynamic.java    From openjdk-8 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);
}