Search in sources :

Example 16 with IdentifierTree

use of com.sun.source.tree.IdentifierTree in project st-js by st-js.

the class TreeUtils method isSpecificFieldAccess.

/**
 * Returns true if and only if the given {@code tree} represents a field access of the given
 * {@link javax.lang.model.element.VariableElement} .
 *
 * @param tree
 *            a {@link com.sun.source.tree.Tree} object.
 * @param var
 *            a {@link javax.lang.model.element.VariableElement} object.
 * @return a boolean.
 */
public static boolean isSpecificFieldAccess(Tree tree, VariableElement var) {
    if (tree instanceof MemberSelectTree) {
        MemberSelectTree memSel = (MemberSelectTree) tree;
        Element field = TreeUtils.elementFromUse(memSel);
        return field.equals(var);
    } else if (tree instanceof IdentifierTree) {
        IdentifierTree idTree = (IdentifierTree) tree;
        Element field = TreeUtils.elementFromUse(idTree);
        return field.equals(var);
    } else {
        return false;
    }
}
Also used : MemberSelectTree(com.sun.source.tree.MemberSelectTree) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) IdentifierTree(com.sun.source.tree.IdentifierTree)

Example 17 with IdentifierTree

use of com.sun.source.tree.IdentifierTree in project st-js by st-js.

the class MemberSelectWriter method buildTemplateName.

private String buildTemplateName(GenerationContext<JS> context) {
    TreeWrapper<IdentifierTree, JS> tw = context.getCurrentWrapper();
    Element def = tw.getElement();
    if (def.getKind() == ElementKind.FIELD) {
        String template = tw.getFieldTemplate();
        if (template != null) {
            return template;
        }
        return "none";
    }
    return "none";
}
Also used : Element(javax.lang.model.element.Element) IdentifierTree(com.sun.source.tree.IdentifierTree)

Example 18 with IdentifierTree

use of com.sun.source.tree.IdentifierTree in project st-js by st-js.

the class MethodInvocationOuterScopeCheck method visit.

/**
 * {@inheritDoc}
 */
@Override
public Void visit(CheckVisitor visitor, MethodInvocationTree tree, GenerationContext<Void> context) {
    Element methodElement = TreeUtils.elementFromUse(tree);
    if (JavaNodes.isStatic(methodElement)) {
        // only instance methods
        return null;
    }
    String name = MethodInvocationWriter.buildMethodName(tree);
    if (GeneratorConstants.THIS.equals(name) || GeneratorConstants.SUPER.equals(name)) {
        // this and super call are ok
        return null;
    }
    if (!(tree.getMethodSelect() instanceof IdentifierTree)) {
        // check for Outer.this check
        return null;
    }
    checkScope(methodElement, tree, context);
    return null;
}
Also used : Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) IdentifierTree(com.sun.source.tree.IdentifierTree)

Example 19 with IdentifierTree

use of com.sun.source.tree.IdentifierTree in project st-js by st-js.

the class NewClassObjectInitCheck method isTemplateAssignExpression.

private boolean isTemplateAssignExpression(ExpressionTree expr) {
    // the expression must be a method call.
    if (!(expr instanceof MethodInvocationTree)) {
        return false;
    }
    MethodInvocationTree meth = (MethodInvocationTree) expr;
    // The method call must be a call without selectors (so directly the method name)
    ExpressionTree select = meth.getMethodSelect();
    if (!(select instanceof IdentifierTree)) {
        return false;
    }
    // The method call must have exactly one argument
    if (meth.getArguments().size() != 1) {
        return false;
    }
    // the method being called must be annotated with @Template
    ExecutableElement elem = TreeUtils.elementFromUse(meth);
    Template template = elem.getAnnotation(Template.class);
    if (template == null) {
        return false;
    }
    // The value of the @Template annotation must be "toProperty"
    if (!"toProperty".equals(template.value())) {
        return false;
    }
    return true;
}
Also used : MethodInvocationTree(com.sun.source.tree.MethodInvocationTree) ExecutableElement(javax.lang.model.element.ExecutableElement) ExpressionTree(com.sun.source.tree.ExpressionTree) IdentifierTree(com.sun.source.tree.IdentifierTree) Template(org.stjs.javascript.annotation.Template)

