Author: akazakov
Date: 2009-10-15 09:11:18 -0400 (Thu, 15 Oct 2009)
New Revision: 18106
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.properties
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ELValidatorContext.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/LinkCollection.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ProjectValidationContext.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4978
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.java 2009-10-15
13:11:18 UTC (rev 18106)
@@ -0,0 +1,27 @@
+ /*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.web.kb;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * @author Alexey Kazakov
+ */
+public class KbMessages {
+ private static final String BUNDLE_NAME =
"org.jboss.tools.jst.web.kb.KBMessages"; //$NON-NLS-1$
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, KbMessages.class);
+ }
+
+ public static String VALIDATION_CONTEXT_LINKED_RESOURCE_PATH_MUST_NOT_BE_NULL;
+ public static String VALIDATION_CONTEXT_VARIABLE_NAME_MUST_NOT_BE_NULL;
+}
\ No newline at end of file
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.properties
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.properties
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.properties 2009-10-15
13:11:18 UTC (rev 18106)
@@ -0,0 +1,2 @@
+VALIDATION_CONTEXT_LINKED_RESOURCE_PATH_MUST_NOT_BE_NULL=Linked resource path must not be
null\!
+VALIDATION_CONTEXT_VARIABLE_NAME_MUST_NOT_BE_NULL=Variable name must not be null\!
\ No newline at end of file
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ELValidatorContext.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ELValidatorContext.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ELValidatorContext.java 2009-10-15
13:11:18 UTC (rev 18106)
@@ -0,0 +1,192 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.web.kb.internal.validation;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IPath;
+import org.jboss.tools.common.xml.XMLUtilities;
+import org.jboss.tools.jst.web.kb.validation.ELReference;
+import org.w3c.dom.Element;
+
+/**
+ * @author Alexey Kazakov
+ */
+public class ELValidatorContext extends LinkCollection {
+
+ private Map<String, Set<ELReference>> elsByVariableName = new
HashMap<String, Set<ELReference>>();
+ private Map<ELReference, Set<String>> variableNamesByEl = new
HashMap<ELReference, Set<String>>();
+ private Map<IPath, Set<ELReference>> elsByResource = new HashMap<IPath,
Set<ELReference>>();
+
+ /**
+ * Save link between EL and variable name.
+ * @param variableName
+ * @param el
+ */
+ public synchronized void addLinkedEl(String variableName, ELReference el) {
+ Set<ELReference> linkedEls = elsByVariableName.get(variableName);
+ if(linkedEls==null) {
+ // create set of linked ELs with variable name.
+ linkedEls = new HashSet<ELReference>();
+ elsByVariableName.put(variableName, linkedEls);
+ }
+ // save linked ELs.
+ linkedEls.add(el);
+
+ // Save link between EL and variable names.
+ Set<String> variableNames = variableNamesByEl.get(el);
+ if(variableNames==null) {
+ variableNames = new HashSet<String>();
+ variableNamesByEl.put(el, variableNames);
+ }
+ variableNames.add(variableName);
+
+ // Save link between EL and resource.
+ Set<ELReference> els = elsByResource.get(el.getPath());
+ if(els==null) {
+ els = new HashSet<ELReference>();
+ elsByResource.put(el.getPath(), els);
+ }
+ els.add(el);
+ }
+
+ public synchronized void removeLinkedEls(Set<IFile> resorces) {
+ for (IFile file : resorces) {
+ removeLinkedEls(file);
+ }
+ }
+
+ public synchronized void removeLinkedEls(IFile resource) {
+ Set<ELReference> els = elsByResource.get(resource.getFullPath());
+ if(els!=null) {
+ elsByResource.remove(resource.getFullPath());
+ for (ELReference el : els) {
+ Set<String> names = variableNamesByEl.get(el);
+ if(names!=null) {
+ String[] nameStrins = names.toArray(new String[0]);
+ for (int i = 0; i < nameStrins.length; i++) {
+ removeLinkedEl(nameStrins[i], el);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Removes link between EL and variable name.
+ * @param name
+ * @param el
+ */
+ public synchronized void removeLinkedEl(String name, ELReference el) {
+ Set<ELReference> linkedEls = elsByVariableName.get(name);
+ if(linkedEls!=null) {
+ linkedEls.remove(el);
+ }
+ if(linkedEls.isEmpty()) {
+ elsByVariableName.remove(name);
+ }
+
+ // Remove link between EL and variable names.
+ Set<String> variableNames = variableNamesByEl.get(el);
+ if(variableNames!=null) {
+ variableNames.remove(name);
+ }
+ if(variableNames.isEmpty()) {
+ variableNamesByEl.remove(el);
+ }
+ }
+
+ /**
+ * Return ELs with given variable name
+ * @param variableName
+ * @return
+ */
+ public synchronized Set<ELReference> getElsByVariableName(String variableName) {
+ return elsByVariableName.get(variableName);
+ }
+
+ /**
+ * @param names
+ * @return
+ */
+ public synchronized Set<ELReference> getElsByVariableNames(Set<String>
names) {
+ Set<ELReference> result = new HashSet<ELReference>();
+ for(String name : names) {
+ Set<ELReference> els = getElsByVariableName(name);
+ if(els!=null) {
+ result.addAll(els);
+ }
+ }
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.internal.validation.LinkCollection#clearAll()
+ */
+ @Override
+ public synchronized void clearAll() {
+ super.clearAll();
+ elsByVariableName.clear();
+ variableNamesByEl.clear();
+ elsByResource.clear();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.internal.validation.LinkCollection#store(org.w3c.dom.Element)
+ */
+ @Override
+ public synchronized void store(Element root) {
+ super.store(root);
+ Set<String> variables = elsByVariableName.keySet();
+ for (String name: variables) {
+ Set<ELReference> els = elsByVariableName.get(name);
+ if(els == null) {
+ continue;
+ }
+ for (ELReference el: els) {
+ Element linkedEl = XMLUtilities.createElement(root, "linked-el");
//$NON-NLS-1$
+ linkedEl.setAttribute("name", name); //$NON-NLS-1$
+ el.store(linkedEl);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.internal.validation.LinkCollection#load(org.w3c.dom.Element)
+ */
+ @Override
+ public synchronized void load(Element root) {
+ super.load(root);
+ if(root == null) {
+ return;
+ }
+ Element[] linkedEls = XMLUtilities.getChildren(root, "linked-el");
//$NON-NLS-1$
+ if(linkedEls != null) {
+ for (int i = 0; i < linkedEls.length; i++) {
+ String name = linkedEls[i].getAttribute("name"); //$NON-NLS-1$
+ if(name == null || name.trim().length() == 0) {
+ continue;
+ }
+ ELReference el = new ELReference();
+ el.load(linkedEls[i]);
+ el.setNeedToInitMarkers(true);
+ addLinkedEl(name, el);
+ }
+ }
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ELValidatorContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/LinkCollection.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/LinkCollection.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/LinkCollection.java 2009-10-15
13:11:18 UTC (rev 18106)
@@ -0,0 +1,277 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.web.kb.internal.validation;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.jboss.tools.common.xml.XMLUtilities;
+import org.jboss.tools.jst.web.kb.KbMessages;
+import org.w3c.dom.Element;
+
+/**
+ * @author Alexey Kazakov
+ */
+public class LinkCollection {
+ protected Map<String, Set<IPath>> resourcesByVariableName = new
HashMap<String, Set<IPath>>();
+ protected Map<IPath, Set<String>> variableNamesByResource = new
HashMap<IPath, Set<String>>();
+ protected Map<String, Set<IPath>> resourcesByDeclaringVariableName = new
HashMap<String, Set<IPath>>();
+ protected Map<IPath, Set<String>> declaringVariableNamesByResource = new
HashMap<IPath, Set<String>>();
+ protected Set<IPath> unnamedResources = new HashSet<IPath>();
+
+ /**
+ * Save link between resource and variable name.
+ * It's needed for incremental validation because we must save all linked resources
of changed java file.
+ */
+ public void addLinkedResource(String variableName, IPath linkedResourcePath, boolean
declaration) {
+ if(linkedResourcePath==null) {
+ throw new
IllegalArgumentException(KbMessages.VALIDATION_CONTEXT_LINKED_RESOURCE_PATH_MUST_NOT_BE_NULL);
+ }
+ if(variableName==null) {
+ throw new
IllegalArgumentException(KbMessages.VALIDATION_CONTEXT_VARIABLE_NAME_MUST_NOT_BE_NULL);
+ }
+
+ synchronized(this) {
+ Set<IPath> linkedResources = resourcesByVariableName.get(variableName);
+ if(linkedResources==null) {
+ // create set of linked resources with variable name.
+ linkedResources = new HashSet<IPath>();
+ resourcesByVariableName.put(variableName, linkedResources);
+ }
+ // save linked resources.
+ linkedResources.add(linkedResourcePath);
+ }
+
+ // Save link between resource and variable names. It's needed if variable name
changes in resource file.
+ Set<String> variableNames = variableNamesByResource.get(linkedResourcePath);
+ if(variableNames==null) {
+ variableNames = new HashSet<String>();
+ variableNamesByResource.put(linkedResourcePath, variableNames);
+ }
+ variableNames.add(variableName);
+
+ if(declaration) {
+ synchronized(this) {
+ Set<IPath> linkedResources =
resourcesByDeclaringVariableName.get(variableName);
+ if(linkedResources==null) {
+ // create set of linked resources with declaring variable name.
+ linkedResources = new HashSet<IPath>();
+ resourcesByDeclaringVariableName.put(variableName, linkedResources);
+ }
+ // save linked resources.
+ linkedResources.add(linkedResourcePath);
+ }
+
+ // Save link between resource and declaring variable names. It's needed if
variable name changes in resource file.
+ variableNames = declaringVariableNamesByResource.get(linkedResourcePath);
+ if(variableNames==null) {
+ variableNames = new HashSet<String>();
+ declaringVariableNamesByResource.put(linkedResourcePath, variableNames);
+ }
+ variableNames.add(variableName);
+ }
+ }
+
+ /**
+ * Removes link between resource and variable name.
+ * @param oldVariableName
+ * @param linkedResourcePath
+ */
+ public void removeLinkedResource(String name, IPath linkedResourcePath) {
+ synchronized(this) {
+ Set<IPath> linkedResources = resourcesByVariableName.get(name);
+ if(linkedResources!=null) {
+ // remove linked resource.
+ linkedResources.remove(linkedResourcePath);
+ }
+ if(linkedResources.isEmpty()) {
+ resourcesByVariableName.remove(name);
+ }
+ }
+ // Remove link between resource and declaring variable names.
+ Set<String> variableNames = variableNamesByResource.get(linkedResourcePath);
+ if(variableNames!=null) {
+ variableNames.remove(name);
+ }
+ if(variableNames.isEmpty()) {
+ variableNamesByResource.remove(linkedResourcePath);
+ }
+ synchronized(this) {
+ Set<IPath> linkedResources = resourcesByDeclaringVariableName.get(name);
+ if(linkedResources!=null) {
+ // remove linked resource.
+ linkedResources.remove(linkedResourcePath);
+ }
+ if(linkedResources.isEmpty()) {
+ resourcesByDeclaringVariableName.remove(name);
+ }
+ }
+ // Remove link between resource and declaring variable names.
+ variableNames = declaringVariableNamesByResource.get(linkedResourcePath);
+ if(variableNames!=null) {
+ variableNames.remove(name);
+ }
+ if(variableNames.isEmpty()) {
+ declaringVariableNamesByResource.remove(linkedResourcePath);
+ }
+ }
+
+ /**
+ * Removes link between resources and variable names.
+ * @param linkedResources
+ */
+ public void removeLinkedResources(Set<IPath> resources) {
+ for (IPath resource : resources) {
+ removeLinkedResource(resource);
+ }
+ }
+
+ /**
+ * Removes link between resource and variable names.
+ * @param linkedResources
+ */
+ public synchronized void removeLinkedResource(IPath resource) {
+ Set<String> resourceNames = variableNamesByResource.get(resource);
+ if(resourceNames!=null) {
+ for (String name : resourceNames) {
+ Set<IPath> linkedResources = resourcesByVariableName.get(name);
+ if(linkedResources!=null) {
+ linkedResources.remove(resource);
+ if(linkedResources.isEmpty()) {
+ resourcesByVariableName.remove(name);
+ }
+ }
+ }
+ }
+ variableNamesByResource.remove(resource);
+
+ resourceNames = declaringVariableNamesByResource.get(resource);
+ if(resourceNames!=null) {
+ for (String name : resourceNames) {
+ Set<IPath> linkedResources = resourcesByDeclaringVariableName.get(name);
+ if(linkedResources!=null) {
+ linkedResources.remove(resource);
+ if(linkedResources.isEmpty()) {
+ resourcesByDeclaringVariableName.remove(name);
+ }
+ }
+ }
+ }
+ declaringVariableNamesByResource.remove(resource);
+ }
+
+ public Set<IPath> getResourcesByVariableName(String variableName, boolean
declaration) {
+ return
declaration?resourcesByDeclaringVariableName.get(variableName):resourcesByVariableName.get(variableName);
+ }
+
+ public synchronized Set<String> getVariableNamesByResource(IPath fullPath, boolean
declaration) {
+ return
declaration?declaringVariableNamesByResource.get(fullPath):variableNamesByResource.get(fullPath);
+ }
+
+ /**
+ * Adds resource without any link to any context variable name.
+ * @param fullPath
+ */
+ public void addUnnamedResource(IPath fullPath) {
+ unnamedResources.add(fullPath);
+ }
+
+ /**
+ * @return Set of resources without any link to any context variable name.
+ * @param fullPath
+ */
+ public Set<IPath> getUnnamedResources() {
+ return unnamedResources;
+ }
+
+ /**
+ * Removes unnamed resource.
+ * @param fullPath
+ */
+ public void removeUnnamedResource(IPath fullPath) {
+ unnamedResources.remove(fullPath);
+ }
+
+ /**
+ * Clear all references
+ */
+ public synchronized void clearAll() {
+ resourcesByVariableName.clear();
+ variableNamesByResource.clear();
+ declaringVariableNamesByResource.clear();
+ resourcesByDeclaringVariableName.clear();
+ unnamedResources.clear();
+ }
+
+ /**
+ * Store the collection to XML
+ * @param root
+ */
+ public synchronized void store(Element root) {
+ Set<String> variables = resourcesByVariableName.keySet();
+ for (String name: variables) {
+ Set<IPath> paths = resourcesByVariableName.get(name);
+ if(paths == null) continue;
+ for (IPath path: paths) {
+ Element linkedResource = XMLUtilities.createElement(root,
"linked-resource"); //$NON-NLS-1$
+ linkedResource.setAttribute("name", name); //$NON-NLS-1$
+ linkedResource.setAttribute("path", path.toString()); //$NON-NLS-1$
+ if(checkDeclaration(path, name)) {
+ linkedResource.setAttribute("declaration", "true");
//$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ }
+ for (IPath unnamedPath: unnamedResources) {
+ Element unnamedPathElement = XMLUtilities.createElement(root,
"unnamed-path"); //$NON-NLS-1$
+ unnamedPathElement.setAttribute("path", unnamedPath.toString());
//$NON-NLS-1$
+ }
+ }
+
+ private boolean checkDeclaration(IPath resource, String variableName) {
+ Set<IPath> paths = resourcesByDeclaringVariableName.get(variableName);
+ if(paths!=null) {
+ for (IPath path : paths) {
+ if(path.equals(resource)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ /**
+ * Load the collection from XML
+ * @param root
+ */
+ public void load(Element root) {
+ if(root == null) return;
+ Element[] linkedResources = XMLUtilities.getChildren(root,
"linked-resource"); //$NON-NLS-1$
+ if(linkedResources != null) for (int i = 0; i < linkedResources.length; i++) {
+ String name = linkedResources[i].getAttribute("name"); //$NON-NLS-1$
+ if(name == null || name.trim().length() == 0) continue;
+ String path = linkedResources[i].getAttribute("path"); //$NON-NLS-1$
+ if(path == null || path.trim().length() == 0) continue;
+ String declaration = linkedResources[i].getAttribute("declaration");
//$NON-NLS-1$
+ boolean declarationFlag = "true".equals(declaration); //$NON-NLS-1$
+ IPath pathObject = new Path(path);
+ addLinkedResource(name, pathObject, declarationFlag);
+ }
+ Element[] unnamedPathElement = XMLUtilities.getChildren(root,
"unnamed-path"); //$NON-NLS-1$
+ if(unnamedPathElement != null) for (int i = 0; i < unnamedPathElement.length; i++)
{
+ String path = unnamedPathElement[i].getAttribute("path"); //$NON-NLS-1$
+ IPath pathObject = new Path(path);
+ addUnnamedResource(pathObject);
+ }
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/LinkCollection.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ProjectValidationContext.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ProjectValidationContext.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ProjectValidationContext.java 2009-10-15
13:11:18 UTC (rev 18106)
@@ -0,0 +1,343 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.web.kb.internal.validation;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.jboss.tools.common.xml.XMLUtilities;
+import org.jboss.tools.jst.web.kb.validation.ELReference;
+import org.jboss.tools.jst.web.kb.validation.IValidationContext;
+import org.jboss.tools.jst.web.kb.validation.IValidator;
+import org.w3c.dom.Element;
+
+/**
+ * Contains information for validators that must be saved between
+ * validation invoking.
+ * @author Alexey Kazakov
+ */
+public class ProjectValidationContext implements IValidationContext {
+
+ // We should load/save these collections between eclipse sessions.
+ private LinkCollection coreLinks = new LinkCollection();
+ private ELValidatorContext elLinks = new ELValidatorContext();
+
+ private Set<IFile> removedFiles = new HashSet<IFile>();
+ private Set<IFile> registeredResources = new HashSet<IFile>();
+ private Set<String> oldVariableNamesForELValidation = new
HashSet<String>();
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#addLinkedCoreResource(java.lang.String,
org.eclipse.core.runtime.IPath, boolean)
+ */
+ public void addLinkedCoreResource(String variableName, IPath linkedResourcePath, boolean
declaration) {
+ coreLinks.addLinkedResource(variableName, linkedResourcePath, declaration);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#removeLinkedCoreResource(java.lang.String,
org.eclipse.core.runtime.IPath)
+ */
+ public void removeLinkedCoreResource(String name, IPath linkedResourcePath) {
+ coreLinks.removeLinkedResource(name, linkedResourcePath);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#removeLinkedCoreResources(java.util.Set)
+ */
+ public void removeLinkedCoreResources(Set<IPath> resources) {
+ coreLinks.removeLinkedResources(resources);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#removeLinkedCoreResource(org.eclipse.core.runtime.IPath)
+ */
+ public void removeLinkedCoreResource(IPath resource) {
+ coreLinks.removeLinkedResource(resource);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#getCoreResourcesByVariableName(java.lang.String,
boolean)
+ */
+ public Set<IPath> getCoreResourcesByVariableName(String variableName, boolean
declaration) {
+ return coreLinks.getResourcesByVariableName(variableName, declaration);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#getVariableNamesByCoreResource(org.eclipse.core.runtime.IPath,
boolean)
+ */
+ public Set<String> getVariableNamesByCoreResource(IPath fullPath, boolean
declaration) {
+ return coreLinks.getVariableNamesByResource(fullPath, declaration);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#addUnnamedCoreResource(org.eclipse.core.runtime.IPath)
+ */
+ public void addUnnamedCoreResource(IPath fullPath) {
+ coreLinks.addUnnamedResource(fullPath);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#getUnnamedCoreResources()
+ */
+ public Set<IPath> getUnnamedCoreResources() {
+ return coreLinks.getUnnamedResources();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#removeUnnamedCoreResource(org.eclipse.core.runtime.IPath)
+ */
+ public void removeUnnamedCoreResource(IPath fullPath) {
+ coreLinks.removeUnnamedResource(fullPath);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#addUnnamedElResource(org.eclipse.core.runtime.IPath)
+ */
+ public void addUnnamedElResource(IPath fullPath) {
+ elLinks.addUnnamedResource(fullPath);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#getUnnamedElResources()
+ */
+ public Set<IPath> getUnnamedElResources() {
+ return elLinks.getUnnamedResources();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#removeUnnamedElResource(org.eclipse.core.runtime.IPath)
+ */
+ public void removeUnnamedElResource(IPath fullPath) {
+ elLinks.removeUnnamedResource(fullPath);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#addVariableNameForELValidation(java.lang.String)
+ */
+ public void addVariableNameForELValidation(String name) {
+ oldVariableNamesForELValidation.add(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#removeLinkedEls(java.util.Set)
+ */
+ public void removeLinkedEls(Set<IFile> resorces) {
+ elLinks.removeLinkedEls(resorces);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#getElsForValidation(java.util.Set,
boolean)
+ */
+ public Set<ELReference> getElsForValidation(Set<IFile> changedFiles, boolean
onlyChangedVariables) {
+ Set<ELReference> result = new HashSet<ELReference>();
+ // Collect all ELs which use new variables names
+ for(IResource resource : changedFiles) {
+ Set<String> newNames = getVariableNamesByCoreResource(resource.getFullPath(),
true);
+ if(newNames!=null) {
+ for (String newName : newNames) {
+ if(!onlyChangedVariables || !oldVariableNamesForELValidation.contains(newName)) {
+ Set<ELReference> els = elLinks.getElsByVariableName(newName);
+ if(els!=null) {
+ result.addAll(els);
+ }
+ }
+ }
+ }
+ for (String oldName : oldVariableNamesForELValidation) {
+ if(!onlyChangedVariables || newNames==null || !newNames.contains(oldName)) {
+ Set<ELReference> els = elLinks.getElsByVariableName(oldName);
+ if(els!=null) {
+ result.addAll(els);
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.validation.IValidationContext#clearAll()
+ */
+ public void clearAll() {
+ removedFiles.clear();
+ synchronized (registeredResources) {
+ registeredResources.clear();
+ }
+ oldVariableNamesForELValidation.clear();
+ coreLinks.clearAll();
+ elLinks.clearAll();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#clearAllResourceLinks()
+ */
+ public void clearAllResourceLinks() {
+ oldVariableNamesForELValidation.clear();
+ coreLinks.clearAll();
+ elLinks.clearAll();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.validation.IValidationContext#clearRegisteredFiles()
+ */
+ public void clearRegisteredFiles() {
+ removedFiles.clear();
+ synchronized (registeredResources) {
+ registeredResources.clear();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.validation.IValidationContext#clearElResourceLinks()
+ */
+ public void clearElResourceLinks() {
+ oldVariableNamesForELValidation.clear();
+ elLinks.clearAll();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#clearOldVariableNameForElValidation()
+ */
+ public void clearOldVariableNameForElValidation() {
+ oldVariableNamesForELValidation.clear();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#addLinkedEl(java.lang.String,
org.jboss.tools.jst.web.kb.validation.ELReference)
+ */
+ public void addLinkedEl(String variableName, ELReference el) {
+ elLinks.addLinkedEl(variableName, el);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#removeLinkedEl(java.lang.String,
org.jboss.tools.jst.web.kb.validation.ELReference)
+ */
+ public void removeLinkedEl(String name, ELReference el) {
+ elLinks.removeLinkedEl(name, el);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#getElsByVariableName(java.lang.String)
+ */
+ public Set<ELReference> getElsByVariableName(String variableName) {
+ return elLinks.getElsByVariableName(variableName);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#store(org.w3c.dom.Element)
+ */
+ public void store(Element root) {
+ Element validation = XMLUtilities.createElement(root, "validation");
//$NON-NLS-1$
+ Element core = XMLUtilities.createElement(validation, "core"); //$NON-NLS-1$
+ coreLinks.store(core);
+ Element el = XMLUtilities.createElement(validation, "el"); //$NON-NLS-1$
+ elLinks.store(el);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#load(org.w3c.dom.Element)
+ */
+ public void load(Element root) {
+ Element validation = XMLUtilities.getUniqueChild(root, "validation");
//$NON-NLS-1$
+ if(validation == null) return;
+ Element core = XMLUtilities.getUniqueChild(validation, "core");
//$NON-NLS-1$
+ if(core != null) {
+ coreLinks.load(core);
+ }
+ Element el = XMLUtilities.getUniqueChild(validation, "el"); //$NON-NLS-1$
+ if(el != null) {
+ elLinks.load(el);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.validation.IValidationContext#getRemovedFiles()
+ */
+ public Set<IFile> getRemovedFiles() {
+ return removedFiles;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#addRemovedFile(org.eclipse.core.resources.IFile)
+ */
+ public void addRemovedFile(IFile file) {
+ removedFiles.add(file);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.validation.IValidationContext#getRegisteredFiles()
+ */
+ public Set<IFile> getRegisteredFiles() {
+ Set<IFile> copy = new HashSet<IFile>();
+ synchronized (registeredResources) {
+ copy.addAll(registeredResources);
+ }
+ return copy;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidationContext#registerFile(org.eclipse.core.resources.IFile)
+ */
+ public void registerFile(IFile file) {
+ synchronized (registeredResources) {
+ registeredResources.add(file);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.validation.IValidationContext#getRootProject()
+ */
+ public IProject getRootProject() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.validation.IValidationContext#getValidators()
+ */
+ public List<IValidator> getValidators() {
+ return null;
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ProjectValidationContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain