Author: vrubezhny
Date: 2009-11-26 09:40:18 -0500 (Thu, 26 Nov 2009)
New Revision: 18853
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java
Log:
JBIDE-5119: Refactor PageContextFactory to improve perfomance of context creation
cleanUp() methods are made due to allow the KbBuilder to clean up the cached contexts
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java 2009-11-26
14:14:46 UTC (rev 18852)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java 2009-11-26
14:40:18 UTC (rev 18853)
@@ -162,6 +162,42 @@
public static ELContext createPageContext(IFile file) {
return getInstance().createPageContext(file, null);
}
+
+ public void cleanUp(IFile file) {
+ if (file == null)
+ return;
+ synchronized (cache) {
+ ELContext removedContext = removeSavedContext(file);
+ if (removedContext == null || removedContext.getResource() == null)
+ return;
+
+ // Remove all the contexts that are parent to the removed context
+ Collection<ELContext> contexts = cache.values();
+ if (contexts != null) {
+ for (ELContext context : contexts) {
+ if (isDependencyContext(context, file)) {
+ removeSavedContext(file);
+ }
+ }
+ }
+ }
+ }
+
+ public void cleanUp(IProject project) {
+ if (project == null)
+ return;
+ synchronized (cache) {
+ // Remove all the contexts that are parent to the removed context
+ Collection<IFile> files = cache.keySet();
+ if (files != null) {
+ for (IFile file : files) {
+ if (project.equals(file.getProject())) {
+ cleanUp(file);
+ }
+ }
+ }
+ }
+ }
// long ctm = 0;
// String getContextType1(IFile file) {
@@ -872,13 +908,13 @@
int kind = delta.getKind();
IResource resource = delta.getResource();
- if(kind == IResourceDelta.CHANGED ||
- kind == IResourceDelta.ADDED ||
- kind == IResourceDelta.REMOVED ||
- kind == IResourceDelta.CONTENT) {
- cleanUpChachedResource(resource);
-// } else {
-// System.out.println("Resource modified [" + kind + "]: " +
resource.getFullPath());
+ if( resource instanceof IProject && (
+// kind == IResourceDelta.CHANGED ||
+// kind == IResourceDelta.ADDED ||
+ kind == IResourceDelta.REMOVED // ||
+// kind == IResourceDelta.CONTENT)
+ )) {
+ cleanUp((IProject)resource);
}
IResourceDelta[] cs = delta.getAffectedChildren();
@@ -888,26 +924,6 @@
return;
}
- private void cleanUpChachedResource(IResource resource) {
- if (resource instanceof IFile) {
- synchronized (cache) {
- ELContext removedContext = removeSavedContext((IFile)resource);
- if (removedContext == null || removedContext.getResource() == null)
- return;
-
- // Remove all the contexts that are parent to the removed context
- Collection<ELContext> contexts = cache.values();
- if (contexts != null) {
- for (ELContext context : contexts) {
- if (isDependencyContext(context, (IFile)resource)) {
- removeSavedContext((IFile)resource);
- }
- }
- }
- }
- }
- }
-
private boolean isDependencyContext(ELContext context, IFile resource) {
if (resource.equals(context.getResource())) {
return true;
@@ -964,7 +980,7 @@
for (ELContext context : contexts) {
if (context instanceof XmlContextImpl &&
event.getDocument().equals(((XmlContextImpl)context).getDocument())) {
- cleanUpChachedResource(context.getResource());
+ cleanUp(context.getResource());
return;
}
}
Show replies by date