@Override public Void visitMemberSelect(MemberSelectTree node, Void unused) { checkForThis(node, node.getIdentifier(), thisClass, state); // Don't examine this.foo or MyClass.this.foo ExpressionTree left = node.getExpression(); if ((left instanceof IdentifierTree && ((IdentifierTree) left).getName().contentEquals("this")) || (left instanceof MemberSelectTree && ((MemberSelectTree) left).getIdentifier().contentEquals("this"))) { return null; } return super.visitMemberSelect(node, unused); }
int j = 0; for (Tree t : argTypes) { types[j++] = controller.getTrees().getTypeMirror(new TreePath(path, t)); Tree mid = mi.getMethodSelect(); path = new TreePath(path, mid); switch (mid.getKind()) { case MEMBER_SELECT: { ExpressionTree exp = ((MemberSelectTree) mid).getExpression(); toolTipData = getMatchingParams(controller, type, controller.getElementUtilities().getMembers(type, acceptor), ((MemberSelectTree) mid).getIdentifier().toString(), types, controller.getTypes()); break; final Trees trees = controller.getTrees(); final TypeElement enclClass = scope.getEnclosingClass(); final boolean isStatic = enclClass != null ? (tu.isStaticContext(scope) || (env.getPath().getLeaf().getKind() == Tree.Kind.BLOCK && ((BlockTree) env.getPath().getLeaf()).isStatic())) : false; ElementUtilities.ElementAcceptor acceptor = new ElementUtilities.ElementAcceptor() { @Override String name = ((IdentifierTree) mid).getName().toString(); if (SUPER_KEYWORD.equals(name) && enclClass != null) { TypeMirror superclass = enclClass.getSuperclass();
private static Matcher<IdentifierTree> identifierHasName(final String name) { return (item, state) -> item.getName().contentEquals(name); }
private static boolean isSuper(ExpressionTree tree) { return tree.getKind() == Kind.IDENTIFIER && ((IdentifierTree) tree).getName().contentEquals("super"); } }
boolean isThisAccess(Tree tree) { if (tree.getKind() == Kind.IDENTIFIER) { return true; } if (tree.getKind() != Kind.MEMBER_SELECT) { return false; } ExpressionTree selected = ((MemberSelectTree) tree).getExpression(); if (!(selected instanceof IdentifierTree)) { return false; } IdentifierTree ident = (IdentifierTree) selected; return ident.getName().contentEquals("this"); }
private void addSyntheticTrees(DiffContext diffContext, Tree node) { if (node == null) return ; if (((JCTree) node).pos == (-1)) { diffContext.syntheticTrees.add(node); return ; } if (node.getKind() == Kind.EXPRESSION_STATEMENT) { ExpressionTree est = ((ExpressionStatementTree) node).getExpression(); if (est.getKind() == Kind.METHOD_INVOCATION) { ExpressionTree select = ((MethodInvocationTree) est).getMethodSelect(); if (select.getKind() == Kind.IDENTIFIER && ((IdentifierTree) select).getName().contentEquals("super")) { if (getTreeUtilities().isSynthetic(diffContext.origUnit, node)) { diffContext.syntheticTrees.add(node); } } } } }
private void insideStringLiteral(Env env) throws IOException { TreePath path = env.getPath(); TreePath parentPath = path.getParentPath(); TreePath grandParentPath = parentPath.getParentPath(); if (grandParentPath != null && grandParentPath.getLeaf().getKind() == Tree.Kind.ANNOTATION && parentPath.getLeaf().getKind() == Tree.Kind.ASSIGNMENT && ((AssignmentTree) parentPath.getLeaf()).getExpression() == path.getLeaf()) { ExpressionTree var = ((AssignmentTree) parentPath.getLeaf()).getVariable(); if (var.getKind() == Tree.Kind.IDENTIFIER) { insideAnnotationAttribute(env, grandParentPath, ((IdentifierTree) var).getName()); } } }
Tree tree = currentPath.getLeaf(); TypeElement te; if (TreeUtilities.CLASS_TREE_KINDS.contains(tree.getKind())) { te = (TypeElement) ci.getTrees().getElement(currentPath); } else { Scope scope = ci.getTreeUtilities().scopeFor(currentOffset); Tree tree = path != null ? path.getLeaf() : null; while (tree.getKind() != Tree.Kind.VARIABLE) { String fieldName = it.getName().toString(); Scope scope = ci.getTreeUtilities().scopeFor(offset); TypeElement te = scope.getEnclosingClass(); List<? extends Element> enclosedElms = te.getEnclosedElements(); for (Element elm : enclosedElms) { if (elm.getKind().equals(ElementKind.FIELD) && elm.getSimpleName().contentEquals(fieldName)) { currentElementPtr[0] = fieldName; break;
SourcePositions sp = trees.getSourcePositions(); for (int treeIndex = 0; treeIndex < length; treeIndex++) { Tree node = treeNodes.get(treeIndex); Tree.Kind kind = node.getKind(); EditorContext.Operation op = null; if (kind.equals(Tree.Kind.METHOD_INVOCATION) || if (!ci.getTreeUtilities().isSynthetic(ci.getTrees().getPath(cu, node))) { int pos = (int) sp.getStartPosition(cu, node); EditorContext.Position startPosition = identifier = ((NewClassTree) node).getIdentifier(); methodName = "<init>"; TreePath iPath = TreePath.getPath(cu, identifier); TypeMirror type = trees.getTypeMirror(iPath); if (type.getKind() == TypeKind.ERROR) { } else { identifier = ((MethodInvocationTree) node).getMethodSelect(); if (identifier.getKind() == Tree.Kind.IDENTIFIER) { methodName = ((IdentifierTree) identifier).getName().toString(); TreePath iPath = TreePath.getPath(cu, identifier); TypeElement te = trees.getScope(iPath).getEnclosingClass(); if (te == null) {
statement.accept( new SimpleTreeVisitor<ExpressionTree, Void>() { @Override return NO_MATCH; ExpressionTree select = ((MethodInvocationTree) expr).getMethodSelect(); switch (select.getKind()) { case IDENTIFIER: break; case MEMBER_SELECT: ExpressionTree receiver = ((MemberSelectTree) select).getExpression(); if (receiver.getKind() != Kind.IDENTIFIER) { return NO_MATCH; if (!((IdentifierTree) receiver).getName().contentEquals("this")) { return NO_MATCH;
@Override public GuardedByExpression visitMethodInvocation( MethodInvocationTree node, BinderContext context) { checkGuardedBy( node.getArguments().isEmpty() && node.getTypeArguments().isEmpty(), "Only nullary methods are allowed."); ExpressionTree methodSelect = node.getMethodSelect(); switch (methodSelect.getKind()) { case IDENTIFIER: { IdentifierTree identifier = (IdentifierTree) methodSelect; Symbol.MethodSymbol method = context.resolver.resolveMethod(node, identifier.getName()); checkGuardedBy(method != null, identifier.toString()); return bindSelect(computeBase(context, method), method); } case MEMBER_SELECT: { MemberSelectTree select = (MemberSelectTree) methodSelect; GuardedByExpression base = visit(select.getExpression(), context); checkGuardedBy(base != null, select.getExpression().toString()); Symbol.MethodSymbol method = context.resolver.resolveMethod(node, base, select.getIdentifier()); checkGuardedBy(method != null, select.toString()); return bindSelect(normalizeBase(context, method, base), method); } default: throw new IllegalGuardedBy(methodSelect.getKind().toString()); } }
if (modifiers.getKind() == Kind.MODIFIERS) { annotations = ((ModifiersTree) modifiers).getAnnotations(); } else if (modifiers.getKind() == Kind.COMPILATION_UNIT) { annotations = ((CompilationUnitTree) modifiers).getPackageAnnotations(); } else { TreePath tp = new TreePath(new TreePath(copy.getCompilationUnit()), at.getAnnotationType()); Element e = copy.getTrees().getElement(tp); ExpressionTree expression; if (et.getKind() == Kind.ASSIGNMENT) { AssignmentTree assignment = (AssignmentTree) et; if (!((IdentifierTree) assignment.getVariable()).getName().contentEquals(attributeName)) continue; if (expression.getKind() == Kind.NEW_ARRAY) { currentValues = ((NewArrayTree) expression).getInitializers(); } else { if (modifiers.getKind() == Kind.MODIFIERS) { return make.addModifiersAnnotation((ModifiersTree) modifiers, newAnnotation); } else if (modifiers.getKind() == Kind.COMPILATION_UNIT) {
private static boolean hasSimpleName(AnnotationTree annotation, String name) { Tree annotationType = annotation.getAnnotationType(); javax.lang.model.element.Name simpleName; if (annotationType instanceof IdentifierTree) { simpleName = ((IdentifierTree) annotationType).getName(); } else if (annotationType instanceof MemberSelectTree) { simpleName = ((MemberSelectTree) annotationType).getIdentifier(); } else { return false; } return simpleName.contentEquals(name); }
boolean allowNonDeterministic) { Receiver receiver; switch (receiverTree.getKind()) { case ARRAY_ACCESS: ArrayAccessTree a = (ArrayAccessTree) receiverTree; if (PurityUtils.isDeterministic(provider, invokedMethod) || allowNonDeterministic) { List<Receiver> parameters = new ArrayList<>(); for (ExpressionTree p : mn.getArguments()) { parameters.add(internalReprOf(provider, p)); methodReceiver = new ClassName(TreeUtils.typeOf(mn.getMethodSelect())); } else { ExpressionTree methodReceiverTree = TreeUtils.getReceiverTree(mn); IdentifierTree identifierTree = (IdentifierTree) receiverTree; TypeMirror typeOfId = TreeUtils.typeOf(identifierTree); if (identifierTree.getName().contentEquals("this") || identifierTree.getName().contentEquals("super")) { receiver = new ThisReference(typeOfId); break;
return NO_MATCH; if (!((IdentifierTree) receiver).getName().contentEquals("super")) { return NO_MATCH; if (!(methodInvocationTree.getArguments().get(i) instanceof IdentifierTree)) { return NO_MATCH; .equals(getSymbol(methodInvocationTree.getArguments().get(i)))) { return NO_MATCH;
@Override public Void visitMethodInvocation(MethodInvocationTree tree, EnumSet<UseTypes> d) { Tree possibleIdent = tree.getMethodSelect(); boolean handled = false; if (possibleIdent.getKind() == Kind.IDENTIFIER) { String ident = ((IdentifierTree) possibleIdent).getName().toString(); Element resolved = info.getTrees().getElement(getCurrentPath()); handlePossibleIdentifier(new TreePath(getCurrentPath(), possibleIdent), EnumSet.of(UseTypes.EXECUTE)); List<? extends Tree> ta = tree.getTypeArguments(); long afterTypeArguments = ta.isEmpty() ? -1 : info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), ta.get(ta.size() - 1)); switch (tree.getMethodSelect().getKind()) { case IDENTIFIER: case MEMBER_SELECT: for (Tree expr : tree.getArguments()) { if (expr instanceof IdentifierTree) { handlePossibleIdentifier(new TreePath(getCurrentPath(), expr), EnumSet.of(UseTypes.READ));
@Override public Boolean visitAnnotation(AnnotationTree node, TreePath p) { if (p == null) return super.visitAnnotation(node, p); AnnotationTree t = (AnnotationTree) p.getLeaf(); List<? extends ExpressionTree> arguments = t.getArguments(); if (arguments.size() == 1) { ExpressionTree arg = arguments.get(0); if (arg.getKind() == Kind.ASSIGNMENT) { AssignmentTree at = (AssignmentTree) arg; if ( at.getVariable().getKind() == Kind.IDENTIFIER && isMultistatementWildcardTree(at.getExpression()) && ((IdentifierTree) at.getVariable()).getName().contentEquals("value")) { arguments = Collections.singletonList(at.getExpression()); } } } if (!checkLists(node.getArguments(), arguments, p)) return false; return scan(node.getAnnotationType(), t.getAnnotationType(), p); }
@Override public Object visitIdentifier(IdentifierTree node, Object p) { if (!fieldNames.contains(node.getName())) { return null; Tree parent = getCurrentPath().getParentPath().getLeaf(); switch (parent.getKind()) { case MEMBER_SELECT: ok = ((MemberSelectTree)parent).getExpression() != node; break; case ASSIGNMENT: if (node.getName().equals(insertedName)) { revDependencies.add(member); addDependency(node.getName());
return super.visitModifiers(node, p); ModifiersTree t = (ModifiersTree) p.getLeaf(); List<AnnotationTree> annotations = new ArrayList<AnnotationTree>(t.getAnnotations()); IdentifierTree ident = !annotations.isEmpty() && annotations.get(0).getAnnotationType().getKind() == Kind.IDENTIFIER ? (IdentifierTree) annotations.get(0).getAnnotationType() : null; State orig = State.copyOf(bindState); if (doSuperScan(r, new TreePath(p, at)) == Boolean.TRUE) { it2.remove(); it.remove(); String name = ident.getName().toString(); TreePath currentPath = new CallableTreePath(getCurrentPath()); TreePath original = bindState.variables.get(name);
private String fullName(Tree tree) { switch (tree.getKind()) { case IDENTIFIER: return ((IdentifierTree) tree).getName().toString(); case MEMBER_SELECT: String sname = fullName(((MemberSelectTree) tree).getExpression()); return sname == null ? null : sname + '.' + ((MemberSelectTree) tree).getIdentifier(); default: return null; } }