com.sun.tools.javac.code.Symbol.ClassSymbol Java Examples

The following examples show how to use com.sun.tools.javac.code.Symbol.ClassSymbol. 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: DependenciesTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void push(ClassSymbol s, CompletionCause phase) {
    String flatname = s.flatName().toString();
    for (Phase p : Phase.values()) {
        if (phase == p.cause) {
            inProcess.push(new PhaseDescription(flatname, p));
            return ;
        }
    }
    if (phase == CompletionCause.MEMBER_ENTER) {
        if (inProcess.isEmpty()) {
            topLevelMemberEnter = flatname;
        } else {
            for (PhaseDescription running : inProcess) {
                if (running == null)
                    continue;

                Set<PhaseDescription> completing =
                        topLevel2Completing.computeIfAbsent(running.flatname, $ -> new HashSet<>());

                completing.add(new PhaseDescription(flatname, running.phase));
            }
        }
    }
    inProcess.push(null);
}
 
Example #2
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
EnumMapping(DiagnosticPosition pos, TypeSymbol forEnum) {
    this.forEnum = forEnum;
    this.values = new LinkedHashMap<>();
    this.pos = pos;
    Name varName = names
        .fromString(target.syntheticNameChar() +
                    "SwitchMap" +
                    target.syntheticNameChar() +
                    writer.xClassName(forEnum.type).toString()
                    .replace('/', '.')
                    .replace('.', target.syntheticNameChar()));
    ClassSymbol outerCacheClass = outerCacheClass();
    this.mapVar = new VarSymbol(STATIC | SYNTHETIC | FINAL,
                                varName,
                                new ArrayType(syms.intType, syms.arrayClass),
                                outerCacheClass);
    enterSynthetic(pos, mapVar, outerCacheClass.members());
}
 
Example #3
Source File: Modules.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void visitUses(JCUses tree) {
    Type st = attr.attribType(tree.qualid, env, syms.objectType);
    Symbol sym = TreeInfo.symbol(tree.qualid);
    if ((sym.flags() & ENUM) != 0) {
        log.error(tree.qualid.pos(), Errors.ServiceDefinitionIsEnum(st.tsym));
    } else if (st.hasTag(CLASS)) {
        ClassSymbol service = (ClassSymbol) st.tsym;
        if (allUses.add(service)) {
            Directive.UsesDirective d = new Directive.UsesDirective(service);
            msym.uses = msym.uses.prepend(d);
            msym.directives = msym.directives.prepend(d);
        } else {
            log.error(tree.pos(), Errors.DuplicateUses(service));
        }
    }
}
 
Example #4
Source File: PackageDocImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a list of all classes contained in this package, including
 * member classes of those classes, and their member classes, etc.
 */
private List<ClassDocImpl> getClasses(boolean filtered) {
    if (allClasses != null && !filtered) {
        return allClasses;
    }
    if (allClassesFiltered != null && filtered) {
        return allClassesFiltered;
    }
    ListBuffer<ClassDocImpl> classes = new ListBuffer<ClassDocImpl>();
    for (Scope.Entry e = sym.members().elems; e != null; e = e.sibling) {
        if (e.sym != null) {
            ClassSymbol s = (ClassSymbol)e.sym;
            ClassDocImpl c = env.getClassDoc(s);
            if (c != null && !c.isSynthetic())
                c.addAllClasses(classes, filtered);
        }
    }
    if (filtered)
        return allClassesFiltered = classes.toList();
    else
        return allClasses = classes.toList();
}
 
Example #5
Source File: DocEnv.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/** Retrieve class symbol by fully-qualified name.
 */
ClassSymbol getClassSymbol(String name) {
    // Name may contain nested class qualification.
    // Generate candidate flatnames with successively shorter
    // package qualifiers and longer nested class qualifiers.
    int nameLen = name.length();
    char[] nameChars = name.toCharArray();
    int idx = name.length();
    for (;;) {
        Name nameImpl = names.fromChars(nameChars, 0, nameLen);
        ModuleSymbol mod = syms.inferModule(Convert.packagePart(nameImpl));
        ClassSymbol s = mod != null ? syms.getClass(mod, nameImpl) : null;
        if (s != null)
            return s; // found it!
        idx = name.substring(0, idx).lastIndexOf('.');
        if (idx < 0) break;
        nameChars[idx] = '$';
    }
    return null;
}
 
