Author: dazarov
Date: 2011-03-11 16:13:04 -0500 (Fri, 11 Mar 2011)
New Revision: 29713
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddSerializableInterfaceMarkerResolution.java
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/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/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MarkerResolutionUtils.java
Log:
https://issues.jboss.org/browse/JBIDE-8550
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 2011-03-11
18:59:22 UTC (rev 29712)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2011-03-11
21:13:04 UTC (rev 29713)
@@ -1759,7 +1759,7 @@
}
if(!passivatingCapable) {
ITextSourceReference reference =
CDIUtil.convertToSourceReference(bean.getBeanClass().getNameRange());
- addError(MessageFormat.format(CDIValidationMessages.NOT_PASSIVATION_CAPABLE_BEAN,
bean.getSimpleJavaName(), scope.getSourceType().getElementName()),
CDIPreferences.NOT_PASSIVATION_CAPABLE_BEAN, reference, bean.getResource());
+ addError(MessageFormat.format(CDIValidationMessages.NOT_PASSIVATION_CAPABLE_BEAN,
bean.getSimpleJavaName(), scope.getSourceType().getElementName()),
CDIPreferences.NOT_PASSIVATION_CAPABLE_BEAN, reference, bean.getResource(),
NOT_PASSIVATION_CAPABLE_BEAN_ID);
}
}
}
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 2011-03-11
18:59:22 UTC (rev 29712)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationErrorManager.java 2011-03-11
21:13:04 UTC (rev 29713)
@@ -26,6 +26,7 @@
public static final int MULTIPLE_INJECTION_CONSTRUCTORS_ID = 6;
public static final int UNSATISFIED_INJECTION_POINTS_ID = 7;
public static final int AMBIGUOUS_INJECTION_POINTS_ID = 8;
+ public static final int NOT_PASSIVATION_CAPABLE_BEAN_ID = 9;
/*
* (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 2011-03-11
18:59:22 UTC (rev 29712)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java 2011-03-11
21:13:04 UTC (rev 29713)
@@ -90,6 +90,7 @@
public static String DELETE_ALL_INJECTED_CONSTRUCTORS_MARKER_RESOLUTION_TITLE;
public static String MAKE_INJECTED_POINT_UNAMBIGUOUS_TITLE;
public static String SELECT_BEAN_TITLE;
+ public static String ADD_SERIALIZABLE_INTERFACE_MARKER_RESOLUTION_TITLE;
public static String SELECT_BEAN_WIZARD_TITLE;
public static String SELECT_BEAN_WIZARD_ENTER_BEAN_NAME;
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 2011-03-11
18:59:22 UTC (rev 29712)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2011-03-11
21:13:04 UTC (rev 29713)
@@ -74,6 +74,7 @@
DELETE_ALL_INJECTED_CONSTRUCTORS_MARKER_RESOLUTION_TITLE=Delete @Inject annotations from
all constructors except ''{0}'' constructor
MAKE_INJECTED_POINT_UNAMBIGUOUS_TITLE=Specify ''{0}'' bean for injection
to the injection point
SELECT_BEAN_TITLE=Select bean to configure the injection point
+ADD_SERIALIZABLE_INTERFACE_MARKER_RESOLUTION_TITLE=Add java.io.Serializable interface to
''{0}'' class
SELECT_BEAN_WIZARD_TITLE=Specify CDI Bean for the Injection Point
SELECT_BEAN_WIZARD_ENTER_BEAN_NAME=Enter CDI Bean name prefix or pattern (? = any
character, * = any string):
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddSerializableInterfaceMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddSerializableInterfaceMarkerResolution.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddSerializableInterfaceMarkerResolution.java 2011-03-11
21:13:04 UTC (rev 29713)
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.ICompilationUnit;
+import org.eclipse.jdt.core.IType;
+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 AddSerializableInterfaceMarkerResolution implements IMarkerResolution2 {
+ public static final String SERIALIZABLE = "java.io.Serializable";
//$NON-NLS-1$
+
+ private String label;
+ private IType type;
+ private IFile file;
+
+
+ public AddSerializableInterfaceMarkerResolution(IType type, IFile file){
+ this.label =
MessageFormat.format(CDIUIMessages.ADD_SERIALIZABLE_INTERFACE_MARKER_RESOLUTION_TITLE, new
Object[]{type.getElementName()});
+ this.type = type;
+ this.file = file;
+ }
+
+ @Override
+ public String getLabel() {
+ return label;
+ }
+
+ @Override
+ public void run(IMarker marker) {
+ try{
+ ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
+ ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+
+ MarkerResolutionUtils.addInterfaceToClass(compilationUnit, type, SERIALIZABLE);
+
+ compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
+ compilationUnit.discardWorkingCopy();
+
+ }catch(CoreException ex){
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ }
+
+ @Override
+ public String getDescription() {
+ return null;
+ }
+
+ @Override
+ public Image getImage() {
+ return null;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddSerializableInterfaceMarkerResolution.java
___________________________________________________________________
Added: 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 2011-03-11
18:59:22 UTC (rev 29712)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java 2011-03-11
21:13:04 UTC (rev 29713)
@@ -147,6 +147,14 @@
return resolutions;
}
}
+ }else if(messageId == CDIValidationErrorManager.NOT_PASSIVATION_CAPABLE_BEAN_ID){
+ IType type = findTypeWithNoSerializable(file, start);
+
+ if(type != null){
+ return new IMarkerResolution[] {
+ new AddSerializableInterfaceMarkerResolution(type, file)
+ };
+ }
}
}
return new IMarkerResolution[] {};
@@ -233,6 +241,23 @@
}
return null;
}
+
+ private IType findTypeWithNoSerializable(IFile file, int start) throws
JavaModelException{
+ IJavaElement javaElement = findJavaElement(file, start);
+ if(javaElement != null && javaElement instanceof IType){
+ IType type = (IType)javaElement;
+ if(!type.isBinary()){
+ String shortName =
MarkerResolutionUtils.getShortName(AddSerializableInterfaceMarkerResolution.SERIALIZABLE);
+ String[] interfaces = type.getSuperInterfaceNames();
+ for(String name : interfaces){
+ if(name.equals(shortName))
+ return null;
+ }
+ return type;
+ }
+ }
+ return null;
+ }
private IJavaElement findJavaElement(IFile file, int start){
try{
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MarkerResolutionUtils.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MarkerResolutionUtils.java 2011-03-11
18:59:22 UTC (rev 29712)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MarkerResolutionUtils.java 2011-03-11
21:13:04 UTC (rev 29713)
@@ -52,8 +52,10 @@
*/
public class MarkerResolutionUtils {
public static final String DOT = "."; //$NON-NLS-1$
+ public static final String COMMA = ","; //$NON-NLS-1$
public static final String SPACE = " "; //$NON-NLS-1$
public static final String AT = "@"; //$NON-NLS-1$
+ public static final String IMPLEMENTS = "implements"; //$NON-NLS-1$
static final HashSet<String> primitives = new HashSet<String>();
static{
@@ -439,6 +441,37 @@
}
}
+ public static void addInterfaceToClass(ICompilationUnit compilationUnit, IType type,
String qualifiedName) throws JavaModelException{
+ String shortName = getShortName(qualifiedName);
+
+ IType[] types = compilationUnit.getTypes();
+ IType workingType = null;
+ for(IType t : types){
+ if(t.getElementName().equals(type.getElementName())){
+ workingType = t;
+ break;
+ }
+ }
+
+ if(workingType != null){
+ addImport(qualifiedName, compilationUnit);
+
+ IBuffer buffer = compilationUnit.getBuffer();
+
+ String text = buffer.getText(workingType.getSourceRange().getOffset(),
workingType.getSourceRange().getLength());
+
+ int namePosition = text.indexOf(workingType.getElementName());
+ if(namePosition >= 0){
+ int implementsPosition = text.indexOf(IMPLEMENTS,namePosition);
+ if(implementsPosition < 0)
+ buffer.replace(workingType.getSourceRange().getOffset()+namePosition+workingType.getElementName().length(),0,SPACE+IMPLEMENTS+SPACE+shortName);
+ else
+ buffer.replace(workingType.getSourceRange().getOffset()+implementsPosition+IMPLEMENTS.length(),0,SPACE+shortName+COMMA);
+ }
+ }
+
+ }
+
private static IJavaElement getInjectedJavaElement(ICompilationUnit compilationUnit,
IInjectionPoint injectionPoint){
if(injectionPoint instanceof IInjectionPointField){
IField field = ((IInjectionPointField)injectionPoint).getField();