use of org.sonar.plugins.java.api.tree.MemberSelectExpressionTree in project sonar-java by SonarSource.
the class ImmediateReverseBoxingCheck method visitMethodInvocationTree.
private void visitMethodInvocationTree(MethodInvocationTree mit) {
ExpressionTree methodSelect = mit.methodSelect();
if (isValueOfInvocation(mit)) {
ExpressionTree arg0 = mit.arguments().get(0);
checkForUnboxing(arg0);
checkForUselessUnboxing(mit.symbolType(), methodSelect, arg0);
} else if (isUnboxingMethodInvocation(mit)) {
if (methodSelect.is(Tree.Kind.MEMBER_SELECT)) {
checkForBoxing(((MemberSelectExpressionTree) methodSelect).expression());
}
} else {
Symbol symbol = mit.symbol();
if (symbol.isMethodSymbol()) {
checkMethodInvocationArguments(mit, ((Symbol.MethodSymbol) symbol).parameterTypes());
}
}
}
use of org.sonar.plugins.java.api.tree.MemberSelectExpressionTree in project sonar-java by SonarSource.
the class ErrorClassExtendedCheck method visitClass.
@Override
public void visitClass(ClassTree tree) {
TypeTree superClass = tree.superClass();
if (tree.is(Tree.Kind.CLASS) && superClass != null) {
if (superClass.is(Tree.Kind.IDENTIFIER)) {
IdentifierTree idt = (IdentifierTree) superClass;
if ("Error".equals(idt.name())) {
context.reportIssue(this, superClass, "Extend \"java.lang.Exception\" or one of its subclasses.");
}
} else if (superClass.is(Tree.Kind.MEMBER_SELECT)) {
MemberSelectExpressionTree mse = (MemberSelectExpressionTree) superClass;
if ("Error".equals(mse.identifier().name()) && isJavaLang(mse.expression())) {
context.reportIssue(this, superClass, "Extend \"java.lang.Exception\" or one of its subclasses.");
}
}
}
super.visitClass(tree);
}
use of org.sonar.plugins.java.api.tree.MemberSelectExpressionTree in project sonar-java by SonarSource.
the class WaitInSynchronizeCheck method onMethodInvocationFound.
@Override
protected void onMethodInvocationFound(MethodInvocationTree mit) {
if (!isInSyncBlock()) {
IdentifierTree methodName = ExpressionUtils.methodName(mit);
ExpressionTree methodSelect = mit.methodSelect();
String lockName;
if (methodSelect.is(Tree.Kind.MEMBER_SELECT)) {
lockName = ((MemberSelectExpressionTree) methodSelect).expression().symbolType().name();
} else {
lockName = "this";
}
reportIssue(methodName, "Move this call to \"" + methodName + "()\" into a synchronized block to be sure the monitor on \"" + lockName + "\" is held.");
}
}
use of org.sonar.plugins.java.api.tree.MemberSelectExpressionTree in project sonar-java by SonarSource.
the class ExpressionsHelper method concatenate.
public static String concatenate(@Nullable ExpressionTree tree) {
if (tree == null) {
return "";
}
Deque<String> pieces = new LinkedList<>();
ExpressionTree expr = tree;
while (expr.is(Tree.Kind.MEMBER_SELECT)) {
MemberSelectExpressionTree mse = (MemberSelectExpressionTree) expr;
pieces.push(mse.identifier().name());
pieces.push(".");
expr = mse.expression();
}
if (expr.is(Tree.Kind.IDENTIFIER)) {
IdentifierTree idt = (IdentifierTree) expr;
pieces.push(idt.name());
}
StringBuilder sb = new StringBuilder();
for (String piece : pieces) {
sb.append(piece);
}
return sb.toString();
}
use of org.sonar.plugins.java.api.tree.MemberSelectExpressionTree in project sonar-java by SonarSource.
the class SyntaxTreeNameFinderTest method testClassCast.
@Test
public void testClassCast() {
MethodTree tree = buildSyntaxTree("public boolean equals(Object obj) {((String) obj).length;}");
BlockTree block = tree.block();
StatementTree statementTree = block.body().get(0);
MemberSelectExpressionTree mse = (MemberSelectExpressionTree) ((ExpressionStatementTree) statementTree).expression();
assertThat(SyntaxTreeNameFinder.getName(mse)).isEqualTo("obj");
}
Aggregations