use of org.sonar.java.model.declaration.EnumConstantTreeImpl in project sonar-java by SonarSource.
the class TreeFactory method newEnumConstant.
public EnumConstantTreeImpl newEnumConstant(Optional<List<AnnotationTreeImpl>> annotations, InternalSyntaxToken identifierToken, Optional<ArgumentListTreeImpl> arguments, Optional<ClassTreeImpl> classBody, Optional<InternalSyntaxToken> commaToken) {
IdentifierTreeImpl identifier = new IdentifierTreeImpl(identifierToken);
ArgumentListTreeImpl defaultArguments = new ArgumentListTreeImpl(ImmutableList.<ExpressionTree>of(), ImmutableList.<SyntaxToken>of());
NewClassTreeImpl newClass = new NewClassTreeImpl(arguments.or(defaultArguments), classBody.orNull());
newClass.completeWithIdentifier(identifier);
return new EnumConstantTreeImpl(modifiers((Optional<List<ModifierTree>>) (Optional<?>) annotations), identifier, newClass, commaToken.orNull());
}
use of org.sonar.java.model.declaration.EnumConstantTreeImpl in project sonar-java by SonarSource.
the class EnumConstantTest method test_annotation.
@Test
public void test_annotation() {
LexerlessGrammarBuilder b = JavaLexer.createGrammarBuilder();
ActionParser<Tree> parser = new ActionParser<>(StandardCharsets.UTF_8, b, JavaGrammar.class, new TreeFactory(), new JavaNodeBuilder(), JavaLexer.ENUM_CONSTANT);
EnumConstantTreeImpl node = (EnumConstantTreeImpl) parser.parse("@Foo CONSTANT");
assertThat(node.modifiers().size()).isEqualTo(1);
assertThat(((IdentifierTree) ((AnnotationTreeImpl) node.modifiers().get(0)).annotationType()).identifierToken().text()).isEqualTo("Foo");
}
use of org.sonar.java.model.declaration.EnumConstantTreeImpl in project sonar-java by SonarSource.
the class TreeFactory method newEnumDeclaration.
public ClassTreeImpl newEnumDeclaration(InternalSyntaxToken enumToken, InternalSyntaxToken identifierToken, Optional<Tuple<InternalSyntaxToken, QualifiedIdentifierListTreeImpl>> implementsClause, InternalSyntaxToken openBraceToken, Optional<List<EnumConstantTreeImpl>> enumConstants, Optional<InternalSyntaxToken> semicolonToken, Optional<List<JavaTree>> enumDeclarations, InternalSyntaxToken closeBraceToken) {
List<JavaTree> members = Lists.newLinkedList();
EnumConstantTreeImpl lastEnumConstant = null;
if (enumConstants.isPresent()) {
for (EnumConstantTreeImpl enumConstant : enumConstants.get()) {
members.add(enumConstant);
lastEnumConstant = enumConstant;
}
}
if (semicolonToken.isPresent()) {
InternalSyntaxToken semicolon = semicolonToken.get();
// add the semicolon as endToken of the last enumConstant, or as empty statement in the enum members
if (lastEnumConstant != null) {
lastEnumConstant.setEndToken(semicolon);
} else {
members.add(newEmptyMember(semicolon));
}
}
if (enumDeclarations.isPresent()) {
for (JavaTree enumDeclaration : enumDeclarations.get()) {
members.add(enumDeclaration);
}
}
ClassTreeImpl result = newClassBody(Kind.ENUM, openBraceToken, Optional.of((List<JavaTree>) ImmutableList.<JavaTree>builder().addAll(members).build()), closeBraceToken);
result.completeDeclarationKeyword(enumToken);
IdentifierTreeImpl identifier = new IdentifierTreeImpl(identifierToken);
result.completeIdentifier(identifier);
if (implementsClause.isPresent()) {
InternalSyntaxToken implementsKeyword = implementsClause.get().first();
QualifiedIdentifierListTreeImpl interfaces = implementsClause.get().second();
result.completeInterfaces(implementsKeyword, interfaces);
}
return result;
}
Aggregations