Author: dazarov
Date: 2010-12-08 10:54:27 -0500 (Wed, 08 Dec 2010)
New Revision: 27236
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeMethodBusinessMarkerResolution.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeMethodPublicMarkerResolution.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationErrorManager.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIMarkerResolutionTest.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseJavaUtil.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AbstractSeamMarkerResolution.java
Log:
https://jira.jboss.org/browse/JBIDE-7669
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java 2010-12-08
15:46:33 UTC (rev 27235)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java 2010-12-08
15:54:27 UTC (rev 27236)
@@ -57,6 +57,7 @@
public String STATELESS_ANNOTATION_TYPE_NAME = "javax.ejb.Stateless";
public String SINGLETON_ANNOTATION_TYPE_NAME = "javax.ejb.Singleton";
public String LOCAL_ANNOTATION_TYPE_NAME = "javax.ejb.Local";
+ public String LOCAL_BEAN_SIMPLE_NAME = "LocalBean";
public String LOCAL_BEAN_ANNOTATION_TYPE_NAME = "javax.ejb.LocalBean";
public String RESOURCE_ANNOTATION_TYPE_NAME = "javax.annotation.Resource";
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-12-08
15:46:33 UTC (rev 27235)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-12-08
15:54:27 UTC (rev 27236)
@@ -1170,7 +1170,7 @@
IMethod method = CDIUtil.getBusinessMethodDeclaration((SessionBean)classBean,
producerMethod);
if(method==null) {
String bindedErrorMessage =
NLS.bind(CDIValidationMessages.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN, new
String[]{producerMethod.getMethod().getElementName(),
producer.getBeanClass().getElementName()});
- addError(bindedErrorMessage,
CDIPreferences.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN, producer.getProducesAnnotation(),
producer.getResource());
+ addError(bindedErrorMessage,
CDIPreferences.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN, producer.getProducesAnnotation(),
producer.getResource(), ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN_ID);
saveAllSuperTypesAsLinkedResources(classBean);
} else if (method != producerMethod.getMethod()) {
getValidationContext().addLinkedCoreResource(classBean.getSourcePath().toOSString(),
method.getResource().getFullPath(), false);
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationErrorManager.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationErrorManager.java 2010-12-08
15:46:33 UTC (rev 27235)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationErrorManager.java 2010-12-08
15:54:27 UTC (rev 27236)
@@ -19,6 +19,7 @@
public static final String MESSAGE_ID_ATTRIBUTE_NAME = "CDI_message_id";
//$NON-NLS-1$
public static final int ILLEGAL_PRODUCER_FIELD_IN_SESSION_BEAN_ID = 1;
+ public static final int ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN_ID = 2;
/*
* (non-Javadoc)
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java 2010-12-08
15:46:33 UTC (rev 27235)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java 2010-12-08
15:54:27 UTC (rev 27236)
@@ -62,8 +62,10 @@
public static String MESSAGE_INTERCEPTOR_BINDINGS_EMPTY;
public static String MAKE_FIELD_STATIC_MARKER_RESOLUTION_TITLE;
-
+ public static String MAKE_METHOD_PUBLIC_MARKER_RESOLUTION_TITLE;
+ public static String MAKE_METHOD_BUSINESS_MARKER_RESOLUTION_TITLE;
+
public static String CDI_GENERATE_BEANS_XML;
public static String CDI_INSTALL_WIZARD_PAGE_FACET;
public static String CDI_INSTALL_WIZARD_PAGE_CONFIGURE;
-}
\ No newline at end of file
+}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2010-12-08
15:46:33 UTC (rev 27235)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2010-12-08
15:54:27 UTC (rev 27236)
@@ -51,7 +51,9 @@
MESSAGE_INTERCEPTOR_BINDINGS_EMPTY=Interceptor Bindings list is empty
MAKE_FIELD_STATIC_MARKER_RESOLUTION_TITLE=Make ''{0}'' field static
+MAKE_METHOD_PUBLIC_MARKER_RESOLUTION_TITLE=Make ''{0}'' method public
+MAKE_METHOD_BUSINESS_MARKER_RESOLUTION_TITLE=Make ''{0}'' method business
method of the session bean and add it to ''{1}'' interface
CDI_GENERATE_BEANS_XML=Generate beans.xml file:
CDI_INSTALL_WIZARD_PAGE_FACET=Context and Dependency Injection (CDI) Facet
-CDI_INSTALL_WIZARD_PAGE_CONFIGURE=Configure Context and Dependency Injection (CDI) Facet
Settings
\ No newline at end of file
+CDI_INSTALL_WIZARD_PAGE_CONFIGURE=Configure Context and Dependency Injection (CDI) Facet
Settings>>>>>>> .r27235
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java 2010-12-08
15:46:33 UTC (rev 27235)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java 2010-12-08
15:54:27 UTC (rev 27236)
@@ -10,20 +10,29 @@
******************************************************************************/
package org.jboss.tools.cdi.ui.marker;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
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.ui.IMarkerResolution;
import org.eclipse.ui.IMarkerResolutionGenerator2;
+import org.jboss.tools.cdi.core.CDIConstants;
import org.jboss.tools.cdi.internal.core.validation.CDIValidationErrorManager;
import org.jboss.tools.cdi.ui.CDIUIPlugin;
import org.jboss.tools.common.EclipseUtil;
+import org.jboss.tools.common.model.util.EclipseJavaUtil;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
/**
* @author Daniel Azarov
@@ -70,25 +79,72 @@
new MakeFieldStaticMarkerResolution(field, file)
};
}
+ }else if (messageId ==
CDIValidationErrorManager.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN_ID) {
+ IMethod method = findMethod(file, start);
+ if(method != null){
+ List<IType> types = findLocalAnnotattedInterfaces(method);
+ if(types.size() == 0){
+ return new IMarkerResolution[] {
+ new MakeMethodPublicMarkerResolution(method, file)
+ };
+ }else{
+ IMarkerResolution[] resolutions = new IMarkerResolution[types.size()];
+ for(int i = 0; i < types.size(); i++){
+ resolutions[i] = new MakeMethodBusinessMarkerResolution(method, types.get(i),
file);
+ }
+ return resolutions;
+ }
+ }
}
}
return new IMarkerResolution[] {};
}
+ private IMethod findMethod(IFile file, int start){
+ try{
+ ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
+ ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+
+ IJavaElement javaElement = compilationUnit.getElementAt(start);
+ if(javaElement != null && javaElement instanceof IMethod){
+ IMethod method = (IMethod)javaElement;
+ if(!method.isBinary())
+ return method;
+ }
+ }catch(CoreException ex){
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ return null;
+ }
+
+ private List<IType> findLocalAnnotattedInterfaces(IMethod method) throws
JavaModelException{
+ ArrayList<IType> types = new ArrayList<IType>();
+ IType type = method.getDeclaringType();
+ String[] is = type.getSuperInterfaceNames();
+ for(int i = 0; i < is.length; i++){
+ String f = EclipseJavaUtil.resolveType(type, is[i]);
+ IType t = EclipseResourceUtil.getValidType(type.getJavaProject().getProject(), f);
+ if(t != null && t.isInterface()){
+ IAnnotation localAnnotation = EclipseJavaUtil.findAnnotation(t, t,
CDIConstants.LOCAL_ANNOTATION_TYPE_NAME);
+ if(localAnnotation != null)
+ types.add(t);
+ }
+ }
+ return types;
+ }
+
private IField findNonStaticField(IFile file, int start){
try{
- ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
- ICompilationUnit compilationUnit = original.getWorkingCopy(new NullProgressMonitor());
-
- IJavaElement javaElement = compilationUnit.getElementAt(start);
- IType type = compilationUnit.findPrimaryType();
- if(javaElement != null && type != null){
- if(javaElement instanceof IField){
+ ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
+ ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+
+ IJavaElement javaElement = compilationUnit.getElementAt(start);
+
+ if(javaElement != null && javaElement instanceof IField){
IField field = (IField)javaElement;
- if((field.getFlags() & Flags.AccStatic) == 0)
+ if((field.getFlags() & Flags.AccStatic) == 0 && !field.isBinary())
return field;
}
- }
}catch(CoreException ex){
CDIUIPlugin.getDefault().logError(ex);
}
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeMethodBusinessMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeMethodBusinessMarkerResolution.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeMethodBusinessMarkerResolution.java 2010-12-08
15:54:27 UTC (rev 27236)
@@ -0,0 +1,217 @@
+/*******************************************************************************
+ * 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.cdi.ui.marker;
+
+import java.text.MessageFormat;
+import java.util.HashSet;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.IBuffer;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IImportDeclaration;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IPackageDeclaration;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.Signature;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IMarkerResolution2;
+import org.jboss.tools.cdi.core.CDIConstants;
+import org.jboss.tools.cdi.ui.CDIUIMessages;
+import org.jboss.tools.cdi.ui.CDIUIPlugin;
+import org.jboss.tools.common.EclipseUtil;
+import org.jboss.tools.common.model.util.EclipseJavaUtil;
+
+/**
+ * @author Daniel Azarov
+ */
+public class MakeMethodBusinessMarkerResolution implements IMarkerResolution2 {
+ private static final String PUBLIC = "public"; //$NON-NLS-1$
+ private static final String PRIVATE = "private"; //$NON-NLS-1$
+ private static final String PROTECTED = "protected"; //$NON-NLS-1$
+ private static final String SPACE = " "; //$NON-NLS-1$
+ private static final String DOT = "."; //$NON-NLS-1$
+
+ static final HashSet<String> primitives = new HashSet<String>();
+ static{
+ primitives.add("int"); //$NON-NLS-1$
+ primitives.add("java.lang.Integer"); //$NON-NLS-1$
+ primitives.add("char"); //$NON-NLS-1$
+ primitives.add("java.lang.Character"); //$NON-NLS-1$
+ primitives.add("boolean"); //$NON-NLS-1$
+ primitives.add("java.lang.Boolean"); //$NON-NLS-1$
+ primitives.add("short"); //$NON-NLS-1$
+ primitives.add("java.lang.Short"); //$NON-NLS-1$
+ primitives.add("long"); //$NON-NLS-1$
+ primitives.add("java.lang.Long"); //$NON-NLS-1$
+ primitives.add("float"); //$NON-NLS-1$
+ primitives.add("java.lang.Float"); //$NON-NLS-1$
+ primitives.add("double"); //$NON-NLS-1$
+ primitives.add("java.lang.Double"); //$NON-NLS-1$
+ primitives.add("byte"); //$NON-NLS-1$
+ primitives.add("java.lang.Byte"); //$NON-NLS-1$
+ primitives.add("java.lang.String"); //$NON-NLS-1$
+ }
+
+ private String label;
+ private IMethod method;
+ private IType localInterface;
+ private IFile file;
+
+ public MakeMethodBusinessMarkerResolution(IMethod method, IType localInterface, IFile
file){
+ this.label =
MessageFormat.format(CDIUIMessages.MAKE_METHOD_BUSINESS_MARKER_RESOLUTION_TITLE, new
Object[]{method.getElementName(), localInterface.getElementName()});
+ this.method = method;
+ this.localInterface = localInterface;
+ this.file = file;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void run(IMarker marker) {
+ try{
+ ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
+ ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+
+ IBuffer buffer = compilationUnit.getBuffer();
+
+ int flag = method.getFlags();
+
+ String text = buffer.getText(method.getSourceRange().getOffset(),
method.getSourceRange().getLength());
+
+ // make method public
+ int position = method.getSourceRange().getOffset();
+ if((flag & Flags.AccPublic) != 0){
+ // do nothing
+ }else if((flag & Flags.AccPrivate) != 0){
+ position += text.indexOf(PRIVATE);
+ buffer.replace(position, PRIVATE.length(), PUBLIC);
+ }else if((flag & Flags.AccProtected) != 0){
+ position += text.indexOf(PROTECTED);
+ buffer.replace(position, PROTECTED.length(), PUBLIC);
+ }else{
+ String type = Signature.getSignatureSimpleName(method.getReturnType());
+ position += text.indexOf(type);
+ buffer.replace(position, 0, PUBLIC+SPACE);
+ }
+
+ synchronized(compilationUnit) {
+ compilationUnit.reconcile(ICompilationUnit.NO_AST, true, null, null);
+ }
+
+ // add @LocalBean annotation
+ IType type = compilationUnit.getType(method.getDeclaringType().getElementName());
+
+ IAnnotation localAnnotation = EclipseJavaUtil.findAnnotation(type, type,
CDIConstants.LOCAL_BEAN_ANNOTATION_TYPE_NAME);
+ if(localAnnotation == null){
+ addImport(CDIConstants.LOCAL_BEAN_ANNOTATION_TYPE_NAME, compilationUnit);
+
+ final String lineDelim= compilationUnit.findRecommendedLineSeparator();
+
+ buffer = compilationUnit.getBuffer();
+
+ buffer.replace(type.getSourceRange().getOffset(), 0,
"(a)"+CDIConstants.LOCAL_BEAN_SIMPLE_NAME+lineDelim);
+ }
+
+ // add method to interface
+
+ compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
+ compilationUnit.discardWorkingCopy();
+
+ original = localInterface.getCompilationUnit();
+ compilationUnit = original.getWorkingCopy(new NullProgressMonitor());
+
+ IType interfaceType = compilationUnit.getType(localInterface.getElementName());
+
+ StringBuffer content = new StringBuffer();
+
+ content.append(PUBLIC+SPACE);
+
+ String simpleType = Signature.getSignatureSimpleName(method.getReturnType());
+ content.append(simpleType);
+ content.append(SPACE);
+ content.append(method.getElementName());
+ content.append("("); //$NON-NLS-1$
+
+ IType originalType = method.getDeclaringType();
+
+ addImport(originalType, simpleType, compilationUnit);
+
+ String[] types = method.getParameterTypes();
+ String[] names = method.getParameterNames();
+
+ for(int i = 0; i < method.getNumberOfParameters(); i++){
+ if(i > 0)
+ content.append(", "); //$NON-NLS-1$
+
+ simpleType = Signature.getSignatureSimpleName(types[i]);
+
+ addImport(originalType, simpleType, compilationUnit);
+
+ content.append(simpleType);
+ content.append(SPACE);
+ content.append(names[i]);
+ }
+
+ content.append(");"); //$NON-NLS-1$
+
+ interfaceType.createMethod(content.toString(), null, false, new
NullProgressMonitor());
+
+ compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
+ compilationUnit.discardWorkingCopy();
+ }catch(CoreException ex){
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ }
+
+ private void addImport(IType originalType, String simpleName, ICompilationUnit
compilationUnit) throws JavaModelException{
+ String qualifiedName = EclipseJavaUtil.resolveType(originalType, simpleName);
+ addImport(qualifiedName, compilationUnit);
+ }
+
+ private void addImport(String qualifiedName, ICompilationUnit compilationUnit) throws
JavaModelException{
+ if(primitives.contains(qualifiedName))
+ return;
+
+ IPackageDeclaration[] packages = compilationUnit.getPackageDeclarations();
+
+ if(qualifiedName.indexOf(DOT) >= 0){
+ String typePackage = qualifiedName.substring(0,qualifiedName.lastIndexOf(DOT));
+
+ for(IPackageDeclaration packageDeclaration : packages){
+ if(packageDeclaration.getElementName().equals(typePackage))
+ return;
+ }
+ }
+
+ if(qualifiedName != null){
+ IImportDeclaration importDeclaration = compilationUnit.getImport(qualifiedName);
+ if(importDeclaration == null || !importDeclaration.exists())
+ compilationUnit.createImport(qualifiedName, null, new NullProgressMonitor());
+ }
+
+ }
+
+ public String getDescription() {
+ return null;
+ }
+
+ public Image getImage() {
+ return null;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeMethodBusinessMarkerResolution.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeMethodPublicMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeMethodPublicMarkerResolution.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeMethodPublicMarkerResolution.java 2010-12-08
15:54:27 UTC (rev 27236)
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * 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.cdi.ui.marker;
+
+import java.text.MessageFormat;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.IBuffer;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.Signature;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IMarkerResolution2;
+import org.jboss.tools.cdi.ui.CDIUIMessages;
+import org.jboss.tools.cdi.ui.CDIUIPlugin;
+import org.jboss.tools.common.EclipseUtil;
+
+/**
+ * @author Daniel Azarov
+ */
+public class MakeMethodPublicMarkerResolution implements IMarkerResolution2 {
+ private static final String PUBLIC = "public"; //$NON-NLS-1$
+ private static final String PRIVATE = "private"; //$NON-NLS-1$
+ private static final String PROTECTED = "protected"; //$NON-NLS-1$
+ private static final String SPACE = " "; //$NON-NLS-1$
+
+ private String label;
+ private IMethod method;
+ private IFile file;
+
+ public MakeMethodPublicMarkerResolution(IMethod method, IFile file){
+ this.label =
MessageFormat.format(CDIUIMessages.MAKE_METHOD_PUBLIC_MARKER_RESOLUTION_TITLE, new
Object[]{method.getElementName()});
+ this.method = method;
+ this.file = file;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void run(IMarker marker) {
+ try{
+ ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
+ ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+
+ IBuffer buffer = compilationUnit.getBuffer();
+
+ int flag = method.getFlags();
+
+ String text = buffer.getText(method.getSourceRange().getOffset(),
method.getSourceRange().getLength());
+
+ // make method public
+ int position = method.getSourceRange().getOffset();
+ if((flag & Flags.AccPublic) != 0){
+ // do nothing
+ }else if((flag & Flags.AccPrivate) != 0){
+ position += text.indexOf(PRIVATE);
+ buffer.replace(position, PRIVATE.length(), PUBLIC);
+ }else if((flag & Flags.AccProtected) != 0){
+ position += text.indexOf(PROTECTED);
+ buffer.replace(position, PROTECTED.length(), PUBLIC);
+ }else{
+ String type = Signature.getSignatureSimpleName(method.getReturnType());
+ position += text.indexOf(type);
+ buffer.replace(position, 0, PUBLIC+SPACE);
+ }
+
+ compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
+ compilationUnit.discardWorkingCopy();
+ }catch(CoreException ex){
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ }
+
+ public String getDescription() {
+ return null;
+ }
+
+ public Image getImage() {
+ return null;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeMethodPublicMarkerResolution.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIMarkerResolutionTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIMarkerResolutionTest.java 2010-12-08
15:46:33 UTC (rev 27235)
+++
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIMarkerResolutionTest.java 2010-12-08
15:54:27 UTC (rev 27236)
@@ -19,6 +19,7 @@
import org.eclipse.ui.ide.IDE;
import org.jboss.tools.cdi.core.test.tck.validation.ValidationTest;
import org.jboss.tools.cdi.ui.marker.MakeFieldStaticMarkerResolution;
+import org.jboss.tools.cdi.ui.marker.MakeMethodBusinessMarkerResolution;
/**
* @author Daniel Azarov
@@ -53,5 +54,30 @@
assertTrue("Quick fix: \"Make field static\" doesn't exist.",
found);
}
+ public void testMakeMethodBusinessResolution() throws CoreException {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/producer/method/broken/enterprise/nonbusiness/FooProducer.java");
+
+ assertTrue("File - "+file.getFullPath()+" must be
exist",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 MakeMethodBusinessMarkerResolution) {
+ found = true;
+ break;
+ }
+ }
+ if (found) {
+ break;
+ }
+ }
+ assertTrue("Quick fix: \"Make method business\" doesn't
exist.", found);
+ }
}
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseJavaUtil.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseJavaUtil.java 2010-12-08
15:46:33 UTC (rev 27235)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseJavaUtil.java 2010-12-08
15:54:27 UTC (rev 27236)
@@ -20,6 +20,8 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.IAnnotatable;
+import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaProject;
@@ -221,4 +223,29 @@
}
return suppers;
}
+
+ public static IAnnotation findAnnotation(IType sourceType, IAnnotatable member, String
qulifiedAnnotationName) throws JavaModelException{
+ IAnnotation[] annotations = member.getAnnotations();
+ String simpleAnnotationTypeName = qulifiedAnnotationName;
+ int lastDot = qulifiedAnnotationName.lastIndexOf('.');
+ if(lastDot>-1) {
+ simpleAnnotationTypeName = simpleAnnotationTypeName.substring(lastDot + 1);
+ }
+ for (IAnnotation annotation : annotations) {
+ if(qulifiedAnnotationName.equals(annotation.getElementName())) {
+ return annotation;
+ }
+ if(simpleAnnotationTypeName.equals(annotation.getElementName())) {
+ String fullAnnotationclassName = EclipseJavaUtil.resolveType(sourceType,
simpleAnnotationTypeName);
+ if(fullAnnotationclassName!=null) {
+ IType annotationType =
sourceType.getJavaProject().findType(fullAnnotationclassName);
+ if(annotationType!=null &&
annotationType.getFullyQualifiedName().equals(qulifiedAnnotationName)) {
+ return annotation;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
}
\ No newline at end of file
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-12-08
15:46:33 UTC (rev 27235)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AbstractSeamMarkerResolution.java 2010-12-08
15:54:27 UTC (rev 27236)
@@ -28,7 +28,6 @@
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;
import org.eclipse.ui.IMarkerResolution2;
import org.jboss.tools.common.EclipseUtil;
@@ -66,7 +65,7 @@
IType type = compilationUnit.findPrimaryType();
if(javaElement != null && type != null){
if(javaElement instanceof IAnnotatable){
- IAnnotation annotation = findAnnotation(type, (IAnnotatable)javaElement);
+ IAnnotation annotation = EclipseJavaUtil.findAnnotation(type,
(IAnnotatable)javaElement, qualifiedName);
if(annotation != null){
IBuffer buffer = compilationUnit.getBuffer();
@@ -224,7 +223,7 @@
IJavaElement javaElement = compilationUnit.getElementAt(start);
IType type = getType(javaElement);
if(type != null){
- IAnnotation annotation = findAnnotation(type, type);
+ IAnnotation annotation = EclipseJavaUtil.findAnnotation(type, type, qualifiedName);
if(annotation != null){
IImportDeclaration importDeclaration = compilationUnit.getImport(qualifiedName);
if(importDeclaration == null || !importDeclaration.exists())
@@ -253,33 +252,6 @@
}
- private IAnnotation findAnnotation(IType sourceType, IAnnotatable member) {
- try {
- IAnnotation[] annotations = member.getAnnotations();
- String simpleAnnotationTypeName = qualifiedName;
- int lastDot = qualifiedName.lastIndexOf('.');
- if(lastDot>-1) {
- simpleAnnotationTypeName = simpleAnnotationTypeName.substring(lastDot + 1);
- }
- for (IAnnotation annotation : annotations) {
- if(qualifiedName.equals(annotation.getElementName())) {
- return annotation;
- }
- if(simpleAnnotationTypeName.equals(annotation.getElementName())) {
- String fullAnnotationclassName = EclipseJavaUtil.resolveType(sourceType,
simpleAnnotationTypeName);
- if(fullAnnotationclassName!=null) {
- IType annotationType =
sourceType.getJavaProject().findType(fullAnnotationclassName);
- if(annotationType!=null &&
annotationType.getFullyQualifiedName().equals(qualifiedName)) {
- return annotation;
- }
- }
- }
- }
- } catch (JavaModelException e) {
- SeamGuiPlugin.getDefault().logError(e);
- }
- return null;
- }
public String getLabel() {
return label;