use of com.sun.source.tree.IdentifierTree in project checker-framework by typetools.
the class TreeParserTest method parsesMethodInvocations.
@Test
public void parsesMethodInvocations() {
String value = "test()";
ExpressionTree parsed = parser.parseTree(value);
Assert.assertTrue(parsed instanceof MethodInvocationTree);
MethodInvocationTree invocation = (MethodInvocationTree) parsed;
Assert.assertTrue(invocation.getMethodSelect() instanceof IdentifierTree);
Assert.assertEquals("test", ((IdentifierTree) invocation.getMethodSelect()).getName().toString());
}
use of com.sun.source.tree.IdentifierTree in project checker-framework by typetools.
the class AnnotatedTypeFactory method isAnyEnclosingThisDeref.
/**
* Does this expression have (the innermost or an outer) "this" as receiver? Note that the
* receiver can be either explicit or implicit.
*
* @param tree the tree to test
* @return true, iff the expression uses (the innermost or an outer) "this" as receiver
*/
public final boolean isAnyEnclosingThisDeref(ExpressionTree tree) {
if (!TreeUtils.isUseOfElement(tree)) {
return false;
}
ExpressionTree recv = TreeUtils.getReceiverTree(tree);
if (recv == null) {
Element element = TreeUtils.elementFromUse(tree);
if (!ElementUtils.hasReceiver(element)) {
return false;
}
tree = TreeUtils.skipParens(tree);
if (tree.getKind() == Tree.Kind.IDENTIFIER) {
Name n = ((IdentifierTree) tree).getName();
if ("this".contentEquals(n) || "super".contentEquals(n)) {
// An explicit reference to "this"/"super" has no receiver.
return false;
}
}
// Must be some access through this.
return true;
} else if (!TreeUtils.isUseOfElement(recv)) {
// The receiver is e.g. a String literal.
return false;
// TODO: I think this:
// (i==9 ? this : this).toString();
// is not a use of an element, as the receiver is an
// expression. How should this be handled?
}
Element element = TreeUtils.elementFromUse(recv);
if (!ElementUtils.hasReceiver(element)) {
return false;
}
return TreeUtils.isExplicitThisDereference(recv);
}
use of com.sun.source.tree.IdentifierTree in project checker-framework by typetools.
the class FormatterVisitor method isWrappedFormatCall.
/**
* Returns true if fc is within a method m annotated as {@code @FormatMethod}, and fc's
* arguments are m's formal parameters. In other words, fc forwards m's arguments to another
* format method.
*/
private boolean isWrappedFormatCall(FormatCall fc) {
MethodTree enclosingMethod = TreeUtils.enclosingMethod(atypeFactory.getPath(fc.node));
if (enclosingMethod == null) {
return false;
}
ExecutableElement enclosingMethodElement = TreeUtils.elementFromDeclaration(enclosingMethod);
boolean withinFormatMethod = (atypeFactory.getDeclAnnotation(enclosingMethodElement, FormatMethod.class) != null);
if (!withinFormatMethod) {
return false;
}
List<? extends ExpressionTree> args = fc.node.getArguments();
List<? extends VariableTree> params = enclosingMethod.getParameters();
List<? extends VariableElement> paramElements = enclosingMethodElement.getParameters();
// Strip off leading Locale arguments.
if (args.size() > 0 && FormatterTreeUtil.isLocale(args.get(0), atypeFactory)) {
args = args.subList(1, args.size());
}
if (params.size() > 0 && TypesUtils.isDeclaredOfName(paramElements.get(0).asType(), "java.util.Locale")) {
params = params.subList(1, params.size());
}
if (args.size() == params.size()) {
for (int i = 0; i < args.size(); i++) {
ExpressionTree arg = args.get(i);
if (!(arg instanceof IdentifierTree && ((IdentifierTree) arg).getName().equals(params.get(i).getName()))) {
return false;
}
}
}
return true;
}
use of com.sun.source.tree.IdentifierTree in project st-js by st-js.
the class DefaultMemberSelectTemplate method getTarget.
private JS getTarget(WriterVisitor<JS> visitor, MemberSelectTree tree, GenerationContext<JS> context) {
if (JavaNodes.isSuper(tree.getExpression())) {
// super.field does not make sense, so convert it to this
return context.js().keyword(Keyword.THIS);
}
TreeWrapper<IdentifierTree, JS> tw = context.getCurrentWrapper();
Tree target = tree.getExpression();
JS targetJS = visitor.scan(target, context);
if (tw.isStatic() && !ElementUtils.isTypeKind(tw.child(target).getElement())) {
// this is static method called from an instances: e.g. x.staticField
targetJS = tw.getContext().js().property(targetJS, JavascriptKeywords.CONSTRUCTOR);
}
return targetJS;
}
use of com.sun.source.tree.IdentifierTree in project st-js by st-js.
the class GetterMemberSelectTemplate method getTarget.
private JS getTarget(WriterVisitor<JS> visitor, MemberSelectTree tree, GenerationContext<JS> context) {
if (JavaNodes.isSuper(tree.getExpression())) {
// super.field does not make sense, so convert it to this
return context.js().keyword(Keyword.THIS);
}
TreeWrapper<IdentifierTree, JS> tw = context.getCurrentWrapper();
Tree target = tree.getExpression();
JS targetJS = visitor.scan(target, context);
if (tw.isStatic() && !ElementUtils.isTypeKind(tw.child(target).getElement())) {
// this is static method called from an instances: e.g. x.staticField
targetJS = tw.getContext().js().property(targetJS, JavascriptKeywords.CONSTRUCTOR);
}
return targetJS;
}
Aggregations