Java Code Examples for com.sun.tools.javac.code.Flags#GENERATEDCONSTR
The following examples show how to use
com.sun.tools.javac.code.Flags#GENERATEDCONSTR .
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: ImmutableTreeTranslator.java From netbeans with Apache License 2.0 | 6 votes |
protected final MethodTree rewriteChildren(MethodTree tree) { ModifiersTree mods = (ModifiersTree)translate(tree.getModifiers()); ExpressionTree restype = (ExpressionTree)translateClassRef(tree.getReturnType()); List<? extends TypeParameterTree> typarams = translateStable(tree.getTypeParameters()); List<? extends VariableTree> params = translateStable(tree.getParameters()); List<? extends ExpressionTree> thrown = translate(tree.getThrows()); ExpressionTree defaultValue = (ExpressionTree)translate(tree.getDefaultValue()); BlockTree body = (BlockTree)translate(tree.getBody()); if (restype!=tree.getReturnType() || !typarams.equals(tree.getTypeParameters()) || !params.equals(tree.getParameters()) || !thrown.equals(tree.getThrows()) || mods!=tree.getModifiers() || defaultValue!=tree.getDefaultValue() || body!=tree.getBody()) { if ((((JCModifiers) mods).flags & Flags.GENERATEDCONSTR) != 0) { mods = make.Modifiers(((JCModifiers) mods).flags & ~Flags.GENERATEDCONSTR, mods.getAnnotations()); } MethodTree n = make.Method(mods, tree.getName().toString(), restype, typarams, params, thrown, body, defaultValue); copyCommentTo(tree,n); copyPosTo(tree,n); tree = n; } return tree; }
Example 3
Source File: TreeMaker.java From netbeans with Apache License 2.0 | 6 votes |
public ModifiersTree removeModifiersModifier(ModifiersTree modifiers, Modifier modifier) { long c = ((JCModifiers) modifiers).flags & ~Flags.GENERATEDCONSTR; switch (modifier) { case ABSTRACT: c = c & ~Flags.ABSTRACT; break; case FINAL: c = c & ~Flags.FINAL; break; case NATIVE: c = c & ~Flags.NATIVE; break; case PRIVATE: c = c & ~Flags.PRIVATE; break; case PROTECTED: c = c & ~Flags.PROTECTED; break; case PUBLIC: c = c & ~Flags.PUBLIC; break; case STATIC: c = c & ~Flags.STATIC; break; case STRICTFP: c = c & ~Flags.STRICTFP; break; case SYNCHRONIZED: c = c & ~Flags.SYNCHRONIZED; break; case TRANSIENT: c = c & ~Flags.TRANSIENT; break; case VOLATILE: c = c & ~Flags.VOLATILE; break; case DEFAULT: c = c & ~Flags.DEFAULT; break; default: break; } return Modifiers(c, modifiers.getAnnotations()); }
Example 4
Source File: ResolveHarness.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Override void process(Diagnostic<? extends JavaFileObject> diagnostic) { Symbol methodSym = (Symbol)methodSym(diagnostic); if ((methodSym.flags() & Flags.GENERATEDCONSTR) != 0) { //skip resolution of default constructor (put there by javac) return; } Candidate c = getCandidateAtPos(methodSym, asJCDiagnostic(diagnostic).getLineNumber(), asJCDiagnostic(diagnostic).getColumnNumber()); if (c == null) { return; //nothing to check } if (c.applicable().length == 0 && c.mostSpecific()) { error("Inapplicable method cannot be most specific " + methodSym); } if (isApplicable(diagnostic) != Arrays.asList(c.applicable()).contains(phase)) { error("Invalid candidate's applicability " + methodSym); } if (success) { for (Phase p : c.applicable()) { if (phase.ordinal() < p.ordinal()) { error("Invalid phase " + p + " on method " + methodSym); } } } if (Arrays.asList(c.applicable()).contains(phase)) { //applicable if (c.mostSpecific() != mostSpecific) { error("Invalid most specific value for method " + methodSym + " " + new ElementKey(methodSym).key); } MethodType mtype = getSig(diagnostic); if (mtype != null) { checkSig(c, methodSym, mtype); } } }
Example 5
Source File: ResolveHarness.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Override void process(Diagnostic<? extends JavaFileObject> diagnostic) { Symbol methodSym = (Symbol)methodSym(diagnostic); if ((methodSym.flags() & Flags.GENERATEDCONSTR) != 0) { //skip resolution of default constructor (put there by javac) return; } Candidate c = getCandidateAtPos(methodSym, asJCDiagnostic(diagnostic).getLineNumber(), asJCDiagnostic(diagnostic).getColumnNumber()); if (c == null) { return; //nothing to check } if (c.applicable().length == 0 && c.mostSpecific()) { error("Inapplicable method cannot be most specific " + methodSym); } if (isApplicable(diagnostic) != Arrays.asList(c.applicable()).contains(phase)) { error("Invalid candidate's applicability " + methodSym); } if (success) { for (Phase p : c.applicable()) { if (phase.ordinal() < p.ordinal()) { error("Invalid phase " + p + " on method " + methodSym); } } } if (Arrays.asList(c.applicable()).contains(phase)) { //applicable if (c.mostSpecific() != mostSpecific) { error("Invalid most specific value for method " + methodSym + " " + new ElementKey(methodSym).key); } MethodType mtype = getSig(diagnostic); if (mtype != null) { checkSig(c, methodSym, mtype); } } }
Example 6
Source File: ResolveHarness.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Override void process(Diagnostic<? extends JavaFileObject> diagnostic) { Symbol methodSym = (Symbol)methodSym(diagnostic); if ((methodSym.flags() & Flags.GENERATEDCONSTR) != 0) { //skip resolution of default constructor (put there by javac) return; } Candidate c = getCandidateAtPos(methodSym, asJCDiagnostic(diagnostic).getLineNumber(), asJCDiagnostic(diagnostic).getColumnNumber()); if (c == null) { return; //nothing to check } if (c.applicable().length == 0 && c.mostSpecific()) { error("Inapplicable method cannot be most specific " + methodSym); } if (isApplicable(diagnostic) != Arrays.asList(c.applicable()).contains(phase)) { error("Invalid candidate's applicability " + methodSym); } if (success) { for (Phase p : c.applicable()) { if (phase.ordinal() < p.ordinal()) { error("Invalid phase " + p + " on method " + methodSym); } } } if (Arrays.asList(c.applicable()).contains(phase)) { //applicable if (c.mostSpecific() != mostSpecific) { error("Invalid most specific value for method " + methodSym + " " + new ElementKey(methodSym).key); } MethodType mtype = getSig(diagnostic); if (mtype != null) { checkSig(c, methodSym, mtype); } } }
Example 7
Source File: ResolveHarness.java From hottub with GNU General Public License v2.0 | 5 votes |
@Override void process(Diagnostic<? extends JavaFileObject> diagnostic) { Symbol methodSym = (Symbol)methodSym(diagnostic); if ((methodSym.flags() & Flags.GENERATEDCONSTR) != 0) { //skip resolution of default constructor (put there by javac) return; } Candidate c = getCandidateAtPos(methodSym, asJCDiagnostic(diagnostic).getLineNumber(), asJCDiagnostic(diagnostic).getColumnNumber()); if (c == null) { return; //nothing to check } if (c.applicable().length == 0 && c.mostSpecific()) { error("Inapplicable method cannot be most specific " + methodSym); } if (isApplicable(diagnostic) != Arrays.asList(c.applicable()).contains(phase)) { error("Invalid candidate's applicability " + methodSym); } if (success) { for (Phase p : c.applicable()) { if (phase.ordinal() < p.ordinal()) { error("Invalid phase " + p + " on method " + methodSym); } } } if (Arrays.asList(c.applicable()).contains(phase)) { //applicable if (c.mostSpecific() != mostSpecific) { error("Invalid most specific value for method " + methodSym + " " + new ElementKey(methodSym).key); } MethodType mtype = getSig(diagnostic); if (mtype != null) { checkSig(c, methodSym, mtype); } } }
Example 8
Source File: ResolveHarness.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override void process(Diagnostic<? extends JavaFileObject> diagnostic) { Symbol methodSym = (Symbol)methodSym(diagnostic); if ((methodSym.flags() & Flags.GENERATEDCONSTR) != 0) { //skip resolution of default constructor (put there by javac) return; } Candidate c = getCandidateAtPos(methodSym, asJCDiagnostic(diagnostic).getLineNumber(), asJCDiagnostic(diagnostic).getColumnNumber()); if (c == null) { return; //nothing to check } if (c.applicable().length == 0 && c.mostSpecific()) { error("Inapplicable method cannot be most specific " + methodSym); } if (isApplicable(diagnostic) != Arrays.asList(c.applicable()).contains(phase)) { error("Invalid candidate's applicability " + methodSym); } if (success) { for (Phase p : c.applicable()) { if (phase.ordinal() < p.ordinal()) { error("Invalid phase " + p + " on method " + methodSym); } } } if (Arrays.asList(c.applicable()).contains(phase)) { //applicable if (c.mostSpecific() != mostSpecific) { error("Invalid most specific value for method " + methodSym + " " + new ElementKey(methodSym).key); } MethodType mtype = getSig(diagnostic); if (mtype != null) { checkSig(c, methodSym, mtype); } } }
Example 9
Source File: HandleUtilityClass.java From EasyMPermission with MIT License | 5 votes |
private void changeModifiersAndGenerateConstructor(JavacNode typeNode, JavacNode errorNode) { JCClassDecl classDecl = (JCClassDecl) typeNode.get(); boolean makeConstructor = true; classDecl.mods.flags |= Flags.FINAL; boolean markStatic = true; if (typeNode.up().getKind() == Kind.COMPILATION_UNIT) markStatic = false; if (markStatic && typeNode.up().getKind() == Kind.TYPE) { JCClassDecl typeDecl = (JCClassDecl) typeNode.up().get(); if ((typeDecl.mods.flags & Flags.INTERFACE) != 0) markStatic = false; } if (markStatic) classDecl.mods.flags |= Flags.STATIC; for (JavacNode element : typeNode.down()) { if (element.getKind() == Kind.FIELD) { JCVariableDecl fieldDecl = (JCVariableDecl) element.get(); fieldDecl.mods.flags |= Flags.STATIC; } else if (element.getKind() == Kind.METHOD) { JCMethodDecl methodDecl = (JCMethodDecl) element.get(); if (methodDecl.name.contentEquals("<init>")) { if (getGeneratedBy(methodDecl) == null && (methodDecl.mods.flags & Flags.GENERATEDCONSTR) == 0) { element.addError("@UtilityClasses cannot have declared constructors."); makeConstructor = false; continue; } } methodDecl.mods.flags |= Flags.STATIC; } else if (element.getKind() == Kind.TYPE) { JCClassDecl innerClassDecl = (JCClassDecl) element.get(); innerClassDecl.mods.flags |= Flags.STATIC; } } if (makeConstructor) createPrivateDefaultConstructor(typeNode); }
Example 10
Source File: StrictJavaDepsPlugin.java From bazel with Apache License 2.0 | 5 votes |
@Override public void visitMethodDef(JCTree.JCMethodDecl method) { if ((method.mods.flags & Flags.GENERATEDCONSTR) != 0) { // If this is the constructor for an anonymous inner class, refrain from checking the // compiler-generated method signature. Don't skip scanning the method body though, there // might have been an anonymous initializer which still needs to be checked. scan(method.body); } else { super.visitMethodDef(method); } }
Example 11
Source File: JavaPluginUtils.java From netbeans with Apache License 2.0 | 5 votes |
static boolean isSynthetic(CompilationInfo info, CompilationUnitTree cut, Tree leaf) throws NullPointerException { JCTree tree = (JCTree) leaf; if (tree.pos == (-1)) return true; if (leaf.getKind() == Kind.METHOD) { //check for synthetic constructor: return (((JCTree.JCMethodDecl)leaf).mods.flags & Flags.GENERATEDCONSTR) != 0L; } //check for synthetic superconstructor call: if (leaf.getKind() == Kind.EXPRESSION_STATEMENT) { ExpressionStatementTree est = (ExpressionStatementTree) leaf; if (est.getExpression().getKind() == Kind.METHOD_INVOCATION) { MethodInvocationTree mit = (MethodInvocationTree) est.getExpression(); if (mit.getMethodSelect().getKind() == Kind.IDENTIFIER) { IdentifierTree it = (IdentifierTree) mit.getMethodSelect(); if ("super".equals(it.getName().toString())) { SourcePositions sp = info.getTrees().getSourcePositions(); return sp.getEndPosition(cut, leaf) == (-1); } } } } return false; }
Example 12
Source File: Utilities.java From netbeans with Apache License 2.0 | 5 votes |
private static boolean isSynthetic(CompilationUnitTree cut, Tree leaf) throws NullPointerException { JCTree tree = (JCTree) leaf; if (tree.pos == (-1)) return true; if (leaf.getKind() == Kind.METHOD) { //check for synthetic constructor: return (((JCMethodDecl)leaf).mods.flags & Flags.GENERATEDCONSTR) != 0L; } //check for synthetic superconstructor call: if (cut != null && leaf.getKind() == Kind.EXPRESSION_STATEMENT) { ExpressionStatementTree est = (ExpressionStatementTree) leaf; if (est.getExpression().getKind() == Kind.METHOD_INVOCATION) { MethodInvocationTree mit = (MethodInvocationTree) est.getExpression(); if (mit.getMethodSelect().getKind() == Kind.IDENTIFIER) { IdentifierTree it = (IdentifierTree) mit.getMethodSelect(); if ("super".equals(it.getName().toString())) { return ((JCCompilationUnit) cut).endPositions.getEndPos(tree) == (-1); } } } } return false; }
Example 13
Source File: TreeUtilities.java From netbeans with Apache License 2.0 | 5 votes |
boolean isSynthetic(CompilationUnitTree cut, Tree leaf) throws NullPointerException { JCTree tree = (JCTree) leaf; if (tree.pos == (-1)) return true; if (leaf.getKind() == Kind.METHOD) { //check for synthetic constructor: return (((JCMethodDecl)leaf).mods.flags & Flags.GENERATEDCONSTR) != 0L; } //check for synthetic superconstructor call: if (leaf.getKind() == Kind.EXPRESSION_STATEMENT) { ExpressionStatementTree est = (ExpressionStatementTree) leaf; if (est.getExpression().getKind() == Kind.METHOD_INVOCATION) { MethodInvocationTree mit = (MethodInvocationTree) est.getExpression(); if (mit.getMethodSelect().getKind() == Kind.IDENTIFIER) { IdentifierTree it = (IdentifierTree) mit.getMethodSelect(); if ("super".equals(it.getName().toString())) { SourcePositions sp = info.getTrees().getSourcePositions(); return sp.getEndPosition(cut, leaf) == (-1); } } } } return false; }
Example 14
Source File: JavacASTVisitor.java From EasyMPermission with MIT License | 5 votes |
@Override public void visitMethod(JavacNode node, JCMethodDecl method) { final String type; if (method.name.contentEquals("<init>")) { if ((method.mods.flags & Flags.GENERATEDCONSTR) != 0) { type = "DEFAULTCONSTRUCTOR"; } else type = "CONSTRUCTOR"; } else type = "METHOD"; print("<%s %s> returns: %s", type, method.name, method.restype); indent++; if (printContent) { if (method.body == null) print("(ABSTRACT)"); else print("%s", method.body); disablePrinting++; } }
Example 15
Source File: TreeFinder.java From annotation-tools with MIT License | 5 votes |
/** * Returns the start position of the method's name. In particular, * works properly for constructors, for which the name field in the * AST is always "<init>" instead of the name from the source. * * @param node AST node of method declaration * @return position of method name (from {@link JCMethodDecl#sym}) in source */ private int findMethodName(JCMethodDecl node) { String sym = node.sym.toString(); String name = sym.substring(0, sym.indexOf('(')); JCModifiers mods = node.getModifiers(); JCBlock body = node.body; if ((mods.flags & Flags.GENERATEDCONSTR) != 0) { return Position.NOPOS; } int nodeStart = node.getStartPosition(); int nodeEnd = node.getEndPosition(tree.endPositions); int nodeLength = nodeEnd - nodeStart; int modsLength = mods.getEndPosition(tree.endPositions) - mods.getStartPosition(); // can't trust string length! int bodyLength = body == null ? 1 : body.getEndPosition(tree.endPositions) - body.getStartPosition(); int start = nodeStart + modsLength; int end = nodeStart + nodeLength - bodyLength; int angle = name.lastIndexOf('>'); // check for type params if (angle >= 0) { name = name.substring(angle + 1); } try { CharSequence s = tree.getSourceFile().getCharContent(true); String regex = "\\b" + Pattern.quote(name) + "\\b"; // sufficient? Pattern pat = Pattern.compile(regex, Pattern.MULTILINE); Matcher mat = pat.matcher(s).region(start, end); return mat.find() ? mat.start() : Position.NOPOS; } catch (IOException e) { throw new RuntimeException(e); } }
Example 16
Source File: VanillaPartialReparser.java From netbeans with Apache License 2.0 | 5 votes |
public BlockTree reattrMethodBody(Context context, Scope scope, MethodTree methodToReparse, BlockTree block) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { Attr attr = Attr.instance(context); // assert ((JCTree.JCMethodDecl)methodToReparse).localEnv != null; JCTree.JCMethodDecl tree = (JCTree.JCMethodDecl) methodToReparse; final Names names = Names.instance(context); final Symtab syms = Symtab.instance(context); final TypeEnter typeEnter = TypeEnter.instance(context); final Log log = Log.instance(context); final TreeMaker make = TreeMaker.instance(context); final Env<AttrContext> env = ((JavacScope) scope).getEnv();//this is a copy anyway... final Symbol.ClassSymbol owner = env.enclClass.sym; if (tree.name == names.init && !owner.type.isErroneous() && owner.type != syms.objectType) { JCTree.JCBlock body = tree.body; if (body.stats.isEmpty() || !TreeInfo.isSelfCall(body.stats.head)) { body.stats = body.stats. prepend(make.at(body.pos).Exec(make.Apply(com.sun.tools.javac.util.List.nil(), make.Ident(names._super), com.sun.tools.javac.util.List.nil()))); } else if ((env.enclClass.sym.flags() & Flags.ENUM) != 0 && (tree.mods.flags & Flags.GENERATEDCONSTR) == 0 && TreeInfo.isSuperCall(body.stats.head)) { // enum constructors are not allowed to call super // directly, so make sure there aren't any super calls // in enum constructors, except in the compiler // generated one. log.error(tree.body.stats.head.pos(), new JCDiagnostic.Error("compiler", "call.to.super.not.allowed.in.enum.ctor", env.enclClass.sym)); } } attr.attribStat((JCTree.JCBlock)block, env); return block; }
Example 17
Source File: JavacElements.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override @DefinedBy(Api.LANGUAGE_MODEL) public Origin getOrigin(Element e) { Symbol sym = cast(Symbol.class, e); if ((sym.flags() & Flags.GENERATEDCONSTR) != 0) return Origin.MANDATED; //TypeElement.getEnclosedElements does not return synthetic elements, //and most synthetic elements are not read from the classfile anyway: return Origin.EXPLICIT; }
Example 18
Source File: ResolveHarness.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override void process(Diagnostic<? extends JavaFileObject> diagnostic) { Symbol methodSym = (Symbol)methodSym(diagnostic); if ((methodSym.flags() & Flags.GENERATEDCONSTR) != 0) { //skip resolution of default constructor (put there by javac) return; } Candidate c = getCandidateAtPos(methodSym, asJCDiagnostic(diagnostic).getLineNumber(), asJCDiagnostic(diagnostic).getColumnNumber()); if (c == null) { return; //nothing to check } if (c.applicable().length == 0 && c.mostSpecific()) { error("Inapplicable method cannot be most specific " + methodSym); } if (isApplicable(diagnostic) != Arrays.asList(c.applicable()).contains(phase)) { error("Invalid candidate's applicability " + methodSym); } if (success) { for (Phase p : c.applicable()) { if (phase.ordinal() < p.ordinal()) { error("Invalid phase " + p + " on method " + methodSym); } } } if (Arrays.asList(c.applicable()).contains(phase)) { //applicable if (c.mostSpecific() != mostSpecific) { error("Invalid most specific value for method " + methodSym + " " + new ElementKey(methodSym).key); } MethodType mtype = getSig(diagnostic); if (mtype != null) { checkSig(c, methodSym, mtype); } } }
Example 19
Source File: ResolveHarness.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Override void process(Diagnostic<? extends JavaFileObject> diagnostic) { Symbol methodSym = (Symbol)methodSym(diagnostic); if ((methodSym.flags() & Flags.GENERATEDCONSTR) != 0) { //skip resolution of default constructor (put there by javac) return; } Candidate c = getCandidateAtPos(methodSym, asJCDiagnostic(diagnostic).getLineNumber(), asJCDiagnostic(diagnostic).getColumnNumber()); if (c == null) { return; //nothing to check } if (c.applicable().length == 0 && c.mostSpecific()) { error("Inapplicable method cannot be most specific " + methodSym); } if (isApplicable(diagnostic) != Arrays.asList(c.applicable()).contains(phase)) { error("Invalid candidate's applicability " + methodSym); } if (success) { for (Phase p : c.applicable()) { if (phase.ordinal() < p.ordinal()) { error("Invalid phase " + p + " on method " + methodSym); } } } if (Arrays.asList(c.applicable()).contains(phase)) { //applicable if (c.mostSpecific() != mostSpecific) { error("Invalid most specific value for method " + methodSym + " " + new ElementKey(methodSym).key); } MethodType mtype = getSig(diagnostic); if (mtype != null) { checkSig(c, methodSym, mtype); } } }
Example 20
Source File: ElementsService.java From netbeans with Apache License 2.0 | 4 votes |
public boolean isSynthetic(Element e) { return (((Symbol) e).flags() & Flags.SYNTHETIC) != 0 || (((Symbol) e).flags() & Flags.GENERATEDCONSTR) != 0; }