IJavaProject javaProject = JavaCore.create(getProject());
SingletonDependencyFinder finder = new SingletonDependencyFinder(projectModel);
Dependency[] dependencies = finder.findSingletonDependencies(singleton, interfacesToSearchFor);
IType type = javaProject.findType(singleton);
ISourceRange sourceRange = type.getSourceRange();
CompilationUnit compilationUnit = cache.getCompilationUnit(type.getCompilationUnit());
TypeDeclaration typeDeclaration = cache.getTypeDeclaration(type);
IAnnotationBinding[] annotations = typeDeclaration.resolveBinding().getAnnotations();
List<String> declaredDependencies = new ArrayList<String>();
for (IAnnotationBinding annotation : annotations) {
if ("javax.ejb.DependsOn".equals(annotation.getAnnotationType().getQualifiedName())) {
IMemberValuePairBinding[] pairs = annotation.getDeclaredMemberValuePairs();
for (int i = 0; i < pairs.length; i++) {
if ("value".equals(pairs[i].getName())) {
if (pairs[i].getValue() instanceof Object[]) {
Object[] values = (Object[]) pairs[i].getValue();
for (int j = 0; j < values.length; j++) {
declaredDependencies.add(values[j].toString());
}
}
}
}
}
}
List<String> expectedDependencies = new ArrayList<String>();
if (dependencies != null) {
for (Dependency dependency : dependencies) {
expectedDependencies.add(dependency.getDependsOn());
}
}
boolean matches = expectedDependencies.size() == declaredDependencies.size();
if (matches) {
for (String dependency : declaredDependencies) {
if (!expectedDependencies.contains(dependency)) {
matches = false;
break;
}
}
}
if (!matches) {
IMarker marker = type.getUnderlyingResource().createMarker(MARKER_TYPE_DEPENDS_ON);
Map attributes = new HashMap();
attributes.put(IMarker.LINE_NUMBER, compilationUnit.getLineNumber(sourceRange.getOffset()));
attributes.put(IMarker.CHAR_START, sourceRange.getOffset());
attributes.put(IMarker.CHAR_END, sourceRange.getOffset() + sourceRange.getLength());
attributes.put(IMarker.LINE_NUMBER, compilationUnit.getLineNumber(sourceRange.getOffset()));
attributes.put(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
attributes.put(IMarker.MESSAGE, expectedDependencies.size() == 0 ? "This bean should not have the @DependsOn annotation" : "This bean requires the @DependsOn annotation, and depends on: " + getDependencyList(expectedDependencies));
attributes.put(ISingletonDependencyMarker.DEPENDENCIES, expectedDependencies.toArray(new String[expectedDependencies.size()]));
attributes.put(ISingletonDependencyMarker.BEAN, singleton);
marker.setAttributes(attributes);