Fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=263098.
Reduce unnecessary reinitialization during attribute validation.
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/region/Region2AttrAdapter.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/region/Region2AttrAdapter.java
index cd29bb9..b1c62db 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/region/Region2AttrAdapter.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/region/Region2AttrAdapter.java
@@ -128,4 +128,14 @@
return ((IDOMAttr) attrAsNode);
}
+
+ @Override
+ public String toString()
+ {
+ return String.format("Region2AttrAdapter: attr=%s, owningElement=%s"
+ , _attr.getNodeName(), getOwningElement().getNodeName());
+
+ }
+
+
}
\ No newline at end of file
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/DTAppManagerUtil.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/DTAppManagerUtil.java
index 8d97815..595d48f 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/DTAppManagerUtil.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/designtime/DTAppManagerUtil.java
@@ -149,13 +149,25 @@
{
return null;
}
+ final IResource resource = resolver.getResource();
+ if (resource != null)
+ {
+ return getViewRootHandle(resource);
+ }
+ return null;
+ }
+ /**
+ * @param res
+ * @return the view root handle for the resource
+ */
+ public static IViewRootHandle getViewRootHandle(final IResource res)
+ {
final DesignTimeApplicationManager manager = DesignTimeApplicationManager
- .getInstance(project);
+ .getInstance(res.getProject());
if (manager != null)
{
- final IResource res = resolver.getResource();
if (res instanceof IFile)
{
final DTFacesContext facesContext = manager
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/JSFValidationContext.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/JSFValidationContext.java
index 0901a0e..baae123 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/JSFValidationContext.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/JSFValidationContext.java
@@ -11,7 +11,9 @@
package org.eclipse.jst.jsf.validation.internal;
import org.eclipse.core.resources.IFile;
+import org.eclipse.jst.jsf.designtime.DTAppManagerUtil;
import org.eclipse.jst.jsf.designtime.internal.view.IDTViewHandler;
+import org.eclipse.jst.jsf.designtime.internal.view.IViewRootHandle;
import org.eclipse.jst.jsf.designtime.resolver.IStructuredDocumentSymbolResolverFactory;
import org.eclipse.jst.jsf.validation.internal.IJSFViewValidator.IValidationReporter;
import org.eclipse.jst.jsf.validation.internal.el.diagnostics.DiagnosticFactory;
@@ -32,6 +34,8 @@
private final IFile _file;
private final IValidationReporter _reporter;
private final IStructuredDocumentSymbolResolverFactory _symbolResolverFactory;
+ // defer initializing this until is asked for because it is expensive
+ private IViewRootHandle _viewRootHandle;
/**
* @param isIncremental --
@@ -133,4 +137,23 @@
return _symbolResolverFactory;
}
+ /**
+ * This method will be long running on first call, since it has to update
+ * the view root if not initialized.
+ *
+ * @return the view root handle
+ */
+ public IViewRootHandle getViewRootHandle()
+ {
+ if (_viewRootHandle == null)
+ {
+ _viewRootHandle = DTAppManagerUtil.getViewRootHandle(_file);
+ if (_viewRootHandle.getCachedViewRoot() == null)
+ {
+ _viewRootHandle.updateViewRoot();
+ }
+ }
+ return _viewRootHandle;
+ }
+
}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/AttributeValidatingStrategy.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/AttributeValidatingStrategy.java
index 9963d7b..a42828c 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/AttributeValidatingStrategy.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/strategy/AttributeValidatingStrategy.java
@@ -48,7 +48,6 @@
import org.eclipse.jst.jsf.core.jsfappconfig.JSFAppConfigManager;
import org.eclipse.jst.jsf.designtime.DTAppManagerUtil;
import org.eclipse.jst.jsf.designtime.internal.view.DTUIViewRoot;
-import org.eclipse.jst.jsf.designtime.internal.view.IViewRootHandle;
import org.eclipse.jst.jsf.designtime.internal.view.XMLViewDefnAdapter;
import org.eclipse.jst.jsf.designtime.internal.view.XMLViewObjectMappingService;
import org.eclipse.jst.jsf.designtime.internal.view.IDTViewHandler.ViewHandlerException;
@@ -103,8 +102,7 @@
*
* @param validationContext
*/
- public AttributeValidatingStrategy(
- final JSFValidationContext validationContext)
+ public AttributeValidatingStrategy(final JSFValidationContext validationContext)
{
super(ID, DISPLAY_NAME);
@@ -125,6 +123,7 @@
{
if (domAdapter instanceof AttrDOMAdapter)
{
+ final long curTime = System.nanoTime();
final Region2AttrAdapter attrAdapter = (Region2AttrAdapter) domAdapter;
// check that this is attribute value region - 221722
if (attrAdapter.getAttributeValueRegion() != null)
@@ -139,6 +138,12 @@
validateAttributeValue(context, attrAdapter);
}
+ if (DEBUG)
+ {
+ System.out.println(String.format("Validation for attribute: %s took %d"
+ , domAdapter.toString()
+ , Long.valueOf(System.nanoTime()-curTime)));
+ }
}
}
@@ -410,11 +415,11 @@
* @return true if alternative type comparison (i.e. post-conversion) passes
*/
private CompositeType maybeAddAlternativeTypes(
- final CompositeType expectedType,
- final CompositeType exprTypes,
+ final CompositeType expectedType, final CompositeType exprTypes,
final Region2ElementAdapter elementAdapter,
final Region2AttrAdapter attrAdapter)
{
+ final long curTime = System.nanoTime();
if (disableAlternativeTypes())
{
return expectedType;
@@ -422,54 +427,58 @@
final IStructuredDocumentContext context = elementAdapter
.getDocumentContext();
- final IViewRootHandle viewRootHandle = DTAppManagerUtil
- .getViewRootHandle(context);
- if (viewRootHandle != null)
+ final DTUIViewRoot viewRoot = _validationContext.getViewRootHandle().getCachedViewRoot();
+ final IAdaptable serviceAdaptable = viewRoot.getServices();
+ final XMLViewObjectMappingService mappingService = (XMLViewObjectMappingService) serviceAdaptable
+ .getAdapter(XMLViewObjectMappingService.class);
+ if (mappingService != null)
{
- // ok to call update view root here since validation not called
- // on the UI thread.
- final DTUIViewRoot viewRoot = viewRootHandle.updateViewRoot();
- final IAdaptable serviceAdaptable = viewRoot.getServices();
- final XMLViewObjectMappingService mappingService = (XMLViewObjectMappingService) serviceAdaptable
- .getAdapter(XMLViewObjectMappingService.class);
- if (mappingService != null)
+ final ElementData elementData = XMLViewObjectMappingService
+ .createElementData(elementAdapter.getNamespace(),
+ elementAdapter.getLocalName(), context,
+ Collections.EMPTY_MAP);
+ final ViewObject viewObject = mappingService
+ .findViewObject(elementData);
+ // if the corresponding view object is a valueholder, then
+ // we need to see if you think there a valid conversion
+ // available
+ if (viewObject instanceof ComponentInfo
+ && ((ComponentInfo) viewObject).getComponentTypeInfo() != null
+ && ((ComponentInfo) viewObject).getComponentTypeInfo()
+ .isInstanceOf(
+ ComponentFactory.INTERFACE_VALUEHOLDER))
{
- final ElementData elementData = XMLViewObjectMappingService
- .createElementData(elementAdapter.getNamespace(),
- elementAdapter.getLocalName(), context,
- Collections.EMPTY_MAP);
- final ViewObject viewObject = mappingService
- .findViewObject(elementData);
- // if the corresponding view object is a valueholder, then
- // we need to see if you think there a valid conversion
- // available
- if (viewObject instanceof ComponentInfo
- && ((ComponentInfo) viewObject).getComponentTypeInfo() != null
- && ((ComponentInfo) viewObject).getComponentTypeInfo()
- .isInstanceOf(
- ComponentFactory.INTERFACE_VALUEHOLDER))
+ final ComponentInfo component = (ComponentInfo) viewObject;
+ // get the original elementData
+ final ElementData mappedElementData = mappingService
+ .findElementData(component);
+ final String propName = mappedElementData
+ .getPropertyName(attrAdapter.getLocalName());
+ if ("value".equals(propName)) //$NON-NLS-1$
{
- final ComponentInfo component = (ComponentInfo) viewObject;
- // get the original elementData
- final ElementData mappedElementData = mappingService
- .findElementData(component);
- final String propName = mappedElementData
- .getPropertyName(attrAdapter.getLocalName());
- if ("value".equals(propName)) //$NON-NLS-1$
- {
- // final List converters =
- // component.getDecorators(ComponentFactory.CONVERTER);
+ // final List converters =
+ // component.getDecorators(ComponentFactory.CONVERTER);
- // (ConverterDecorator) it.next();
- return createCompositeType(
- expectedType,
- exprTypes,
- component
- .getDecorators(ComponentFactory.CONVERTER));
+ // (ConverterDecorator) it.next();
+ final CompositeType alternativeTypes = createCompositeType(
+ expectedType, exprTypes, component
+ .getDecorators(ComponentFactory.CONVERTER));
+ if (DEBUG)
+ {
+ System.out.println(String.format(
+ "maybeAddAlternative took %d", Long.valueOf(System
+ .nanoTime()
+ - curTime)));
}
+ return alternativeTypes;
}
}
}
+ if (DEBUG)
+ {
+ System.out.println(String.format("maybeAddAlternative took %d", Long
+ .valueOf(System.nanoTime() - curTime)));
+ }
// don't add anything by default
return expectedType;
}