org.sonar.plugins.java.api.semantic.Type Java Examples

The following examples show how to use org.sonar.plugins.java.api.semantic.Type. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BadConstantNameCheck.java    From vjtools with Apache License 2.0 6 votes vote down vote up
@Override
public void visitNode(Tree tree) {
	ClassTree classTree = (ClassTree) tree;
	for (Tree member : classTree.members()) {
		if (member.is(Tree.Kind.VARIABLE) && hasSemantic()) {
			VariableTree variableTree = (VariableTree) member;
			Type symbolType = variableTree.type().symbolType();
			 if (isConstantType(symbolType) && (classTree.is(Tree.Kind.INTERFACE, Tree.Kind.ANNOTATION_TYPE) || isStaticFinal(variableTree))) {
		          checkName(variableTree);
		     }
		}
		// VJ Remove //
		// else if (member.is(Tree.Kind.ENUM_CONSTANT)) {
		// checkName((VariableTree) member);
		// }
	}
}
 
Example #2
Source File: BadConstantNameCheck.java    From vjtools with Apache License 2.0 6 votes vote down vote up
@Override
public void visitNode(Tree tree) {
	ClassTree classTree = (ClassTree) tree;
	for (Tree member : classTree.members()) {
		if (member.is(Tree.Kind.VARIABLE) && hasSemantic()) {
			VariableTree variableTree = (VariableTree) member;
			Type symbolType = variableTree.type().symbolType();
			 if (isConstantType(symbolType) && (classTree.is(Tree.Kind.INTERFACE, Tree.Kind.ANNOTATION_TYPE) || isStaticFinal(variableTree))) {
		          checkName(variableTree);
		     }
		}
		// VJ Remove //
		// else if (member.is(Tree.Kind.ENUM_CONSTANT)) {
		// checkName((VariableTree) member);
		// }
	}
}
 
Example #3
Source File: BadConstantNameCheck.java    From vjtools with Apache License 2.0 5 votes vote down vote up
private static boolean isConstantType(Type symbolType) {
	return symbolType.isPrimitive() || symbolType.is("java.lang.String") ||  symbolType.is("java.lang.Byte") ||
			symbolType.is("java.lang.Character") ||
			symbolType.is("java.lang.Short") ||
			symbolType.is("java.lang.Integer") ||
			symbolType.is("java.lang.Long") ||
			symbolType.is("java.lang.Float") ||
			symbolType.is("java.lang.Double") ||
			symbolType.is("java.lang.Boolean");
}
 
Example #4
Source File: BadConstantNameCheck.java    From vjtools with Apache License 2.0 5 votes vote down vote up
private static boolean isConstantType(Type symbolType) {
	return symbolType.isPrimitive() || symbolType.is("java.lang.String") ||  symbolType.is("java.lang.Byte") ||
			symbolType.is("java.lang.Character") ||
			symbolType.is("java.lang.Short") ||
			symbolType.is("java.lang.Integer") ||
			symbolType.is("java.lang.Long") ||
			symbolType.is("java.lang.Float") ||
			symbolType.is("java.lang.Double") ||
			symbolType.is("java.lang.Boolean");
}
 
Example #5
Source File: MethodParametersPredicate.java    From AEM-Rules-for-SonarQube with Apache License 2.0 5 votes vote down vote up
static boolean allParameterTypesMatch(List<Type> actualParameterTypes, List<ParameterTypePredicate> expectedParameterTypes) {
    if (actualParameterTypes.size() != expectedParameterTypes.size()) {
        return false;
    }

    boolean result = true;
    for (int parameterTypeIndex = 0; parameterTypeIndex < actualParameterTypes.size(); parameterTypeIndex++) {
        if (!expectedParameterTypes.get(parameterTypeIndex).test(actualParameterTypes.get(parameterTypeIndex))) {
            result = false;
        }
    }
    return result;
}
 
Example #6
Source File: AbstractSmellCheck.java    From qualinsight-plugins-sonarqube-smell with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void visitNode(final Tree tree) {
    final AnnotationTree annotationTree = (AnnotationTree) tree;
    final Type symbolType = annotationTree.annotationType()
        .symbolType();
    if (symbolType.is("com.qualinsight.plugins.sonarqube.smell.api.annotation.Smell")) {
        handleSmellAnnotation(annotationTree);
    }
}
 
Example #7
Source File: UnusedMethodParameterCheck.java    From vjtools with Apache License 2.0 4 votes vote down vote up
private static boolean isStrutsActionParameter(VariableTree variableTree) {
	Type superClass = variableTree.symbol().enclosingClass().superClass();
	return superClass != null && superClass.isSubtypeOf(STRUTS_ACTION_SUPERCLASS)
			&& EXCLUDED_STRUTS_ACTION_PARAMETER_TYPES.contains(variableTree.symbol().type().fullyQualifiedName());
}
 
Example #8
Source File: UnusedMethodParameterCheck.java    From vjtools with Apache License 2.0 4 votes vote down vote up
private static boolean isStrutsActionParameter(VariableTree variableTree) {
	Type superClass = variableTree.symbol().enclosingClass().superClass();
	return superClass != null && superClass.isSubtypeOf(STRUTS_ACTION_SUPERCLASS)
			&& EXCLUDED_STRUTS_ACTION_PARAMETER_TYPES.contains(variableTree.symbol().type().fullyQualifiedName());
}
 
Example #9
Source File: PreferSlingServletAnnotation.java    From AEM-Rules-for-SonarQube with Apache License 2.0 4 votes vote down vote up
private boolean isSlingServlet(ClassTree tree) {
    Type type = tree.symbol().type();
    boolean allMethodsServlet = type.isSubtypeOf("org.apache.sling.api.servlets.SlingAllMethodsServlet");
    boolean safeMethodsServlet = type.isSubtypeOf("org.apache.sling.api.servlets.SlingSafeMethodsServlet");
    return allMethodsServlet || safeMethodsServlet;
}