Example #6
Source File: ClassFinder.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Load a toplevel class with given fully qualified name
 *  The class is entered into `classes' only if load was successful.
 */
public ClassSymbol loadClass(ModuleSymbol msym, Name flatname) throws CompletionFailure {
    Assert.checkNonNull(msym);
    Name packageName = Convert.packagePart(flatname);
    PackageSymbol ps = syms.lookupPackage(msym, packageName);

    Assert.checkNonNull(ps.modle, () -> "msym=" + msym + "; flatName=" + flatname);

    boolean absent = syms.getClass(ps.modle, flatname) == null;
    ClassSymbol c = syms.enterClass(ps.modle, flatname);

    if (c.members_field == null) {
        try {
            c.complete();
        } catch (CompletionFailure ex) {
            if (absent) syms.removeClass(ps.modle, flatname);
            throw ex;
        }
    }
    return c;
}
 
Example #7
Source File: TestSymtabItems.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
void show(String label, Element e) {
    System.err.println(sp(indent) + label
            + ": mods:" + e.getModifiers()
            + " " + e.getSimpleName()
            + ", kind: " + e.getKind()
            + ", type: " + e.asType()
            + ", encl: " + e.getEnclosingElement());

    // The following checks help establish why NPE might occur when trying to scan children
    if (e instanceof ClassSymbol) {
        ClassSymbol csym = (ClassSymbol) e;
        if (csym.members_field == null)
            error("members_field is null");
        if (csym.type == null)
            System.err.println("type is null");
    }
}
 
Example #8
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 #9
Source File: JavacElements.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns a symbol given the type's or package's canonical name,
 * or null if the name isn't found.
 */
private <S extends Symbol> S nameToSymbol(ModuleSymbol module, String nameStr, Class<S> clazz) {
    Name name = names.fromString(nameStr);
    // First check cache.
    Symbol sym = (clazz == ClassSymbol.class)
                ? syms.getClass(module, name)
                : syms.lookupPackage(module, name);

    try {
        if (sym == null)
            sym = javaCompiler.resolveIdent(module, nameStr);

        sym.complete();

        return (sym.kind != ERR &&
                sym.exists() &&
                clazz.isInstance(sym) &&
                name.equals(sym.getQualifiedName()))
            ? clazz.cast(sym)
            : null;
    } catch (CompletionFailure e) {
        return null;
    }
}
 
Example #10
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void checkFunctionalInterface(JCClassDecl tree, ClassSymbol cs) {
    Compound functionalType = cs.attribute(syms.functionalInterfaceType.tsym);

    if (functionalType != null) {
        try {
            types.findDescriptorSymbol((TypeSymbol)cs);
        } catch (Types.FunctionDescriptorLookupError ex) {
            DiagnosticPosition pos = tree.pos();
            for (JCAnnotation a : tree.getModifiers().annotations) {
                if (a.annotationType.type.tsym == syms.functionalInterfaceType.tsym) {
                    pos = a.pos();
                    break;
                }
            }
            log.error(pos, Errors.BadFunctionalIntfAnno1(ex.getDiagnostic()));
        }
    }
}
 
Example #11
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 #12
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void visitUses(JCUses tree) {
    Type st = attr.attribType(tree.qualid, env, syms.objectType);
    Symbol sym = TreeInfo.symbol(tree.qualid);
    if ((sym.flags() & ENUM) != 0) {
        log.error(tree.qualid.pos(), Errors.ServiceDefinitionIsEnum(st.tsym));
    } else if (st.hasTag(CLASS)) {
        ClassSymbol service = (ClassSymbol) st.tsym;
        if (allUses.add(service)) {
            Directive.UsesDirective d = new Directive.UsesDirective(service);
            msym.uses = msym.uses.prepend(d);
            msym.directives = msym.directives.prepend(d);
        } else {
            log.error(tree.pos(), Errors.DuplicateUses(service));
        }
    }
}
 
Example #13
Source File: JNIWriter.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/** Emit a class file for a given class.
 *  @param c      The class from which a class file is generated.
 */
public FileObject write(ClassSymbol c)
    throws IOException
{
    String className = c.flatName().toString();
    FileObject outFile
        = fileManager.getFileForOutput(StandardLocation.NATIVE_HEADER_OUTPUT,
            "", className.replaceAll("[.$]", "_") + ".h", null);
    Writer out = outFile.openWriter();
    try {
        write(out, c);
        if (verbose)
            log.printVerbose("wrote.file", outFile);
        out.close();
        out = null;
    } finally {
        if (out != null) {
            // if we are propogating an exception, delete the file
            out.close();
            outFile.delete();
            outFile = null;
        }
    }
    return outFile; // may be null if write failed
}
 
Example #14
Source File: JavacTrees.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private Symbol attributeParamIdentifier(TreePath path, DCParam ptag) {
    Symbol javadocSymbol = getElement(path);
    if (javadocSymbol == null)
        return null;
    ElementKind kind = javadocSymbol.getKind();
    List<? extends Symbol> params = List.nil();
    if (kind == ElementKind.METHOD || kind == ElementKind.CONSTRUCTOR) {
        MethodSymbol ee = (MethodSymbol) javadocSymbol;
        params = ptag.isTypeParameter()
                ? ee.getTypeParameters()
                : ee.getParameters();
    } else if (kind.isClass() || kind.isInterface()) {
        ClassSymbol te = (ClassSymbol) javadocSymbol;
        params = te.getTypeParameters();
    }

    for (Symbol param : params) {
        if (param.getSimpleName() == ptag.getName().getName()) {
            return param;
        }
    }
    return null;
}
 
Example #15
Source File: JavacTrees.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private Symbol attributeParamIdentifier(TreePath path, DCParam ptag) {
    Symbol javadocSymbol = getElement(path);
    if (javadocSymbol == null)
        return null;
    ElementKind kind = javadocSymbol.getKind();
    List<? extends Symbol> params = List.nil();
    if (kind == ElementKind.METHOD || kind == ElementKind.CONSTRUCTOR) {
        MethodSymbol ee = (MethodSymbol) javadocSymbol;
        params = ptag.isTypeParameter()
                ? ee.getTypeParameters()
                : ee.getParameters();
    } else if (kind.isClass() || kind.isInterface()) {
        ClassSymbol te = (ClassSymbol) javadocSymbol;
        params = te.getTypeParameters();
    }

    for (Symbol param : params) {
        if (param.getSimpleName() == ptag.getName().getName()) {
            return param;
        }
    }
    return null;
}
 
Example #16
Source File: PackageDocImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a list of all classes contained in this package, including
 * member classes of those classes, and their member classes, etc.
 */
private List<ClassDocImpl> getClasses(boolean filtered) {
    if (allClasses != null && !filtered) {
        return allClasses;
    }
    if (allClassesFiltered != null && filtered) {
        return allClassesFiltered;
    }
    ListBuffer<ClassDocImpl> classes = new ListBuffer<ClassDocImpl>();
    for (Scope.Entry e = sym.members().elems; e != null; e = e.sibling) {
        if (e.sym != null) {
            ClassSymbol s = (ClassSymbol)e.sym;
            ClassDocImpl c = env.getClassDoc(s);
            if (c != null && !c.isSynthetic())
                c.addAllClasses(classes, filtered);
        }
    }
    if (filtered)
        return allClassesFiltered = classes.toList();
    else
        return allClasses = classes.toList();
}
 
Example #17
Source File: ClassWriter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Write "inner classes" attribute.
 */
void writeInnerClasses() {
    int alenIdx = writeAttr(names.InnerClasses);
    databuf.appendChar(innerClassesQueue.length());
    for (List<ClassSymbol> l = innerClassesQueue.toList();
         l.nonEmpty();
         l = l.tail) {
        ClassSymbol inner = l.head;
        inner.markAbstractIfNeeded(types);
        char flags = (char) adjustFlags(inner.flags_field);
        if ((flags & INTERFACE) != 0) flags |= ABSTRACT; // Interfaces are always ABSTRACT
        flags &= ~STRICTFP; //inner classes should not have the strictfp flag set.
        if (dumpInnerClassModifiers) {
            PrintWriter pw = log.getWriter(Log.WriterKind.ERROR);
            pw.println("INNERCLASS  " + inner.name);
            pw.println("---" + flagNames(flags));
        }
        databuf.appendChar(pool.get(inner));
        databuf.appendChar(
            inner.owner.kind == TYP && !inner.name.isEmpty() ? pool.get(inner.owner) : 0);
        databuf.appendChar(
            !inner.name.isEmpty() ? pool.get(inner.name) : 0);
        databuf.appendChar(flags);
    }
    endAttr(alenIdx);
}
 
Example #18
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Type bsmStaticArgToType(Object arg) {
    Assert.checkNonNull(arg);
    if (arg instanceof ClassSymbol) {
        return syms.classType;
    } else if (arg instanceof Integer) {
        return syms.intType;
    } else if (arg instanceof Long) {
        return syms.longType;
    } else if (arg instanceof Float) {
        return syms.floatType;
    } else if (arg instanceof Double) {
        return syms.doubleType;
    } else if (arg instanceof String) {
        return syms.stringType;
    } else if (arg instanceof Pool.MethodHandle) {
        return syms.methodHandleType;
    } else if (arg instanceof MethodType) {
        return syms.methodTypeType;
    } else {
        Assert.error("bad static arg " + arg.getClass());
        return null;
    }
}
 
Example #19
Source File: LambdaToMethod.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
void captureLocalClassDefs(Symbol csym, final LambdaTranslationContext lambdaContext) {
        JCClassDecl localCDef = localClassDefs.get(csym);
        if (localCDef != null && lambdaContext.freeVarProcessedLocalClasses.add(csym)) {
            BasicFreeVarCollector fvc = lower.new BasicFreeVarCollector() {
                @Override
                void addFreeVars(ClassSymbol c) {
                    captureLocalClassDefs(c, lambdaContext);
                }
                @Override
                void visitSymbol(Symbol sym) {
                    if (sym.kind == VAR &&
                            sym.owner.kind == MTH &&
                            ((VarSymbol)sym).getConstValue() == null) {
                        TranslationContext<?> localContext = context();
                        while (localContext != null) {
                            if (localContext.tree.getTag() == LAMBDA) {
                                JCTree block = capturedDecl(localContext.depth, sym);
                                if (block == null) break;
                                ((LambdaTranslationContext)localContext).addSymbol(sym, CAPTURED_VAR);
                            }
                            localContext = localContext.prev;
                        }
                    }
                }
            };
            fvc.scan(localCDef);
        }
}
 
Example #20
Source File: TypeVariableImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the class, interface, method, or constructor within
 * which this type variable is declared.
 */
public ProgramElementDoc owner() {
    Symbol osym = type.tsym.owner;
    if ((osym.kind & Kinds.TYP) != 0) {
        return env.getClassDoc((ClassSymbol)osym);
    }
    Names names = osym.name.table.names;
    if (osym.name == names.init) {
        return env.getConstructorDoc((MethodSymbol)osym);
    } else {
        return env.getMethodDoc((MethodSymbol)osym);
    }
}
 
Example #21
Source File: JavacTrees.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/** @see com.sun.tools.javadoc.ClassDocImpl#findConstructor */
MethodSymbol findConstructor(ClassSymbol tsym, List<Type> paramTypes) {
    for (com.sun.tools.javac.code.Scope.Entry e = tsym.members().lookup(names.init);
            e.scope != null; e = e.next()) {
        if (e.sym.kind == Kinds.MTH) {
            if (hasParameterTypes((MethodSymbol) e.sym, paramTypes)) {
                return (MethodSymbol) e.sym;
            }
        }
    }
    return null;
}
 
Example #22
Source File: ToolEnvironment.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Load a class by qualified name.
 */
public TypeElement loadClass(String name) {
    try {
        Name nameImpl = names.fromString(name);
        ModuleSymbol mod = syms.inferModule(Convert.packagePart(nameImpl));
        ClassSymbol c = finder.loadClass(mod != null ? mod : syms.errModule, nameImpl);
        return c;
    } catch (CompletionFailure ex) {
        chk.completionError(null, ex);
        return null;
    }
}
 
Example #23
Source File: LambdaToMethod.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
TranslationContext(T tree) {
    this.tree = tree;
    this.owner = owner();
    this.depth = frameStack.size() - 1;
    this.prev = context();
    ClassSymbol csym =
            types.makeFunctionalInterfaceClass(attrEnv, names.empty, tree.targets, ABSTRACT | INTERFACE);
    this.bridges = types.functionalInterfaceBridges(csym);
}
 
Example #24
Source File: JavacTransitive.java    From bazel with Apache License 2.0 5 votes vote down vote up
private void recordSuperClosure(Symbol bound) {
  if (!(bound instanceof ClassSymbol)) {
    return;
  }
  ClassSymbol info = (ClassSymbol) bound;
  closure.add(info);
  recordSuperClosure(info.getSuperclass().asElement());
  for (Type i : info.getInterfaces()) {
    recordSuperClosure(i.asElement());
  }
}
 
Example #25
Source File: DeferredAttr.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void visitClassDef(JCClassDecl tree) {
    ClassSymbol csym = tree.sym;
    //if something went wrong during method applicability check
    //it is possible that nested expressions inside argument expression
    //are left unchecked - in such cases there's nothing to clean up.
    if (csym == null) return;
    typeEnvs.remove(csym);
    chk.removeCompiled(csym);
    chk.clearLocalClassNameIndexes(csym);
    syms.removeClass(msym, csym.flatname);
    super.visitClassDef(tree);
}
 
Example #26
Source File: NewDependencyCollector.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void collectPubApisOfDependencies(Context context,
                                          Collection<JavaFileObject> explicitJFOs) {
    PubAPIs pubApis = PubAPIs.instance(context);
    for (CompletionNode cDepNode : getDependencyNodes(context, explicitJFOs, false)) {
        ClassSymbol cs = cDepNode.getClassSymbol().outermostClass();
        Location loc = getLocationOf(cs);
        // We're completely ignorant of PLATFORM_CLASS_PATH classes
        if (loc == StandardLocation.CLASS_PATH || loc == StandardLocation.SOURCE_PATH)
            pubApis.visitPubapi(cs);
    }
}
 
Example #27
Source File: Modules.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitExports(JCExports tree) {
    Iterable<Symbol> packageContent = tree.directive.packge.members().getSymbols();
    List<JavaFileObject> filesToCheck = List.nil();
    boolean packageNotEmpty = false;
    for (Symbol sym : packageContent) {
        if (sym.kind != Kinds.Kind.TYP)
            continue;
        ClassSymbol csym = (ClassSymbol) sym;
        if (sym.completer.isTerminal() ||
            csym.classfile.getKind() == Kind.CLASS) {
            packageNotEmpty = true;
            filesToCheck = List.nil();
            break;
        }
        if (csym.classfile.getKind() == Kind.SOURCE) {
            filesToCheck = filesToCheck.prepend(csym.classfile);
        }
    }
    for (JavaFileObject jfo : filesToCheck) {
        if (findPackageInFile.findPackageNameOf(jfo) == tree.directive.packge.fullname) {
            packageNotEmpty = true;
            break;
        }
    }
    if (!packageNotEmpty) {
        log.error(tree.qualid.pos(), Errors.PackageEmptyOrNotFound(tree.directive.packge));
    }
    msym.directives = msym.directives.prepend(tree.directive);
}
 
Example #28
Source File: TypeMaker.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("fallthrough")
private static com.sun.javadoc.Type getTypeImpl(DocEnv env, Type t,
        boolean errToClassDoc, boolean considerAnnotations) {
    if (env.legacyDoclet) {
        t = env.types.erasure(t);
    }

    if (considerAnnotations && t.isAnnotated()) {
        return new AnnotatedTypeImpl(env, t);
    }

    switch (t.getTag()) {
    case CLASS:
        if (ClassDocImpl.isGeneric((ClassSymbol)t.tsym)) {
            return env.getParameterizedType((ClassType)t);
        } else {
            return env.getClassDoc((ClassSymbol)t.tsym);
        }
    case WILDCARD:
        Type.WildcardType a = (Type.WildcardType)t;
        return new WildcardTypeImpl(env, a);
    case TYPEVAR: return new TypeVariableImpl(env, (TypeVar)t);
    case ARRAY: return new ArrayTypeImpl(env, t);
    case BYTE: return PrimitiveType.byteType;
    case CHAR: return PrimitiveType.charType;
    case SHORT: return PrimitiveType.shortType;
    case INT: return PrimitiveType.intType;
    case LONG: return PrimitiveType.longType;
    case FLOAT: return PrimitiveType.floatType;
    case DOUBLE: return PrimitiveType.doubleType;
    case BOOLEAN: return PrimitiveType.booleanType;
    case VOID: return PrimitiveType.voidType;
    case ERROR:
        if (errToClassDoc)
            return env.getClassDoc((ClassSymbol)t.tsym);
        // FALLTHRU
    default:
        return new PrimitiveType(t.tsym.getQualifiedName().toString());
    }
}
 
Example #29
Source File: LambdaToMethod.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the declaration corresponding to a symbol in the enclosing
 * scope; the depth parameter is used to filter out symbols defined
 * in nested scopes (which do not need to undergo capture).
 */
private JCTree capturedDecl(int depth, Symbol sym) {
    int currentDepth = frameStack.size() - 1;
    for (Frame block : frameStack) {
        switch (block.tree.getTag()) {
            case CLASSDEF:
                ClassSymbol clazz = ((JCClassDecl)block.tree).sym;
                if (clazz.isSubClass(sym, types) || sym.isMemberOf(clazz, types)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case VARDEF:
                if (((JCVariableDecl)block.tree).sym == sym &&
                        sym.owner.kind == MTH) { //only locals are captured
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case BLOCK:
            case METHODDEF:
            case LAMBDA:
                if (block.locals != null && block.locals.contains(sym)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            default:
                Assert.error("bad decl kind " + block.tree.getTag());
        }
        currentDepth--;
    }
    return null;
}
 
Example #30
Source File: TypeEnter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Complete entering a class.
 *  @param sym         The symbol of the class to be completed.
 */
@Override
public void complete(Symbol sym) throws CompletionFailure {
    // Suppress some (recursive) MemberEnter invocations
    if (!completionEnabled) {
        // Re-install same completer for next time around and return.
        Assert.check((sym.flags() & Flags.COMPOUND) == 0);
        sym.completer = this;
        return;
    }

    try {
        annotate.blockAnnotations();
        sym.flags_field |= UNATTRIBUTED;

        List<Env<AttrContext>> queue;

        dependencies.push((ClassSymbol) sym, CompletionCause.MEMBER_ENTER);
        try {
            queue = completeClass.completeEnvs(List.of(typeEnvs.get((ClassSymbol) sym)));
        } finally {
            dependencies.pop();
        }

        if (!queue.isEmpty()) {
            Set<JCCompilationUnit> seen = new HashSet<>();

            for (Env<AttrContext> env : queue) {
                if (env.toplevel.defs.contains(env.enclClass) && seen.add(env.toplevel)) {
                    finishImports(env.toplevel, () -> {});
                }
            }
        }
    } finally {
        annotate.unblockAnnotations();
    }
}