Author: dazarov
Date: 2010-09-03 12:02:37 -0400 (Fri, 03 Sep 2010)
New Revision: 24703
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AbstractSeamMarkerResolution.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AddAnnotaionMarkerResolution.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/DeleteAnnotaionMarkerResolution.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/SeamProblemMarkerResolutionGenerator.java
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/marker/SeamMarkerResolutionTest.java
Log:
https://jira.jboss.org/browse/JBIDE-6877
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AbstractSeamMarkerResolution.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AbstractSeamMarkerResolution.java 2010-09-03
15:55:04 UTC (rev 24702)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AbstractSeamMarkerResolution.java 2010-09-03
16:02:37 UTC (rev 24703)
@@ -10,12 +10,14 @@
******************************************************************************/
package org.jboss.tools.seam.ui.marker;
+import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IAnnotatable;
import org.eclipse.jdt.core.IAnnotation;
@@ -30,17 +32,25 @@
import org.eclipse.ui.IMarkerResolution2;
import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
+import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.ui.SeamGuiPlugin;
+import org.jboss.tools.seam.ui.internal.project.facet.SeamValidatorFactory;
/**
* @author Daniel Azarov
*/
public abstract class AbstractSeamMarkerResolution implements
IMarkerResolution2 {
+ protected String label;
+ protected String qualifiedName;
+
protected IFile file;
protected int start, end;
- public AbstractSeamMarkerResolution(IFile file, int start, int end){
+ public AbstractSeamMarkerResolution(String label, String qualifiedName, IFile file, int
start, int end){
+ this.label = label;
+ this.qualifiedName = qualifiedName;
this.file = file;
this.start = start;
this.end = end;
@@ -109,7 +119,33 @@
return name;
}
- protected void addAnnotation(String annotationTypeName, String annotationString){
+ protected boolean validateComponentName(String value){
+ ISeamProject seamProject = getSeamProject();
+ Map<String, IStatus> errors =
SeamValidatorFactory.SEAM_COMPONENT_NAME_VALIDATOR.validate(value, seamProject);
+ if(errors.isEmpty())
+ return true;
+
+ return false;
+ }
+
+ protected ISeamProject getSeamProject(){
+ return SeamCorePlugin.getSeamProject(file.getProject(), true);
+ }
+
+ protected String generateComponentName(String className){
+ String componentName = className.toLowerCase();
+ if(validateComponentName(componentName))
+ return componentName;
+ int index = 2;
+ String name = componentName;
+ while(!validateComponentName(componentName) && index < 100){
+ name = componentName+index;
+ index++;
+ }
+ return name;
+ }
+
+ protected void addAnnotation(String annotationTypeName, String annotationString, boolean
insertName){
try{
ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
@@ -117,13 +153,18 @@
IJavaElement javaElement = compilationUnit.getElementAt(start);
IType type = getType(javaElement);
if(type != null){
- if(compilationUnit.getImport(annotationTypeName) == null){
+ IImportDeclaration importDeclaration = compilationUnit.getImport(annotationTypeName);
+ if(importDeclaration == null || !importDeclaration.exists())
compilationUnit.createImport(annotationTypeName, null, new NullProgressMonitor());
- }
IBuffer buffer = compilationUnit.getBuffer();
- buffer.replace(type.getSourceRange().getOffset(), 0, annotationString+'\n');
+ String name="";
+ if(insertName){
+ name="(\""+generateComponentName(compilationUnit.findPrimaryType().getElementName())+"\")";
+ }
+
+ buffer.replace(type.getSourceRange().getOffset(), 0,
annotationString+name+'\n');
compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
}
}catch(CoreException ex){
@@ -161,7 +202,7 @@
}
public String getLabel() {
- return null;
+ return label;
}
public void run(IMarker marker) {
@@ -174,4 +215,13 @@
public Image getImage() {
return null;
}
+
+ /**
+ * Returns qualified name for test purpose
+ * @return
+ */
+ public String getQualifiedName(){
+ return qualifiedName;
+ }
+
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AddAnnotaionMarkerResolution.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AddAnnotaionMarkerResolution.java 2010-09-03
15:55:04 UTC (rev 24702)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AddAnnotaionMarkerResolution.java 2010-09-03
16:02:37 UTC (rev 24703)
@@ -18,21 +18,15 @@
*/
public class AddAnnotaionMarkerResolution extends
AbstractSeamMarkerResolution {
- private String label;
- private String qualifiedName;
+ boolean insertName;
- public AddAnnotaionMarkerResolution(String label, String qualifiedName, IFile file, int
start, int end){
- super(file, start, end);
- this.label = label;
- this.qualifiedName = qualifiedName;
+ public AddAnnotaionMarkerResolution(String label, String qualifiedName, IFile file, int
start, int end, boolean insertName){
+ super(label, qualifiedName, file, start, end);
+ this.insertName = insertName;
}
- public String getLabel() {
- return label;
- }
-
public void run(IMarker marker) {
- addAnnotation(qualifiedName,"@"+getShortName(qualifiedName)); //$NON-NLS-1$
+ addAnnotation(qualifiedName,"@"+getShortName(qualifiedName), insertName);
//$NON-NLS-1$
}
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/DeleteAnnotaionMarkerResolution.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/DeleteAnnotaionMarkerResolution.java 2010-09-03
15:55:04 UTC (rev 24702)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/DeleteAnnotaionMarkerResolution.java 2010-09-03
16:02:37 UTC (rev 24703)
@@ -18,13 +18,9 @@
*/
public class DeleteAnnotaionMarkerResolution extends
AbstractSeamMarkerResolution {
- private String label;
- private String qualifiedName;
public DeleteAnnotaionMarkerResolution(String label, String qualifiedName, IFile file,
int start, int end){
- super(file, start, end);
- this.label = label;
- this.qualifiedName = qualifiedName;
+ super(label, qualifiedName, file, start, end);
}
public String getLabel() {
@@ -34,13 +30,4 @@
public void run(IMarker marker) {
deleteAnnotation(qualifiedName);
}
-
- /**
- * Returns qualified name for test purpose
- * @return
- */
- public String getQualifiedName(){
- return qualifiedName;
- }
-
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/SeamProblemMarkerResolutionGenerator.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/SeamProblemMarkerResolutionGenerator.java 2010-09-03
15:55:04 UTC (rev 24702)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/SeamProblemMarkerResolutionGenerator.java 2010-09-03
16:02:37 UTC (rev 24703)
@@ -66,17 +66,17 @@
return new IMarkerResolution[]{new
DeleteAnnotaionMarkerResolution(SeamUIMessages.DELETE_DESTROY_ANNOTATION_MARKER_RESOLUTION_TITLE,
"org.jboss.seam.annotations.Destroy", file, start, end)};
else if(messageId == SeamCoreValidator.CREATE_DOESNT_BELONG_TO_COMPONENT_MESSAGE_ID)
return new IMarkerResolution[]{
- new
AddAnnotaionMarkerResolution(SeamUIMessages.ADD_NAME_ANNOTATION_MARKER_RESOLUTION_TITLE,
"org.jboss.seam.annotations.Name", file, start, end),
+ new
AddAnnotaionMarkerResolution(SeamUIMessages.ADD_NAME_ANNOTATION_MARKER_RESOLUTION_TITLE,
"org.jboss.seam.annotations.Name", file, start, end, true),
new
DeleteAnnotaionMarkerResolution(SeamUIMessages.DELETE_CREATE_ANNOTATION_MARKER_RESOLUTION_TITLE,
"org.jboss.seam.annotations.Create", file, start, end)
};
else if(messageId == SeamCoreValidator.UNWRAP_DOESNT_BELONG_TO_COMPONENT_MESSAGE_ID)
return new IMarkerResolution[]{
- new
AddAnnotaionMarkerResolution(SeamUIMessages.ADD_NAME_ANNOTATION_MARKER_RESOLUTION_TITLE,
"org.jboss.seam.annotations.Name", file, start, end),
+ new
AddAnnotaionMarkerResolution(SeamUIMessages.ADD_NAME_ANNOTATION_MARKER_RESOLUTION_TITLE,
"org.jboss.seam.annotations.Name", file, start, end, true),
new
DeleteAnnotaionMarkerResolution(SeamUIMessages.DELETE_UNWRAP_ANNOTATION_MARKER_RESOLUTION_TITLE,
"org.jboss.seam.annotations.Unwrap", file, start, end)
};
else if(messageId == SeamCoreValidator.OBSERVER_DOESNT_BELONG_TO_COMPONENT_MESSAGE_ID)
return new IMarkerResolution[]{
- new
AddAnnotaionMarkerResolution(SeamUIMessages.ADD_NAME_ANNOTATION_MARKER_RESOLUTION_TITLE,
"org.jboss.seam.annotations.Name", file, start, end),
+ new
AddAnnotaionMarkerResolution(SeamUIMessages.ADD_NAME_ANNOTATION_MARKER_RESOLUTION_TITLE,
"org.jboss.seam.annotations.Name", file, start, end, true),
new
DeleteAnnotaionMarkerResolution(SeamUIMessages.DELETE_OBSERVER_ANNOTATION_MARKER_RESOLUTION_TITLE,
"org.jboss.seam.annotations.Observer", file, start, end)
};
Modified:
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/marker/SeamMarkerResolutionTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/marker/SeamMarkerResolutionTest.java 2010-09-03
15:55:04 UTC (rev 24702)
+++
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/marker/SeamMarkerResolutionTest.java 2010-09-03
16:02:37 UTC (rev 24703)
@@ -21,6 +21,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.ide.IDE;
+import org.jboss.tools.seam.ui.marker.AddAnnotaionMarkerResolution;
import org.jboss.tools.seam.ui.marker.DeleteAnnotaionMarkerResolution;
import org.jboss.tools.test.util.JobUtils;
@@ -183,5 +184,104 @@
}
assertTrue("The quickfix \"Delete @Unwrap annotation\" doesn't
exist.", found);
}
+
+ public void testOnlyComponentClassCanHaveCreateMethodResolution() throws CoreException
{
+ String TARGET_FILE_NAME =
"src/action/org/domain/SeamWebWarTestProject/session/NonComponentWithCreateMethod.java";
+ IFile file = project.getFile(TARGET_FILE_NAME);
+
+ assertTrue("File - "+TARGET_FILE_NAME+" must be
exists",file.exists());
+
+ IMarker[] markers = file.findMarkers(MARKER_TYPE, true, IResource.DEPTH_INFINITE);
+
+ boolean dFound = false;
+ boolean cFound = false;
+ for (int i = 0; i < markers.length; i++) {
+ IMarker marker = markers[i];
+ IMarkerResolution[] resolutions = IDE.getMarkerHelpRegistry()
+ .getResolutions(marker);
+ for (int j = 0; j < resolutions.length; j++) {
+ IMarkerResolution resolution = resolutions[j];
+ if (resolution instanceof DeleteAnnotaionMarkerResolution) {
+ assertEquals("org.jboss.seam.annotations.Create",
((DeleteAnnotaionMarkerResolution)resolution).getQualifiedName());
+ dFound = true;
+ }
+ if (resolution instanceof AddAnnotaionMarkerResolution) {
+ assertEquals("org.jboss.seam.annotations.Name",
((AddAnnotaionMarkerResolution)resolution).getQualifiedName());
+ cFound = true;
+ }
+ }
+ if (dFound && cFound) {
+ break;
+ }
+ }
+ assertTrue("The quickfix \"Delete @Create annotation\" doesn't
exist.", dFound);
+ assertTrue("The quickfix \"Add @Name annotation\" doesn't
exist.", cFound);
+ }
+
+ public void testOnlyComponentClassCanHaveUnwrapMethodResolution() throws CoreException
{
+ String TARGET_FILE_NAME =
"src/action/org/domain/SeamWebWarTestProject/session/NonComponentWithUnwrapMethod.java";
+ IFile file = project.getFile(TARGET_FILE_NAME);
+
+ assertTrue("File - "+TARGET_FILE_NAME+" must be
exists",file.exists());
+
+ IMarker[] markers = file.findMarkers(MARKER_TYPE, true, IResource.DEPTH_INFINITE);
+
+ boolean dFound = false;
+ boolean cFound = false;
+ for (int i = 0; i < markers.length; i++) {
+ IMarker marker = markers[i];
+ IMarkerResolution[] resolutions = IDE.getMarkerHelpRegistry()
+ .getResolutions(marker);
+ for (int j = 0; j < resolutions.length; j++) {
+ IMarkerResolution resolution = resolutions[j];
+ if (resolution instanceof DeleteAnnotaionMarkerResolution) {
+ assertEquals("org.jboss.seam.annotations.Unwrap",
((DeleteAnnotaionMarkerResolution)resolution).getQualifiedName());
+ dFound = true;
+ }
+ if (resolution instanceof AddAnnotaionMarkerResolution) {
+ assertEquals("org.jboss.seam.annotations.Name",
((AddAnnotaionMarkerResolution)resolution).getQualifiedName());
+ cFound = true;
+ }
+ }
+ if (dFound && cFound) {
+ break;
+ }
+ }
+ assertTrue("The quickfix \"Delete @Unwrap annotation\" doesn't
exist.", dFound);
+ assertTrue("The quickfix \"Add @Name annotation\" doesn't
exist.", cFound);
+ }
+
+ public void testOnlyComponentClassCanHaveObserverMethodResolution() throws CoreException
{
+ String TARGET_FILE_NAME =
"src/action/org/domain/SeamWebWarTestProject/session/NonComponentWithObserverMethod.java";
+ IFile file = project.getFile(TARGET_FILE_NAME);
+
+ assertTrue("File - "+TARGET_FILE_NAME+" must be
exists",file.exists());
+
+ IMarker[] markers = file.findMarkers(MARKER_TYPE, true, IResource.DEPTH_INFINITE);
+
+ boolean dFound = false;
+ boolean cFound = false;
+ for (int i = 0; i < markers.length; i++) {
+ IMarker marker = markers[i];
+ IMarkerResolution[] resolutions = IDE.getMarkerHelpRegistry()
+ .getResolutions(marker);
+ for (int j = 0; j < resolutions.length; j++) {
+ IMarkerResolution resolution = resolutions[j];
+ if (resolution instanceof DeleteAnnotaionMarkerResolution) {
+ assertEquals("org.jboss.seam.annotations.Observer",
((DeleteAnnotaionMarkerResolution)resolution).getQualifiedName());
+ dFound = true;
+ }
+ if (resolution instanceof AddAnnotaionMarkerResolution) {
+ assertEquals("org.jboss.seam.annotations.Name",
((AddAnnotaionMarkerResolution)resolution).getQualifiedName());
+ cFound = true;
+ }
+ }
+ if (dFound && cFound) {
+ break;
+ }
+ }
+ assertTrue("The quickfix \"Delete @Observer annotation\" doesn't
exist.", dFound);
+ assertTrue("The quickfix \"Add @Name annotation\" doesn't
exist.", cFound);
+ }
}