}
fields = resource.getTypedNodeList(node, ASTNode.METHOD_INVOCATION, true);
for (Object methodInvObj : fields) {
MethodInvocation methInv = (MethodInvocation) methodInvObj;
IMethodBinding binding = (IMethodBinding) methInv.getName().resolveBinding();
if (methInv.getExpression() != null) {
ITypeBinding typeBinding = methInv.getExpression().resolveTypeBinding();
if (binding != null && typeBinding != null) {
allReferences.addTypeReference(typeBinding, methInv);
methodCalls.put(typeBinding, binding);
ITypeBinding returnType = binding.getReturnType();
if (returnType != null) {
if (!returnType.isPrimitive()) {
allReferences.addTypeReference(returnType, methInv);
}
}
}
}
}
fields = resource.getTypedNodeList(node, ASTNode.VARIABLE_DECLARATION_STATEMENT, true);
for (Object varObj: fields) {
VariableDeclarationStatement varDecl = (VariableDeclarationStatement) varObj;
Type type = varDecl.getType();
addAllIncludedTypes(type, allReferences);
}
fields = resource.getTypedNodeList(node, ASTNode.METHOD_DECLARATION, true);
for (Object methDeclObj : fields) {
MethodDeclaration methDecl = (MethodDeclaration) methDeclObj;
Type returnType = methDecl.getReturnType2();
if (returnType != null) {
addAllIncludedTypes(returnType, allReferences);
}
// look at all parameters...
for (Object varObj : methDecl.parameters()) {
SingleVariableDeclaration var = (SingleVariableDeclaration) varObj;
addAllIncludedTypes(var.getType(), allReferences);
}
}
fields = resource.getTypedNodeList(node, ASTNode.CLASS_INSTANCE_CREATION, true);
for (Object classCreationObj : fields) {
ClassInstanceCreation classCreation = (ClassInstanceCreation) classCreationObj;
if (classCreation.getType() != null) {
addAllIncludedTypes(classCreation.getType(), allReferences);
}
}
for (ITypeBinding binding : allReferences.getTypeReferences()) {
String className = binding.getQualifiedName();
if (className == null || className.equals("")) {
continue;
}
String refCompName = mappingHelper.getComponentName(binding);
if (refCompName != null) {
// look if that class may be known to this class
if (!mappingHelper.mayClassReferenceOtherClass(mainTypeBinding.getQualifiedName(),
compName, className, refCompName)) {
for (ASTNode refNode : allReferences.getOccurrencesOfTypeReference(binding)) {
StyleCheckResult.generateResultsForASTNode(this, history.getHistoryId(), refNode, resource,
"The class '"+ binding.getName()
+"' belongs to the component '"+ refCompName+
"' and may not be referenced from this class");
}
}
} else {
boolean unchecked = false;
for (String pkg : UNCHECKED_PACKAGES) {
if (className.startsWith(pkg)) {
unchecked = true;
}
}
if (!unchecked && warningsForUnmappedClasses) {
// non-standard classes must belong to a component!
for (ASTNode refNode : allReferences.getOccurrencesOfTypeReference(binding)) {
StyleCheckResult.generateResultsForASTNode(this, history.getHistoryId(),
refNode, resource, "The referenced class "+ binding.getName()
+" does not belong to a component");
}
}
}
}