com.sun.tools.javac.tree.JCTree.JCClassDecl Java Examples
The following examples show how to use
com.sun.tools.javac.tree.JCTree.JCClassDecl.
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: JavacProcessingEnvironment.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void visitClassDef(JCClassDecl node) { super.visitClassDef(node); // remove generated constructor that may have been added during attribution: List<JCTree> beforeConstructor = List.nil(); List<JCTree> defs = node.defs; while (defs.nonEmpty() && !defs.head.hasTag(Tag.METHODDEF)) { beforeConstructor = beforeConstructor.prepend(defs.head); defs = defs.tail; } if (defs.nonEmpty() && (((JCMethodDecl) defs.head).mods.flags & Flags.GENERATEDCONSTR) != 0) { defs = defs.tail; while (beforeConstructor.nonEmpty()) { defs = defs.prepend(beforeConstructor.head); beforeConstructor = beforeConstructor.tail; } node.defs = defs; } if (node.sym != null) { node.sym.completer = new ImplicitCompleter(topLevel); } node.sym = null; }
Example #2
Source File: JavaCompiler.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** Emit plain Java source for a class. * @param env The attribution environment of the outermost class * containing this class. * @param cdef The class definition to be printed. */ JavaFileObject printSource(Env<AttrContext> env, JCClassDecl cdef) throws IOException { JavaFileObject outFile = fileManager.getJavaFileForOutput(CLASS_OUTPUT, cdef.sym.flatname.toString(), JavaFileObject.Kind.SOURCE, null); if (inputFiles.contains(outFile)) { log.error(cdef.pos(), Errors.SourceCantOverwriteInputFile(outFile)); return null; } else { try (BufferedWriter out = new BufferedWriter(outFile.openWriter())) { new Pretty(out, true).printUnit(env.toplevel, cdef); if (verbose) log.printVerbose("wrote.file", outFile); } return outFile; } }
Example #3
Source File: Lower.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** Add all required access methods for a private symbol to enclosing class. * @param sym The symbol. */ void makeAccessible(Symbol sym) { JCClassDecl cdef = classDef(sym.owner.enclClass()); if (cdef == null) Assert.error("class def not found: " + sym + " in " + sym.owner); if (sym.name == names.init) { cdef.defs = cdef.defs.prepend( accessConstructorDef(cdef.pos, sym, accessConstrs.get(sym))); } else { MethodSymbol[] accessors = accessSyms.get(sym); for (int i = 0; i < AccessCode.numberOfAccessCodes; i++) { if (accessors[i] != null) cdef.defs = cdef.defs.prepend( accessDef(cdef.pos, sym, accessors[i], i)); } } }
Example #4
Source File: JavacTaskImpl.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void handleFlowResults(Queue<Env<AttrContext>> queue, ListBuffer<Element> elems) { for (Env<AttrContext> env: queue) { switch (env.tree.getTag()) { case CLASSDEF: JCClassDecl cdef = (JCClassDecl) env.tree; if (cdef.sym != null) elems.append(cdef.sym); break; case MODULEDEF: JCModuleDecl mod = (JCModuleDecl) env.tree; if (mod.sym != null) elems.append(mod.sym); break; case PACKAGEDEF: JCCompilationUnit unit = env.toplevel; if (unit.packge != null) elems.append(unit.packge); break; } } genList.addAll(queue); }
Example #5
Source File: TypeEnter.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected void doCompleteEnvs(List<Env<AttrContext>> envs) { for (Env<AttrContext> env : envs) { JCClassDecl tree = (JCClassDecl)env.tree; queue.add(env); JavaFileObject prev = log.useSource(env.toplevel.sourcefile); DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos()); try { dependencies.push(env.enclClass.sym, phaseName); runPhase(env); } catch (CompletionFailure ex) { chk.completionError(tree.pos(), ex); } finally { dependencies.pop(); deferredLintHandler.setPos(prevLintPos); log.useSource(prev); } } }
Example #6
Source File: Lower.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** Map a class symbol to its definition. * @param c The class symbol of which we want to determine the definition. */ JCClassDecl classDef(ClassSymbol c) { // First lookup the class in the classdefs table. JCClassDecl def = classdefs.get(c); if (def == null && outermostMemberDef != null) { // If this fails, traverse outermost member definition, entering all // local classes into classdefs, and try again. classMap.scan(outermostMemberDef); def = classdefs.get(c); } if (def == null) { // If this fails, traverse outermost class definition, entering all // local classes into classdefs, and try again. classMap.scan(outermostClassDef); def = classdefs.get(c); } return def; }
Example #7
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** Check for cycles in the graph of annotation elements. */ void checkNonCyclicElements(JCClassDecl tree) { if ((tree.sym.flags_field & ANNOTATION) == 0) return; Assert.check((tree.sym.flags_field & LOCKED) == 0); try { tree.sym.flags_field |= LOCKED; for (JCTree def : tree.defs) { if (!def.hasTag(METHODDEF)) continue; JCMethodDecl meth = (JCMethodDecl)def; checkAnnotationResType(meth.pos(), meth.restype.type); } } finally { tree.sym.flags_field &= ~LOCKED; tree.sym.flags_field |= ACYCLIC_ANN; } }
Example #8
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** Check for cycles in the graph of constructors calling other * constructors. */ void checkCyclicConstructors(JCClassDecl tree) { Map<Symbol,Symbol> callMap = new HashMap<>(); // enter each constructor this-call into the map for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { JCMethodInvocation app = TreeInfo.firstConstructorCall(l.head); if (app == null) continue; JCMethodDecl meth = (JCMethodDecl) l.head; if (TreeInfo.name(app.meth) == names._this) { callMap.put(meth.sym, TreeInfo.symbol(app.meth)); } else { meth.sym.flags_field |= ACYCLIC; } } // Check for cycles in the map Symbol[] ctors = new Symbol[0]; ctors = callMap.keySet().toArray(ctors); for (Symbol caller : ctors) { checkCyclicConstructor(tree, caller, callMap); } }
Example #9
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 #10
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Look in the map to see if the given constructor is part of a * call cycle. */ private void checkCyclicConstructor(JCClassDecl tree, Symbol ctor, Map<Symbol,Symbol> callMap) { if (ctor != null && (ctor.flags_field & ACYCLIC) == 0) { if ((ctor.flags_field & LOCKED) != 0) { log.error(TreeInfo.diagnosticPositionFor(ctor, tree), Errors.RecursiveCtorInvocation); } else { ctor.flags_field |= LOCKED; checkCyclicConstructor(tree, callMap.remove(ctor), callMap); ctor.flags_field &= ~LOCKED; } ctor.flags_field |= ACYCLIC; } }
Example #11
Source File: TypeEnter.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void runPhase(Env<AttrContext> env) { JCClassDecl tree = env.enclClass; ClassSymbol sym = tree.sym; ClassType ct = (ClassType)sym.type; Env<AttrContext> baseEnv = baseEnv(tree, env); attribSuperTypes(env, baseEnv); if (sym.fullname == names.java_lang_Object) { if (tree.extending != null) { chk.checkNonCyclic(tree.extending.pos(), ct.supertype_field); ct.supertype_field = Type.noType; } else if (tree.implementing.nonEmpty()) { chk.checkNonCyclic(tree.implementing.head.pos(), ct.interfaces_field.head); ct.interfaces_field = List.nil(); } } markDeprecated(sym, tree.mods.annotations, baseEnv); chk.checkNonCyclicDecl(tree); }
Example #12
Source File: DeferredAttr.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 #13
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 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 #14
Source File: TypeEnter.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Enter members for a class. */ void finishClass(JCClassDecl tree, Env<AttrContext> env) { if ((tree.mods.flags & Flags.ENUM) != 0 && !tree.sym.type.hasTag(ERROR) && (types.supertype(tree.sym.type).tsym.flags() & Flags.ENUM) == 0) { addEnumMembers(tree, env); } memberEnter.memberEnter(tree.defs, env); if (tree.sym.isAnnotationType()) { Assert.check(tree.sym.isCompleted()); tree.sym.setAnnotationTypeMetadata(new AnnotationTypeMetadata(tree.sym, annotate.annotationTypeSourceCompleter())); } }
Example #15
Source File: Lower.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void visitClassDef(JCClassDecl that) { TypeSymbol prevCurrentClass = currentClass; currentClass = that.sym; try { super.visitClassDef(that); } finally { currentClass = prevCurrentClass; } }
Example #16
Source File: Flow.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void visitClassDef(JCClassDecl tree) { if (tree.sym == null) return; boolean alivePrev = alive; ListBuffer<PendingExit> pendingExitsPrev = pendingExits; Lint lintPrev = lint; pendingExits = new ListBuffer<>(); lint = lint.augment(tree.sym); try { // process all the static initializers for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { if (!l.head.hasTag(METHODDEF) && (TreeInfo.flags(l.head) & STATIC) != 0) { scanDef(l.head); } } // process all the instance initializers for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { if (!l.head.hasTag(METHODDEF) && (TreeInfo.flags(l.head) & STATIC) == 0) { scanDef(l.head); } } // process all the methods for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { if (l.head.hasTag(METHODDEF)) { scan(l.head); } } } finally { pendingExits = pendingExitsPrev; alive = alivePrev; lint = lintPrev; } }
Example #17
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void visitClassDef(JCClassDecl tree) { List<JCTree> supertypes = List.nil(); if (tree.getExtendsClause() != null) { supertypes = supertypes.prepend(tree.getExtendsClause()); } if (tree.getImplementsClause() != null) { for (JCTree intf : tree.getImplementsClause()) { supertypes = supertypes.prepend(intf); } } checkClass(tree.pos(), tree.sym, supertypes); }
Example #18
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
private ClassSymbol currentClass() { for (Frame frame : frameStack) { if (frame.tree.hasTag(JCTree.Tag.CLASSDEF)) { JCClassDecl cdef = (JCClassDecl) frame.tree; return cdef.sym; } } return null; }
Example #19
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
void checkNonCyclicDecl(JCClassDecl tree) { CycleChecker cc = new CycleChecker(); cc.scan(tree); if (!cc.errorFound && !cc.partialCheck) { tree.sym.flags_field |= ACYCLIC; } }
Example #20
Source File: JavacProcessingEnvironment.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
private List<ClassSymbol> getTopLevelClasses(List<? extends JCCompilationUnit> units) { List<ClassSymbol> classes = List.nil(); for (JCCompilationUnit unit : units) { for (JCTree node : unit.defs) { if (node.hasTag(JCTree.Tag.CLASSDEF)) { ClassSymbol sym = ((JCClassDecl) node).sym; Assert.checkNonNull(sym); classes = classes.prepend(sym); } } } return classes.reverse(); }
Example #21
Source File: GenStubs.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * methods: remove method bodies, make methods native */ @Override public void visitClassDef(JCClassDecl tree) { long prevClassMods = currClassMods; currClassMods = tree.mods.flags; try { super.visitClassDef(tree);; } finally { currClassMods = prevClassMods; } }
Example #22
Source File: Lower.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
JCClassDecl makeEmptyClass(long flags, ClassSymbol owner, Name flatname, boolean addToDefs) { // Create class symbol. ClassSymbol c = syms.defineClass(names.empty, owner); if (flatname != null) { c.flatname = flatname; } else { c.flatname = chk.localClassName(c); } c.sourcefile = owner.sourcefile; c.completer = Completer.NULL_COMPLETER; c.members_field = WriteableScope.create(c); c.flags_field = flags; ClassType ctype = (ClassType) c.type; ctype.supertype_field = syms.objectType; ctype.interfaces_field = List.nil(); JCClassDecl odef = classDef(owner); // Enter class symbol in owner scope and compiled table. enterSynthetic(odef.pos(), c, owner.members()); chk.putCompiled(c); // Create class definition tree. JCClassDecl cdef = make.ClassDef( make.Modifiers(flags), names.empty, List.nil(), null, List.nil(), List.nil()); cdef.sym = c; cdef.type = c.type; // Append class definition tree to owner's definitions. if (addToDefs) odef.defs = odef.defs.prepend(cdef); return cdef; }
Example #23
Source File: TypeAnnotations.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void visitNewClass(JCNewClass tree) { if (tree.def != null && !tree.def.mods.annotations.isEmpty()) { JCClassDecl classdecl = tree.def; TypeAnnotationPosition pos; if (classdecl.extending == tree.clazz) { pos = TypeAnnotationPosition.classExtends(tree.pos); } else if (classdecl.implementing.contains(tree.clazz)) { final int index = classdecl.implementing.indexOf(tree.clazz); pos = TypeAnnotationPosition.classExtends(index, tree.pos); } else { // In contrast to CLASS elsewhere, typarams cannot occur here. throw new AssertionError("Could not determine position of tree " + tree); } Type before = classdecl.sym.type; separateAnnotationsKinds(classdecl, tree.clazz.type, classdecl.sym, pos); copyNewClassAnnotationsToOwner(tree); // classdecl.sym.type now contains an annotated type, which // is not what we want there. // TODO: should we put this type somewhere in the superclass/interface? classdecl.sym.type = before; } scan(tree.encl); scan(tree.typeargs); if (tree.def == null) { scan(tree.clazz); } // else super type will already have been scanned in the context of the anonymous class. scan(tree.args); // The class body will already be scanned. // scan(tree.def); }
Example #24
Source File: TypeAnnotations.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void visitClassDef(JCClassDecl tree) { if (isInClass) return; isInClass = true; if (sigOnly) { scan(tree.mods); scan(tree.typarams); scan(tree.extending); scan(tree.implementing); } scan(tree.defs); }
Example #25
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
private KlassInfo(JCClassDecl clazz) { this.clazz = clazz; appendedMethodList = new ListBuffer<>(); deserializeCases = new HashMap<>(); MethodType type = new MethodType(List.of(syms.serializedLambdaType), syms.objectType, List.nil(), syms.methodClass); deserMethodSym = makePrivateSyntheticMethod(STATIC, names.deserializeLambda, type, clazz.sym); deserParamSym = new VarSymbol(FINAL, names.fromString("lambda"), syms.serializedLambdaType, deserMethodSym); }
Example #26
Source File: TypeAnnotations.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void validateTypeAnnotationsSignatures(final Env<AttrContext> env, final JCClassDecl tree) { annotate.validate(() -> { //validate annotations JavaFileObject oldSource = log.useSource(env.toplevel.sourcefile); try { attr.validateTypeAnnotations(tree, true); } finally { log.useSource(oldSource); } }); }
Example #27
Source File: TypeAnnotations.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Separate type annotations from declaration annotations and * determine the correct positions for type annotations. * This version only visits types in signatures and should be * called from MemberEnter. */ public void organizeTypeAnnotationsSignatures(final Env<AttrContext> env, final JCClassDecl tree) { annotate.afterTypes(() -> { JavaFileObject oldSource = log.useSource(env.toplevel.sourcefile); try { new TypeAnnotationPositions(true).scan(tree); } finally { log.useSource(oldSource); } }); }
Example #28
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 #29
Source File: JavaCompiler.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Prepare attributed parse trees, in conjunction with their attribution contexts, * for source or code generation. * If any errors occur, an empty list will be returned. * @return a list containing the classes to be generated */ public Queue<Pair<Env<AttrContext>, JCClassDecl>> desugar(Queue<Env<AttrContext>> envs) { ListBuffer<Pair<Env<AttrContext>, JCClassDecl>> results = new ListBuffer<>(); for (Env<AttrContext> env: envs) desugar(env, results); return stopIfError(CompileState.FLOW, results); }
Example #30
Source File: TypeEnter.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Add the implicit members for an enum type * to the symbol table. */ private void addEnumMembers(JCClassDecl tree, Env<AttrContext> env) { JCExpression valuesType = make.Type(new ArrayType(tree.sym.type, syms.arrayClass)); // public static T[] values() { return ???; } JCMethodDecl values = make. MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC), names.values, valuesType, List.nil(), List.nil(), List.nil(), // thrown null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))), null); memberEnter.memberEnter(values, env); // public static T valueOf(String name) { return ???; } JCMethodDecl valueOf = make. MethodDef(make.Modifiers(Flags.PUBLIC|Flags.STATIC), names.valueOf, make.Type(tree.sym.type), List.nil(), List.of(make.VarDef(make.Modifiers(Flags.PARAMETER | Flags.MANDATED), names.fromString("name"), make.Type(syms.stringType), null)), List.nil(), // thrown null, //make.Block(0, Tree.emptyList.prepend(make.Return(make.Ident(names._null)))), null); memberEnter.memberEnter(valueOf, env); }