/** 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(), "source.cant.overwrite.input.file", outFile); return null; } else { BufferedWriter out = new BufferedWriter(outFile.openWriter()); try { new Pretty(out, true).printUnit(env.toplevel, cdef); if (verbose) printVerbose("wrote.file", outFile); } finally { out.close(); } return outFile; } }
/** Generate code and emit a class file for a given class * @param env The attribution environment of the outermost class * containing this class. * @param cdef The class definition from which code is generated. */ JavaFileObject genCode(Env<AttrContext> env, JCClassDecl cdef) throws IOException { try { if (gen.genClass(env, cdef)) return writer.writeClass(cdef.sym); } catch (ClassWriter.PoolOverflow ex) { log.error(cdef.pos(), "limit.pool"); } catch (ClassWriter.StringOverflow ex) { log.error(cdef.pos(), "limit.string.overflow", ex.value.substring(0, 20)); } catch (CompletionFailure ex) { chk.completionError(cdef.pos(), ex); } return null; }
/** Generate code and emit a class file for a given class * @param env The attribution environment of the outermost class * containing this class. * @param cdef The class definition from which code is generated. */ JavaFileObject genCode(Env<AttrContext> env, JCClassDecl cdef) throws IOException { try { if (gen.genClass(env, cdef) && (errorCount() == 0)) return writer.writeClass(cdef.sym); } catch (ClassWriter.PoolOverflow ex) { log.error(cdef.pos(), "limit.pool"); } catch (ClassWriter.StringOverflow ex) { log.error(cdef.pos(), "limit.string.overflow", ex.value.substring(0, 20)); } catch (CompletionFailure ex) { chk.completionError(cdef.pos(), ex); } return null; }
public void visitClassDef(JCClassDecl tree) { // Local classes have not been entered yet, so we need to do it now: if ((env.info.scope.owner.kind & (VAR | MTH)) != 0) enter.classEnter(tree, env); ClassSymbol c = tree.sym; if (c == null) { // exit in case something drastic went wrong during enter. result = null; } else { // make sure class has been completed: c.complete(); // If this class appears as an anonymous class // in a superclass constructor call where // no explicit outer instance is given, // disable implicit outer instance from being passed. // (This would be an illegal access to "this before super"). if (env.info.isSelfCall && env.tree.getTag() == JCTree.NEWCLASS && ((JCNewClass) env.tree).encl == null) { c.flags_field |= NOOUTERTHIS; } attribClass(tree.pos(), c); result = tree.type = c.type; } }
public Symbol getElement(TreePath path) { JCTree tree = (JCTree) path.getLeaf(); Symbol sym = TreeInfo.symbolFor(tree); if (sym == null) { if (TreeInfo.isDeclaration(tree)) { for (TreePath p = path; p != null; p = p.getParentPath()) { JCTree t = (JCTree) p.getLeaf(); if (t.hasTag(JCTree.Tag.CLASSDEF)) { JCClassDecl ct = (JCClassDecl) t; if (ct.sym != null) { if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) { attr.attribClass(ct.pos(), ct.sym); sym = TreeInfo.symbolFor(tree); } break; } } } } } return sym; }
/** * Create a MethodInvocation to test that we are running in the correct * Thread. This must return true or false only. * @param p Annotation, used by overridden versions to pass alternate parameters * @param utils * @param e * @param cd * @param executorFactoryIdent * @param isMethod * @return */ protected JCTree.JCMethodInvocation isThread( final Annotation p, int pos, final JavacUtils utils, final Element e, final JCTree.JCClassDecl cd, final JCTree.JCExpression executorFactoryIdent, final String isMethod ) { return utils.makeCall( e, cd.pos(), pos, executorFactoryIdent, utils.fromString( isMethod ), List.<JCTree.JCExpression>nil() ); }
/** Check that an appropriate serialVersionUID member is defined. */ private void checkSerialVersionUID(JCClassDecl tree, ClassSymbol c) { // check for presence of serialVersionUID Scope.Entry e = c.members().lookup(names.serialVersionUID); while (e.scope != null && e.sym.kind != VAR) e = e.next(); if (e.scope == null) { log.warning(LintCategory.SERIAL, tree.pos(), "missing.SVUID", c); return; } // check that it is static final VarSymbol svuid = (VarSymbol)e.sym; if ((svuid.flags() & (STATIC | FINAL)) != (STATIC | FINAL)) log.warning(LintCategory.SERIAL, TreeInfo.diagnosticPositionFor(svuid, tree), "improper.SVUID", c); // check that it is long else if (!svuid.type.hasTag(LONG)) log.warning(LintCategory.SERIAL, TreeInfo.diagnosticPositionFor(svuid, tree), "long.SVUID", c); // check constant else if (svuid.getConstValue() == null) log.warning(LintCategory.SERIAL, TreeInfo.diagnosticPositionFor(svuid, tree), "constant.SVUID", c); }
public Symbol getElement(TreePath path) { JCTree tree = (JCTree) path.getLeaf(); Symbol sym = TreeInfo.symbolFor(tree); if (sym == null) { if (TreeInfo.isDeclaration(tree)) { for (TreePath p = path; p != null; p = p.getParentPath()) { JCTree t = (JCTree) p.getLeaf(); if (t.hasTag(JCTree.Tag.CLASSDEF)) { JCClassDecl ct = (JCClassDecl) t; if (ct.sym != null) { if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) { attr.attribClass(ct.pos(), ct.sym); sym = TreeInfo.symbolFor(tree); } break; } } } } } return sym; }
/** Generate code and emit a class file for a given class * @param env The attribution environment of the outermost class * containing this class. * @param cdef The class definition from which code is generated. */ JavaFileObject genCode(Env<AttrContext> env, JCClassDecl cdef) throws IOException { try { if (gen.genClass(env, cdef) && (errorCount() == 0)) return writer.writeClass(cdef.sym); } catch (ClassWriter.PoolOverflow ex) { log.error(cdef.pos(), "limit.pool"); } catch (ClassWriter.StringOverflow ex) { log.error(cdef.pos(), "limit.string.overflow", ex.value.substring(0, 20)); } catch (CompletionFailure ex) { chk.completionError(cdef.pos(), ex); } return null; }
/** Generate code and emit a class file for a given class * @param env The attribution environment of the outermost class * containing this class. * @param cdef The class definition from which code is generated. */ JavaFileObject genCode(Env<AttrContext> env, JCClassDecl cdef) throws IOException { try { if (gen.genClass(env, cdef) && (errorCount() == 0)) return writer.writeClass(cdef.sym); } catch (ClassWriter.PoolOverflow ex) { log.error(cdef.pos(), "limit.pool"); } catch (ClassWriter.StringOverflow ex) { log.error(cdef.pos(), "limit.string.overflow", ex.value.substring(0, 20)); } catch (CompletionFailure ex) { chk.completionError(cdef.pos(), ex); } return null; }
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, "bad.functional.intf.anno.1", ex.getDiagnostic()); } } } }
/** Check that an appropriate serialVersionUID member is defined. */ private void checkSerialVersionUID(JCClassDecl tree, ClassSymbol c) { // check for presence of serialVersionUID Scope.Entry e = c.members().lookup(names.serialVersionUID); while (e.scope != null && e.sym.kind != VAR) e = e.next(); if (e.scope == null) { log.warning(tree.pos(), "missing.SVUID", c); return; } // check that it is static final VarSymbol svuid = (VarSymbol)e.sym; if ((svuid.flags() & (STATIC | FINAL)) != (STATIC | FINAL)) log.warning(TreeInfo.diagnosticPositionFor(svuid, tree), "improper.SVUID", c); // check that it is long else if (svuid.type.tag != TypeTags.LONG) log.warning(TreeInfo.diagnosticPositionFor(svuid, tree), "long.SVUID", c); // check constant else if (svuid.getConstValue() == null) log.warning(TreeInfo.diagnosticPositionFor(svuid, tree), "constant.SVUID", c); }
/** Check that an appropriate serialVersionUID member is defined. */ private void checkSerialVersionUID(JCClassDecl tree, ClassSymbol c) { // check for presence of serialVersionUID Scope.Entry e = c.members().lookup(names.serialVersionUID); while (e.scope != null && e.sym.kind != VAR) e = e.next(); if (e.scope == null) { log.warning(tree.pos(), "missing.SVUID", c); return; } // check that it is static final VarSymbol svuid = (VarSymbol)e.sym; if ((svuid.flags() & (STATIC | FINAL)) != (STATIC | FINAL)) log.warning(TreeInfo.diagnosticPositionFor(svuid, tree), "improper.SVUID", c); // check that it is long else if (svuid.type.tag != TypeTags.LONG) log.warning(TreeInfo.diagnosticPositionFor(svuid, tree), "long.SVUID", c); // check constant else if (svuid.getConstValue() == null) log.warning(TreeInfo.diagnosticPositionFor(svuid, tree), "constant.SVUID", c); }
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, "bad.functional.intf.anno.1", ex.getDiagnostic()); } } } }
@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); }
private MethodSymbol addEnumFieldNameMethod(JCClassDecl cdef, VarSymbol nameSymbol) { // Add the accessor methods for name Symbol nameSym = lookupMethod(cdef.pos(), names._name, cdef.type, List.<Type>nil()); assert(nameSym != null); assert(nameSym instanceof MethodSymbol); JCStatement ret = make.Return(make.Ident(nameSymbol)); cdef.defs = cdef.defs.append(make.MethodDef((MethodSymbol)nameSym, make.Block(0L, List.of(ret)))); return (MethodSymbol)nameSym; }
private MethodSymbol addEnumFieldOrdinalMethod(JCClassDecl cdef, VarSymbol ordinalSymbol) { // Add the accessor methods for ordinal Symbol ordinalSym = lookupMethod(cdef.pos(), names.ordinal, cdef.type, List.<Type>nil()); assert(ordinalSym != null); assert(ordinalSym instanceof MethodSymbol); JCStatement ret = make.Return(make.Ident(ordinalSymbol)); cdef.defs = cdef.defs.append(make.MethodDef((MethodSymbol)ordinalSym, make.Block(0L, List.of(ret)))); return (MethodSymbol)ordinalSym; }
private MethodSymbol addEnumFieldOrdinalMethod(JCClassDecl cdef, VarSymbol ordinalSymbol) { // Add the accessor methods for ordinal Symbol ordinalSym = lookupMethod(cdef.pos(), names.ordinal, cdef.type, List.<Type>nil()); assert(ordinalSym != null); assert(ordinalSym instanceof MethodSymbol); JCStatement ret = make.Return(make.Ident(ordinalSymbol)); cdef.defs = cdef.defs.append(make.MethodDef((MethodSymbol)ordinalSym, make.Block(0L, List.of(ret)))); return (MethodSymbol)ordinalSym; }
private MethodSymbol addEnumFieldNameMethod(JCClassDecl cdef, VarSymbol nameSymbol) { // Add the accessor methods for name Symbol nameSym = lookupMethod(cdef.pos(), names._name, cdef.type, List.<Type>nil()); assert(nameSym != null); assert(nameSym instanceof MethodSymbol); JCStatement ret = make.Return(make.Ident(nameSymbol)); cdef.defs = cdef.defs.append(make.MethodDef((MethodSymbol)nameSym, make.Block(0L, List.of(ret)))); return (MethodSymbol)nameSym; }
@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); }