Search in sources :

Example 6 with IdentifierTreeImpl

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());
}
Also used : ModifierTree(org.sonar.plugins.java.api.tree.ModifierTree) Optional(com.sonar.sslr.api.typed.Optional) IdentifierTreeImpl(org.sonar.java.model.expression.IdentifierTreeImpl) NewClassTreeImpl(org.sonar.java.model.expression.NewClassTreeImpl) EnumConstantTreeImpl(org.sonar.java.model.declaration.EnumConstantTreeImpl) TypeArgumentListTreeImpl(org.sonar.java.model.expression.TypeArgumentListTreeImpl)

Example 7 with IdentifierTreeImpl

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);
}
Also used : ConstraintManager(org.sonar.java.se.constraint.ConstraintManager) IdentifierTreeImpl(org.sonar.java.model.expression.IdentifierTreeImpl) SyntaxTrivia(org.sonar.plugins.java.api.tree.SyntaxTrivia) IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) SymbolicValue(org.sonar.java.se.symbolicvalues.SymbolicValue) Test(org.junit.Test)

Example 8 with IdentifierTreeImpl

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);
    }
}
Also used : IdentifierTreeImpl(org.sonar.java.model.expression.IdentifierTreeImpl) LabeledStatementTree(org.sonar.plugins.java.api.tree.LabeledStatementTree)

Example 9 with IdentifierTreeImpl

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);
}
Also used : IdentifierTreeImpl(org.sonar.java.model.expression.IdentifierTreeImpl) ArrayTypeTreeImpl(org.sonar.java.model.JavaTree.ArrayTypeTreeImpl) MemberSelectExpressionTreeImpl(org.sonar.java.model.expression.MemberSelectExpressionTreeImpl)

Example 10 with IdentifierTreeImpl

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));
}
Also used : SyntaxToken(org.sonar.plugins.java.api.tree.SyntaxToken) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken) IdentifierTreeImpl(org.sonar.java.model.expression.IdentifierTreeImpl) ArrayList(java.util.ArrayList) IdentifierTree(org.sonar.plugins.java.api.tree.IdentifierTree) InternalSyntaxToken(org.sonar.java.model.InternalSyntaxToken)

Aggregations

IdentifierTreeImpl (org.sonar.java.model.expression.IdentifierTreeImpl)18 InternalSyntaxToken (org.sonar.java.model.InternalSyntaxToken)9 ArrayTypeTreeImpl (org.sonar.java.model.JavaTree.ArrayTypeTreeImpl)5 MemberSelectExpressionTreeImpl (org.sonar.java.model.expression.MemberSelectExpressionTreeImpl)5 ExpressionTree (org.sonar.plugins.java.api.tree.ExpressionTree)5 NewClassTreeImpl (org.sonar.java.model.expression.NewClassTreeImpl)3 ParameterizedTypeTree (org.sonar.plugins.java.api.tree.ParameterizedTypeTree)3 TypeTree (org.sonar.plugins.java.api.tree.TypeTree)3 Optional (com.sonar.sslr.api.typed.Optional)2 ArrayList (java.util.ArrayList)2 JavaTree (org.sonar.java.model.JavaTree)2 EnumConstantTreeImpl (org.sonar.java.model.declaration.EnumConstantTreeImpl)2 VariableTreeImpl (org.sonar.java.model.declaration.VariableTreeImpl)2 MethodInvocationTreeImpl (org.sonar.java.model.expression.MethodInvocationTreeImpl)2 TypeArgumentListTreeImpl (org.sonar.java.model.expression.TypeArgumentListTreeImpl)2 IdentifierTree (org.sonar.plugins.java.api.tree.IdentifierTree)2 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 Test (org.junit.Test)1 ImportTreeImpl (org.sonar.java.model.JavaTree.ImportTreeImpl)1