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: PackageDocImpl.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * 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 #2
Source File: Modules.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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 #3
Source File: DocEnv.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** 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 #4
Source File: JNIWriter.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** 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 #5
Source File: JavacTrees.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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 #6
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #7
Source File: Modules.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@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 #8
Source File: SerializedForm.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
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: TestSymtabItems.java From hottub with GNU General Public License v2.0 | 6 votes |
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 #10
Source File: WorkArounds.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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 #11
Source File: ClassFinder.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** 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 #12
Source File: JavacElements.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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 #13
Source File: DependenciesTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@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 #14
Source File: ClassWriter.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** 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 #15
Source File: PackageDocImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * 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 #16
Source File: JavacTrees.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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 #17
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #18
Source File: Lower.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #19
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
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: Inliner.java From Refaster with Apache License 2.0 | 5 votes |
public ClassSymbol resolveClass(String qualifiedClass) throws CouldNotResolveImportException { Symbol symbol = JavaCompiler.instance(context).resolveIdent(qualifiedClass); if (symbol.equals(symtab().errSymbol) || !(symbol instanceof ClassSymbol)) { throw new CouldNotResolveImportException(qualifiedClass); } else { return (ClassSymbol) symbol; } }
Example #21
Source File: JNIWriter.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public boolean needsHeader(ClassSymbol c) { if (c.isLocal() || (c.flags() & Flags.SYNTHETIC) != 0) return false; if (checkAll) return needsHeader(c.outermostClass(), true); else return needsHeader(c, false); }
Example #22
Source File: JNIWriter.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
public boolean needsHeader(ClassSymbol c) { lazyInit(); if (c.isLocal() || isSynthetic(c)) return false; return (checkAll) ? needsHeader(c.outermostClass(), true) : needsHeader(c, false); }
Example #23
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Check that all abstract members of given class have definitions. * @param pos Position to be used for error reporting. * @param c The class. */ void checkAllDefined(DiagnosticPosition pos, ClassSymbol c) { MethodSymbol undef = types.firstUnimplementedAbstract(c); if (undef != null) { MethodSymbol undef1 = new MethodSymbol(undef.flags(), undef.name, types.memberType(c.type, undef), undef.owner); log.error(pos, Errors.DoesNotOverrideAbstract(c, undef1, undef1.location())); } }
Example #24
Source File: LambdaToMethod.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Override public void visitClassDef(JCClassDecl tree) { List<Frame> prevStack = frameStack; SyntheticMethodNameCounter prevSyntheticMethodNameCounts = syntheticMethodNameCounts; Map<ClassSymbol, Symbol> prevClinits = clinits; DiagnosticSource prevSource = log.currentSource(); try { log.useSource(tree.sym.sourcefile); syntheticMethodNameCounts = new SyntheticMethodNameCounter(); prevClinits = new HashMap<ClassSymbol, Symbol>(); if (tree.sym.owner.kind == MTH) { localClassDefs.put(tree.sym, tree); } if (directlyEnclosingLambda() != null) { tree.sym.owner = owner(); if (tree.sym.hasOuterInstance()) { //if a class is defined within a lambda, the lambda must capture //its enclosing instance (if any) TranslationContext<?> localContext = context(); while (localContext != null) { if (localContext.tree.getTag() == LAMBDA) { ((LambdaTranslationContext)localContext) .addSymbol(tree.sym.type.getEnclosingType().tsym, CAPTURED_THIS); } localContext = localContext.prev; } } } frameStack = frameStack.prepend(new Frame(tree)); super.visitClassDef(tree); } finally { log.useSource(prevSource.getFile()); frameStack = prevStack; syntheticMethodNameCounts = prevSyntheticMethodNameCounts; clinits = prevClinits; } }
Example #25
Source File: JNIWriter.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
protected void writeStatics(Writer out, ClassSymbol sym) throws IOException { List<VariableElement> classfields = getAllFields(sym); for (VariableElement v: classfields) { if (!v.getModifiers().contains(Modifier.STATIC)) continue; String s = null; s = defineForStatic(sym, v); if (s != null) { println(out, s); } } }
Example #26
Source File: JavacTrees.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public boolean isAccessible(Scope scope, TypeElement type) { if (scope instanceof JavacScope && type instanceof ClassSymbol) { Env<AttrContext> env = ((JavacScope) scope).env; return resolve.isAccessible(env, (ClassSymbol)type, true); } else return false; }
Example #27
Source File: TypeEnter.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** 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(); } }
Example #28
Source File: ClassReader.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
AnnotationCompleter(Symbol sym, List<CompoundAnnotationProxy> l) { super(currentOwner.kind == MTH ? currentOwner.enclClass() : (ClassSymbol)currentOwner); if (sym.kind == TYP && sym.owner.kind == MDL) { this.sym = sym.owner; } else { this.sym = sym; } this.l = l; this.classFile = currentClassFile; }
Example #29
Source File: TypeMaker.java From hottub with GNU General Public License v2.0 | 5 votes |
@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 #30
Source File: Modules.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@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); }