use of com.sun.source.tree.VariableTree in project st-js by st-js.
the class ClassWriter method getAnnotationDescription.
/**
* build the annotation description element
*
* <pre>
* $annotations : {
* _: {....}
* field1: {...}
* method1: {...}
* method1$0: {...}
* method1$1: {...}...
* }
* </pre>
*
* for each annotation list you have:
*
* <pre>
* {
* "annotationType1": [expr1, expr2, expr3],
* "annotationType2": []
* }
* </pre>
*/
private JS getAnnotationDescription(WriterVisitor<JS> visitor, ClassTree classTree, GenerationContext<JS> context) {
List<NameValue<JS>> props = new ArrayList<NameValue<JS>>();
addAnnotationsForElement("_", props, visitor, classTree.getModifiers().getAnnotations(), context);
for (Tree member : classTree.getMembers()) {
if (MemberWriters.shouldSkip(context.getCurrentWrapper().child(member))) {
continue;
}
if (member instanceof VariableTree) {
VariableTree field = (VariableTree) member;
addAnnotationsForElement(field.getName().toString(), props, visitor, field.getModifiers().getAnnotations(), context);
} else if (member instanceof MethodTree) {
addAnnotationsForMethod((MethodTree) member, props, visitor, context);
}
}
return context.js().object(props);
}
use of com.sun.source.tree.VariableTree in project st-js by st-js.
the class ClassDuplicateMemberNameCheck method checkField.
private void checkField(Tree member, GenerationContext<Void> context, Multimap<String, Element> existingNames) {
if (member instanceof VariableTree) {
TreeWrapper<Tree, Void> tw = context.getCurrentWrapper().child(member);
if (MemberWriters.shouldSkip(tw)) {
return;
}
String name = ((VariableTree) member).getName().toString();
Collection<Element> sameName = existingNames.get(name);
if (sameName.isEmpty()) {
Element variableElement = TreeUtils.elementFromDeclaration((VariableTree) member);
existingNames.put(name, variableElement);
} else {
if (!hasOnlyFields(sameName)) {
// accept fields with the same name, but not methods and fields
context.addError(member, "The type (or one of its parents) contains already a method called [" + name + "]. Javascript cannot distinguish methods/fields with the same name");
}
}
}
}
use of com.sun.source.tree.VariableTree in project st-js by st-js.
the class ClassEnumWithoutMembersCheck method checkMember.
private void checkMember(Tree member, GenerationContext<Void> context) {
if (InternalUtils.isSyntheticConstructor(member)) {
return;
}
boolean ok = false;
if (member instanceof VariableTree) {
Element memberElement = TreeUtils.elementFromDeclaration((VariableTree) member);
ok = memberElement.getKind() == ElementKind.ENUM_CONSTANT;
}
if (!ok) {
context.addError(member, "Enums with fields or methods are not supported");
}
}
use of com.sun.source.tree.VariableTree in project st-js by st-js.
the class FieldInitializerCheck method visit.
/**
* {@inheritDoc}
*/
@Override
public Void visit(CheckVisitor visitor, VariableTree tree, GenerationContext<Void> context) {
Element element = TreeUtils.elementFromDeclaration(tree);
if (element.getKind() != ElementKind.FIELD) {
// only deals with fields
return null;
}
TreeWrapper<Tree, Void> tw = context.getCurrentWrapper();
if (MemberWriters.shouldSkip(tw)) {
return null;
}
// static -> ok1
if (JavaNodes.isStatic(element)) {
return null;
}
if (checkInitializer(tree)) {
return null;
}
if (!JavaNodes.isJavaScriptPrimitive(context.getTrees().getTypeMirror(context.getCurrentPath()))) {
context.addError(tree, "Instance field inline initialization is allowed only for string and number field types");
return null;
}
context.addError(tree, "Instance field inline initialization can only done with literal constants");
return null;
}
use of com.sun.source.tree.VariableTree in project error-prone by google.
the class ASTHelpersTest method getUpperBoundScanner.
/* Tests for ASTHelpers#getUpperBound */
private TestScanner getUpperBoundScanner(final String expectedBound) {
return new TestScanner() {
@Override
public Void visitVariable(VariableTree tree, VisitorState state) {
setAssertionsComplete();
Type varType = ASTHelpers.getType(tree.getType());
assertThat(ASTHelpers.getUpperBound(varType.getTypeArguments().get(0), state.getTypes()).toString()).isEqualTo(expectedBound);
return super.visitVariable(tree, state);
}
};
}
Aggregations