Author: scabanovich
Date: 2011-08-11 16:56:13 -0400 (Thu, 11 Aug 2011)
New Revision: 33817
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/DefinitionContext.java
Log:
JBIDE-9531
https://issues.jboss.org/browse/JBIDE-9531
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.java 2011-08-11
16:19:27 UTC (rev 33816)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.java 2011-08-11
20:56:13 UTC (rev 33817)
@@ -169,14 +169,14 @@
}
public List<AnnotationDefinition> getAllAnnotations() {
- Set<CDICoreNature> ps = getCDIProjects(true);
+ Set<CDICoreNature> ps = getCDIProjects(false);
if(ps == null || ps.isEmpty()) {
return getDefinitions().getAllAnnotations();
}
List<AnnotationDefinition> result = new ArrayList<AnnotationDefinition>();
Set<IType> types = new HashSet<IType>();
for (CDICoreNature p: ps) {
- List<AnnotationDefinition> ds2 = p.getDefinitions().getAllAnnotations();
+ List<AnnotationDefinition> ds2 = p.getAllAnnotations();
for (AnnotationDefinition d: ds2) {
IType t = d.getType();
if(t != null && !types.contains(t)) {
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2011-08-11
16:19:27 UTC (rev 33816)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2011-08-11
20:56:13 UTC (rev 33817)
@@ -175,19 +175,17 @@
public IClassBean getBeanClass(IType type) {
IPath path = type.getPath();
- if(path != null) {
- Set<IBean> bs = null;
- synchronized (beansByPath) {
- bs = beansByPath.get(path);
- }
- if(bs != null) {
- synchronized(bs) {
- for (IBean b: bs) {
- if(b instanceof IClassBean) {
- IClassBean result = (IClassBean)b;
- if(type.getFullyQualifiedName().equals(result.getBeanClass().getFullyQualifiedName()))
{
- return result;
- }
+ Set<IBean> bs = null;
+ synchronized (beansByPath) {
+ bs = beansByPath.get(path);
+ }
+ if(bs != null) {
+ synchronized(bs) {
+ for (IBean b: bs) {
+ if(b instanceof IClassBean) {
+ IClassBean result = (IClassBean)b;
+ if(type.getFullyQualifiedName().equals(result.getBeanClass().getFullyQualifiedName()))
{
+ return result;
}
}
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java 2011-08-11
16:19:27 UTC (rev 33816)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ClassBean.java 2011-08-11
20:56:13 UTC (rev 33817)
@@ -71,6 +71,10 @@
super.setDefinition(definition);
List<MethodDefinition> ms = definition.getMethods();
for (MethodDefinition m: ms) {
+ if(!m.getMethod().exists()) {
+ //update may be run on project that was not rebuilt
+ continue;
+ }
BeanMethod bm = null;
if(m.getProducesAnnotation() != null) {
bm = newProducerMethod(m);
@@ -88,6 +92,10 @@
}
List<FieldDefinition> fs = definition.getFields();
for (FieldDefinition f: fs) {
+ if(!f.getField().exists()) {
+ //update may be run on project that was not rebuilt
+ continue;
+ }
BeanField bf = null;
if(f.getProducesAnnotation() != null) {
bf = newProducerField(f);
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/DefinitionContext.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/DefinitionContext.java 2011-08-11
16:19:27 UTC (rev 33816)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/DefinitionContext.java 2011-08-11
20:56:13 UTC (rev 33817)
@@ -40,6 +40,7 @@
private Map<IPath, Set<String>> resources = new HashMap<IPath,
Set<String>>();
private Map<String, TypeDefinition> typeDefinitions = new HashMap<String,
TypeDefinition>();
private Map<String, AnnotationDefinition> annotations = new HashMap<String,
AnnotationDefinition>();
+ private Map<String, AnnotationDefinition> usedAnnotations = new HashMap<String,
AnnotationDefinition>();
private Set<String> packages = new HashSet<String>();
private Map<String, PackageDefinition> packageDefinitions = new HashMap<String,
PackageDefinition>();
@@ -393,39 +394,71 @@
}
public AnnotationDefinition getAnnotation(IType type) {
- String name = type.getFullyQualifiedName();
- AnnotationDefinition result = annotations.get(name);
- if(result == null) {
- Set<CDICoreNature> ns = project.getCDIProjects(true);
- for (CDICoreNature n: ns) {
- result = n.getDefinitions().getAnnotation(type);
- if(result != null) {
- break;
- }
- }
- }
- return result;
+ return getAnnotation(type.getFullyQualifiedName());
}
+ /**
+ * Looks up for annotation definition loaded by this project or by projects used by it.
+ */
public AnnotationDefinition getAnnotation(String fullyQualifiedName) {
+ //1. Look in annotations loaded by this project
AnnotationDefinition result = annotations.get(fullyQualifiedName);
- if(result == null) {
+ //2. Validate result.
+ if(result != null && (!result.getType().exists())) {
+ synchronized (annotations) {
+ annotations.remove(fullyQualifiedName);
+ }
+ result = null;
+ }
+ if(result == null || usedAnnotations.containsKey(fullyQualifiedName)
+ || (result.getType().getResource() != null &&
result.getType().getResource().getProject() != project.getProject())
+ ) {
+ //3. Look in annotations loaded by used projects
Set<CDICoreNature> ns = project.getCDIProjects(true);
for (CDICoreNature n: ns) {
- result = n.getDefinitions().getAnnotation(fullyQualifiedName);
- if(result != null) {
+ AnnotationDefinition r = n.getDefinitions().getAnnotation(fullyQualifiedName);
+ if(r != null) {
+ result = r;
+ //4. Store result for the case if used project is cleaned.
+ synchronized (usedAnnotations) {
+ usedAnnotations.put(fullyQualifiedName, result);
+ }
break;
}
}
}
+ if(result == null && usedAnnotations.containsKey(fullyQualifiedName)) {
+ //4. Finally, try in annotations obtained earlier from used projects - they may be
cleaned now.
+ // The result may be out-of-date until used project is rebuilt.
+ result = usedAnnotations.get(fullyQualifiedName);
+ if(!result.getType().exists()) {
+ synchronized (usedAnnotations) {
+ usedAnnotations.remove(fullyQualifiedName);
+ }
+ result = null;
+ }
+ }
return result;
}
+ /**
+ * Returns both annotations loaded by this project, and stored annotations
+ * loaded by used projects. This method can be only used in combination with
+ * getting up-to-date annotations from used projects. Stored annotations
+ * can only be used if used project is cleaned.
+ *
+ * @return
+ */
public List<AnnotationDefinition> getAllAnnotations() {
List<AnnotationDefinition> result = new ArrayList<AnnotationDefinition>();
+ //1. Add annotations loaded by this project.
synchronized (annotations) {
result.addAll(annotations.values());
}
+ //2. Add stored annotations loaded by used projects. They may be out-of-date.
+ synchronized (usedAnnotations) {
+ result.addAll(usedAnnotations.values());
+ }
return result;
}