Author: dazarov
Date: 2010-09-08 08:31:17 -0400 (Wed, 08 Sep 2010)
New Revision: 24811
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AddAnnotatedMethodMarkerResolution.java
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/SeamWebWarTestProject/src/action/org/domain/SeamWebWarTestProject/session/StatefulComponentWithoutDestroy.java
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/SeamWebWarTestProject/src/action/org/domain/SeamWebWarTestProject/session/StatefulComponentWithoutRemove.java
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.ui/src/org/jboss/tools/seam/ui/SeamUIMessages.java
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/AddAnnotationMarkerResolution.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/DeleteAnnotationMarkerResolution.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/RenameAnnotationMarkerResolution.java
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/messages.properties
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-6870
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 2010-09-08
11:09:24 UTC (rev 24810)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java 2010-09-08
12:31:17 UTC (rev 24811)
@@ -96,7 +96,10 @@
public static final int CREATE_DOESNT_BELONG_TO_COMPONENT_MESSAGE_ID = 7;
public static final int UNWRAP_DOESNT_BELONG_TO_COMPONENT_MESSAGE_ID = 8;
public static final int OBSERVER_DOESNT_BELONG_TO_COMPONENT_MESSAGE_ID = 9;
+ public static final int STATEFUL_COMPONENT_DOES_NOT_CONTAIN_REMOVE_ID = 10;
+ public static final int STATEFUL_COMPONENT_DOES_NOT_CONTAIN_DESTROY_ID = 11;
+
private ISeamProject seamProject;
private String projectName;
@@ -756,8 +759,8 @@
private void validateStatefulComponent(ISeamComponent component) {
if(component.isStateful()) {
ISeamJavaComponentDeclaration javaDeclaration = component.getJavaDeclaration();
- validateStatefulComponentMethods(SeamComponentMethodType.DESTROY, component,
SeamValidationMessages.STATEFUL_COMPONENT_DOES_NOT_CONTAIN_DESTROY,
SeamPreferences.STATEFUL_COMPONENT_DOES_NOT_CONTENT_DESTROY);
- validateStatefulComponentMethods(SeamComponentMethodType.REMOVE, component,
SeamValidationMessages.STATEFUL_COMPONENT_DOES_NOT_CONTAIN_REMOVE,
SeamPreferences.STATEFUL_COMPONENT_DOES_NOT_CONTENT_REMOVE);
+ validateStatefulComponentMethods(SeamComponentMethodType.DESTROY, component,
SeamValidationMessages.STATEFUL_COMPONENT_DOES_NOT_CONTAIN_DESTROY,
SeamPreferences.STATEFUL_COMPONENT_DOES_NOT_CONTENT_DESTROY,
STATEFUL_COMPONENT_DOES_NOT_CONTAIN_DESTROY_ID);
+ validateStatefulComponentMethods(SeamComponentMethodType.REMOVE, component,
SeamValidationMessages.STATEFUL_COMPONENT_DOES_NOT_CONTAIN_REMOVE,
SeamPreferences.STATEFUL_COMPONENT_DOES_NOT_CONTENT_REMOVE,
STATEFUL_COMPONENT_DOES_NOT_CONTAIN_REMOVE_ID);
ScopeType scope = component.getScope();
if(scope == ScopeType.PAGE || scope == ScopeType.STATELESS) {
ITextSourceReference location = getScopeLocation(component);
@@ -767,12 +770,12 @@
}
}
- private void validateStatefulComponentMethods(SeamComponentMethodType methodType,
ISeamComponent component, String message, String preferenceKey) {
+ private void validateStatefulComponentMethods(SeamComponentMethodType methodType,
ISeamComponent component, String message, String preferenceKey, int id) {
ISeamJavaComponentDeclaration javaDeclaration = component.getJavaDeclaration();
ITextSourceReference classNameLocation = getNameLocation(javaDeclaration);
Set<ISeamComponentMethod> methods =
javaDeclaration.getMethodsByType(methodType);
if(methods==null || methods.isEmpty()) {
- addError(message, preferenceKey, new String[]{component.getName()}, classNameLocation,
javaDeclaration.getResource());
+ addError(message, preferenceKey, new String[]{component.getName()}, classNameLocation,
javaDeclaration.getResource(), id);
}
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamUIMessages.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamUIMessages.java 2010-09-08
11:09:24 UTC (rev 24810)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamUIMessages.java 2010-09-08
12:31:17 UTC (rev 24811)
@@ -376,6 +376,10 @@
public static String RENAME_NAME_ANNOTATION_MARKER_RESOLUTION_TITLE;
+ public static String ADD_ANNOTATED_REMOVE_METHOD_MARKER_RESOLUTION_TITLE;
+
+ public static String ADD_ANNOTATED_DESTROY_METHOD_MARKER_RESOLUTION_TITLE;
+
static {
// load message values from bundle file
NLS.initializeMessages(BUNDLE_NAME, SeamUIMessages.class);
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-08
11:09:24 UTC (rev 24810)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AbstractSeamMarkerResolution.java 2010-09-08
12:31:17 UTC (rev 24811)
@@ -26,6 +26,7 @@
import org.eclipse.jdt.core.IImportContainer;
import org.eclipse.jdt.core.IImportDeclaration;
import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.swt.graphics.Image;
@@ -78,7 +79,7 @@
if(importDeclaration != null && importContainer != null){
int importSize =
importContainer.getSourceRange().getOffset()+importContainer.getSourceRange().getLength();
String text = buffer.getText(importSize, buffer.getLength()-importSize);
- if(checkImport(text, qualifiedName))
+ if(checkImport(text))
importDeclaration.delete(false, new NullProgressMonitor());
}
compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
@@ -101,15 +102,15 @@
return null;
}
- private boolean checkImport(String text, String qualifiedName){
- String name = getShortName(qualifiedName);
+ private boolean checkImport(String text){
+ String name = getShortName();
Pattern p = Pattern.compile(".*\\W"+name+"\\W.*",Pattern.DOTALL);
//$NON-NLS-1$ //$NON-NLS-2$
Matcher m = p.matcher(text);
return !m.matches();
}
- protected String getShortName(String qualifiedName){
+ protected String getShortName(){
int lastDot = qualifiedName.lastIndexOf('.');
String name;
if(lastDot < 0)
@@ -150,6 +151,8 @@
ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+ final String lineDelim= compilationUnit.findRecommendedLineSeparator();
+
IJavaElement javaElement = compilationUnit.getElementAt(start);
IType type = getType(javaElement);
if(type != null){
@@ -164,7 +167,7 @@
name="(\""+generateComponentName(compilationUnit.findPrimaryType().getElementName())+"\")";
}
- buffer.replace(type.getSourceRange().getOffset(), 0,
annotationString+name+'\n');
+ buffer.replace(type.getSourceRange().getOffset(), 0,
annotationString+name+lineDelim);
compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
}
}catch(CoreException ex){
@@ -172,6 +175,44 @@
}
}
+ protected void addAnnotatedMethod(){
+ try{
+ ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
+ ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+
+ final String lineDelim= compilationUnit.findRecommendedLineSeparator();
+
+ IType type = compilationUnit.findPrimaryType();
+ if(type != null){
+ IImportDeclaration importDeclaration = compilationUnit.getImport(qualifiedName);
+ if(importDeclaration == null || !importDeclaration.exists())
+ compilationUnit.createImport(qualifiedName, null, new NullProgressMonitor());
+
+ String annotation = getShortName();
+ String methodName = annotation.toLowerCase();
+
+ IMethod oldMethod = type.getMethod(methodName, new String[]{});
+ if(oldMethod == null || !oldMethod.exists()){
+ StringBuffer buf= new StringBuffer();
+
+ buf.append("@"+annotation); //$NON-NLS-1$
+ buf.append(lineDelim);
+ buf.append("public void "+methodName+"() {"); //$NON-NLS-1$
//$NON-NLS-2$
+ buf.append(lineDelim);
+ buf.append("}"); //$NON-NLS-1$
+ type.createMethod(buf.toString(), null, false, null);
+ }else{
+ IBuffer buffer = compilationUnit.getBuffer();
+ buffer.replace(oldMethod.getSourceRange().getOffset(), 0,
"@"+annotation+lineDelim);
+ }
+
+ compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
+ }
+ }catch(CoreException ex){
+ SeamGuiPlugin.getPluginLog().logError(ex);
+ }
+ }
+
protected void renameAnnotation(String annotationString){
try{
ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AddAnnotatedMethodMarkerResolution.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AddAnnotatedMethodMarkerResolution.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AddAnnotatedMethodMarkerResolution.java 2010-09-08
12:31:17 UTC (rev 24811)
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.seam.ui.marker;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+
+/**
+ * @author Daniel Azarov
+ */
+public class AddAnnotatedMethodMarkerResolution extends AbstractSeamMarkerResolution {
+ public AddAnnotatedMethodMarkerResolution(String label, String qualifiedName, IFile
file, int start, int end){
+ super(label, qualifiedName, file, start, end);
+ }
+
+ public void run(IMarker marker) {
+ addAnnotatedMethod();
+ }
+
+}
Property changes on:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AddAnnotatedMethodMarkerResolution.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AddAnnotationMarkerResolution.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AddAnnotationMarkerResolution.java 2010-09-08
11:09:24 UTC (rev 24810)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AddAnnotationMarkerResolution.java 2010-09-08
12:31:17 UTC (rev 24811)
@@ -26,7 +26,7 @@
}
public void run(IMarker marker) {
- addAnnotation("@"+getShortName(qualifiedName), insertName); //$NON-NLS-1$
+ addAnnotation("@"+getShortName(), insertName); //$NON-NLS-1$
}
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/DeleteAnnotationMarkerResolution.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/DeleteAnnotationMarkerResolution.java 2010-09-08
11:09:24 UTC (rev 24810)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/DeleteAnnotationMarkerResolution.java 2010-09-08
12:31:17 UTC (rev 24811)
@@ -23,10 +23,6 @@
super(label, qualifiedName, file, start, end);
}
- public String getLabel() {
- return label;
- }
-
public void run(IMarker marker) {
deleteAnnotation();
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/RenameAnnotationMarkerResolution.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/RenameAnnotationMarkerResolution.java 2010-09-08
11:09:24 UTC (rev 24810)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/RenameAnnotationMarkerResolution.java 2010-09-08
12:31:17 UTC (rev 24811)
@@ -25,6 +25,6 @@
}
public void run(IMarker marker) {
- renameAnnotation("@"+getShortName(qualifiedName)); //$NON-NLS-1$
+ renameAnnotation("@"+getShortName()); //$NON-NLS-1$
}
}
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-08
11:09:24 UTC (rev 24810)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/SeamProblemMarkerResolutionGenerator.java 2010-09-08
12:31:17 UTC (rev 24811)
@@ -86,6 +86,11 @@
new
AddAnnotationMarkerResolution(SeamUIMessages.ADD_NAME_ANNOTATION_MARKER_RESOLUTION_TITLE,
"org.jboss.seam.annotations.Name", file, start, end, true),
new
DeleteAnnotationMarkerResolution(SeamUIMessages.DELETE_OBSERVER_ANNOTATION_MARKER_RESOLUTION_TITLE,
"org.jboss.seam.annotations.Observer", file, start, end)
};
+ else if(messageId == SeamCoreValidator.STATEFUL_COMPONENT_DOES_NOT_CONTAIN_REMOVE_ID)
+ return new IMarkerResolution[]{new
AddAnnotatedMethodMarkerResolution(SeamUIMessages.ADD_ANNOTATED_REMOVE_METHOD_MARKER_RESOLUTION_TITLE,
"javax.ejb.Remove", file, start, end)};
+ else if(messageId == SeamCoreValidator.STATEFUL_COMPONENT_DOES_NOT_CONTAIN_DESTROY_ID)
+ return new IMarkerResolution[]{new
AddAnnotatedMethodMarkerResolution(SeamUIMessages.ADD_ANNOTATED_DESTROY_METHOD_MARKER_RESOLUTION_TITLE,
"org.jboss.seam.annotations.Destroy", file, start, end)};
+
return new IMarkerResolution[]{};
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/messages.properties
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/messages.properties 2010-09-08
11:09:24 UTC (rev 24810)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/messages.properties 2010-09-08
12:31:17 UTC (rev 24811)
@@ -196,3 +196,5 @@
DELETE_OBSERVER_ANNOTATION_MARKER_RESOLUTION_TITLE=Delete @Oserver annotation
ADD_NAME_ANNOTATION_MARKER_RESOLUTION_TITLE=Add @Name annotation
RENAME_NAME_ANNOTATION_MARKER_RESOLUTION_TITLE=Rename @Name annotation
+ADD_ANNOTATED_REMOVE_METHOD_MARKER_RESOLUTION_TITLE=Add @Remove annotated method
+ADD_ANNOTATED_DESTROY_METHOD_MARKER_RESOLUTION_TITLE=Add @Destroy annotated method
Added:
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/SeamWebWarTestProject/src/action/org/domain/SeamWebWarTestProject/session/StatefulComponentWithoutDestroy.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/SeamWebWarTestProject/src/action/org/domain/SeamWebWarTestProject/session/StatefulComponentWithoutDestroy.java
(rev 0)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/SeamWebWarTestProject/src/action/org/domain/SeamWebWarTestProject/session/StatefulComponentWithoutDestroy.java 2010-09-08
12:31:17 UTC (rev 24811)
@@ -0,0 +1,43 @@
+package org.domain.SeamWebWarTestProject.session;
+
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Logger;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.log.Log;
+
+@Name("statefulComponentWithoutDestroy")
+@Stateful
+(a)Scope(ScopeType.APPLICATION)
+public class StatefulComponentWithoutDestroy {
+
+ private String abc;
+
+ @Logger private Log log;
+
+
+ //seam-gen method
+ public String statefulComponent()
+ {
+ //implement your business logic here
+ log.info("statefulComponent.statefulComponent() action called");
+ return "success";
+ }
+
+ @Remove
+ public void removeMethod(){
+
+ }
+
+ public String getAbc() {
+ return abc;
+ }
+
+ public void setAbc(String abc) {
+ this.abc = abc;
+ }
+
+}
\ No newline at end of file
Property changes on:
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/SeamWebWarTestProject/src/action/org/domain/SeamWebWarTestProject/session/StatefulComponentWithoutDestroy.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/SeamWebWarTestProject/src/action/org/domain/SeamWebWarTestProject/session/StatefulComponentWithoutRemove.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/SeamWebWarTestProject/src/action/org/domain/SeamWebWarTestProject/session/StatefulComponentWithoutRemove.java
(rev 0)
+++
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/SeamWebWarTestProject/src/action/org/domain/SeamWebWarTestProject/session/StatefulComponentWithoutRemove.java 2010-09-08
12:31:17 UTC (rev 24811)
@@ -0,0 +1,43 @@
+package org.domain.SeamWebWarTestProject.session;
+
+import javax.ejb.Stateful;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Destroy;
+import org.jboss.seam.annotations.Logger;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.log.Log;
+
+@Name("statefulComponentWithoutRemove")
+@Stateful
+(a)Scope(ScopeType.APPLICATION)
+public class StatefulComponentWithoutRemove {
+
+ private String abc;
+
+ @Logger private Log log;
+
+
+ //seam-gen method
+ public String statefulComponent()
+ {
+ //implement your business logic here
+ log.info("statefulComponent.statefulComponent() action called");
+ return "success";
+ }
+
+ @Destroy
+ public void destroyMethod(){
+
+ }
+
+ public String getAbc() {
+ return abc;
+ }
+
+ public void setAbc(String abc) {
+ this.abc = abc;
+ }
+
+}
\ No newline at end of file
Property changes on:
trunk/seam/tests/org.jboss.tools.seam.core.test/projects/SeamWebWarTestProject/src/action/org/domain/SeamWebWarTestProject/session/StatefulComponentWithoutRemove.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-08
11:09:24 UTC (rev 24810)
+++
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/marker/SeamMarkerResolutionTest.java 2010-09-08
12:31:17 UTC (rev 24811)
@@ -10,17 +10,23 @@
************************************************************************************/
package org.jboss.tools.seam.ui.test.marker;
+import java.io.IOException;
+
import junit.framework.TestCase;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.preference.IPersistentPreferenceStore;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.ide.IDE;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.core.SeamPreferences;
+import org.jboss.tools.seam.ui.marker.AddAnnotatedMethodMarkerResolution;
import org.jboss.tools.seam.ui.marker.AddAnnotationMarkerResolution;
import org.jboss.tools.seam.ui.marker.DeleteAnnotationMarkerResolution;
import org.jboss.tools.seam.ui.marker.RenameAnnotationMarkerResolution;
@@ -32,6 +38,7 @@
*/
public class SeamMarkerResolutionTest extends TestCase {
public static final String MARKER_TYPE =
"org.eclipse.wst.validation.problemmarker";
+ //public static final String TEXT_MARKER_TYPE =
"org.eclipse.wst.validation.textmarker";
private IProject project;
@@ -40,6 +47,18 @@
JobUtils.waitForIdle();
IResource project =
ResourcesPlugin.getWorkspace().getRoot().findMember("SeamWebWarTestProject");
this.project = project.getProject();
+
+ IPreferenceStore store = SeamCorePlugin.getDefault().getPreferenceStore();
+ store.putValue(SeamPreferences.STATEFUL_COMPONENT_DOES_NOT_CONTENT_REMOVE,
SeamPreferences.ERROR);
+ store.putValue(SeamPreferences.STATEFUL_COMPONENT_DOES_NOT_CONTENT_DESTROY,
SeamPreferences.ERROR);
+
+ if(store instanceof IPersistentPreferenceStore) {
+ try {
+ ((IPersistentPreferenceStore)store).save();
+ } catch (IOException e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ }
+ }
}
@Override
@@ -318,5 +337,60 @@
assertTrue("The quickfix \"Rename @Name annotation\" doesn't
exist.", cFound);
}
+ public void testAddRemoveMethodResolution() throws CoreException {
+ String TARGET_FILE_NAME =
"src/action/org/domain/SeamWebWarTestProject/session/StatefulComponentWithoutRemove.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 found = 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 AddAnnotatedMethodMarkerResolution) {
+ assertEquals("javax.ejb.Remove",
((AddAnnotatedMethodMarkerResolution)resolution).getQualifiedName());
+ found = true;
+ break;
+ }
+ }
+ if (found) {
+ break;
+ }
+ }
+ assertTrue("The quickfix \"Add @Remove annotated method\" doesn't
exist.", found);
+ }
+ public void testAddDestroyMethodResolution() throws CoreException {
+ String TARGET_FILE_NAME =
"src/action/org/domain/SeamWebWarTestProject/session/StatefulComponentWithoutDestroy.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 found = 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 AddAnnotatedMethodMarkerResolution) {
+ assertEquals("org.jboss.seam.annotations.Destroy",
((AddAnnotatedMethodMarkerResolution)resolution).getQualifiedName());
+ found = true;
+ break;
+ }
+ }
+ if (found) {
+ break;
+ }
+ }
+ assertTrue("The quickfix \"Add @Destroy annotated method\" doesn't
exist.", found);
+ }
+
}