Author: scabanovich
Date: 2007-11-19 10:51:19 -0500 (Mon, 19 Nov 2007)
New Revision: 4971
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamJavaComponentDeclaration.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java
Log:
JBIDE-1333
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java 2007-11-19
11:55:52 UTC (rev 4970)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java 2007-11-19
15:51:19 UTC (rev 4971)
@@ -152,6 +152,10 @@
*/
public Set<ISeamContextVariable> getVariables(boolean includeShortNames);
+ public void addVariable(ISeamContextVariable v);
+
+ public void removeVariable(ISeamContextVariable v);
+
/**
* @param name
* @return all seam variables by name from all contexts
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamJavaComponentDeclaration.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamJavaComponentDeclaration.java 2007-11-19
11:55:52 UTC (rev 4970)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamJavaComponentDeclaration.java 2007-11-19
15:51:19 UTC (rev 4971)
@@ -231,7 +231,7 @@
bijectedAttributes.add(loaded);
ISeamProject p = getSeamProject();
if(p != null && loaded.isContextVariable()) {
- p.getVariables().add(loaded);
+ p.addVariable(loaded);
}
Change change = new Change(this, null, null, loaded);
children.addChildren(Change.addChange(null, change));
@@ -243,8 +243,8 @@
if(wasOut != isOut) {
ISeamProject p = getSeamProject();
if(p != null) {
- if(wasOut) p.getVariables().remove(current);
- if(isOut) p.getVariables().add(current);
+ if(wasOut) p.removeVariable(current);
+ if(isOut) p.addVariable(current);
}
}
}
@@ -253,7 +253,7 @@
for (BijectedAttribute r: bijectedMap.values()) {
bijectedAttributes.remove(r);
ISeamProject p = getSeamProject();
- if(p != null) p.getVariables().remove(r);
+ if(p != null) p.removeVariable(r);
Change change = new Change(this, null, r, null);
children.addChildren(Change.addChange(null, change));
}
@@ -272,7 +272,7 @@
adopt(loaded);
roles.add(loaded);
ISeamProject p = getSeamProject();
- if(p != null) p.getVariables().add(loaded);
+ if(p != null) p.addVariable(loaded);
Change change = new Change(this, null, null, loaded);
children.addChildren(Change.addChange(null, change));
} else {
@@ -284,7 +284,7 @@
for (Role r: roleMap.values()) {
roles.remove(r);
ISeamProject p = getSeamProject();
- if(p != null) p.getVariables().remove(r);
+ if(p != null) p.removeVariable(r);
Change change = new Change(this, null, r, null);
children.addChildren(Change.addChange(null, change));
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2007-11-19
11:55:52 UTC (rev 4970)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2007-11-19
15:51:19 UTC (rev 4971)
@@ -49,7 +49,6 @@
import org.jboss.tools.seam.core.ScopeType;
import org.jboss.tools.seam.core.SeamCoreBuilder;
import org.jboss.tools.seam.core.SeamCorePlugin;
-import org.jboss.tools.seam.core.SeamPreferences;
import org.jboss.tools.seam.core.event.Change;
import org.jboss.tools.seam.core.event.ISeamProjectChangeListener;
import org.jboss.tools.seam.core.event.SeamProjectChangeEvent;
@@ -102,7 +101,10 @@
protected Set<ISeamFactory> allFactories = new HashSet<ISeamFactory>();
Set<ISeamContextVariable> allVariables = new
HashSet<ISeamContextVariable>();
-
+
+ Set<ISeamContextVariable> allVariablesCopy = null;
+ Set<ISeamContextVariable> allVariablesPlusShort = null;
+
Map<String, SeamJavaComponentDeclaration> javaDeclarations = new
HashMap<String, SeamJavaComponentDeclaration>();
Map<String, ISeamPackage> packages = new HashMap<String, ISeamPackage>();
@@ -572,9 +574,9 @@
revalidateLock++;
if(ds.getImports().size() > 0) {
- imports.put(source.toString(), ds.getImports());
- } else if(imports.containsKey(source.toString())) {
- imports.remove(source.toString());
+ setImports(source.toString(), ds.getImports());
+ } else {
+ removeImports(source.toString());
}
Map<Object,ISeamComponentDeclaration> currentComponents =
findComponentDeclarations(source);
@@ -624,7 +626,7 @@
ScopeType scopeType = loaded.getScope();
c = newComponent(name, scopeType);
allComponents.put(name, c);
- allVariables.add(c);
+ addVariable(c);
c.addDeclaration(loaded);
addedComponents = Change.addChange(addedComponents, new Change(this, null, null,
c));
} else if(c != null) {
@@ -636,7 +638,7 @@
if(loaded instanceof ISeamJavaComponentDeclaration) {
SeamJavaComponentDeclaration jd = (SeamJavaComponentDeclaration)loaded;
javaDeclarations.put(jd.getClassName(), jd);
- allVariables.addAll(jd.getDeclaredVariables());
+ for (ISeamContextVariable v: jd.getDeclaredVariables()) addVariable(v);
Set<ISeamComponent> cs = getComponentsByClass(jd.getClassName());
for (ISeamComponent ci: cs) {
if(ci == c) continue;
@@ -671,7 +673,7 @@
adopt(factories[i]);
}
allFactories.add(factories[i]);
- allVariables.add(factories[i]);
+ addVariable(factories[i]);
addedFactories = Change.addChange(addedFactories, new Change(this, null, null,
loaded));
}
fireChanges(addedFactories);
@@ -762,7 +764,7 @@
public void pathRemoved(IPath source) {
if(!sourcePaths.contains(source)) return;
sourcePaths.remove(source);
- imports.remove(source.toString());
+ removeImports(source.toString());
revalidateLock++;
Iterator<SeamComponent> iterator = allComponents.values().iterator();
while(iterator.hasNext()) {
@@ -776,7 +778,7 @@
SeamJavaComponentDeclaration jd = (SeamJavaComponentDeclaration)ds[i];
String className = jd.getClassName();
javaDeclarations.remove(className);
- allVariables.removeAll(jd.getDeclaredVariables());
+ for (ISeamContextVariable v: jd.getDeclaredVariables()) removeVariable(v);
}
changes = Change.addChange(changes, new Change(c, null, ds[i], null));
}
@@ -796,9 +798,8 @@
if(source.equals(f.getSourcePath())) {
List<Change> changes = Change.addChange(null, new Change(this, null, f,
null));
factories.remove();
- allVariables.remove(f);
+ removeVariable(f);
fireChanges(changes);
-// System.out.println("Factory removed 1 " + f.getName());
}
}
@@ -844,7 +845,7 @@
if(javaDeclarations.get(className) == jd) {
javaDeclarations.remove(className);
}
- allVariables.removeAll(jd.getDeclaredVariables());
+ for (ISeamContextVariable v: jd.getDeclaredVariables()) removeVariable(v);
}
}
@@ -877,7 +878,7 @@
((SeamScope)p).removeComponent(c);
changes = Change.addChange(null, new Change(p, null, c, null));
}
- allVariables.remove(c);
+ removeVariable(c);
changes = Change.addChange(changes, new Change(this, null, c, null));
return changes;
}
@@ -918,8 +919,7 @@
AbstractContextVariable c = (AbstractContextVariable)iterator.next();
if(removed.containsKey(c.getId())) {
iterator.remove();
- allVariables.remove(c);
-// System.out.println("Factory removed 2 " + c.getName());
+ removeVariable(c);
changes = Change.addChange(changes, new Change(this, null, c, null));
}
}
@@ -977,26 +977,73 @@
* @see org.jboss.tools.seam.core.ISeamProject#getVariables()
*/
public Set<ISeamContextVariable> getVariables() {
- return allVariables;
+ Set<ISeamContextVariable> vs = allVariablesCopy;
+ if(vs == null) {
+ synchronized(this) {
+ allVariablesCopy = new HashSet<ISeamContextVariable>();
+ allVariablesCopy.addAll(allVariables);
+ vs = allVariablesCopy;
+ }
+ }
+ return vs;
}
+
+ public synchronized void addVariable(ISeamContextVariable v) {
+ allVariablesCopy = null;
+ allVariablesPlusShort = null;
+ allVariables.add(v);
+ }
+ public synchronized void removeVariable(ISeamContextVariable v) {
+ allVariablesCopy = null;
+ allVariablesPlusShort = null;
+ allVariables.remove(v);
+ }
+
+ public synchronized void setImports(String source, List<String> paths) {
+ if(equalLists(imports.get(source), paths)) return;
+ allVariablesPlusShort = null;
+ imports.put(source, paths);
+ }
+
+ private boolean equalLists(List<String> s1, List<String> s2) {
+ if(s1 == null || s2 == null) return s1 == s2;
+ if(s1.size() != s2.size()) return false;
+ for (int i = 0; i < s1.size(); i++) {
+ if(!s1.get(i).equals(s2.get(i))) return false;
+ }
+ return true;
+ }
+
+ public synchronized void removeImports(String source) {
+ if(!imports.containsKey(source)) return;
+ allVariablesPlusShort = null;
+ imports.remove(source);
+ }
+
/**
* @see org.jboss.tools.seam.core.ISeamProject#getVariables()
*/
public Set<ISeamContextVariable> getVariables(boolean includeShortNames) {
+ Set<ISeamContextVariable> vs = getVariables();
if(!includeShortNames) {
- return allVariables;
+ return vs;
}
- Set<ISeamContextVariable> result = new HashSet<ISeamContextVariable>();
- result.addAll(allVariables);
- for (ISeamContextVariable v: allVariables) {
- String n = v.getName();
- int i = n.lastIndexOf('.');
- if(i < 0) continue;
- String packageName = n.substring(0, i);
- if(isImportedPackage(packageName)) {
- result.add(new SeamContextShortVariable(v));
+ Set<ISeamContextVariable> result = allVariablesPlusShort;
+ if(result != null) return result;
+ synchronized (this) {
+ result = new HashSet<ISeamContextVariable>();
+ result.addAll(vs);
+ for (ISeamContextVariable v: vs) {
+ String n = v.getName();
+ int i = n.lastIndexOf('.');
+ if(i < 0) continue;
+ String packageName = n.substring(0, i);
+ if(isImportedPackage(packageName)) {
+ result.add(new SeamContextShortVariable(v));
+ }
}
+ allVariablesPlusShort = result;
}
return result;
}
@@ -1134,8 +1181,7 @@
*/
public void removeFactory(ISeamFactory factory) {
allFactories.remove(factory);
-// System.out.println("Factory removed 3 " + factory.getName());
- allVariables.remove(factory);
+ removeVariable(factory);
}
/**