Author: scabanovich
Date: 2009-12-29 11:26:04 -0500 (Tue, 29 Dec 2009)
New Revision: 19607
Added:
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/CDIValidationErrorManager.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/META-INF/MANIFEST.MF
trunk/cdi/plugins/org.jboss.tools.cdi.core/plugin.xml
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.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/definition/AbstractMemberDefinition.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4943
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/META-INF/MANIFEST.MF 2009-12-29 15:05:07
UTC (rev 19606)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/META-INF/MANIFEST.MF 2009-12-29 16:26:04
UTC (rev 19607)
@@ -14,6 +14,7 @@
org.eclipse.wst.common.project.facet.core,
org.eclipse.wst.common.modulecore,
org.eclipse.wst.common.frameworks,
+ org.eclipse.wst.validation,
org.jboss.tools.jst.web.kb,
org.jboss.tools.common.el.core,
org.eclipse.jface.text,
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/plugin.xml
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/plugin.xml 2009-12-29 15:05:07 UTC (rev
19606)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/plugin.xml 2009-12-29 16:26:04 UTC (rev
19607)
@@ -95,4 +95,13 @@
<extension point="org.eclipse.core.runtime.preferences">
<initializer
class="org.jboss.tools.cdi.core.preferences.CDIPreferenceInitializer"/>
</extension>
+
+ <extension
+ point="org.jboss.tools.jst.web.kb.validator">
+ <validator
+
class="org.jboss.tools.cdi.internal.core.validation.CDICoreValidator"
+ id="org.jboss.tools.cdi.core.CoreValidator">
+ </validator>
+ </extension>
+
</plugin>
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.java 2009-12-29
15:05:07 UTC (rev 19606)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.java 2009-12-29
16:26:04 UTC (rev 19607)
@@ -27,6 +27,7 @@
import org.jboss.tools.cdi.internal.core.impl.definition.DefinitionContext;
import org.jboss.tools.cdi.internal.core.scanner.lib.ClassPathMonitor;
import org.jboss.tools.common.util.FileUtil;
+import org.jboss.tools.jst.web.kb.internal.validation.ProjectValidationContext;
public class CDICoreNature implements IProjectNature {
public static String NATURE_ID = "org.jboss.tools.cdi.core.cdinature";
@@ -37,6 +38,8 @@
ClassPathMonitor classPath = new ClassPathMonitor(this);
DefinitionContext definitions = new DefinitionContext();
+ ProjectValidationContext validationContext = null;
+
boolean isBuilt = false;
// Map<IPath, Object> sourcePaths2 = new HashMap<IPath, Object>(); //TODO
@@ -262,5 +265,15 @@
//TODO
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.seam.core.ISeamProject#getValidationContext()
+ */
+ public ProjectValidationContext getValidationContext() {
+ if(validationContext==null) {
+ validationContext = new ProjectValidationContext();
+ }
+ return validationContext;
+ }
}
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 2009-12-29
15:05:07 UTC (rev 19606)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIAnnotationElement.java 2009-12-29
16:26:04 UTC (rev 19607)
@@ -10,6 +10,9 @@
******************************************************************************/
package org.jboss.tools.cdi.internal.core.impl;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jdt.core.IType;
import org.jboss.tools.cdi.core.IAnnotationDeclaration;
import org.jboss.tools.cdi.core.ICDIAnnotation;
@@ -37,4 +40,14 @@
return definition.getInheritedAnnotation();
}
+ public List<IAnnotationDeclaration> getAnnotationDeclarations() {
+ List<IAnnotationDeclaration> result = new
ArrayList<IAnnotationDeclaration>();
+ result.addAll(definition.getAnnotations());
+ return result;
+ }
+
+ public IAnnotationDeclaration getAnnotationDeclaration(String typeName) {
+ return definition.getAnnotation(typeName);
+ }
+
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractMemberDefinition.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractMemberDefinition.java 2009-12-29
15:05:07 UTC (rev 19606)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractMemberDefinition.java 2009-12-29
16:26:04 UTC (rev 19607)
@@ -79,6 +79,10 @@
return annotations;
}
+ public AnnotationDeclaration getAnnotation(String typeName) {
+ return annotationsByType.get(typeName);
+ }
+
public AnnotationDeclaration getNamedAnnotation() {
return annotationsByType.get(CDIConstants.NAMED_QUALIFIER_TYPE_NAME);
}
Added:
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
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2009-12-29
16:26:04 UTC (rev 19607)
@@ -0,0 +1,174 @@
+package org.jboss.tools.cdi.internal.core.validation;
+
+import java.util.ArrayList;
+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.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jdt.core.IAnnotation;
+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;
+import org.jboss.tools.cdi.core.CDIConstants;
+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.IQualifierDeclaration;
+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;
+import org.jboss.tools.jst.web.kb.internal.KbProject;
+import org.jboss.tools.jst.web.kb.internal.validation.ContextValidationHelper;
+import org.jboss.tools.jst.web.kb.internal.validation.ValidatingProjectSet;
+import org.jboss.tools.jst.web.kb.internal.validation.ValidatorManager;
+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;
+
+public class CDICoreValidator extends CDIValidationErrorManager implements IValidator {
+ public static final String ID = "org.jboss.tools.cdi.core.CoreValidator";
+
+ CDIProject cdiProject;
+ String projectName;
+
+ public String getId() {
+ return ID;
+ }
+
+ public IValidatingProjectSet getValidatingProjects(IProject project) {
+ IValidationContext rootContext = null;
+ IProject war = null; //TODO get war ?
+ if(war != null && war.isAccessible()) {
+ IKbProject kbProject = KbProjectFactory.getKbProject(war, false);
+ if(kbProject!=null) {
+ rootContext = kbProject.getValidationContext();
+ } else {
+ KbProject.checkKBBuilderInstalled(war);
+ CDICoreNature cdiProject = CDICorePlugin.getCDI(project, false);
+ if(cdiProject != null) {
+ rootContext = null; //cdiProject.getDelegate().getValidationContext();
+ }
+ }
+ }
+ if(rootContext == null) {
+ CDICoreNature cdiProject = CDICorePlugin.getCDI(project, false);
+ if(cdiProject != null) {
+ rootContext = cdiProject.getValidationContext();
+ }
+ }
+
+ List<IProject> projects = new ArrayList<IProject>();
+ projects.add(project);
+// IProject[] array = set.getAllProjects();
+// for (int i = 0; i < array.length; i++) {
+// if(array[i].isAccessible()) {
+// projects.add(array[i]);
+// }
+// }
+ return new ValidatingProjectSet(project, projects, rootContext);
+ }
+
+ public boolean shouldValidate(IProject project) {
+ try {
+ // TODO check preferences
+ return project != null && project.isAccessible() &&
project.hasNature(CDICoreNature.NATURE_ID);
+ } catch (CoreException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.jboss.tools.jst.web.kb.internal.validation.ValidationErrorManager#init(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,
org.jboss.tools.jst.web.kb.validation.IValidationContext)
+ */
+ @Override
+ 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;
+
+ projectName = project.getName();
+ }
+
+ public IStatus validate(Set<IFile> changedFiles, IProject project,
+ ContextValidationHelper validationHelper, ValidatorManager manager,
+ IReporter reporter) throws ValidationException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public IStatus validateAll(IProject project,
+ ContextValidationHelper validationHelper, ValidatorManager manager,
+ IReporter reporter) throws ValidationException {
+ init(project, validationHelper, manager, reporter);
+ removeAllMessagesFromResource(cdiProject.getNature().getProject());
+ if(cdiProject != null) {
+ validateStereotypes();
+
+ }
+ // 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;
+ }
+ 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);
+ }
+ }
+ }
+
+// 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);
+ }
+
+// 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);
+ }
+ }
+ }
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationErrorManager.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationErrorManager.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationErrorManager.java 2009-12-29
16:26:04 UTC (rev 19607)
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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 org.eclipse.core.resources.IProject;
+import org.jboss.tools.cdi.core.preferences.CDIPreferences;
+import org.jboss.tools.jst.web.kb.internal.validation.ValidationErrorManager;
+
+public class CDIValidationErrorManager extends ValidationErrorManager {
+
+ @Override
+ protected String getPreference(IProject project, String preferenceKey) {
+ return CDIPreferences.getInstance().getProjectPreference(project, preferenceKey);
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationErrorManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain