com.sun.source.tree.MethodInvocationTree Java Examples
The following examples show how to use
com.sun.source.tree.MethodInvocationTree.
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: UncaughtException.java From netbeans with Apache License 2.0 | 6 votes |
/** * Detects if we are parameter of this() or super() call * @return true if yes */ private boolean isThisParameter(TreePath path) { //anonymous class must not be on the path to top while(!TreeUtilities.CLASS_TREE_KINDS.contains(path.getLeaf().getKind()) && path.getLeaf().getKind() != Kind.COMPILATION_UNIT) { if (path.getParentPath().getLeaf().getKind() == Kind.METHOD_INVOCATION) { MethodInvocationTree mi = (MethodInvocationTree) path.getParentPath().getLeaf(); if(mi.getMethodSelect().getKind() == Kind.IDENTIFIER) { String id = ((IdentifierTree) mi.getMethodSelect()).getName().toString(); if ("super".equals(id) || "this".equals(id)) return true; } } path = path.getParentPath(); } return false; }
Example #2
Source File: JavaInputAstVisitor.java From google-java-format with Apache License 2.0 | 6 votes |
private void dotExpressionUpToArgs(ExpressionTree expression, Optional<BreakTag> tyargTag) { expression = getArrayBase(expression); switch (expression.getKind()) { case MEMBER_SELECT: MemberSelectTree fieldAccess = (MemberSelectTree) expression; visit(fieldAccess.getIdentifier()); break; case METHOD_INVOCATION: MethodInvocationTree methodInvocation = (MethodInvocationTree) expression; if (!methodInvocation.getTypeArguments().isEmpty()) { builder.open(plusFour); addTypeArguments(methodInvocation.getTypeArguments(), ZERO); // TODO(jdd): Should indent the name -4. builder.breakOp(Doc.FillMode.UNIFIED, "", ZERO, tyargTag); builder.close(); } visit(getMethodName(methodInvocation)); break; case IDENTIFIER: visit(((IdentifierTree) expression).getName()); break; default: scan(expression, null); break; } }
Example #3
Source File: LoggerStringConcat.java From netbeans with Apache License 2.0 | 6 votes |
@Override protected void performRewrite(TransformationContext ctx) { WorkingCopy wc = ctx.getWorkingCopy(); TreePath invocation = ctx.getPath(); TreePath message = FixImpl.this.message.resolve(wc); MethodInvocationTree mit = (MethodInvocationTree) invocation.getLeaf(); ExpressionTree level = null; if (logMethodName != null) { String logMethodNameUpper = logMethodName.toUpperCase(); VariableElement c = findConstant(wc, logMethodNameUpper); level = wc.getTreeMaker().QualIdent(c); } else { level = mit.getArguments().get(0); } rewrite(wc, level, mit, message); }
Example #4
Source File: TypeUtilitiesTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testTypeName() throws Exception { FileObject root = FileUtil.createMemoryFileSystem().getRoot(); FileObject src = root.createData("Test.java"); TestUtilities.copyStringToFile(src, "package test; public class Test { { get().run(); } private <Z extends Exception&Runnable> Z get() { return null; } }"); JavaSource js = JavaSource.create(ClasspathInfo.create(ClassPathSupport.createClassPath(SourceUtilsTestUtil.getBootClassPath().toArray(new URL[0])), ClassPathSupport.createClassPath(new URL[0]), ClassPathSupport.createClassPath(new URL[0])), src); js.runUserActionTask(new Task<CompilationController>() { public void run(CompilationController info) throws IOException { info.toPhase(JavaSource.Phase.RESOLVED); TypeElement context = info.getTopLevelElements().get(0); assertEquals("java.util.List<java.lang.String>[]", info.getTypeUtilities().getTypeName(info.getTreeUtilities().parseType("java.util.List<java.lang.String>[]", context), TypeUtilities.TypeNameOptions.PRINT_FQN)); assertEquals("List<String>[]", info.getTypeUtilities().getTypeName(info.getTreeUtilities().parseType("java.util.List<java.lang.String>[]", context))); assertEquals("java.util.List<java.lang.String>...", info.getTypeUtilities().getTypeName(info.getTreeUtilities().parseType("java.util.List<java.lang.String>[]", context), TypeUtilities.TypeNameOptions.PRINT_FQN, TypeUtilities.TypeNameOptions.PRINT_AS_VARARG)); assertEquals("List<String>...", info.getTypeUtilities().getTypeName(info.getTreeUtilities().parseType("java.util.List<java.lang.String>[]", context), TypeUtilities.TypeNameOptions.PRINT_AS_VARARG)); ClassTree clazz = (ClassTree) info.getCompilationUnit().getTypeDecls().get(0); BlockTree init = (BlockTree) clazz.getMembers().get(1); ExpressionStatementTree var = (ExpressionStatementTree) init.getStatements().get(0); ExpressionTree getInvocation = ((MemberSelectTree) ((MethodInvocationTree) var.getExpression()).getMethodSelect()).getExpression(); TypeMirror intersectionType = info.getTrees().getTypeMirror(info.getTrees().getPath(info.getCompilationUnit(), getInvocation)); assertEquals("Exception & Runnable", info.getTypeUtilities().getTypeName(intersectionType)); } }, true); }
Example #5
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 #6
Source File: ResourceStringFoldProvider.java From netbeans with Apache License 2.0 | 6 votes |
private String getBundleName(MethodInvocationTree n, int index, String bfn) { if (n.getArguments().size() <= index) { return null; } ExpressionTree t = n.getArguments().get(index); // recognize just string literals + .class references if (t.getKind() == Tree.Kind.STRING_LITERAL) { Object o = ((LiteralTree)t).getValue(); return o == null ? null : o.toString(); } else if (t.getKind() == Tree.Kind.MEMBER_SELECT) { MemberSelectTree mst = (MemberSelectTree)t; if (!mst.getIdentifier().contentEquals("class")) { return null; } return bundleFileFromClass(new TreePath(getCurrentPath(), mst.getExpression()), bfn); } 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: JavaInputAstVisitor.java From javaide with GNU General Public License v3.0 | 6 votes |
private void dotExpressionUpToArgs(ExpressionTree expression, Optional<BreakTag> tyargTag) { expression = getArrayBase(expression); switch (expression.getKind()) { case MEMBER_SELECT: MemberSelectTree fieldAccess = (MemberSelectTree) expression; visit(fieldAccess.getIdentifier()); break; case METHOD_INVOCATION: MethodInvocationTree methodInvocation = (MethodInvocationTree) expression; if (!methodInvocation.getTypeArguments().isEmpty()) { builder.open(plusFour); addTypeArguments(methodInvocation.getTypeArguments(), ZERO); // TODO(jdd): Should indent the name -4. builder.breakOp(Doc.FillMode.UNIFIED, "", ZERO, tyargTag); builder.close(); } visit(getMethodName(methodInvocation)); break; case IDENTIFIER: visit(((IdentifierTree) expression).getName()); break; default: scan(expression, null); break; } }
Example #9
Source File: Tiny.java From netbeans with Apache License 2.0 | 6 votes |
@Override protected void performRewrite(JavaFix.TransformationContext ctx) throws Exception { Tree t = ctx.getPath().getLeaf(); if (t.getKind() != Tree.Kind.METHOD_INVOCATION) { return; } MethodInvocationTree mi = (MethodInvocationTree)t; if (mi.getMethodSelect().getKind() != Tree.Kind.MEMBER_SELECT) { return; } MemberSelectTree selector = ((MemberSelectTree)mi.getMethodSelect()); TreeMaker maker = ctx.getWorkingCopy().getTreeMaker(); ExpressionTree ms = maker.MemberSelect(maker.QualIdent("java.util.Arrays"), deep ? "deepHashCode" : "hashCode"); // NOI18N Tree nue = maker.MethodInvocation( Collections.<ExpressionTree>emptyList(), ms, Collections.singletonList(selector.getExpression()) ); ctx.getWorkingCopy().rewrite(t, nue); }
Example #10
Source File: XPFlagCleaner.java From piranha with Apache License 2.0 | 6 votes |
private API getXPAPI(ExpressionTree et) { et = ASTHelpers.stripParentheses(et); Kind k = et.getKind(); if (k.equals(Tree.Kind.METHOD_INVOCATION)) { MethodInvocationTree mit = (MethodInvocationTree) et; if (!mit.getMethodSelect().getKind().equals(Kind.MEMBER_SELECT)) { return API.UNKNOWN; } MemberSelectTree mst = (MemberSelectTree) mit.getMethodSelect(); String methodName = mst.getIdentifier().toString(); if (!disabled && configMethodProperties.containsKey(methodName)) { return getXPAPI(mit, configMethodProperties.get(methodName)); } } return API.UNKNOWN; }
Example #11
Source File: ProtobufCheck.java From startup-os with Apache License 2.0 | 6 votes |
@Override public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { // check whether it's a newBuilder() method of any protobuf-generated message class if (NEW_BUILDER.matches(tree, state)) { // find next method invocation in chain (on obj.method1().method2() it would return method2) ExpressionTree methodInvocation = ASTHelpers.findEnclosingNode(state.getPath(), MethodInvocationTree.class); // next invoked message is a build() method of any protobuf-generated message builder class if (BUILDER_BUILD.matches(methodInvocation, state)) { // select "newBuilder().build()" part of tree int start = state.getEndPosition(tree) - "newBuilder()".length(); int end = state.getEndPosition(methodInvocation); // suggest to replace it with "getDefaultInstance()" return describeMatch( methodInvocation, SuggestedFix.builder().replace(start, end, "getDefaultInstance()").build()); } } return NO_MATCH; }
Example #12
Source File: TreeUtilitiesTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testForEachLoop() throws Exception { prepareTest("Test", "package test; public class Test { public Test(java.util.List<String> ll) { for (String s : ll.subList(0, ll.size()) ) { } } }"); TreePath tp1 = info.getTreeUtilities().pathFor(122 - 30); assertEquals(Kind.IDENTIFIER, tp1.getLeaf().getKind()); assertEquals("ll", ((IdentifierTree) tp1.getLeaf()).getName().toString()); TreePath tp2 = info.getTreeUtilities().pathFor(127 - 30); assertEquals(Kind.MEMBER_SELECT, tp2.getLeaf().getKind()); assertEquals("subList", ((MemberSelectTree) tp2.getLeaf()).getIdentifier().toString()); TreePath tp3 = info.getTreeUtilities().pathFor(140 - 30); assertEquals(Kind.MEMBER_SELECT, tp3.getLeaf().getKind()); assertEquals("size", ((MemberSelectTree) tp3.getLeaf()).getIdentifier().toString()); TreePath tp4 = info.getTreeUtilities().pathFor(146 - 30); assertEquals(Kind.METHOD_INVOCATION, tp4.getLeaf().getKind()); assertEquals("subList", ((MemberSelectTree) ((MethodInvocationTree) tp4.getLeaf()).getMethodSelect()).getIdentifier().toString()); }
Example #13
Source File: MethodArgumentsScanner.java From netbeans with Apache License 2.0 | 6 votes |
@Override public MethodArgument[] visitMethodInvocation(MethodInvocationTree node, Object p) { if (!methodInvocation || offset != positions.getEndPosition(tree, node.getMethodSelect())) { return super.visitMethodInvocation(node, p); /*MethodArgument[] r = scan(node.getTypeArguments(), p); r = scanAndReduce(node.getMethodSelect(), p, r); r = scanAndReduce(node.getArguments(), p, r); return r;*/ } List<? extends ExpressionTree> args = node.getArguments(); List<? extends Tree> argTypes = node.getTypeArguments(); /*int n = args.size(); arguments = new MethodArgument[n]; for (int i = 0; i < n; i++) { arguments[i] = new MethodArgument(args.get(i).toString(), argTypes.get(i).toString()); } return arguments;*/ arguments = composeArguments(args, argTypes); return arguments; }
Example #14
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 #15
Source File: RestrictiveAnnotationHandler.java From NullAway with MIT License | 6 votes |
@Override public boolean onOverrideMayBeNullExpr( NullAway analysis, ExpressionTree expr, VisitorState state, boolean exprMayBeNull) { if (expr.getKind().equals(Tree.Kind.METHOD_INVOCATION)) { Symbol.MethodSymbol methodSymbol = ASTHelpers.getSymbol((MethodInvocationTree) expr); if (NullabilityUtil.isUnannotated(methodSymbol, config)) { // with the generated-as-unannotated option enabled, we want to ignore // annotations in generated code if (config.treatGeneratedAsUnannotated() && NullabilityUtil.isGenerated(methodSymbol)) { return exprMayBeNull; } else { return Nullness.hasNullableAnnotation(methodSymbol, config) || exprMayBeNull; } } else { return exprMayBeNull; } } return exprMayBeNull; }
Example #16
Source File: CreateElementUtilities.java From netbeans with Apache License 2.0 | 6 votes |
private static List<? extends TypeMirror> computeMethodInvocation(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) { MethodInvocationTree nat = (MethodInvocationTree) parent.getLeaf(); boolean errorInRealArguments = false; for (Tree param : nat.getArguments()) { errorInRealArguments |= param == error; } if (errorInRealArguments) { List<TypeMirror> proposedTypes = new ArrayList<TypeMirror>(); int[] proposedIndex = new int[1]; List<ExecutableElement> ee = fuzzyResolveMethodInvocation(info, parent, proposedTypes, proposedIndex); if (ee.isEmpty()) { //cannot be resolved return null; } types.add(ElementKind.PARAMETER); types.add(ElementKind.LOCAL_VARIABLE); types.add(ElementKind.FIELD); return proposedTypes; } return null; }
Example #17
Source File: TooStrongCast.java From netbeans with Apache License 2.0 | 6 votes |
/** * Checks whether a method or constructor call would become ambiguous if the parameter type changes. * * @param info compilation context * @param parentExec path to the constructor or method invocation * @param argIndex * @param casteeType * @return */ private static boolean checkAmbiguous(CompilationInfo info, final TreePath parentExec, int argIndex, TypeMirror casteeType, TreePath realArgTree) { CharSequence altType = info.getTypeUtilities().getTypeName(casteeType, TypeUtilities.TypeNameOptions.PRINT_FQN); String prefix = null; if (casteeType != null && !(casteeType.getKind() == TypeKind.NULL || casteeType.getKind() == TypeKind.INTERSECTION)) { prefix = "(" + altType + ")"; // NOI18N } Tree leaf = parentExec.getLeaf(); List<? extends Tree> arguments; if (leaf instanceof MethodInvocationTree) { MethodInvocationTree mi = (MethodInvocationTree)leaf; arguments = mi.getArguments(); } else { arguments = ((NewClassTree)leaf).getArguments(); } Tree argTree = arguments.get(argIndex); TreePath argPath = new TreePath(parentExec, argTree); return !Utilities.checkAlternativeInvocation(info, parentExec, argPath, realArgTree, prefix); }
Example #18
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 #19
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 #20
Source File: UMethodInvocation.java From Refaster with Apache License 2.0 | 5 votes |
@Override @Nullable public Unifier visitMethodInvocation( MethodInvocationTree methodInvocation, @Nullable Unifier unifier) { unifier = getMethodSelect().unify(methodInvocation.getMethodSelect(), unifier); return Unifier.unifyList( unifier, getArguments(), methodInvocation.getArguments(), allowVarargs()); }
Example #21
Source File: TreeNode.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Void visitMethodInvocation(MethodInvocationTree tree, List<Node> d) { List<Node> below = new ArrayList<Node>(); addCorrespondingElement(below); addCorrespondingType(below); addCorrespondingComments(below); super.visitMethodInvocation(tree, below); d.add(new TreeNode(info, getCurrentPath(), below)); return null; }
Example #22
Source File: MethodCallScanner.java From annotation-tools with MIT License | 5 votes |
@Override public Void visitMethodInvocation(MethodInvocationTree node, Void p) { if (!done) { index++; } if (tree == node) { done = true; } return super.visitMethodInvocation(node, p); }
Example #23
Source File: ToStringGenerator.java From netbeans with Apache License 2.0 | 5 votes |
private static MethodInvocationTree createAppendInvocation(TreeMaker make, ExpressionTree expression, List<? extends ExpressionTree> arguments){ return make.MethodInvocation( // sb.append() Collections.emptyList(), make.MemberSelect(expression, "append"), // NOI18N arguments ); }
Example #24
Source File: ConvertToLambdaPreconditionChecker.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Tree visitMethodInvocation(MethodInvocationTree methodInvocationTree, Trees trees) { String nameSuggestion = org.netbeans.modules.editor.java.Utilities.varNameSuggestion(methodInvocationTree.getMethodSelect()); //check for recursion if (nameSuggestion != null && lambdaMethodTree.getName().contentEquals(nameSuggestion)) { ExpressionTree selector = getSelector(methodInvocationTree); if (selector == null || (org.netbeans.modules.editor.java.Utilities.varNameSuggestion(selector) != null && org.netbeans.modules.editor.java.Utilities.varNameSuggestion(selector).contentEquals("this"))) { foundRecursiveCall = true; } } if (singleStatementLambdaMethodBody == getCurrentPath().getParentPath().getParentPath().getLeaf()) { Tree parent = getCurrentPath().getParentPath().getLeaf(); if (parent.getKind() == Tree.Kind.EXPRESSION_STATEMENT || parent.getKind() == Tree.Kind.RETURN) { boolean check = true; Iterator<? extends VariableTree> paramsIt = lambdaMethodTree.getParameters().iterator(); ExpressionTree methodSelect = methodInvocationTree.getMethodSelect(); if (paramsIt.hasNext() && methodSelect.getKind() == Tree.Kind.MEMBER_SELECT) { ExpressionTree expr = ((MemberSelectTree) methodSelect).getExpression(); if (expr.getKind() == Tree.Kind.IDENTIFIER) { if (!((IdentifierTree)expr).getName().contentEquals(paramsIt.next().getName())) { paramsIt = lambdaMethodTree.getParameters().iterator(); } } } Iterator<? extends ExpressionTree> argsIt = methodInvocationTree.getArguments().iterator(); while (check && argsIt.hasNext() && paramsIt.hasNext()) { ExpressionTree arg = argsIt.next(); if (arg.getKind() != Tree.Kind.IDENTIFIER || !paramsIt.next().getName().contentEquals(((IdentifierTree)arg).getName())) { check = false; } } if (check && !paramsIt.hasNext() && !argsIt.hasNext()) { foundMemberReferenceCandidate = true; } } } return super.visitMethodInvocation(methodInvocationTree, trees); }
Example #25
Source File: SemanticHighlighterBase.java From netbeans with Apache License 2.0 | 5 votes |
private void addParameterInlineHint(Tree tree) { TreePath pp = getCurrentPath().getParentPath(); Tree leaf = pp.getLeaf(); if (leaf != null && (leaf.getKind() == Kind.METHOD_INVOCATION || leaf.getKind() == Kind.NEW_CLASS)) { int pos = -1; if (leaf.getKind() == Kind.METHOD_INVOCATION) { pos = MethodInvocationTree.class.cast(leaf).getArguments().indexOf(tree); } else if (leaf.getKind() == Kind.NEW_CLASS) { pos = NewClassTree.class.cast(leaf).getArguments().indexOf(tree); } if (pos != (-1)) { Element invoked = info.getTrees().getElement(pp); if (invoked != null && (invoked.getKind() == ElementKind.METHOD || invoked.getKind() == ElementKind.CONSTRUCTOR)) { long start = sourcePositions.getStartPosition(info.getCompilationUnit(), tree); long end = start + 1; ExecutableElement invokedMethod = (ExecutableElement) invoked; pos = Math.min(pos, invokedMethod.getParameters().size() - 1); if (pos != (-1)) { boolean shouldBeAdded = true; if (tree.getKind() == Kind.IDENTIFIER && invokedMethod.getParameters().get(pos).getSimpleName().equals( IdentifierTree.class.cast(tree).getName())) { shouldBeAdded = false; } if (shouldBeAdded) { preText.put(new int[] {(int) start, (int) end}, invokedMethod.getParameters().get(pos).getSimpleName() + ":"); } } } } } }
Example #26
Source File: AbstractTestGenerator.java From netbeans with Apache License 2.0 | 5 votes |
private StatementTree generateEJBCleanUpCode(TreeMaker maker) { IdentifierTree container = maker.Identifier(CONTAINER_VAR_NAME); MethodInvocationTree invocation = maker.MethodInvocation( Collections.<ExpressionTree>emptyList(), maker.MemberSelect(container, "close"), // NOI18N Collections.<ExpressionTree>emptyList() ); return maker.ExpressionStatement(invocation); }
Example #27
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 #28
Source File: BaseNoOpHandler.java From NullAway with MIT License | 5 votes |
@Override public void onMatchMethodInvocation( NullAway analysis, MethodInvocationTree tree, VisitorState state, Symbol.MethodSymbol methodSymbol) { // NoOp }
Example #29
Source File: JavaFixUtilities.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Number visitMethodInvocation(MethodInvocationTree node, Void p) { List<? extends ExpressionTree> typeArgs = (List<? extends ExpressionTree>) resolveMultiParameters(node.getTypeArguments()); List<? extends ExpressionTree> args = resolveMultiParameters(node.getArguments()); MethodInvocationTree nue = make.MethodInvocation(typeArgs, node.getMethodSelect(), args); rewrite(node, nue); return super.visitMethodInvocation(nue, p); }
Example #30
Source File: Trees.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * Returns the simple name of a (possibly qualified) method invocation expression. */ static Name getMethodName(MethodInvocationTree methodInvocation) { ExpressionTree select = methodInvocation.getMethodSelect(); return select instanceof MemberSelectTree ? ((MemberSelectTree) select).getIdentifier() : ((IdentifierTree) select).getName(); }