com.sun.tools.javac.tree.JCTree.JCMethodInvocation Java Examples
The following examples show how to use
com.sun.tools.javac.tree.JCTree.JCMethodInvocation.
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: PostFlowAnalysis.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void visitApply(JCMethodInvocation tree) { boolean prevCheckThis = checkThis; try { Symbol meth = TreeInfo.symbol(tree.meth); Name methName = TreeInfo.name(tree.meth); if (meth != null && meth.name == names.init) { Symbol c = meth.owner; if (c.hasOuterInstance()) { checkThis = false; if (tree.meth.getTag() != JCTree.Tag.SELECT && (c.isLocal() || methName == names._this)) { checkThis(tree.meth.pos(), c.type.getEnclosingType().tsym); } } } super.visitApply(tree); } finally { checkThis = prevCheckThis; } }
Example #2
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 #3
Source File: TestInvokeDynamic.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public Void visitMethodInvocation(MethodInvocationTree node, Void p) { super.visitMethodInvocation(node, p); JCMethodInvocation apply = (JCMethodInvocation)node; JCIdent ident = (JCIdent)apply.meth; Symbol oldSym = ident.sym; if (!oldSym.isConstructor()) { Object[] staticArgs = new Object[arity.arity]; for (int i = 0; i < arity.arity ; i++) { staticArgs[i] = saks[i].getValue(syms, names, types); } ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name, oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs); } return null; }
Example #4
Source File: TestInvokeDynamic.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public Void visitMethodInvocation(MethodInvocationTree node, Void p) { super.visitMethodInvocation(node, p); JCMethodInvocation apply = (JCMethodInvocation)node; JCIdent ident = (JCIdent)apply.meth; Symbol oldSym = ident.sym; if (!oldSym.isConstructor()) { Object[] staticArgs = new Object[arity.arity]; for (int i = 0; i < arity.arity ; i++) { staticArgs[i] = saks[i].getValue(syms, names, types); } ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name, oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs); } return null; }
Example #5
Source File: TestInvokeDynamic.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override public Void visitMethodInvocation(MethodInvocationTree node, Void p) { super.visitMethodInvocation(node, p); JCMethodInvocation apply = (JCMethodInvocation)node; JCIdent ident = (JCIdent)apply.meth; Symbol oldSym = ident.sym; if (!oldSym.isConstructor()) { Object[] staticArgs = new Object[arity.arity]; for (int i = 0; i < arity.arity ; i++) { staticArgs[i] = saks[i].getValue(syms, names, types); } ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name, oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs); } return null; }
Example #6
Source File: TestInvokeDynamic.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Override public Void visitMethodInvocation(MethodInvocationTree node, Void p) { super.visitMethodInvocation(node, p); JCMethodInvocation apply = (JCMethodInvocation)node; JCIdent ident = (JCIdent)apply.meth; Symbol oldSym = ident.sym; if (!oldSym.isConstructor()) { Object[] staticArgs = new Object[arity.arity]; for (int i = 0; i < arity.arity ; i++) { staticArgs[i] = saks[i].getValue(syms, names, types); } ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name, oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs); } return null; }
Example #7
Source File: TestInvokeDynamic.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override public Void visitMethodInvocation(MethodInvocationTree node, Void p) { super.visitMethodInvocation(node, p); JCMethodInvocation apply = (JCMethodInvocation)node; JCIdent ident = (JCIdent)apply.meth; Symbol oldSym = ident.sym; if (!oldSym.isConstructor()) { Object[] staticArgs = new Object[arity.arity]; for (int i = 0; i < arity.arity ; i++) { staticArgs[i] = saks[i].getValue(syms, names, types); } ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name, oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs); } return null; }
Example #8
Source File: TestInvokeDynamic.java From hottub with GNU General Public License v2.0 | 6 votes |
@Override public Void visitMethodInvocation(MethodInvocationTree node, Void p) { super.visitMethodInvocation(node, p); JCMethodInvocation apply = (JCMethodInvocation)node; JCIdent ident = (JCIdent)apply.meth; Symbol oldSym = ident.sym; if (!oldSym.isConstructor()) { Object[] staticArgs = new Object[arity.arity]; for (int i = 0; i < arity.arity ; i++) { staticArgs[i] = saks[i].getValue(syms, names, types); } ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name, oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs); } return null; }
Example #9
Source File: TestInvokeDynamic.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
@Override public Void visitMethodInvocation(MethodInvocationTree node, Void p) { super.visitMethodInvocation(node, p); JCMethodInvocation apply = (JCMethodInvocation)node; JCIdent ident = (JCIdent)apply.meth; Symbol oldSym = ident.sym; if (!oldSym.isConstructor()) { Object[] staticArgs = new Object[arity.arity]; for (int i = 0; i < arity.arity ; i++) { staticArgs[i] = saks[i].getValue(syms, names, types); } ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name, oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs); } return null; }
Example #10
Source File: TestInvokeDynamic.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
@Override public Void visitMethodInvocation(MethodInvocationTree node, Void p) { super.visitMethodInvocation(node, p); JCMethodInvocation apply = (JCMethodInvocation)node; JCIdent ident = (JCIdent)apply.meth; Symbol oldSym = ident.sym; if (!oldSym.isConstructor()) { Object[] staticArgs = new Object[arity.arity]; for (int i = 0; i < arity.arity ; i++) { staticArgs[i] = saks[i].getValue(syms, names, types); } ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name, oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs); } return null; }
Example #11
Source File: PrettyCommentsPrinter.java From EasyMPermission with MIT License | 6 votes |
public void visitApply(JCMethodInvocation tree) { try { if (!tree.typeargs.isEmpty()) { if (SELECT.equals(treeTag(tree.meth))) { JCFieldAccess left = (JCFieldAccess)tree.meth; printExpr(left.selected); print(".<"); printExprs(tree.typeargs); print(">" + left.name); } else { print("<"); printExprs(tree.typeargs); print(">"); printExpr(tree.meth); } } else { printExpr(tree.meth); } print("("); printExprs(tree.args); print(")"); } catch (IOException e) { throw new UncheckedIOException(e); } }
Example #12
Source File: HandleLog.java From EasyMPermission with MIT License | 6 votes |
private static boolean createField(LoggingFramework framework, JavacNode typeNode, JCFieldAccess loggingType, JCTree source, String logFieldName, boolean useStatic, String loggerTopic) { JavacTreeMaker maker = typeNode.getTreeMaker(); // private static final <loggerType> log = <factoryMethod>(<parameter>); JCExpression loggerType = chainDotsString(typeNode, framework.getLoggerTypeName()); JCExpression factoryMethod = chainDotsString(typeNode, framework.getLoggerFactoryMethodName()); JCExpression loggerName; if (loggerTopic == null || loggerTopic.trim().length() == 0) { loggerName = framework.createFactoryParameter(typeNode, loggingType); } else { loggerName = maker.Literal(loggerTopic); } JCMethodInvocation factoryMethodCall = maker.Apply(List.<JCExpression>nil(), factoryMethod, List.<JCExpression>of(loggerName)); JCVariableDecl fieldDecl = recursiveSetGeneratedBy(maker.VarDef( maker.Modifiers(Flags.PRIVATE | Flags.FINAL | (useStatic ? Flags.STATIC : 0)), typeNode.toName(logFieldName), loggerType, factoryMethodCall), source, typeNode.getContext()); injectFieldAndMarkGenerated(typeNode, fieldDecl); return true; }
Example #13
Source File: JavacHandlerUtil.java From EasyMPermission with MIT License | 6 votes |
public static boolean isConstructorCall(final JCStatement statement) { if (!(statement instanceof JCExpressionStatement)) return false; JCExpression expr = ((JCExpressionStatement) statement).expr; if (!(expr instanceof JCMethodInvocation)) return false; JCExpression invocation = ((JCMethodInvocation) expr).meth; String name; if (invocation instanceof JCFieldAccess) { name = ((JCFieldAccess) invocation).name.toString(); } else if (invocation instanceof JCIdent) { name = ((JCIdent) invocation).name.toString(); } else { name = ""; } return "super".equals(name) || "this".equals(name); }
Example #14
Source File: TreePruner.java From bazel with Apache License 2.0 | 6 votes |
private static boolean delegatingConstructor(List<JCStatement> stats) { if (stats.isEmpty()) { return false; } JCStatement stat = stats.get(0); if (stat.getKind() != Kind.EXPRESSION_STATEMENT) { return false; } JCExpression expr = ((JCExpressionStatement) stat).getExpression(); if (expr.getKind() != Kind.METHOD_INVOCATION) { return false; } JCExpression method = ((JCMethodInvocation) expr).getMethodSelect(); Name name; switch (method.getKind()) { case IDENTIFIER: name = ((JCIdent) method).getName(); break; case MEMBER_SELECT: name = ((JCFieldAccess) method).getIdentifier(); break; default: return false; } return name.contentEquals("this") || name.contentEquals("super"); }
Example #15
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void visitApply(JCMethodInvocation tree) { List<ClassSymbol> previousNascentTypes = typesUnderConstruction; try { Name methName = TreeInfo.name(tree.meth); if (methName == names._this || methName == names._super) { typesUnderConstruction = typesUnderConstruction.prepend(currentClass()); } super.visitApply(tree); } finally { typesUnderConstruction = previousNascentTypes; } }
Example #16
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Generate an indy method call with given name, type and static bootstrap * arguments types */ private JCExpression makeIndyCall(DiagnosticPosition pos, Type site, Name bsmName, List<Object> staticArgs, MethodType indyType, List<JCExpression> indyArgs, Name methName) { int prevPos = make.pos; try { make.at(pos); List<Type> bsm_staticArgs = List.of(syms.methodHandleLookupType, syms.stringType, syms.methodTypeType).appendList(bsmStaticArgToTypes(staticArgs)); Symbol bsm = rs.resolveInternalMethod(pos, attrEnv, site, bsmName, bsm_staticArgs, List.nil()); DynamicMethodSymbol dynSym = new DynamicMethodSymbol(methName, syms.noSymbol, bsm.isStatic() ? ClassFile.REF_invokeStatic : ClassFile.REF_invokeVirtual, (MethodSymbol)bsm, indyType, staticArgs.toArray()); JCFieldAccess qualifier = make.Select(make.QualIdent(site.tsym), bsmName); qualifier.sym = dynSym; qualifier.type = indyType.getReturnType(); JCMethodInvocation proxyCall = make.Apply(List.nil(), qualifier, indyArgs); proxyCall.type = indyType.getReturnType(); return proxyCall; } finally { make.at(prevPos); } }
Example #17
Source File: CompilationUnitBuilder.java From j2cl with Apache License 2.0 | 5 votes |
/** * Returns a qualifier for a method invocation that doesn't have one, specifically, * instanceMethod() will return a resolved qualifier that may refer to "this" or to the enclosing * instances. A staticMethod() will return null. */ private static JCExpression getExplicitQualifier(JCMethodInvocation methodInvocation) { if (methodInvocation.getMethodSelect().getKind() != Kind.IDENTIFIER) { return getQualifier(methodInvocation.getMethodSelect()); } // No qualifier specified. MethodSymbol memberSymbol = getMemberSymbol(methodInvocation.getMethodSelect()); if (memberSymbol.isStatic()) { return null; } return getQualifier(methodInvocation.getMethodSelect()); }
Example #18
Source File: AssertCheckAnalyzer.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public void visitApply(JCMethodInvocation tree) { Symbol m = TreeInfo.symbolFor(tree); AssertOverloadKind ak = assertOverloadKind(m); if (ak != AssertOverloadKind.NONE && !m.name.contentEquals("error")) { JCExpression lastParam = tree.args.last(); if (isSimpleStringArg(lastParam) != ak.simpleArgExpected()) { messages.error(lastParam, ak.errKey); } } super.visitApply(tree); }
Example #19
Source File: ArgumentAttr.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public void visitApply(JCMethodInvocation that) { if (that.getTypeArguments().isEmpty()) { processArg(that, speculativeTree -> new ResolvedMethodType(that, env, speculativeTree)); } else { //not a poly expression, just call Attr setResult(that, attr.attribTree(that, env, attr.unknownExprInfo)); } }
Example #20
Source File: Analyzer.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override void process (JCMethodInvocation oldTree, JCMethodInvocation newTree, boolean hasErrors){ if (!hasErrors) { //exact match log.warning(oldTree, "method.redundant.typeargs"); } }
Example #21
Source File: TestBootstrapMethodsCount.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public Void visitMethodInvocation(MethodInvocationTree node, Void p) { super.visitMethodInvocation(node, p); JCMethodInvocation apply = (JCMethodInvocation)node; JCIdent ident = (JCIdent)apply.meth; Symbol oldSym = ident.sym; if (!oldSym.isConstructor()) { ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name, oldSym.owner, REF_invokeStatic, bsm, oldSym.type, new Object[0]); } return null; }
Example #22
Source File: PrettyCommentsPrinter.java From EasyMPermission with MIT License | 5 votes |
private boolean isNoArgsSuperCall(JCExpression expr) { if (!(expr instanceof JCMethodInvocation)) return false; JCMethodInvocation tree = (JCMethodInvocation) expr; if (!tree.typeargs.isEmpty() || !tree.args.isEmpty()) return false; if (!(tree.meth instanceof JCIdent)) return false; return ((JCIdent) tree.meth).name.toString().equals("super"); }
Example #23
Source File: ArgumentAttr.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void visitApply(JCMethodInvocation that) { if (that.getTypeArguments().isEmpty()) { processArg(that, speculativeTree -> new ResolvedMethodType(that, env, speculativeTree)); } else { //not a poly expression, just call Attr setResult(that, attr.attribTree(that, env, attr.unknownExprInfo)); } }
Example #24
Source File: JavacHandlerUtil.java From EasyMPermission with MIT License | 5 votes |
static JCExpression createFieldAccessor(JavacTreeMaker maker, JavacNode field, FieldAccess fieldAccess, JCExpression receiver) { boolean lookForGetter = lookForGetter(field, fieldAccess); GetterMethod getter = lookForGetter ? findGetter(field) : null; JCVariableDecl fieldDecl = (JCVariableDecl) field.get(); if (getter == null) { if (receiver == null) { if ((fieldDecl.mods.flags & Flags.STATIC) == 0) { receiver = maker.Ident(field.toName("this")); } else { JavacNode containerNode = field.up(); if (containerNode != null && containerNode.get() instanceof JCClassDecl) { JCClassDecl container = (JCClassDecl) field.up().get(); receiver = maker.Ident(container.name); } } } return receiver == null ? maker.Ident(fieldDecl.name) : maker.Select(receiver, fieldDecl.name); } if (receiver == null) receiver = maker.Ident(field.toName("this")); JCMethodInvocation call = maker.Apply(List.<JCExpression>nil(), maker.Select(receiver, getter.name), List.<JCExpression>nil()); return call; }
Example #25
Source File: HandleCleanup.java From EasyMPermission with MIT License | 5 votes |
public JCExpression preventNullAnalysis(JavacTreeMaker maker, JavacNode node, JCExpression expression) { if (LombokOptionsFactory.getDelombokOptions(node.getContext()).getFormatPreferences().danceAroundIdeChecks()) { JCMethodInvocation singletonList = maker.Apply(List.<JCExpression>nil(), chainDotsString(node, "java.util.Collections.singletonList"), List.of(expression)); JCMethodInvocation cleanedExpr = maker.Apply(List.<JCExpression>nil(), maker.Select(singletonList, node.toName("get")) , List.<JCExpression>of(maker.Literal(CTC_INT, 0))); return cleanedExpr; } else { return expression; } }
Example #26
Source File: HandleExtensionMethod.java From EasyMPermission with MIT License | 5 votes |
private void handleMethodCall(final JCMethodInvocation methodCall) { JavacNode methodCallNode = annotationNode.getAst().get(methodCall); if (methodCallNode == null) { // This should mean the node does not exist in the source at all. This is the case for generated nodes, such as implicit super() calls. return; } JavacNode surroundingType = upToTypeNode(methodCallNode); TypeSymbol surroundingTypeSymbol = ((JCClassDecl)surroundingType.get()).sym; JCExpression receiver = receiverOf(methodCall); String methodName = methodNameOf(methodCall); if ("this".equals(methodName) || "super".equals(methodName)) return; Type resolvedMethodCall = CLASS_AND_METHOD.resolveMember(methodCallNode, methodCall); if (resolvedMethodCall == null) return; if (!suppressBaseMethods && !(resolvedMethodCall instanceof ErrorType)) return; Type receiverType = CLASS_AND_METHOD.resolveMember(methodCallNode, receiver); if (receiverType == null) return; if (receiverType.tsym.toString().endsWith(receiver.toString())) return; Types types = Types.instance(annotationNode.getContext()); for (Extension extension : extensions) { TypeSymbol extensionProvider = extension.extensionProvider; if (surroundingTypeSymbol == extensionProvider) continue; for (MethodSymbol extensionMethod : extension.extensionMethods) { if (!methodName.equals(extensionMethod.name.toString())) continue; Type extensionMethodType = extensionMethod.type; if (!MethodType.class.isInstance(extensionMethodType) && !ForAll.class.isInstance(extensionMethodType)) continue; Type firstArgType = types.erasure(extensionMethodType.asMethodType().argtypes.get(0)); if (!types.isAssignable(receiverType, firstArgType)) continue; methodCall.args = methodCall.args.prepend(receiver); methodCall.meth = chainDotsString(annotationNode, extensionProvider.toString() + "." + methodName); return; } } }
Example #27
Source File: HandleExtensionMethod.java From EasyMPermission with MIT License | 5 votes |
private String methodNameOf(final JCMethodInvocation methodCall) { if (methodCall.meth instanceof JCIdent) { return ((JCIdent) methodCall.meth).name.toString(); } else { return ((JCFieldAccess) methodCall.meth).name.toString(); } }
Example #28
Source File: HandleExtensionMethod.java From EasyMPermission with MIT License | 5 votes |
private JCExpression receiverOf(final JCMethodInvocation methodCall) { if (methodCall.meth instanceof JCIdent) { return annotationNode.getTreeMaker().Ident(annotationNode.toName("this")); } else { return ((JCFieldAccess) methodCall.meth).selected; } }
Example #29
Source File: UMethodInvocation.java From Refaster with Apache License 2.0 | 5 votes |
@Override public JCMethodInvocation inline(Inliner inliner) throws CouldNotResolveImportException { return inliner.maker().Apply( com.sun.tools.javac.util.List.<JCExpression>nil(), getMethodSelect().inline(inliner), inliner.<JCExpression, UExpression>inlineList(getArguments())); }
Example #30
Source File: Lower.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** If tree refers to a superclass constructor call, * add all free variables of the superclass. */ public void visitApply(JCMethodInvocation tree) { if (TreeInfo.name(tree.meth) == names._super) { addFreeVars((ClassSymbol) TreeInfo.symbol(tree.meth).owner); } super.visitApply(tree); }