Author: akazakov
Date: 2010-01-22 07:48:57 -0500 (Fri, 22 Jan 2010)
New Revision: 19878
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/ICDINamedAnnotation.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/validation/ValidatorUtil.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/ICDIAnnotation.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/ICDIProject.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IStereotype.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIAnnotationElement.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/StereotypeElement.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2708
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java 2010-01-22
11:04:18 UTC (rev 19877)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java 2010-01-22
12:48:57 UTC (rev 19878)
@@ -26,6 +26,13 @@
public interface IBeanManager {
/**
+ * Returns all the beans.
+ *
+ * @return all the beans
+ */
+ IBean[] getBeans();
+
+ /**
* Returns all @Named beans.
*
* @param attemptToResolveAmbiguousNames
@@ -115,7 +122,7 @@
*
* @return all the available stereotypes.
*/
- Set<IType> getStereotypes();
+ IStereotype[] getStereotypes();
/**
* Returns stereotype model element for fully qualified name
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/ICDIAnnotation.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/ICDIAnnotation.java 2010-01-22
11:04:18 UTC (rev 19877)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/ICDIAnnotation.java 2010-01-22
12:48:57 UTC (rev 19878)
@@ -1,12 +1,14 @@
package org.jboss.tools.cdi.core;
+import java.util.List;
+
import org.eclipse.jdt.core.IType;
/**
- * Common interface for qualifier, stereotype, intercepror binding and scope objects.
+ * Common interface for an annotation interface.
*
* @author Viacheslav Kabanovich
- *
+ *
*/
public interface ICDIAnnotation extends ICDIElement {
@@ -15,14 +17,31 @@
*
* @return the corresponding IType
*/
- public IType getSourceType();
+ IType getSourceType();
/**
- * Returns the location of @Inherited declaration of this annotation type. If the bean
- * doesn't have the @Inherited declaration then null will be returned.
+ * Returns the declaration of @Inherited declaration of this annotation
+ * type. If the interface doesn't have the @Inherited declaration then null
+ * will be returned.
*
- * @return the location of @Name declaration of this bean.
+ * @return the declaration of @Inherited declaration of this bean
*/
- public IAnnotationDeclaration getInheritedDeclaration();
+ IAnnotationDeclaration getInheritedDeclaration();
-}
+ /**
+ * Returns all the available annotations which are declared for this
+ * interface.
+ *
+ * @return all the available annotations which are declared for this
+ * interface
+ */
+ List<IAnnotationDeclaration> getAnnotationDeclarations();
+
+ /**
+ * Returns the annotations with given type name.
+ *
+ * @param typeName
+ * @return the annotations with given type name
+ */
+ IAnnotationDeclaration getAnnotationDeclaration(String typeName);
+}
\ No newline at end of file
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/ICDINamedAnnotation.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/ICDINamedAnnotation.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/ICDINamedAnnotation.java 2010-01-22
12:48:57 UTC (rev 19878)
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.cdi.core;
+
+/**
+ * A common interface for an annotation interface with can have @Named
+ * annotation.
+ *
+ * @author Alexey Kazakov
+ */
+public interface ICDINamedAnnotation extends ICDIAnnotation {
+
+ /**
+ * Returns the declaration of @Named declaration of this annotation type. If
+ * the interface doesn't have the @Named declaration then null will be
+ * returned.
+ *
+ * @return the declaration of @Named declaration of this bean
+ */
+ IAnnotationDeclaration getNameDeclaration();
+}
\ No newline at end of file
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/ICDINamedAnnotation.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/ICDIProject.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/ICDIProject.java 2010-01-22
11:04:18 UTC (rev 19877)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/ICDIProject.java 2010-01-22
12:48:57 UTC (rev 19878)
@@ -15,7 +15,7 @@
*/
public interface ICDIProject extends IBeanManager {
+ public CDICoreNature getNature();
public void setNature(CDICoreNature n);
public void update();
-
}
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IStereotype.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IStereotype.java 2010-01-22
11:04:18 UTC (rev 19877)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IStereotype.java 2010-01-22
12:48:57 UTC (rev 19878)
@@ -13,14 +13,13 @@
import java.util.Set;
import org.eclipse.jdt.core.IAnnotation;
-import org.eclipse.jdt.core.IType;
/**
* Represents a stereotype.
*
* @author Alexey Kazakov
*/
-public interface IStereotype extends IScoped, ICDIAnnotation {
+public interface IStereotype extends IScoped, ICDINamedAnnotation {
/**
* Returns the location of @Name declaration of this stereotype. If the bean
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIAnnotationElement.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIAnnotationElement.java 2010-01-22
11:04:18 UTC (rev 19877)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIAnnotationElement.java 2010-01-22
12:48:57 UTC (rev 19878)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
+ * 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,
@@ -32,22 +32,37 @@
this.definition = definition;
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.ICDIAnnotation#getSourceType()
+ */
public IType getSourceType() {
return definition.getType();
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.ICDIAnnotation#getInheritedDeclaration()
+ */
public IAnnotationDeclaration getInheritedDeclaration() {
return definition.getInheritedAnnotation();
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.ICDIAnnotation#getAnnotationDeclarations()
+ */
public List<IAnnotationDeclaration> getAnnotationDeclarations() {
List<IAnnotationDeclaration> result = new
ArrayList<IAnnotationDeclaration>();
result.addAll(definition.getAnnotations());
return result;
}
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.cdi.core.ICDIAnnotation#getAnnotationDeclaration(java.lang.String)
+ */
public IAnnotationDeclaration getAnnotationDeclaration(String typeName) {
return definition.getAnnotation(typeName);
}
-
-}
+}
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2010-01-22
11:04:18 UTC (rev 19877)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2010-01-22
12:48:57 UTC (rev 19878)
@@ -53,6 +53,7 @@
private Map<String, QualifierElement> qualifiers = new HashMap<String,
QualifierElement>();
private Map<String, ScopeElement> scopes = new HashMap<String,
ScopeElement>();
+ private Set<IBean> allBeans = new HashSet<IBean>();
private Map<IPath, Set<IBean>> beansByPath = new HashMap<IPath,
Set<IBean>>();
private Map<String, Set<IBean>> beansByName = new HashMap<String,
Set<IBean>>();
private Set<IBean> namedBeans = new HashSet<IBean>();
@@ -70,6 +71,24 @@
this.n = n;
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.IBeanManager#getBeans()
+ */
+ public IBean[] getBeans() {
+ if(allBeans == null || allBeans.isEmpty()) {
+ return new IBean[0];
+ }
+ IBean[] result = new IBean[allBeans.size()];
+ synchronized (allBeans) {
+ int i=0;
+ for (IBean bean : allBeans) {
+ result[i++] = bean;
+ }
+ }
+ return result;
+ }
+
public List<INodeReference> getAlternativeClasses() {
List<INodeReference> result = new ArrayList<INodeReference>();
Set<INodeReference> typeAlternatives = beansXMLData.getTypeAlternatives();
@@ -221,10 +240,17 @@
return result;
}
- public Set<IType> getStereotypes() {
- Set<IType> result = new HashSet<IType>();
- for (IStereotype d: stereotypes.values()) {
- result.add(d.getSourceType());
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.IBeanManager#getStereotypes()
+ */
+ public IStereotype[] getStereotypes() {
+ IStereotype[] result = new IStereotype[stereotypes.size()];
+ synchronized (stereotypes) {
+ int i=0;
+ for (IStereotype s: stereotypes.values()) {
+ result[i++] = s;
+ }
}
return result;
}
@@ -449,6 +475,10 @@
synchronized (namedBeans) {
namedBeans.clear();
}
+ synchronized (allBeans) {
+ allBeans.clear();
+ }
+
classBeans = newClassBeans;
for (IBean bean: beans) {
addBean(bean);
@@ -490,6 +520,9 @@
synchronized (bs) {
bs.add(bean);
}
+ synchronized (allBeans) {
+ allBeans.add(bean);
+ }
}
void rebuildXML() {
@@ -539,5 +572,4 @@
}
return result;
}
-
}
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/StereotypeElement.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/StereotypeElement.java 2010-01-22
11:04:18 UTC (rev 19877)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/StereotypeElement.java 2010-01-22
12:48:57 UTC (rev 19878)
@@ -15,8 +15,6 @@
import java.util.Set;
import org.eclipse.jdt.core.IAnnotation;
-import org.eclipse.jdt.core.IType;
-import org.jboss.tools.cdi.core.IAnnotationDeclaration;
import org.jboss.tools.cdi.core.IInterceptorBindingDeclaration;
import org.jboss.tools.cdi.core.IScope;
import org.jboss.tools.cdi.core.IScopeDeclaration;
@@ -32,14 +30,26 @@
public StereotypeElement() {}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.IStereotype#getAlternativeDeclaration()
+ */
public AnnotationDeclaration getAlternativeDeclaration() {
return definition.getAlternativeAnnotation();
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.ICDINamedAnnotation#getNameDeclaration()
+ */
public AnnotationDeclaration getNameDeclaration() {
return definition.getNamedAnnotation();
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.IStereotype#getInterceptorBindingDeclarations()
+ */
public Set<IInterceptorBindingDeclaration> getInterceptorBindingDeclarations() {
Set<IInterceptorBindingDeclaration> result = new
HashSet<IInterceptorBindingDeclaration>();
List<AnnotationDeclaration> as = definition.getAnnotations();
@@ -51,10 +61,18 @@
return result;
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.IStereotype#getNameLocation()
+ */
public IAnnotation getNameLocation() {
return getNameDeclaration() != null ? getNameDeclaration().getDeclaration() : null;
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.IStereotype#getStereotypeDeclarations()
+ */
public Set<IStereotypeDeclaration> getStereotypeDeclarations() {
Set<IStereotypeDeclaration> result = new
HashSet<IStereotypeDeclaration>();
for (AnnotationDeclaration d: definition.getAnnotations()) {
@@ -65,6 +83,10 @@
return result;
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.IStereotype#isAlternative()
+ */
public boolean isAlternative() {
if(getAlternativeDeclaration() != null) return true;
Set<IStereotypeDeclaration> ds = getStereotypeDeclarations();
@@ -75,6 +97,10 @@
return false;
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.IScoped#getScope()
+ */
public IScope getScope() {
Set<IScopeDeclaration> ss = getScopeDeclarations();
if(!ss.isEmpty()) {
@@ -91,8 +117,11 @@
return null;
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.IScoped#getScopeDeclarations()
+ */
public Set<IScopeDeclaration> getScopeDeclarations() {
return ProducerField.getScopeDeclarations(getCDIProject().getNature(),
definition.getAnnotations());
}
-
-}
+}
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-01-22
11:04:18 UTC (rev 19877)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-01-22
12:48:57 UTC (rev 19878)
@@ -1,17 +1,30 @@
+/*******************************************************************************
+ * 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.cdi.internal.core.validation;
import java.util.ArrayList;
+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.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IMemberValuePair;
-import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.wst.validation.internal.core.ValidationException;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -19,11 +32,11 @@
import org.jboss.tools.cdi.core.CDICoreNature;
import org.jboss.tools.cdi.core.CDICorePlugin;
import org.jboss.tools.cdi.core.IAnnotationDeclaration;
+import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.core.ICDIProject;
import org.jboss.tools.cdi.core.IQualifierDeclaration;
+import org.jboss.tools.cdi.core.IStereotype;
import org.jboss.tools.cdi.core.preferences.CDIPreferences;
-import org.jboss.tools.cdi.internal.core.impl.AnnotationDeclaration;
-import org.jboss.tools.cdi.internal.core.impl.CDIProject;
-import org.jboss.tools.cdi.internal.core.impl.StereotypeElement;
import org.jboss.tools.common.text.ITextSourceReference;
import org.jboss.tools.jst.web.kb.IKbProject;
import org.jboss.tools.jst.web.kb.KbProjectFactory;
@@ -34,17 +47,26 @@
import org.jboss.tools.jst.web.kb.validation.IValidatingProjectSet;
import org.jboss.tools.jst.web.kb.validation.IValidationContext;
import org.jboss.tools.jst.web.kb.validation.IValidator;
+import org.jboss.tools.jst.web.kb.validation.ValidatorUtil;
public class CDICoreValidator extends CDIValidationErrorManager implements IValidator {
public static final String ID = "org.jboss.tools.cdi.core.CoreValidator";
- CDIProject cdiProject;
+ ICDIProject cdiProject;
String projectName;
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.validation.IValidator#getId()
+ */
public String getId() {
return ID;
}
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidator#getValidatingProjects(org.eclipse.core.resources.IProject)
+ */
public IValidatingProjectSet getValidatingProjects(IProject project) {
IValidationContext rootContext = null;
IProject war = null; //TODO get war ?
@@ -78,6 +100,10 @@
return new ValidatingProjectSet(project, projects, rootContext);
}
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidator#shouldValidate(org.eclipse.core.resources.IProject)
+ */
public boolean shouldValidate(IProject project) {
try {
// TODO check preferences
@@ -96,79 +122,165 @@
public void init(IProject project, ContextValidationHelper validationHelper,
org.eclipse.wst.validation.internal.provisional.core.IValidator manager, IReporter
reporter) {
super.init(project, validationHelper, manager, reporter);
-// SeamProjectsSet set = new SeamProjectsSet(project);
-// IProject warProject = set.getWarProject();
CDICoreNature nature = CDICorePlugin.getCDI(project, false);
- cdiProject = nature != null ? (CDIProject)nature.getDelegate() : null;
-
+ cdiProject = nature != null ? nature.getDelegate() : null;
+
projectName = project.getName();
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.validation.IValidator#validate(java.util.Set,
org.eclipse.core.resources.IProject,
org.jboss.tools.jst.web.kb.internal.validation.ContextValidationHelper,
org.jboss.tools.jst.web.kb.internal.validation.ValidatorManager,
org.eclipse.wst.validation.internal.provisional.core.IReporter)
+ */
public IStatus validate(Set<IFile> changedFiles, IProject project,
ContextValidationHelper validationHelper, ValidatorManager manager,
IReporter reporter) throws ValidationException {
- // TODO Auto-generated method stub
- return null;
+ init(project, validationHelper, manager, reporter);
+ displaySubtask(CDIValidationMessages.SEARCHING_RESOURCES);
+
+ if(cdiProject == null) {
+ return OK_STATUS;
+ }
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ Set<IPath> resources = new HashSet<IPath>(); // Resources which we have to
validate.
+ for(IFile currentFile : changedFiles) {
+ if(reporter.isCancelled()) {
+ break;
+ }
+ if (ValidatorUtil.checkFileExtensionForJavaAndXml(currentFile)) {
+ resources.add(currentFile.getFullPath());
+
+ // Get all the paths of related resources for given file. These links were saved in
previous validation process.
+ Set<String> oldReletedResources =
validationContext.getVariableNamesByCoreResource(currentFile.getFullPath(), false);
+ for (String resourcePath : oldReletedResources) {
+ resources.add(Path.fromOSString(resourcePath));
+ }
+ }
+ }
+ // Validate all collected linked resources.
+ // Remove all links between collected resources because they will be linked again
during validation.
+ validationContext.removeLinkedCoreResources(resources);
+
+ IFile[] filesToValidate = new IFile[resources.size()];
+ int i = 0;
+ // We have to remove markers from all collected source files first
+ for (IPath linkedResource : resources) {
+ filesToValidate[i] = root.getFile(linkedResource);
+ removeAllMessagesFromResource(filesToValidate[i++]);
+ }
+ i = 0;
+ // Then we can validate them
+ for (IFile file : filesToValidate) {
+ validateResource(file);
+ }
+
+ return OK_STATUS;
}
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.validation.IValidator#validateAll(org.eclipse.core.resources.IProject,
org.jboss.tools.jst.web.kb.internal.validation.ContextValidationHelper,
org.jboss.tools.jst.web.kb.internal.validation.ValidatorManager,
org.eclipse.wst.validation.internal.provisional.core.IReporter)
+ */
public IStatus validateAll(IProject project,
ContextValidationHelper validationHelper, ValidatorManager manager,
IReporter reporter) throws ValidationException {
init(project, validationHelper, manager, reporter);
+ displaySubtask(CDIValidationMessages.VALIDATING_PROJECT, new String[]{projectName});
removeAllMessagesFromResource(cdiProject.getNature().getProject());
- if(cdiProject != null) {
- validateStereotypes();
-
+ if(cdiProject == null) {
+ return OK_STATUS;
}
- // TODO
+ IBean[] beans = cdiProject.getBeans();
+ for (IBean bean : beans) {
+ validateBean(bean);
+ }
+
+ IStereotype[] stereoTypes = cdiProject.getStereotypes();
+ for (IStereotype type: stereoTypes) {
+ validateStereotype(type);
+ }
+
+ // TODO
return OK_STATUS;
}
- public void validateStereotypes() {
- Set<IType> ts = cdiProject.getStereotypes();
- for (IType t: ts) {
- StereotypeElement s = cdiProject.getStereotype(t.getFullyQualifiedName());
- if(s == null) continue;
- IResource resource = s.getResource();
- if(resource == null || !resource.getName().endsWith(".java")) {
- //validate sources only
- continue;
+ /**
+ * Validates a resource.
+ *
+ * @param file
+ */
+ private void validateResource(IFile file) {
+ if(reporter.isCancelled() || file==null || !file.isAccessible()) {
+ return;
+ }
+ Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
+ for (IBean bean : beans) {
+ validateBean(bean);
+ }
+ }
+
+ /**
+ * Validates a bean.
+ *
+ * @param bean
+ */
+ private void validateBean(IBean bean) {
+ if(reporter.isCancelled()) {
+ return;
+ }
+ String name = bean.getName();
+ if(name!=null) {
+ validationContext.addVariableNameForELValidation(name);
+ }
+ }
+
+ /**
+ * Validates a stereotype.
+ *
+ * @param type
+ */
+ private void validateStereotype(IStereotype stereotype) {
+ if(stereotype == null) {
+ return;
+ }
+ IResource resource = stereotype.getResource();
+ if(resource == null || !resource.getName().toLowerCase().endsWith(".java"))
{
+ //validate sources only
+ return;
+ }
+ List<IAnnotationDeclaration> as = stereotype.getAnnotationDeclarations();
+
+// 1. non-empty name
+ IAnnotationDeclaration nameDeclaration = stereotype.getNameDeclaration();
+ if(nameDeclaration != null) {
+ IMemberValuePair[] ps = null;
+ try {
+ ps = nameDeclaration.getDeclaration().getMemberValuePairs();
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
}
- List<IAnnotationDeclaration> as = s.getAnnotationDeclarations();
-
-// 1. non-empty name
- AnnotationDeclaration nameDeclaration = s.getNameDeclaration();
- if(nameDeclaration != null) {
- IMemberValuePair[] ps = null;
- try {
- ps = nameDeclaration.getDeclaration().getMemberValuePairs();
- } catch (JavaModelException e) {
- CDICorePlugin.getDefault().logError(e);
+ if(ps != null && ps.length > 0) {
+ Object name = ps[0].getValue();
+ if(name != null && name.toString().length() > 0) {
+ ITextSourceReference location = nameDeclaration;
+ addError(CDIValidationMessages.STEREOTYPE_DECLARES_NON_EMPTY_NAME,
CDIPreferences.STEREOTYPE_DECLARES_NON_EMPTY_NAME, location, resource);
}
- if(ps != null && ps.length > 0) {
- Object name = ps[0].getValue();
- if(name != null && name.toString().length() > 0) {
- ITextSourceReference location = nameDeclaration;
- addError(CDIValidationMessages.STEREOTYPE_DECLARES_NON_EMPTY_NAME,
CDIPreferences.STEREOTYPE_DECLARES_NON_EMPTY_NAME, location, resource);
- }
- }
}
+ }
-// 2. typed annotation
- IAnnotationDeclaration typedDeclaration =
s.getAnnotationDeclaration(CDIConstants.TYPED_ANNOTATION_TYPE_NAME);
- if(typedDeclaration != null) {
- ITextSourceReference location = typedDeclaration;
- addError(CDIValidationMessages.STEREOTYPE_IS_ANNOTATED_TYPED,
CDIPreferences.STEREOTYPE_IS_ANNOTATED_TYPED, location, resource);
- }
+// 2. typed annotation
+ IAnnotationDeclaration typedDeclaration =
stereotype.getAnnotationDeclaration(CDIConstants.TYPED_ANNOTATION_TYPE_NAME);
+ if(typedDeclaration != null) {
+ ITextSourceReference location = typedDeclaration;
+ addError(CDIValidationMessages.STEREOTYPE_IS_ANNOTATED_TYPED,
CDIPreferences.STEREOTYPE_IS_ANNOTATED_TYPED, location, resource);
+ }
-// 3. Qualifier other than @Named
- for (IAnnotationDeclaration a: as) {
- if(a instanceof IQualifierDeclaration && a != nameDeclaration) {
- ITextSourceReference location = a;
- addError(CDIValidationMessages.ILLEGAL_QUALIFIER_IN_STEREOTYPE,
CDIPreferences.ILLEGAL_QUALIFIER_IN_STEREOTYPE, location, resource);
- }
+// 3. Qualifier other than @Named
+ for (IAnnotationDeclaration a: as) {
+ if(a instanceof IQualifierDeclaration && a != nameDeclaration) {
+ ITextSourceReference location = a;
+ addError(CDIValidationMessages.ILLEGAL_QUALIFIER_IN_STEREOTYPE,
CDIPreferences.ILLEGAL_QUALIFIER_IN_STEREOTYPE, location, resource);
}
}
}
-
-}
+}
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.java 2010-01-22
11:04:18 UTC (rev 19877)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.java 2010-01-22
12:48:57 UTC (rev 19878)
@@ -94,6 +94,10 @@
public static String ILLEGAL_INJECTING_INJECTIONPOINT_TYPE;
public static String ILLEGAL_QUALIFIER_IN_STEREOTYPE;
+ public static String SEARCHING_RESOURCES;
+ public static String VALIDATING_RESOURCE;
+ public static String VALIDATING_PROJECT;
+
static {
NLS.initializeMessages(BUNDLE_NAME, CDIValidationMessages.class);
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties 2010-01-22
11:04:18 UTC (rev 19877)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties 2010-01-22
12:48:57 UTC (rev 19878)
@@ -73,3 +73,8 @@
ILLEGAL_INJECTING_USERTRANSACTION_TYPE=Java EE component class has an injection point of
type UserTransaction and qualifier @Default, and may not validly make use of the JTA
UserTransaction according to the Java EE platform specification
ILLEGAL_INJECTING_INJECTIONPOINT_TYPE=Java EE component class supporting injection that
is not a bean has an injection point of type InjectionPoint and qualifier @Default
ILLEGAL_QUALIFIER_IN_STEREOTYPE=Stereotype declares any qualifier annotation other than
@Named
+
+#Messages for Progress Monitor
+SEARCHING_RESOURCES=project "{0}"; searching resources for validation.
+VALIDATING_RESOURCE=project "{0}"; resource "{1}"
+VALIDATING_PROJECT=project "{0}"
\ No newline at end of file
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/validation/ValidatorUtil.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/validation/ValidatorUtil.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/validation/ValidatorUtil.java 2010-01-22
12:48:57 UTC (rev 19878)
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.validation;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+
+/**
+ * @author Alexey Kazakov
+ */
+public class ValidatorUtil {
+
+ public final static Set<String> EXTNS;
+ static {
+ EXTNS = new HashSet<String>();
+ EXTNS.add("java"); //$NON-NLS-1$
+ EXTNS.add("xml"); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns true if the file name has "java" or "xml" extension.
+ * @param file
+ * @return
+ */
+ public static boolean checkFileExtensionForJavaAndXml(IFile file) {
+ return EXTNS.contains(file.getFileExtension());
+ }
+}
\ 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/validation/ValidatorUtil.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java 2010-01-22
11:04:18 UTC (rev 19877)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java 2010-01-22
12:48:57 UTC (rev 19878)
@@ -47,6 +47,7 @@
import org.jboss.tools.jst.web.kb.validation.IValidatingProjectSet;
import org.jboss.tools.jst.web.kb.validation.IValidationContext;
import org.jboss.tools.jst.web.kb.validation.IValidator;
+import org.jboss.tools.jst.web.kb.validation.ValidatorUtil;
import org.jboss.tools.seam.core.BijectedAttributeType;
import org.jboss.tools.seam.core.IBijectedAttribute;
import org.jboss.tools.seam.core.ISeamAnnotatedFactory;
@@ -189,7 +190,7 @@
// We need to check only file names here.
validateUnnamedResources = fileName.endsWith(".java") ||
fileName.endsWith(".properties") || fileName.equals("components.xml");
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
- if (checkFileExtension(currentFile)) {
+ if (ValidatorUtil.checkFileExtensionForJavaAndXml(currentFile)) {
resources.add(currentFile.getFullPath());
// Get new variable names from model
Set<String> newVariableNamesOfChangedFile =
getVariablesNameByResource(currentFile.getFullPath());
@@ -245,7 +246,7 @@
Set<IPath> unnamedResources = validationContext.getUnnamedCoreResources();
newResources.addAll(unnamedResources);
for (IPath path : newResources) {
- IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ IFile file = root.getFile(path);
if(file!=null && file.exists()) {
if(!resources.contains(path)) {
removeAllMessagesFromResource(file);
@@ -932,16 +933,4 @@
}
return true;
}
-
- private final static String[] extns = new String[]{"java", "xml"};
//$NON-NLS-1$ //$NON-NLS-2$
-
- private boolean checkFileExtension(IFile file) {
- String ext = file.getFileExtension();
- for (int i = 0; i < extns.length; i++) {
- if(extns[i].equalsIgnoreCase(ext)) {
- return true;
- }
- }
- return false;
- }
}
\ No newline at end of file