[jbosstools-commits] JBoss Tools SVN: r39327 - in trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core: validation and 1 other directory.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Tue Mar 6 20:35:47 EST 2012
Author: scabanovich
Date: 2012-03-06 20:35:47 -0500 (Tue, 06 Mar 2012)
New Revision: 39327
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/BeansXMLDefinition.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/BeansXmlValidationDelegate.java
Log:
JBIDE-11173
https://issues.jboss.org/browse/JBIDE-11173
Attributes 'path' and 'attribute' are set to error markers created by beans.xml validator.
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/BeansXMLDefinition.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/BeansXMLDefinition.java 2012-03-07 01:33:50 UTC (rev 39326)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/BeansXMLDefinition.java 2012-03-07 01:35:47 UTC (rev 39327)
@@ -14,6 +14,7 @@
import java.util.Set;
import org.eclipse.core.runtime.IPath;
+import org.jboss.tools.cdi.xml.beans.model.CDIBeansConstants;
import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.filesystems.impl.FileAnyImpl;
import org.jboss.tools.common.model.filesystems.impl.FolderImpl;
@@ -24,12 +25,7 @@
* @author Viacheslav Kabanovich
*
*/
-public class BeansXMLDefinition {
- static String NODE_INTERCEPTORS = "Interceptors";
- static String NODE_DECORATORS = "Decorators";
- static String NODE_ALTERNATIVES = "Alternatives";
- static String ATTR_CLASS = "class";
- static String ATTR_STEREOTYPE = "stereotype";
+public class BeansXMLDefinition implements CDIBeansConstants {
private IPath path;
private Set<INodeReference> typeAlternatives = new HashSet<INodeReference>();
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/BeansXmlValidationDelegate.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/BeansXmlValidationDelegate.java 2012-03-07 01:33:50 UTC (rev 39326)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/BeansXmlValidationDelegate.java 2012-03-07 01:35:47 UTC (rev 39327)
@@ -21,6 +21,7 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
@@ -45,7 +46,10 @@
import org.jboss.tools.cdi.core.IInterceptor;
import org.jboss.tools.cdi.core.IStereotype;
import org.jboss.tools.cdi.core.preferences.CDIPreferences;
+import org.jboss.tools.cdi.xml.beans.model.CDIBeansConstants;
import org.jboss.tools.common.EclipseUtil;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.impl.XModelObjectImpl;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.w3c.dom.Element;
@@ -97,6 +101,9 @@
}
public void validateBeansXml(CDICoreValidator.CDIValidationContext context, IFile beansXml) {
+ XModelObject f = EclipseResourceUtil.createObjectForResource(beansXml);
+ String xmodelpath = (f == null) ? "" : f.getPath();
+
IModelManager manager = StructuredModelManager.getModelManager();
if(manager == null) {
// this may happen if plug-in org.eclipse.wst.sse.core
@@ -120,7 +127,7 @@
* - If the same type is listed twice under the <alternatives> element, the container automatically detects the problem and
* treats it as a deployment problem.
*/
- validateTypeBeanForBeansXml(context, getAlternativeClassValidator(), document, beansXml);
+ validateTypeBeanForBeansXml(context, getAlternativeClassValidator(), document, beansXml, xmodelpath + "/" + CDIBeansConstants.NODE_ALTERNATIVES); //$NON-NLS-1$
/*
* 5.1.1. Declaring selected alternatives for a bean archive
@@ -130,7 +137,7 @@
* - If the same type is listed twice under the <alternatives> element, the container automatically detects the problem and
* treats it as a deployment problem.
*/
- validateTypeBeanForBeansXml(context, getAlternativeStereotypeValidator(), document, beansXml);
+ validateTypeBeanForBeansXml(context, getAlternativeStereotypeValidator(), document, beansXml, xmodelpath + "/" + CDIBeansConstants.NODE_ALTERNATIVES); //$NON-NLS-1$
/*
* 8.2. Decorator enablement and ordering
@@ -140,7 +147,7 @@
* - If the same class is listed twice under the <decorators> element, the container automatically detects the problem and
* treats it as a deployment problem.
*/
- validateTypeBeanForBeansXml(context, getDecoratorTypeValidator(), document, beansXml);
+ validateTypeBeanForBeansXml(context, getDecoratorTypeValidator(), document, beansXml, xmodelpath + "/" + CDIBeansConstants.NODE_DECORATORS); //$NON-NLS-1$
/*
* 9.4. Interceptor enablement and ordering
@@ -150,7 +157,7 @@
* - If the same class is listed twice under the <interceptors> element, the container automatically detects the problem and treats it as
* a deployment problem.
*/
- validateTypeBeanForBeansXml(context, getInterceptorTypeValidator(), document, beansXml);
+ validateTypeBeanForBeansXml(context, getInterceptorTypeValidator(), document, beansXml, xmodelpath + "/" + CDIBeansConstants.NODE_INTERCEPTORS); //$NON-NLS-1$
}
} catch (CoreException e) {
CDICorePlugin.getDefault().logError(e);
@@ -163,7 +170,7 @@
}
}
- private void validateTypeBeanForBeansXml(CDICoreValidator.CDIValidationContext context, TypeValidator typeValidator, IDOMDocument document, IFile beansXml) {
+ private void validateTypeBeanForBeansXml(CDICoreValidator.CDIValidationContext context, TypeValidator typeValidator, IDOMDocument document, IFile beansXml, String xmodelpath) {
try {
NodeList parentNodeList = document.getElementsByTagName(typeValidator.getParrentElementname());
for (int i = 0; i < parentNodeList.getLength(); i++) {
@@ -172,7 +179,13 @@
List<TypeNode> typeNodes = getTypeElements((Element)parentNode, typeValidator.getTypeElementName());
Map<String, TypeNode> uniqueTypes = new HashMap<String, TypeNode>();
for (TypeNode typeNode : typeNodes) {
- IType type = getType(beansXml, typeNode, typeValidator.getUnknownTypeErrorMessage(), typeValidator.getUnknownTypeErrorMessageId());
+ String typepath = xmodelpath;
+ String attr = null;
+ if(typeNode.getTypeName().length() > 0) {
+ typepath = typepath + "/" + typeNode.getTypeName();
+ attr = typeValidator.getTypeElementName();
+ }
+ IType type = getType(beansXml, typeNode, typeValidator.getUnknownTypeErrorMessage(), typeValidator.getUnknownTypeErrorMessageId(), typepath, attr);
if(type!=null) {
if(!type.isBinary()) {
validator.getValidationContext().addLinkedCoreResource(CDICoreValidator.SHORT_ID, beansXml.getFullPath().toOSString(), type.getPath(), false);
@@ -186,29 +199,42 @@
}
}
if(!typeValidator.validateKindOfType(type)) {
- validator.addError(typeValidator.getIllegalTypeErrorMessage(), CDIPreferences.ILLEGAL_TYPE_NAME_IN_BEANS_XML,
+ IMarker marker = validator.addError(typeValidator.getIllegalTypeErrorMessage(), CDIPreferences.ILLEGAL_TYPE_NAME_IN_BEANS_XML,
new String[]{}, typeNode.getLength(), typeNode.getStartOffset(), beansXml, typeValidator.getIllegalTypeErrorMessageId());
+ if(marker != null) bindMarkerToModel(marker, typepath, typeValidator.getTypeElementName());
} else if(type.isBinary()) {
if(!typeValidator.validateBinaryType(type)) {
- validator.addError(typeValidator.getIllegalTypeErrorMessage(), CDIPreferences.ILLEGAL_TYPE_NAME_IN_BEANS_XML,
+ IMarker marker = validator.addError(typeValidator.getIllegalTypeErrorMessage(), CDIPreferences.ILLEGAL_TYPE_NAME_IN_BEANS_XML,
new String[]{}, typeNode.getLength(), typeNode.getStartOffset(), beansXml, typeValidator.getIllegalTypeErrorMessageId());
+ if(marker != null) bindMarkerToModel(marker, typepath, typeValidator.getTypeElementName());
}
continue;
} else {
if(!typeValidator.validateSourceType(context, type)) {
- validator.addError(typeValidator.getIllegalTypeErrorMessage(), CDIPreferences.ILLEGAL_TYPE_NAME_IN_BEANS_XML,
+ IMarker marker = validator.addError(typeValidator.getIllegalTypeErrorMessage(), CDIPreferences.ILLEGAL_TYPE_NAME_IN_BEANS_XML,
new String[]{}, typeNode.getLength(), typeNode.getStartOffset(), beansXml, typeValidator.getIllegalTypeErrorMessageId());
+ if(marker != null) bindMarkerToModel(marker, typepath, typeValidator.getTypeElementName());
}
}
TypeNode node = uniqueTypes.get(typeNode.getTypeName());
if(node!=null) {
if(!node.isMarkedAsDuplicated()) {
- validator.addError(typeValidator.getDuplicateTypeErrorMessage(), CDIPreferences.DUPLICATE_TYPE_IN_BEANS_XML,
+ IMarker marker = validator.addError(typeValidator.getDuplicateTypeErrorMessage(), CDIPreferences.DUPLICATE_TYPE_IN_BEANS_XML,
new String[]{}, node.getLength(), node.getStartOffset(), beansXml);
+ if(marker != null) bindMarkerToModel(marker, typepath, typeValidator.getTypeElementName());
}
node.setMarkedAsDuplicated(true);
- validator.addError(typeValidator.getDuplicateTypeErrorMessage(), CDIPreferences.DUPLICATE_TYPE_IN_BEANS_XML,
+ typeNode.setMarkedAsDuplicated(true);
+ typeNode.setDuplicationIndex(node.getDuplicationIndex() + 1);
+ IMarker marker = validator.addError(typeValidator.getDuplicateTypeErrorMessage(), CDIPreferences.DUPLICATE_TYPE_IN_BEANS_XML,
new String[]{}, typeNode.getLength(), typeNode.getStartOffset(), beansXml);
+ if(marker != null) {
+ int di = typeNode.getDuplicationIndex();
+ if(di > 0) {
+ typepath += XModelObjectImpl.DUPLICATE + di;
+ }
+ bindMarkerToModel(marker, typepath, typeValidator.getTypeElementName());
+ }
}
uniqueTypes.put(typeNode.getTypeName(), typeNode);
}
@@ -240,7 +266,7 @@
return null;
}
- private IType getType(IFile beansXml, TypeNode node, String errorMessage, int errorMessageId) {
+ private IType getType(IFile beansXml, TypeNode node, String errorMessage, int errorMessageId, String xmodelpath, String attr) {
IType type = null;
if(node.getTypeName()!=null) {
try {
@@ -255,12 +281,27 @@
}
if(type==null) {
addLinkedResourcesForUnknownType(beansXml, node.getTypeName());
- validator.addError(errorMessage, CDIPreferences.ILLEGAL_TYPE_NAME_IN_BEANS_XML,
+ IMarker marker = validator.addError(errorMessage, CDIPreferences.ILLEGAL_TYPE_NAME_IN_BEANS_XML,
new String[]{}, node.getLength(), node.getStartOffset(), beansXml, errorMessageId);
+ bindMarkerToModel(marker, xmodelpath, attr);
}
return type;
}
+ private void bindMarkerToModel(IMarker marker, String path, String attribute) {
+ try {
+ if(marker!=null) {
+ marker.setAttribute("path", path); //$NON-NLS-1$
+ if(attribute != null) {
+ marker.setAttribute("attribute", attribute); //$NON-NLS-1$
+ }
+ }
+ } catch(CoreException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
+
+ }
+
private void addLinkedResourcesForUnknownType(IFile beansXml, String typeName) {
if(typeName!=null && typeName.trim().length()>0) {
IStatus status = JavaConventions.validateJavaTypeName(typeName, CompilerOptions.VERSION_1_7, CompilerOptions.VERSION_1_7);
@@ -318,6 +359,7 @@
private int length;
private String typeName;
private boolean markedAsDuplicated;
+ private int duplicationIndex = 0;
public TypeNode(int startOffset, int length, String typeName) {
this.startOffset = startOffset;
@@ -356,6 +398,14 @@
public void setMarkedAsDuplicated(boolean markedAsDuplicated) {
this.markedAsDuplicated = markedAsDuplicated;
}
+
+ public int getDuplicationIndex() {
+ return duplicationIndex;
+ }
+
+ public void setDuplicationIndex(int i) {
+ duplicationIndex = i;
+ }
}
private static interface TypeValidator {
More information about the jbosstools-commits
mailing list