use of org.sonar.java.model.InternalSyntaxToken in project sonar-java by SonarSource.
the class TreeFactory method newClassCastExpression.
public TypeCastExpressionTreeImpl newClassCastExpression(TypeTree type, Optional<Tuple<InternalSyntaxToken, BoundListTreeImpl>> classTypes, InternalSyntaxToken closeParenToken, ExpressionTree expression) {
BoundListTreeImpl bounds = BoundListTreeImpl.emptyList();
InternalSyntaxToken andToken = null;
if (classTypes.isPresent()) {
andToken = classTypes.get().first();
bounds = classTypes.get().second();
}
return new TypeCastExpressionTreeImpl(type, andToken, bounds, closeParenToken, expression);
}
use of org.sonar.java.model.InternalSyntaxToken in project sonar-java by SonarSource.
the class TreeFactory method newArrayInitializer.
public NewArrayTreeImpl newArrayInitializer(InternalSyntaxToken openBraceToken, Optional<InternalSyntaxToken> optionalComma, Optional<List<Tuple<ExpressionTree, Optional<InternalSyntaxToken>>>> rests, InternalSyntaxToken closeBraceToken) {
ImmutableList.Builder<ExpressionTree> initializers = ImmutableList.builder();
ImmutableList.Builder<SyntaxToken> separators = ImmutableList.builder();
if (optionalComma.isPresent()) {
separators.add(optionalComma.get());
}
if (rests.isPresent()) {
for (Tuple<ExpressionTree, Optional<InternalSyntaxToken>> rest : rests.get()) {
initializers.add(rest.first());
if (rest.second().isPresent()) {
separators.add(rest.second().get());
}
}
}
return new NewArrayTreeImpl(ImmutableList.<ArrayDimensionTree>of(), new InitializerListTreeImpl(initializers.build(), separators.build())).completeWithCurlyBraces(openBraceToken, closeBraceToken);
}
use of org.sonar.java.model.InternalSyntaxToken in project sonar-java by SonarSource.
the class TreeFactory method newAnnotationTypeMethod.
public MethodTreeImpl newAnnotationTypeMethod(InternalSyntaxToken openParenToken, InternalSyntaxToken closeParenToken, Optional<Tuple<InternalSyntaxToken, ExpressionTree>> defaultValue) {
FormalParametersListTreeImpl parameters = new FormalParametersListTreeImpl(openParenToken, closeParenToken);
InternalSyntaxToken defaultToken = null;
ExpressionTree defaultExpression = null;
if (defaultValue.isPresent()) {
defaultToken = defaultValue.get().first();
defaultExpression = defaultValue.get().second();
}
return new MethodTreeImpl(parameters, defaultToken, defaultExpression);
}
use of org.sonar.java.model.InternalSyntaxToken in project sonar-java by SonarSource.
the class TreeFactory method newRequiresModuleDirective.
public ModuleDirectiveTree newRequiresModuleDirective(InternalSyntaxToken requiresToken, Optional<List<InternalSyntaxToken>> modifiers, ModuleNameTree moduleName, InternalSyntaxToken semicolonToken) {
ModifiersTreeImpl newModifiers = ModifiersTreeImpl.emptyModifiers();
if (modifiers.isPresent()) {
List<ModifierTree> modifierKeywords = new ArrayList<>();
// JLS9 - ยง7.7.1 'requires' only 'static' and 'transitive' modifiers are allowed
for (InternalSyntaxToken modifierAsSyntaxToken : modifiers.get()) {
if (JavaRestrictedKeyword.TRANSITIVE.getValue().equals(modifierAsSyntaxToken.text())) {
modifierKeywords.add(new ModifierKeywordTreeImpl(Modifier.TRANSITIVE, modifierAsSyntaxToken));
} else {
modifierKeywords.add(new ModifierKeywordTreeImpl(Modifier.STATIC, modifierAsSyntaxToken));
}
}
newModifiers = new ModifiersTreeImpl(modifierKeywords);
}
return new RequiresDirectiveTreeImpl(requiresToken, newModifiers, moduleName, semicolonToken);
}
use of org.sonar.java.model.InternalSyntaxToken in project sonar-java by SonarSource.
the class JavaNodeBuilder method createNonTerminal.
@Override
public Object createNonTerminal(GrammarRuleKey ruleKey, Rule rule, List<Object> children, int startIndex, int endIndex) {
for (Object child : children) {
if (child instanceof InternalSyntaxToken) {
InternalSyntaxToken syntaxToken = (InternalSyntaxToken) child;
syntaxToken.setGrammarRuleKey(ruleKey);
return child;
}
}
return new InternalSyntaxSpacing(startIndex, endIndex);
}
Aggregations