Author: akazakov
Date: 2009-06-08 15:27:21 -0400 (Mon, 08 Jun 2009)
New Revision: 15782
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamValidatorsTest.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4393
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 2009-06-08
18:22:53 UTC (rev 15781)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java 2009-06-08
19:27:21 UTC (rev 15782)
@@ -483,12 +483,74 @@
private void validateXmlComponentDeclarations(ISeamComponent component) {
String componentName = component.getName();
if(componentName!=null) {
+ HashMap<String, ISeamXmlComponentDeclaration> usedPrecedences = new
HashMap<String, ISeamXmlComponentDeclaration>();
+ Set<ISeamXmlComponentDeclaration> markedDeclarations = new
HashSet<ISeamXmlComponentDeclaration>();
+ Set<ISeamJavaComponentDeclaration> markedJavaDeclarations = new
HashSet<ISeamJavaComponentDeclaration>();
Set<ISeamXmlComponentDeclaration> declarations =
component.getXmlDeclarations();
+ ISeamXmlComponentDeclaration firstNamedDeclaration = null;
for (ISeamXmlComponentDeclaration declaration : declarations) {
if(coreHelper.isJar(declaration)) {
return;
}
+ //do not check files declared in another project
+ if(declaration.getSeamProject() != seamProject) continue;
+
validationContext.addLinkedCoreResource(componentName, declaration.getSourcePath());
+
+ if(firstNamedDeclaration == null && declaration.getName()!=null) {
+ firstNamedDeclaration = declaration;
+ }
+ String precedence = declaration.getPrecedence();
+ if(declaration.getName()!=null && firstNamedDeclaration!=declaration) {
+ // Check precedence
+ ISeamXmlComponentDeclaration checkedDeclaration = usedPrecedences.get(precedence);
+ if(checkedDeclaration==null) {
+ usedPrecedences.put(precedence, declaration);
+ } else {
+ // Mark not-unique name.
+ if(!markedDeclarations.contains(checkedDeclaration)) {
+ // Mark first wrong declaration with that name
+ IResource checkedDeclarationResource = checkedDeclaration.getResource();
+ ITextSourceReference location =
((SeamComponentDeclaration)checkedDeclaration).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
+ if(!isEmptyLocation(location)) {
+ addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID,
SeamPreferences.NONUNIQUE_COMPONENT_NAME, new String[]{componentName}, location,
checkedDeclarationResource);
+ }
+ markedDeclarations.add(checkedDeclaration);
+ }
+ // Mark next wrong declaration with that name
+ markedDeclarations.add(declaration);
+ ITextSourceReference location =
((SeamComponentDeclaration)declaration).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
+ if(!isEmptyLocation(location)) {
+ addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID,
SeamPreferences.NONUNIQUE_COMPONENT_NAME, new String[]{componentName}, location,
declaration.getResource());
+ }
+ }
+ }
+
+ // Check Java declarations with the same name
+ Set<ISeamComponentDeclaration> decls = component.getAllDeclarations();
+ for (ISeamComponentDeclaration dec : decls) {
+ if(dec instanceof ISeamJavaComponentDeclaration) {
+ ISeamJavaComponentDeclaration javaDec = (ISeamJavaComponentDeclaration)dec;
+ // Check names
+ if(javaDec.getName()!=null &&
javaDec.getName().equals(declaration.getName())) {
+ // Check precedences
+ String javaPrecedence = "" + javaDec.getPrecedence();
+ if(javaPrecedence.equals(precedence)) {
+ if(!markedJavaDeclarations.contains(javaDec)) {
+ markedJavaDeclarations.add(javaDec);
+ ITextSourceReference location =
((SeamComponentDeclaration)javaDec).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
+ addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID,
SeamPreferences.NONUNIQUE_COMPONENT_NAME, new String[]{componentName}, location,
declaration.getResource());
+ }
+ if(!markedJavaDeclarations.contains(javaDec)) {
+ markedDeclarations.add(declaration);
+ ITextSourceReference location =
((SeamComponentDeclaration)declaration).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
+ addError(NONUNIQUE_COMPONENT_NAME_MESSAGE_ID,
SeamPreferences.NONUNIQUE_COMPONENT_NAME, new String[]{componentName}, location,
declaration.getResource());
+ }
+ }
+ }
+ }
+ }
+
String className = component.getClassName();
if(className!=null) {
IType type = null;
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamValidatorsTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamValidatorsTest.java 2009-06-08
18:22:53 UTC (rev 15781)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamValidatorsTest.java 2009-06-08
19:27:21 UTC (rev 15782)
@@ -857,9 +857,9 @@
public static int getMarkersNumber(IResource resource){
try{
IMarker[] markers = resource.findMarkers(MARKER_TYPE, true,
IResource.DEPTH_INFINITE);
- for(int i=0;i<markers.length;i++){
- System.out.println("Marker - "+markers[i].getAttribute(IMarker.MESSAGE,
""));
- }
+// for(int i=0;i<markers.length;i++){
+// System.out.println("Marker - "+markers[i].getAttribute(IMarker.MESSAGE,
""));
+// }
return markers.length;
}catch(CoreException ex){
JUnitUtils.fail("Can'r get problem markers", ex);