Author: dazarov
Date: 2010-12-02 08:47:54 -0500 (Thu, 02 Dec 2010)
New Revision: 27093
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/
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/MakeFieldStaticMarkerResolution.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.ui/plugin.xml
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
Log:
https://jira.jboss.org/browse/JBIDE-7674
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-02
13:28:22 UTC (rev 27092)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-12-02
13:47:54 UTC (rev 27093)
@@ -22,6 +22,7 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
@@ -104,7 +105,12 @@
public class CDICoreValidator extends CDIValidationErrorManager implements IValidator {
public static final String ID = "org.jboss.tools.cdi.core.CoreValidator";
//$NON-NLS-1$
public static final String PROBLEM_TYPE =
"org.jboss.tools.cdi.core.cdiproblem"; //$NON-NLS-1$
+
+ 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;
+
ICDIProject cdiProject;
String projectName;
CDIProjectSet projectSet;
@@ -1090,7 +1096,7 @@
* - non-static field of a session bean class is annotated @Produces
*/
if(producer.getClassBean() instanceof ISessionBean &&
!Flags.isStatic(producerField.getField().getFlags())) {
- addError(CDIValidationMessages.ILLEGAL_PRODUCER_FIELD_IN_SESSION_BEAN,
CDIPreferences.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN, producer.getProducesAnnotation(),
producer.getResource());
+ addError(CDIValidationMessages.ILLEGAL_PRODUCER_FIELD_IN_SESSION_BEAN,
CDIPreferences.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN, producer.getProducesAnnotation(),
producer.getResource(), ILLEGAL_PRODUCER_FIELD_IN_SESSION_BEAN_ID);
}
} else {
IProducerMethod producerMethod = (IProducerMethod) producer;
@@ -2169,4 +2175,18 @@
CDICorePlugin.getDefault().logError(e);
}
}
+
+ public IMarker addError(String message, String preferenceKey,
+ ITextSourceReference location, IResource target, int messageId) {
+ IMarker marker = addError(message, preferenceKey, location, target);
+ try{
+ if(marker!=null) {
+ marker.setAttribute(MESSAGE_ID_ATTRIBUTE_NAME, new Integer(messageId));
+ }
+ }catch(CoreException ex){
+ CDICorePlugin.getDefault().logError(ex);
+ }
+ return marker;
+ }
+
}
\ No newline at end of file
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.ui/plugin.xml
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.ui/plugin.xml 2010-12-02 13:28:22 UTC (rev
27092)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/plugin.xml 2010-12-02 13:47:54 UTC (rev
27093)
@@ -228,5 +228,10 @@
</contentType>
</proposalComputer>
</extension>
+ <extension point="org.eclipse.ui.ide.markerResolution">
+ <markerResolutionGenerator
+ markerType="org.jboss.tools.cdi.core.cdiproblem"
+ class="org.jboss.tools.cdi.ui.marker.CDIProblemMarkerResolutionGenerator"/>
+ </extension>
</plugin>
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-02
13:28:22 UTC (rev 27092)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java 2010-12-02
13:47:54 UTC (rev 27093)
@@ -61,4 +61,6 @@
public static String MESSAGE_INTERCEPTOR_BINDINGS_EMPTY;
+ public static String MAKE_FIELD_STATIC_MARKER_RESOLUTION_TITLE;
+
}
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-02
13:28:22 UTC (rev 27092)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2010-12-02
13:47:54 UTC (rev 27093)
@@ -49,3 +49,5 @@
MESSAGE_FIELD_NAME_NOT_VALID=Field Name is not valid. {0}
MESSAGE_INTERCEPTOR_BINDINGS_EMPTY=Interceptor Bindings list is empty
+
+MAKE_FIELD_STATIC_MARKER_RESOLUTION_TITLE=Make field: ''{0}'' static
Added:
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
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java 2010-12-02
13:47:54 UTC (rev 27093)
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * 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 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.ICompilationUnit;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.ui.IMarkerResolution;
+import org.eclipse.ui.IMarkerResolutionGenerator2;
+import org.jboss.tools.cdi.internal.core.validation.CDICoreValidator;
+import org.jboss.tools.cdi.ui.CDIUIPlugin;
+import org.jboss.tools.common.EclipseUtil;
+
+/**
+ * @author Daniel Azarov
+ */
+public class CDIProblemMarkerResolutionGenerator implements
+ IMarkerResolutionGenerator2 {
+ private static final String JAVA_EXTENSION = "java"; //$NON-NLS-1$
+
+ public IMarkerResolution[] getResolutions(IMarker marker) {
+ try {
+ return findResolutions(marker);
+ } catch (CoreException ex) {
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ return new IMarkerResolution[] {};
+ }
+
+ private IMarkerResolution[] findResolutions(IMarker marker)
+ throws CoreException {
+ Integer attribute = ((Integer) marker
+ .getAttribute(CDICoreValidator.MESSAGE_ID_ATTRIBUTE_NAME));
+ if (attribute == null)
+ return new IMarkerResolution[] {};
+
+ int messageId = attribute.intValue();
+
+ IFile file = (IFile) marker.getResource();
+
+ attribute = ((Integer) marker.getAttribute(IMarker.CHAR_START));
+ if (attribute == null)
+ 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 == CDICoreValidator.ILLEGAL_PRODUCER_FIELD_IN_SESSION_BEAN_ID) {
+ IField field = findNonStaticField(file, start);
+ if(field != null){
+ return new IMarkerResolution[] {
+ new MakeFieldStaticMarkerResolution(field, file)
+ };
+ }
+ }
+ }
+ return new IMarkerResolution[] {};
+ }
+
+ 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){
+ IField field = (IField)javaElement;
+ if((field.getFlags() & Flags.AccStatic) == 0)
+ return field;
+ }
+ }
+ }catch(CoreException ex){
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ return null;
+ }
+
+ public boolean hasResolutions(IMarker marker) {
+ try {
+ if (findResolutions(marker).length != 0)
+ return true;
+ } catch (CoreException ex) {
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ return false;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeFieldStaticMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeFieldStaticMarkerResolution.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MakeFieldStaticMarkerResolution.java 2010-12-02
13:47:54 UTC (rev 27093)
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * 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.IField;
+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 MakeFieldStaticMarkerResolution 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 STATIC = " static"; //$NON-NLS-1$
+
+ private String label;
+ private IField field;
+ private IFile file;
+
+ public MakeFieldStaticMarkerResolution(IField field, IFile file){
+ this.label =
MessageFormat.format(CDIUIMessages.MAKE_FIELD_STATIC_MARKER_RESOLUTION_TITLE, new
Object[]{field.getElementName()});
+ this.field = field;
+ 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 = field.getFlags();
+
+ String text = buffer.getText(field.getSourceRange().getOffset(),
field.getSourceRange().getLength());
+
+ int position = field.getSourceRange().getOffset();
+ if((flag & Flags.AccPublic) != 0){
+ position += text.indexOf(PUBLIC)+PUBLIC.length();
+ buffer.replace(position, 0, STATIC);
+ }else if((flag & Flags.AccPrivate) != 0){
+ position += text.indexOf(PRIVATE)+PRIVATE.length();
+ buffer.replace(position, 0, STATIC);
+ }else if((flag & Flags.AccProtected) != 0){
+ position += text.indexOf(PROTECTED)+PROTECTED.length();
+ buffer.replace(position, 0, STATIC);
+ }
+
+ 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/MakeFieldStaticMarkerResolution.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain