use of org.sonar.plugins.java.api.tree.ReturnStatementTree in project sonar-java by SonarSource.
the class ImmediatelyReturnedVariableCheck method getReturnOrThrowIdentifier.
@CheckForNull
private String getReturnOrThrowIdentifier(StatementTree lastStatementOfBlock) {
lastTypeForMessage = null;
ExpressionTree expr = null;
if (lastStatementOfBlock.is(Kind.THROW_STATEMENT)) {
lastTypeForMessage = MESSAGE_KEYS.get(Kind.THROW_STATEMENT);
expr = ((ThrowStatementTree) lastStatementOfBlock).expression();
} else if (lastStatementOfBlock.is(Kind.RETURN_STATEMENT)) {
lastTypeForMessage = MESSAGE_KEYS.get(Kind.RETURN_STATEMENT);
expr = ((ReturnStatementTree) lastStatementOfBlock).expression();
}
if (expr != null && expr.is(Kind.IDENTIFIER)) {
return ((IdentifierTree) expr).name();
}
return null;
}
use of org.sonar.plugins.java.api.tree.ReturnStatementTree in project sonar-java by SonarSource.
the class MethodReferenceResolutionTest method method_reference_constructor_inference.
@Test
public void method_reference_constructor_inference() throws Exception {
Result result = Result.createFor("ConstructorInMethodRef");
MethodTree methodTree = (MethodTree) result.symbol("erased").declaration();
Type returnStatementType = ((ReturnStatementTree) methodTree.block().body().get(0)).expression().symbolType();
assertThat(returnStatementType.is("java.util.List")).isTrue();
assertThat(((JavaType) returnStatementType).isParameterized()).isTrue();
assertThat(((ParametrizedTypeJavaType) returnStatementType).typeSubstitution.substitutedTypes()).hasSize(1);
assertThat(((ParametrizedTypeJavaType) returnStatementType).typeSubstitution.substitutedTypes().get(0).is("java.util.LinkedHashSet")).isTrue();
methodTree = (MethodTree) result.symbol("erased2").declaration();
returnStatementType = ((ReturnStatementTree) methodTree.block().body().get(0)).expression().symbolType();
assertThat(returnStatementType.is("java.util.List")).isTrue();
assertThat(((JavaType) returnStatementType).isParameterized()).isTrue();
assertThat(((ParametrizedTypeJavaType) returnStatementType).typeSubstitution.substitutedTypes()).hasSize(1);
assertThat(((ParametrizedTypeJavaType) returnStatementType).typeSubstitution.substitutedTypes().get(0).is("java.util.LinkedHashSet")).isTrue();
}
Aggregations