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;
}
}
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";
}
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;
}
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;
}
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);
}
Aggregations