### Eclipse Workspace Patch 1.0 #P org.eclipse.jst.jsp.core Index: src/org/eclipse/jst/jsp/core/internal/modelquery/JSPModelQueryImpl.java =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/modelquery/JSPModelQueryImpl.java,v retrieving revision 1.7 diff -u -r1.7 JSPModelQueryImpl.java --- src/org/eclipse/jst/jsp/core/internal/modelquery/JSPModelQueryImpl.java 19 Apr 2007 04:42:35 -0000 1.7 +++ src/org/eclipse/jst/jsp/core/internal/modelquery/JSPModelQueryImpl.java 24 Feb 2010 04:17:38 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,6 +13,8 @@ import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.WeakHashMap; import org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapter; import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver; @@ -23,6 +25,7 @@ import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; +import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.IModelQueryExtension; import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; import org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.ModelQueryImpl; import org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.SimpleAssociationProvider; @@ -31,11 +34,13 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; -public class JSPModelQueryImpl extends ModelQueryImpl { +public class JSPModelQueryImpl extends ModelQueryImpl implements IModelQueryExtension { // ISSUE: jspModel doesn't seem used? protected IStructuredModel jspModel = null; private HashMap embeddedModelQueries = new HashMap(); + private Map fQuerySessionCache = null; + private int fQuerySession; public JSPModelQueryImpl(IStructuredModel model, URIResolver resolver) { super(new SimpleAssociationProvider(new JSPModelQueryCMProvider())); @@ -46,13 +51,25 @@ * @see ModelQuery#getCMElementDeclaration(Element) */ public CMElementDeclaration getCMElementDeclaration(Element element) { - CMElementDeclaration result = super.getCMElementDeclaration(element); + CMElementDeclaration result = null; + if (fQuerySessionCache != null) { + result = (CMElementDeclaration) getQuerySessionCache().get(element); + if (result != null) + return result; + } + + result = super.getCMElementDeclaration(element); if (result == null) { ModelQuery query = getEmbeddedModelQuery(element); if (query != null) { result = query.getCMElementDeclaration(element); } } + + if (result != null && fQuerySessionCache != null) { + getQuerySessionCache().put(element, result); + } + return result; } @@ -160,4 +177,26 @@ public ModelQuery internalTestOnly_getEmbeddedModelQuery(Node node) { return getEmbeddedModelQuery(node); } + + public void startQuerySession() { + if (fQuerySession++ == 0) { + fQuerySessionCache = new WeakHashMap(); + } + } + + public void stopQuerySession() { + if (--fQuerySession == 0) { + fQuerySessionCache = null; + } + } + + /** + * @return the querySessionCache + */ + private Map getQuerySessionCache() { + Map map = fQuerySessionCache; + if (map != null) + return map; + return new HashMap(); + } } Index: src/org/eclipse/jst/jsp/core/internal/validation/JSPActionValidator.java =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/validation/JSPActionValidator.java,v retrieving revision 1.13 diff -u -r1.13 JSPActionValidator.java --- src/org/eclipse/jst/jsp/core/internal/validation/JSPActionValidator.java 12 Jan 2010 20:13:20 -0000 1.13 +++ src/org/eclipse/jst/jsp/core/internal/validation/JSPActionValidator.java 24 Feb 2010 04:17:38 -0000 @@ -56,6 +56,7 @@ import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; import org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl; +import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.IModelQueryExtension; import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; import org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper; @@ -381,28 +382,39 @@ loadPreferences(f); IStructuredDocument sDoc = model.getStructuredDocument(); - fIsELIgnored = isElIgnored(f.getFullPath(), model); - // iterate all document regions - IStructuredDocumentRegion region = sDoc.getRegionAtCharacterOffset(validateRegion.getOffset()); - while (region != null && !reporter.isCancelled() && (region.getStartOffset() <= (validateRegion.getOffset() + validateRegion.getLength()))) { - if (region.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) { - // only checking directives - processDirective(reporter, f, model, region); - fTaglibPrefixes.clear(); - } - else if (region.getType() == DOMRegionContext.XML_TAG_NAME) { - // and jsp tags - String tagName = getStartTagName(region); - int colonPosition = tagName.indexOf(':'); - if (colonPosition > -1) { - // get tag's prefix and check if it's really a jsp action - // tag - String prefix = tagName.substring(0, colonPosition); - if (getTaglibPrefixes(sDoc).contains(prefix)) - processDirective(reporter, f, model, region); + ModelQuery mq = ModelQueryUtil.getModelQuery(model); + try { + if (mq instanceof IModelQueryExtension) { + ((IModelQueryExtension) mq).startQuerySession(); + } + fIsELIgnored = isElIgnored(f.getFullPath(), model); + // iterate all document regions + IStructuredDocumentRegion region = sDoc.getRegionAtCharacterOffset(validateRegion.getOffset()); + while (region != null && !reporter.isCancelled() && (region.getStartOffset() <= (validateRegion.getOffset() + validateRegion.getLength()))) { + if (region.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) { + // only checking directives + processDirective(reporter, f, model, region); + fTaglibPrefixes.clear(); + } + else if (region.getType() == DOMRegionContext.XML_TAG_NAME) { + // and jsp tags + String tagName = getStartTagName(region); + int colonPosition = tagName.indexOf(':'); + if (colonPosition > -1) { + // get tag's prefix and check if it's really a jsp action + // tag + String prefix = tagName.substring(0, colonPosition); + if (getTaglibPrefixes(sDoc).contains(prefix)) + processDirective(reporter, f, model, region); + } } + region = region.getNext(); + } + } + finally { + if (mq instanceof IModelQueryExtension) { + ((IModelQueryExtension) mq).stopQuerySession(); } - region = region.getNext(); } unloadPreferences(); } Index: src/org/eclipse/jst/jsp/core/internal/validation/JSPContentValidator.java =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/validation/JSPContentValidator.java,v retrieving revision 1.3 diff -u -r1.3 JSPContentValidator.java --- src/org/eclipse/jst/jsp/core/internal/validation/JSPContentValidator.java 21 Oct 2008 02:53:35 -0000 1.3 +++ src/org/eclipse/jst/jsp/core/internal/validation/JSPContentValidator.java 24 Feb 2010 04:17:38 -0000 @@ -32,7 +32,10 @@ import org.eclipse.wst.validation.ValidationResult; import org.eclipse.wst.validation.ValidationState; import org.eclipse.wst.validation.internal.provisional.core.IReporter; +import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.IModelQueryExtension; +import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; import org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter; +import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; import org.eclipse.wst.xml.core.internal.validation.eclipse.Validator; @@ -204,7 +207,20 @@ HTMLValidationReporter rep = getReporter(reporter, file, model); rep.clear(); adapter.setReporter(rep); - adapter.validate(document); + + ModelQuery mq = ModelQueryUtil.getModelQuery(document); + try { + if (mq instanceof IModelQueryExtension) { + ((IModelQueryExtension) mq).startQuerySession(); + } + + adapter.validate(document); + } + finally { + if (mq instanceof IModelQueryExtension) { + ((IModelQueryExtension) mq).stopQuerySession(); + } + } } } #P org.eclipse.wst.html.core Index: src/org/eclipse/wst/html/core/internal/modelquery/HTMLModelQueryImpl.java =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/modelquery/HTMLModelQueryImpl.java,v retrieving revision 1.6 diff -u -r1.6 HTMLModelQueryImpl.java --- src/org/eclipse/wst/html/core/internal/modelquery/HTMLModelQueryImpl.java 10 Apr 2007 18:31:49 -0000 1.6 +++ src/org/eclipse/wst/html/core/internal/modelquery/HTMLModelQueryImpl.java 24 Feb 2010 04:17:38 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,14 +11,18 @@ package org.eclipse.wst.html.core.internal.modelquery; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Vector; +import java.util.WeakHashMap; import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver; import org.eclipse.wst.html.core.internal.provisional.HTMLCMProperties; import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; import org.eclipse.wst.xml.core.internal.contentmodel.CMNode; +import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.IModelQueryExtension; import org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.ModelQueryImpl; import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache; import org.eclipse.wst.xml.core.internal.modelquery.XMLModelQueryAssociationProvider; @@ -33,10 +37,12 @@ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=119084 */ -public class HTMLModelQueryImpl extends ModelQueryImpl implements MovableModelQuery { +public class HTMLModelQueryImpl extends ModelQueryImpl implements MovableModelQuery, IModelQueryExtension { protected CMDocumentCache fCache = null; protected XMLModelQueryAssociationProvider xmlAssocProv = null; + private Map fQuerySessionCache = null; + private int fQuerySession; public HTMLModelQueryImpl(CMDocumentCache cache, URIResolver idResolver) { super(new HTMLModelQueryAssociationProvider(cache, idResolver)); @@ -146,11 +152,47 @@ } public CMElementDeclaration getCMElementDeclaration(Element element) { - CMElementDeclaration result = super.getCMElementDeclaration(element); - if (null != result) - return result; - - return xmlAssocProv.getCMElementDeclaration(element); + CMElementDeclaration result = null; + if (fQuerySessionCache != null) { + result = (CMElementDeclaration) getQuerySessionCache().get(element); + if (result != null) + return result; + } + + if (null == result) { + result = super.getCMElementDeclaration(element); + } + + if (null == result) { + result = xmlAssocProv.getCMElementDeclaration(element); + } + + if (result != null && fQuerySessionCache != null) { + getQuerySessionCache().put(element, result); + } + + return result; } + public void startQuerySession() { + if (fQuerySession++ == 0) { + fQuerySessionCache = new WeakHashMap(); + } + } + + public void stopQuerySession() { + if (--fQuerySession == 0) { + fQuerySessionCache = null; + } + } + + /** + * @return the querySessionCache + */ + private Map getQuerySessionCache() { + Map map = fQuerySessionCache; + if (map != null) + return map; + return new HashMap(); + } } #P org.eclipse.wst.html.ui Index: src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidator.java =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.html.ui/src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidator.java,v retrieving revision 1.26 diff -u -r1.26 HTMLValidator.java --- src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidator.java 17 Feb 2009 01:44:39 -0000 1.26 +++ src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidator.java 24 Feb 2010 04:17:39 -0000 @@ -65,7 +65,10 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter; import org.eclipse.wst.validation.internal.provisional.core.IValidationContext; import org.eclipse.wst.validation.internal.provisional.core.IValidatorJob; +import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.IModelQueryExtension; +import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; import org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter; +import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; import org.w3c.dom.Text; @@ -429,7 +432,20 @@ HTMLValidationReporter rep = getReporter(reporter, file, model); rep.clear(); adapter.setReporter(rep); - adapter.validate(document); + + ModelQuery mq = ModelQueryUtil.getModelQuery(document); + try { + if (mq instanceof IModelQueryExtension) { + ((IModelQueryExtension) mq).startQuerySession(); + } + + adapter.validate(document); + } + finally { + if (mq instanceof IModelQueryExtension) { + ((IModelQueryExtension) mq).stopQuerySession(); + } + } return rep.getResult(); } #P org.eclipse.wst.xml.core Index: src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/IModelQueryExtension.java =================================================================== RCS file: src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/IModelQueryExtension.java diff -N src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/IModelQueryExtension.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src-contentmodel/org/eclipse/wst/xml/core/internal/contentmodel/modelquery/IModelQueryExtension.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.wst.xml.core.internal.contentmodel.modelquery; + +/** + * Defines the ability to start and stop a "query session", during which time + * the model query can assume queried documents will be relatively unchanged + * and may employ performance tuning. + */ +public interface IModelQueryExtension { + /** + * Indicate to this model query that a "query session" is beginning, in + * which many lookups of declarations will occur. + */ + void startQuerySession(); + + /** + * Indicate to this model query that a "query session" has ended. + */ + void stopQuerySession(); +}