Example 20 with IdentifierTree

use of com.sun.source.tree.IdentifierTree in project error-prone by google.

the class ASTHelpers method hasSimpleName.

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);
}
Also used : MemberSelectTree(com.sun.source.tree.MemberSelectTree) CompoundAssignmentTree(com.sun.source.tree.CompoundAssignmentTree) MethodInvocationTree(com.sun.source.tree.MethodInvocationTree) AssignmentTree(com.sun.source.tree.AssignmentTree) LambdaExpressionTree(com.sun.source.tree.LambdaExpressionTree) ForLoopTree(com.sun.source.tree.ForLoopTree) ParenthesizedTree(com.sun.source.tree.ParenthesizedTree) ConditionalExpressionTree(com.sun.source.tree.ConditionalExpressionTree) MemberSelectTree(com.sun.source.tree.MemberSelectTree) ReturnTree(com.sun.source.tree.ReturnTree) UnaryTree(com.sun.source.tree.UnaryTree) VariableTree(com.sun.source.tree.VariableTree) TypeParameterTree(com.sun.source.tree.TypeParameterTree) NewClassTree(com.sun.source.tree.NewClassTree) ParameterizedTypeTree(com.sun.source.tree.ParameterizedTypeTree) Tree(com.sun.source.tree.Tree) ExpressionTree(com.sun.source.tree.ExpressionTree) ArrayAccessTree(com.sun.source.tree.ArrayAccessTree) PackageTree(com.sun.source.tree.PackageTree) IdentifierTree(com.sun.source.tree.IdentifierTree) SwitchTree(com.sun.source.tree.SwitchTree) ModifiersTree(com.sun.source.tree.ModifiersTree) WhileLoopTree(com.sun.source.tree.WhileLoopTree) AnnotationTree(com.sun.source.tree.AnnotationTree) MethodTree(com.sun.source.tree.MethodTree) BinaryTree(com.sun.source.tree.BinaryTree) ClassTree(com.sun.source.tree.ClassTree) IfTree(com.sun.source.tree.IfTree) MemberReferenceTree(com.sun.source.tree.MemberReferenceTree) JCTree(com.sun.tools.javac.tree.JCTree) DoWhileLoopTree(com.sun.source.tree.DoWhileLoopTree) IdentifierTree(com.sun.source.tree.IdentifierTree)

Aggregations

IdentifierTree (com.sun.source.tree.IdentifierTree)82 ExpressionTree (com.sun.source.tree.ExpressionTree)41 MemberSelectTree (com.sun.source.tree.MemberSelectTree)36 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)28 Element (javax.lang.model.element.Element)24 Tree (com.sun.source.tree.Tree)21 ExecutableElement (javax.lang.model.element.ExecutableElement)18 VariableTree (com.sun.source.tree.VariableTree)17 TypeElement (javax.lang.model.element.TypeElement)16 MethodTree (com.sun.source.tree.MethodTree)13 VariableElement (javax.lang.model.element.VariableElement)13 ClassTree (com.sun.source.tree.ClassTree)12 ConditionalExpressionTree (com.sun.source.tree.ConditionalExpressionTree)11 ArrayAccessTree (com.sun.source.tree.ArrayAccessTree)10 NewClassTree (com.sun.source.tree.NewClassTree)10 AssignmentTree (com.sun.source.tree.AssignmentTree)9 BinaryTree (com.sun.source.tree.BinaryTree)9 LiteralTree (com.sun.source.tree.LiteralTree)8 StatementTree (com.sun.source.tree.StatementTree)8 Symbol (com.sun.tools.javac.code.Symbol)8