Author: scabanovich
Date: 2011-05-12 12:29:30 -0400 (Thu, 12 May 2011)
New Revision: 31244
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/CDISeamConfigPreferences.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/TextSourceReference.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/validation/
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/validation/SeamConfigValidationMessages.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/validation/messages.properties
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/CDISeamConfigConstants.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/CDISeamConfigExtension.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/ConfigDefinitionContext.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/SeamBeansDefinition.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/scanner/SeamDefinitionBuilder.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/xml/SAXAttribute.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/xml/SAXParser.java
Log:
JBIDE-8940
https://issues.jboss.org/browse/JBIDE-8940
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/CDISeamConfigConstants.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/CDISeamConfigConstants.java 2011-05-12
16:27:35 UTC (rev 31243)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/CDISeamConfigConstants.java 2011-05-12
16:29:30 UTC (rev 31244)
@@ -28,6 +28,10 @@
public String ERROR_UNRESOLVED_MEMBER = "Unresolved member";
+ public String ERROR_UNRESOLVED_METHOD = "Unresolved method";
+
+ public String ERROR_UNRESOLVED_CONSTRUCTOR = "Unresolved constructor";
+
//Problem id: node was expected to be resolved to annotation type
public String ERROR_ANNOTATION_EXPECTED = "Annotation expected";
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/CDISeamConfigExtension.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/CDISeamConfigExtension.java 2011-05-12
16:27:35 UTC (rev 31243)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/CDISeamConfigExtension.java 2011-05-12
16:29:30 UTC (rev 31244)
@@ -13,6 +13,8 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.core.resources.IFile;
@@ -21,14 +23,22 @@
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.osgi.util.NLS;
import org.jboss.tools.cdi.core.CDICoreNature;
import org.jboss.tools.cdi.core.extension.ICDIExtension;
import org.jboss.tools.cdi.core.extension.IDefinitionContextExtension;
import org.jboss.tools.cdi.core.extension.feature.IBuildParticipantFeature;
+import org.jboss.tools.cdi.core.extension.feature.IValidatorFeature;
import org.jboss.tools.cdi.internal.core.scanner.FileSet;
+import org.jboss.tools.cdi.internal.core.validation.CDICoreValidator;
import org.jboss.tools.cdi.seam.config.core.definition.SeamBeansDefinition;
+import org.jboss.tools.cdi.seam.config.core.definition.TextSourceReference;
import org.jboss.tools.cdi.seam.config.core.scanner.ConfigFileSet;
import org.jboss.tools.cdi.seam.config.core.scanner.SeamDefinitionBuilder;
+import org.jboss.tools.cdi.seam.config.core.validation.SeamConfigValidationMessages;
+import org.jboss.tools.cdi.seam.config.core.xml.SAXAttribute;
+import org.jboss.tools.cdi.seam.config.core.xml.SAXElement;
+import org.jboss.tools.cdi.seam.config.core.xml.SAXNode;
import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.filesystems.impl.FileAnyImpl;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
@@ -38,7 +48,7 @@
* @author Viacheslav Kabanovich
*
*/
-public class CDISeamConfigExtension implements ICDIExtension, IBuildParticipantFeature {
+public class CDISeamConfigExtension implements ICDIExtension, IBuildParticipantFeature,
IValidatorFeature {
CDICoreNature project;
ConfigDefinitionContext context = new ConfigDefinitionContext();
@@ -147,4 +157,34 @@
return o;
}
+ public void validateResource(IFile file, CDICoreValidator validator) {
+ SeamBeansDefinition def = context.getDefinition(file.getFullPath());
+ if(def != null) {
+ Map<SAXNode, String> nodes = def.getUnresolvedNodes();
+ for (Entry<SAXNode, String> entry: nodes.entrySet()) {
+ SAXNode node = entry.getKey();
+ String problemId = entry.getValue();
+ if(CDISeamConfigConstants.ERROR_UNRESOLVED_TYPE.equals(problemId)) {
+ String name = node instanceof SAXElement ? ((SAXElement)node).getName() : node
instanceof SAXAttribute ? ((SAXAttribute)node).getName() : null;
+ String message = NLS.bind(SeamConfigValidationMessages.UNRESOLVED_TYPE, name);
+ validator.addError(message, CDISeamConfigPreferences.UNRESOLVED_TYPE, new
TextSourceReference(file, node), file);
+ } else if(CDISeamConfigConstants.ERROR_UNRESOLVED_MEMBER.equals(problemId)) {
+ String name = node instanceof SAXElement ? ((SAXElement)node).getName() : node
instanceof SAXAttribute ? ((SAXAttribute)node).getName() : null;
+ String message = NLS.bind(SeamConfigValidationMessages.UNRESOLVED_MEMBER, name);
+ validator.addError(message, CDISeamConfigPreferences.UNRESOLVED_MEMBER, new
TextSourceReference(file, node), file);
+ } else if(CDISeamConfigConstants.ERROR_UNRESOLVED_METHOD.equals(problemId)) {
+ String message = NLS.bind(SeamConfigValidationMessages.UNRESOLVED_METHOD,
((SAXElement)node).getName());
+ validator.addError(message, CDISeamConfigPreferences.UNRESOLVED_METHOD, new
TextSourceReference(file, node), file);
+ } else if(CDISeamConfigConstants.ERROR_UNRESOLVED_CONSTRUCTOR.equals(problemId)) {
+ String name = node instanceof SAXElement && ((SAXElement)node).getParent()
!= null ? ((SAXElement)node).getParent().getName() : null;
+ String message = NLS.bind(SeamConfigValidationMessages.UNRESOLVED_CONSTRUCTOR,
((SAXElement)node).getParent().getName());
+ validator.addError(message, CDISeamConfigPreferences.UNRESOLVED_CONSTRUCTOR, new
TextSourceReference(file, node), file);
+ } else if(CDISeamConfigConstants.ERROR_ANNOTATION_EXPECTED.equals(problemId)) {
+ String message = NLS.bind(SeamConfigValidationMessages.ANNOTATION_EXPECTED, null);
+ validator.addError(message, CDISeamConfigPreferences.ANNOTATION_EXPECTED, new
TextSourceReference(file, node), file);
+ }
+ }
+ }
+ }
+
}
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/CDISeamConfigPreferences.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/CDISeamConfigPreferences.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/CDISeamConfigPreferences.java 2011-05-12
16:29:30 UTC (rev 31244)
@@ -0,0 +1,42 @@
+package org.jboss.tools.cdi.seam.config.core;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.tools.common.preferences.SeverityPreferences;
+
+public class CDISeamConfigPreferences extends SeverityPreferences {
+ public static final Set<String> SEVERITY_OPTION_NAMES = new
HashSet<String>();
+
+ private static CDISeamConfigPreferences INSTANCE = new CDISeamConfigPreferences();
+
+ public static final String UNRESOLVED_TYPE =
INSTANCE.createSeverityOption("unresolvedType");
+ public static final String UNRESOLVED_MEMBER =
INSTANCE.createSeverityOption("unresolvedMember");
+ public static final String UNRESOLVED_METHOD =
INSTANCE.createSeverityOption("unresolvedMethod");
+ public static final String UNRESOLVED_CONSTRUCTOR =
INSTANCE.createSeverityOption("unresolvedConstructor");
+ public static final String ANNOTATION_EXPECTED =
INSTANCE.createSeverityOption("annotationExpected");
+
+ public static CDISeamConfigPreferences getInstance() {
+ return INSTANCE;
+ }
+
+ private CDISeamConfigPreferences() {}
+
+ @Override
+ protected Set<String> getSeverityOptionNames() {
+ return SEVERITY_OPTION_NAMES;
+ }
+
+ @Override
+ protected String createSeverityOption(String shortName) {
+ String name = getPluginId() + ".validator.problem." + shortName;
//$NON-NLS-1$
+ SEVERITY_OPTION_NAMES.add(name);
+ return name;
+ }
+
+ @Override
+ protected String getPluginId() {
+ return CDISeamConfigCorePlugin.PLUGIN_ID;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/CDISeamConfigPreferences.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/ConfigDefinitionContext.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/ConfigDefinitionContext.java 2011-05-12
16:27:35 UTC (rev 31243)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/ConfigDefinitionContext.java 2011-05-12
16:29:30 UTC (rev 31244)
@@ -58,7 +58,8 @@
beanXMLs = copy.beanXMLs;
seambeanXMLs = copy.seambeanXMLs;
- for (String s: annotations.keySet()) {
+ String[] as = annotations.keySet().toArray(new String[0]);
+ for (String s: as) {
if(!copy.annotations.containsKey(s)) {
//Remove from root and reload it in root.
AnnotationDefinition d = annotations.get(s);
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/SeamBeansDefinition.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/SeamBeansDefinition.java 2011-05-12
16:27:35 UTC (rev 31243)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/SeamBeansDefinition.java 2011-05-12
16:29:30 UTC (rev 31244)
@@ -100,7 +100,10 @@
}
//Initialize typeDef taking into account replaces and modifies
int flags = AbstractMemberDefinition.FLAG_ALL_MEMBERS;
- if(replaces) flags |= AbstractMemberDefinition.FLAG_NO_ANNOTATIONS;
+ if(!modifies) {
+ //For replacing or created - no annotations loaded.
+ flags |= AbstractMemberDefinition.FLAG_NO_ANNOTATIONS;
+ }
typeDef.setType(type, context.getRootContext(), flags);
mergeTypeDefinition(def, typeDef, context);
@@ -134,7 +137,7 @@
String n = fieldDef.getField().getElementName();
SeamFieldDefinition f = def.getField(n);
if(f != null) {
- fieldDef.setOriginalDefinition(new TextSourceReference(f.getNode().getLocation()));
+ fieldDef.setOriginalDefinition(new TextSourceReference(resource, f.getNode()));
mergeAnnotations(f, fieldDef, context);
}
}
@@ -172,25 +175,4 @@
}
}
- class TextSourceReference implements ITextSourceReference {
- Location location;
-
- public TextSourceReference(Location location) {
- this.location = location;
- }
-
- public int getStartPosition() {
- return location.getStartPosition();
- }
-
- public int getLength() {
- return location.getLength();
- }
-
- public IResource getResource() {
- return resource;
- }
-
- }
-
}
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/TextSourceReference.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/TextSourceReference.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/TextSourceReference.java 2011-05-12
16:29:30 UTC (rev 31244)
@@ -0,0 +1,28 @@
+package org.jboss.tools.cdi.seam.config.core.definition;
+
+import org.eclipse.core.resources.IResource;
+import org.jboss.tools.cdi.seam.config.core.xml.SAXNode;
+import org.jboss.tools.common.text.ITextSourceReference;
+
+public class TextSourceReference implements ITextSourceReference {
+ IResource resource;
+ SAXNode node;
+
+ public TextSourceReference(IResource resource, SAXNode node) {
+ this.resource = resource;
+ this.node = node;
+ }
+
+ public int getStartPosition() {
+ return node.getLocation().getStartPosition();
+ }
+
+ public int getLength() {
+ return node.getLocation().getLength();
+ }
+
+ public IResource getResource() {
+ return resource;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/definition/TextSourceReference.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/scanner/SeamDefinitionBuilder.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/scanner/SeamDefinitionBuilder.java 2011-05-12
16:27:35 UTC (rev 31243)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/scanner/SeamDefinitionBuilder.java 2011-05-12
16:29:30 UTC (rev 31244)
@@ -227,6 +227,8 @@
IJavaAnnotation a = loadAnnotationDeclaration(c, IN_ANNOTATION_TYPE);
if(a != null) def.addAnnotation(a);
continue;
+ } else {
+ result.addUnresolvedNode(c, CDISeamConfigConstants.ERROR_UNRESOLVED_TYPE);
}
}
@@ -315,6 +317,8 @@
IJavaAnnotation a = loadAnnotationDeclaration(c, IN_ANNOTATION_TYPE);
if(a != null) def.addAnnotation(a);
continue;
+ } else {
+ result.addUnresolvedNode(c, CDISeamConfigConstants.ERROR_UNRESOLVED_TYPE);
}
}
@@ -326,6 +330,9 @@
}
if(method != null) {
def.setMethod(method);
+ } else {
+ result.addUnresolvedNode(element, CDISeamConfigConstants.ERROR_UNRESOLVED_METHOD);
+ def = null;
}
return def;
}
@@ -353,6 +360,9 @@
}
if(method != null) {
def.setMethod(method);
+ } else {
+ result.addUnresolvedNode(element,
CDISeamConfigConstants.ERROR_UNRESOLVED_CONSTRUCTOR);
+ def = null;
}
return def;
@@ -435,8 +445,13 @@
value, IMemberValuePair.K_STRING, type);
Set<String> ns = element.getAttributeNames();
for (String n: ns) {
- String v = element.getAttribute(n).getValue();
+ SAXAttribute attr = element.getAttribute(n);
+ String v = attr.getValue();
literal.addMemberValuePair(n, v, IMemberValuePair.K_STRING);
+ IMethod m = type.getMethod(n, new String[0]);
+ if(!m.exists()) {
+ result.addUnresolvedNode(attr, CDISeamConfigConstants.ERROR_UNRESOLVED_MEMBER);
+ }
}
return literal;
} else if(contextKind == IN_ANNOTATION_TYPE) {
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/validation/SeamConfigValidationMessages.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/validation/SeamConfigValidationMessages.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/validation/SeamConfigValidationMessages.java 2011-05-12
16:29:30 UTC (rev 31244)
@@ -0,0 +1,19 @@
+package org.jboss.tools.cdi.seam.config.core.validation;
+
+import org.eclipse.osgi.util.NLS;
+
+public class SeamConfigValidationMessages {
+
+ private static final String BUNDLE_NAME =
SeamConfigValidationMessages.class.getPackage().getName() + ".messages";
//$NON-NLS-1$
+
+ public static String UNRESOLVED_TYPE;
+ public static String UNRESOLVED_MEMBER;
+ public static String UNRESOLVED_METHOD;
+ public static String UNRESOLVED_CONSTRUCTOR;
+ public static String ANNOTATION_EXPECTED;
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, SeamConfigValidationMessages.class);
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/validation/SeamConfigValidationMessages.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/validation/messages.properties
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/validation/messages.properties
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/validation/messages.properties 2011-05-12
16:29:30 UTC (rev 31244)
@@ -0,0 +1,5 @@
+UNRESOLVED_TYPE=Cannot resolve type in node {0}.
+UNRESOLVED_MEMBER=Cannot resolve member in node {0}.
+UNRESOLVED_METHOD=Cannot resolve method in node {0}.
+UNRESOLVED_CONSTRUCTOR=Cannot resolve constructor in type node {0}.
+ANNOTATION_EXPECTED=Annotation types are only allowed here.
\ No newline at end of file
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/validation/messages.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/xml/SAXAttribute.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/xml/SAXAttribute.java 2011-05-12
16:27:35 UTC (rev 31243)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/xml/SAXAttribute.java 2011-05-12
16:29:30 UTC (rev 31244)
@@ -17,7 +17,7 @@
*/
public class SAXAttribute extends SAXText {
private String name;
- private Location nameLocation;
+ private Location valueLocation;
private SAXElement parent;
@@ -30,19 +30,19 @@
}
public void setNameLocation(Location location) {
- nameLocation = location;
+ setLocation(location);
}
public Location getNameLocation() {
- return nameLocation;
+ return getLocation();
}
public void setValueLocation(Location location) {
- setLocation(location);
+ valueLocation = location;
}
public Location getValueLocation() {
- return getLocation();
+ return valueLocation;
}
public void setParent(SAXElement parent) {
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/xml/SAXParser.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/xml/SAXParser.java 2011-05-12
16:27:35 UTC (rev 31243)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.config.core/src/org/jboss/tools/cdi/seam/config/core/xml/SAXParser.java 2011-05-12
16:29:30 UTC (rev 31244)
@@ -43,7 +43,7 @@
setFeature(parserInstance, VALIDATION_SCHEMA_FEATURE_ID, true);
setFeature(parserInstance, VALIDATION_SCHEMA_CHECKING_FEATURE_ID, false);
setFeature(parserInstance, VALIDATION_DYNAMIC_FEATURE_ID, false);
- setFeature(parserInstance, FATAL_ERROR_PROCESSING_FEATURE_ID, false);
+ setFeature(parserInstance, FATAL_ERROR_PROCESSING_FEATURE_ID, true);
try {
parserInstance.setProperty(ENTITY_RESOLVER_PROPERTY_ID, new XMLEntityResolverImpl());