use of org.sonar.java.model.expression.IdentifierTreeImpl 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.expression.IdentifierTreeImpl in project sonar-java by SonarSource.
the class SymbolicValueFactoryTest method testFactory.
@Test
public void testFactory() {
final IdentifierTree tree = new IdentifierTreeImpl(new InternalSyntaxToken(1, 1, "id", Collections.<SyntaxTrivia>emptyList(), 0, 0, false));
final ConstraintManager manager = new ConstraintManager();
SymbolicValue symbolicValue = manager.createSymbolicValue(tree);
assertThat(symbolicValue.getClass()).as("Created without factory").isSameAs(SymbolicValue.class);
manager.setValueFactory(new TestSymbolicValueFactory());
symbolicValue = manager.createSymbolicValue(tree);
assertThat(symbolicValue.getClass()).as("Created with factory").isSameAs(TestSymbolicValue.class);
assertThat(symbolicValue.references(symbolicValue)).isFalse();
manager.setValueFactory(new TestSymbolicValueFactory());
try {
manager.setValueFactory(new TestSymbolicValueFactory());
fail("Able to add a second factory to the contraints manager");
} catch (IllegalStateException e) {
assertThat(e.getMessage()).as("Exception message").isEqualTo("The symbolic value factory has already been defined by another checker!");
}
symbolicValue = manager.createSymbolicValue(tree);
assertThat(symbolicValue.getClass()).as("Created with first factory").isSameAs(TestSymbolicValue.class);
symbolicValue = manager.createSymbolicValue(tree);
assertThat(symbolicValue.getClass()).as("Created after factory usage").isSameAs(SymbolicValue.class);
}
use of org.sonar.java.model.expression.IdentifierTreeImpl in project sonar-java by SonarSource.
the class LabelsVisitor method associateLabel.
private void associateLabel(@Nullable IdentifierTree label) {
if (label == null) {
return;
}
LabeledStatementTree labelTree = labelTrees.get(label.name());
if (labelTree != null) {
JavaSymbol symbol = (JavaSymbol) labelTree.symbol();
((IdentifierTreeImpl) label).setSymbol(symbol);
symbol.addUsage(label);
}
}
use of org.sonar.java.model.expression.IdentifierTreeImpl in project sonar-java by SonarSource.
the class TreeFactory method newDotClassSelector.
public ExpressionTree newDotClassSelector(Optional<List<Tuple<InternalSyntaxToken, InternalSyntaxToken>>> dimensions, InternalSyntaxToken dotToken, InternalSyntaxToken classToken) {
IdentifierTreeImpl identifier = new IdentifierTreeImpl(classToken);
ArrayTypeTreeImpl nestedDimensions = newArrayTypeTree(dimensions);
return new MemberSelectExpressionTreeImpl(nestedDimensions, dotToken, identifier);
}
use of org.sonar.java.model.expression.IdentifierTreeImpl in project sonar-java by SonarSource.
the class TreeFactory method newModuleName.
public ModuleNameTree newModuleName(InternalSyntaxToken firstIdentifier, Optional<List<Tuple<InternalSyntaxToken, InternalSyntaxToken>>> rest) {
List<IdentifierTree> identifiers = new ArrayList<>();
List<SyntaxToken> separators = new ArrayList<>();
identifiers.add(new IdentifierTreeImpl(firstIdentifier));
if (rest.isPresent()) {
for (Tuple<InternalSyntaxToken, InternalSyntaxToken> modulePart : rest.get()) {
separators.add(modulePart.first());
identifiers.add(new IdentifierTreeImpl(modulePart.second()));
}
}
return new ModuleNameTreeImpl(Collections.unmodifiableList(identifiers), Collections.unmodifiableList(separators));
}
Aggregations