Author: dazarov
Date: 2010-12-09 10:28:29 -0500 (Thu, 09 Dec 2010)
New Revision: 27282
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddLocalBeanMarkerResolution.java
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.properties
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/MakeMethodBusinessMarkerResolution.java
Log:
https://jira.jboss.org/browse/JBIDE-7669
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-09
14:43:42 UTC (rev 27281)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java 2010-12-09
15:28:29 UTC (rev 27282)
@@ -64,6 +64,7 @@
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 ADD_LOCAL_BEAN_MARKER_RESOLUTION_TITLE;
public static String CDI_GENERATE_BEANS_XML;
public static String CDI_INSTALL_WIZARD_PAGE_FACET;
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-09
14:43:42 UTC (rev 27281)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2010-12-09
15:28:29 UTC (rev 27282)
@@ -52,7 +52,8 @@
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
+MAKE_METHOD_BUSINESS_MARKER_RESOLUTION_TITLE=Add ''{0}'' method to
''{1}'' interface
+ADD_LOCAL_BEAN_MARKER_RESOLUTION_TITLE=Add @LocalBean annotation to
''{0}'' class
CDI_GENERATE_BEANS_XML=Generate beans.xml file:
CDI_INSTALL_WIZARD_PAGE_FACET=Context and Dependency Injection (CDI) Facet
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddLocalBeanMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddLocalBeanMarkerResolution.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddLocalBeanMarkerResolution.java 2010-12-09
15:28:29 UTC (rev 27282)
@@ -0,0 +1,131 @@
+/*******************************************************************************
+ * 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.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.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 AddLocalBeanMarkerResolution 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 AddLocalBeanMarkerResolution(IMethod method, IFile file){
+ this.label = MessageFormat.format(CDIUIMessages.ADD_LOCAL_BEAN_MARKER_RESOLUTION_TITLE,
new Object[]{method.getDeclaringType().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);
+ }
+
+ 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();
+
+ }catch(CoreException ex){
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ }
+
+ private void addImport(String qualifiedName, ICompilationUnit compilationUnit) throws
JavaModelException{
+ 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/AddLocalBeanMarkerResolution.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-09
14:43:42 UTC (rev 27281)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java 2010-12-09
15:28:29 UTC (rev 27282)
@@ -66,11 +66,6 @@
return new IMarkerResolution[] {};
int start = attribute.intValue();
- attribute = ((Integer) marker.getAttribute(IMarker.CHAR_END));
- if (attribute == null)
- return new IMarkerResolution[] {};
- int end = attribute.intValue();
-
if (JAVA_EXTENSION.equals(file.getFileExtension())) {
if (messageId == CDIValidationErrorManager.ILLEGAL_PRODUCER_FIELD_IN_SESSION_BEAN_ID)
{
IField field = findNonStaticField(file, start);
@@ -88,10 +83,11 @@
new MakeMethodPublicMarkerResolution(method, file)
};
}else{
- IMarkerResolution[] resolutions = new IMarkerResolution[types.size()];
+ IMarkerResolution[] resolutions = new IMarkerResolution[types.size()+1];
for(int i = 0; i < types.size(); i++){
resolutions[i] = new MakeMethodBusinessMarkerResolution(method, types.get(i),
file);
}
+ resolutions[types.size()] = new AddLocalBeanMarkerResolution(method, file);
return resolutions;
}
}
Modified:
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 2010-12-09
14:43:42 UTC (rev 27281)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeMethodBusinessMarkerResolution.java 2010-12-09
15:28:29 UTC (rev 27282)
@@ -18,7 +18,6 @@
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;
@@ -29,7 +28,6 @@
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;
@@ -109,29 +107,11 @@
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();
+ // add method to interface
+
original = localInterface.getCompilationUnit();
compilationUnit = original.getWorkingCopy(new NullProgressMonitor());