Author: dazarov
Date: 2011-07-21 19:12:46 -0400 (Thu, 21 Jul 2011)
New Revision: 33124
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddAnnotationMarkerResolution.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAnnotationMarkerResolution.java
Removed:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddNonbindingAnnotationMarkerResolution.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
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIMarkerResolutionTest.java
Log:
https://issues.jboss.org/browse/JBIDE-7667
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-07-21
22:25:52 UTC (rev 33123)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2011-07-21
23:12:46 UTC (rev 33124)
@@ -927,9 +927,10 @@
if (injectDeclaration != null) {
String pref =
observer.getMethod().isConstructor()?CDIPreferences.CONSTRUCTOR_PARAMETER_ILLEGALLY_ANNOTATED:CDIPreferences.OBSERVER_ANNOTATED_INJECT;
String message =
observer.getMethod().isConstructor()?CDIValidationMessages.CONSTRUCTOR_PARAMETER_ANNOTATED_OBSERVES:CDIValidationMessages.OBSERVER_ANNOTATED_INJECT;
- addError(message, pref, injectDeclaration, bean.getResource());
+ int messageId =
observer.getMethod().isConstructor()?CONSTRUCTOR_PARAMETER_ANNOTATED_OBSERVES_ID:OBSERVER_ANNOTATED_INJECT_ID;
+ addError(message, pref, injectDeclaration, bean.getResource(), messageId);
for (ITextSourceReference declaration : declarations) {
- addError(message, pref, declaration, bean.getResource());
+ addError(message, pref, declaration, bean.getResource(), messageId);
}
}
} catch (JavaModelException e) {
@@ -1039,9 +1040,10 @@
if (injectDeclaration != null) {
String pref =
disposer.getMethod().isConstructor()?CDIPreferences.CONSTRUCTOR_PARAMETER_ILLEGALLY_ANNOTATED:CDIPreferences.DISPOSER_ANNOTATED_INJECT;
String message =
disposer.getMethod().isConstructor()?CDIValidationMessages.CONSTRUCTOR_PARAMETER_ANNOTATED_DISPOSES:CDIValidationMessages.DISPOSER_ANNOTATED_INJECT;
- addError(message, pref, injectDeclaration, bean.getResource());
+ int messageId =
disposer.getMethod().isConstructor()?CONSTRUCTOR_PARAMETER_ANNOTATED_DISPOSES_ID:DISPOSER_ANNOTATED_INJECT_ID;
+ addError(message, pref, injectDeclaration, bean.getResource(), messageId);
for (ITextSourceReference declaration : disposerDeclarations) {
- addError(message, pref, declaration, bean.getResource());
+ addError(message, pref, declaration, bean.getResource(), messageId);
}
}
} catch (JavaModelException e) {
@@ -1185,7 +1187,7 @@
*/
IAnnotationDeclaration inject =
producer.getAnnotation(CDIConstants.INJECT_ANNOTATION_TYPE_NAME);
if (inject != null) {
- addError(CDIValidationMessages.PRODUCER_ANNOTATED_INJECT,
CDIPreferences.PRODUCER_ANNOTATED_INJECT, inject, inject.getResource() != null ?
inject.getResource() : producer.getResource());
+ addError(CDIValidationMessages.PRODUCER_ANNOTATED_INJECT,
CDIPreferences.PRODUCER_ANNOTATED_INJECT, inject, inject.getResource() != null ?
inject.getResource() : producer.getResource(), PRODUCER_ANNOTATED_INJECT_ID);
}
if (producer instanceof IProducerField) {
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-07-21
22:25:52 UTC (rev 33123)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationErrorManager.java 2011-07-21
23:12:46 UTC (rev 33124)
@@ -39,6 +39,12 @@
public static final int MISSING_NONBINDING_FOR_ARRAY_VALUE_IN_QUALIFIER_TYPE_MEMBER_ID =
18;
public static final int
MISSING_NONBINDING_FOR_ANNOTATION_VALUE_IN_INTERCEPTOR_BINDING_TYPE_MEMBER_ID = 19;
public static final int
MISSING_NONBINDING_FOR_ARRAY_VALUE_IN_INTERCEPTOR_BINDING_TYPE_MEMBER_ID = 20;
+ public static final int PRODUCER_ANNOTATED_INJECT_ID = 21;
+ public static final int OBSERVER_ANNOTATED_INJECT_ID = 22;
+ public static final int DISPOSER_ANNOTATED_INJECT_ID = 23;
+
+ public static final int CONSTRUCTOR_PARAMETER_ANNOTATED_OBSERVES_ID = 24;
+ public static final int CONSTRUCTOR_PARAMETER_ANNOTATED_DISPOSES_ID = 25;
/*
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-07-21
22:25:52 UTC (rev 33123)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java 2011-07-21
23:12:46 UTC (rev 33124)
@@ -107,7 +107,8 @@
public static String CHANGE_RETENTION_MARKER_RESOLUTION_TITLE;
public static String ADD_TARGET_MARKER_RESOLUTION_TITLE;
public static String CHANGE_TARGET_MARKER_RESOLUTION_TITLE;
- public static String ADD_NONBINDING_MARKER_RESOLUTION_TITLE;
+ public static String ADD_ANNOTATION_MARKER_RESOLUTION_TITLE;
+ public static String DELETE_ANNOTATION_MARKER_RESOLUTION_TITLE;
public static String QUESTION;
public static String DECREASING_FIELD_VISIBILITY_MAY_CAUSE_COMPILATION_PROBLEMS;
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-07-21
22:25:52 UTC (rev 33123)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2011-07-21
23:12:46 UTC (rev 33124)
@@ -91,7 +91,8 @@
CHANGE_RETENTION_MARKER_RESOLUTION_TITLE=Change ''{0}'' annotation to
@Retention(RUNTIME)
ADD_TARGET_MARKER_RESOLUTION_TITLE=Add @Target({0}) annotation to ''{1}''
class
CHANGE_TARGET_MARKER_RESOLUTION_TITLE=Change ''{0}'' annotation to
@Target({1})
-ADD_NONBINDING_MARKER_RESOLUTION_TITLE=Add @Nonbinding annotation to
''{0}'' member
+ADD_ANNOTATION_MARKER_RESOLUTION_TITLE=Add @{0} annotation to ''{1}''
{2}
+DELETE_ANNOTATION_MARKER_RESOLUTION_TITLE=Delete @{0} annotation from
''{1}'' {2}
QUESTION=Question
DECREASING_FIELD_VISIBILITY_MAY_CAUSE_COMPILATION_PROBLEMS=Decreasing field visibility
may cause compilation problems. Do you want to continue?
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddAnnotationMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddAnnotationMarkerResolution.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddAnnotationMarkerResolution.java 2011-07-21
23:12:46 UTC (rev 33124)
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * 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 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.IField;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.ILocalVariable;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.osgi.util.NLS;
+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;
+
+public class AddAnnotationMarkerResolution implements
+ IMarkerResolution2 {
+ private IJavaElement element;
+ private String qualifiedName;
+ private String label;
+
+ public AddAnnotationMarkerResolution(IJavaElement element, String qualifiedName){
+ this.element = element;
+ this.qualifiedName = qualifiedName;
+ String shortName = MarkerResolutionUtils.getShortName(qualifiedName);
+ String type = "";
+ if(element instanceof IType){
+ type = "class";
+ }else if(element instanceof IMethod){
+ type = "method";
+ }else if(element instanceof IField){
+ type = "field";
+ }else if(element instanceof ILocalVariable && ((ILocalVariable)
element).isParameter()){
+ type = "parameter";
+ }
+
+ label = NLS.bind(CDIUIMessages.ADD_ANNOTATION_MARKER_RESOLUTION_TITLE, new
String[]{shortName, element.getElementName(), type});
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void run(IMarker marker) {
+ try{
+ ICompilationUnit original =
MarkerResolutionUtils.getJavaMember(element).getCompilationUnit();
+ ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+
+ MarkerResolutionUtils.addAnnotation(qualifiedName, compilationUnit, element);
+
+ compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
+ compilationUnit.discardWorkingCopy();
+ }catch(CoreException ex){
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ }
+
+ public String getDescription() {
+ return label;
+ }
+
+ public Image getImage() {
+ return null;
+ }
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddAnnotationMarkerResolution.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddNonbindingAnnotationMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddNonbindingAnnotationMarkerResolution.java 2011-07-21
22:25:52 UTC (rev 33123)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddNonbindingAnnotationMarkerResolution.java 2011-07-21
23:12:46 UTC (rev 33124)
@@ -1,60 +0,0 @@
-/*******************************************************************************
- * 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 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.IMember;
-import org.eclipse.osgi.util.NLS;
-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;
-
-public class AddNonbindingAnnotationMarkerResolution implements
- IMarkerResolution2 {
- private IMember member;
- private String label;
-
- public AddNonbindingAnnotationMarkerResolution(IMember member){
- this.member = member;
- label = NLS.bind(CDIUIMessages.ADD_NONBINDING_MARKER_RESOLUTION_TITLE,
member.getElementName());
- }
-
- public String getLabel() {
- return label;
- }
-
- public void run(IMarker marker) {
- try{
- ICompilationUnit original = member.getCompilationUnit();
- ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
-
- MarkerResolutionUtils.addAnnotation(CDIConstants.NON_BINDING_ANNOTATION_TYPE_NAME,
compilationUnit, member);
-
- compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
- compilationUnit.discardWorkingCopy();
- }catch(CoreException ex){
- CDIUIPlugin.getDefault().logError(ex);
- }
- }
-
- public String getDescription() {
- return label;
- }
-
- public Image getImage() {
- return null;
- }
-}
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-07-21
22:25:52 UTC (rev 33123)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java 2011-07-21
23:12:46 UTC (rev 33124)
@@ -24,6 +24,7 @@
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.ILocalVariable;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
@@ -267,10 +268,46 @@
IAnnotation annotation = getAnnotation(element,
CDIConstants.NON_BINDING_ANNOTATION_TYPE_NAME);
if(element instanceof IMember && annotation == null){
return new IMarkerResolution[] {
- new AddNonbindingAnnotationMarkerResolution((IMember)element)
+ new AddAnnotationMarkerResolution((IMember)element,
CDIConstants.NON_BINDING_ANNOTATION_TYPE_NAME)
};
}
}
+ }else if(messageId == CDIValidationErrorManager.DISPOSER_ANNOTATED_INJECT_ID){
+ IJavaElement element = findJavaElement(file, start);
+ if(element != null){
+ IJavaElement injectElement = findJavaElementByAnnotation(element,
CDIConstants.INJECT_ANNOTATION_TYPE_NAME);
+ IJavaElement disposesElement = findJavaElementByAnnotation(element,
CDIConstants.DISPOSES_ANNOTATION_TYPE_NAME);
+ if(injectElement != null && disposesElement != null){
+ return new IMarkerResolution[] {
+ new DeleteAnnotationMarkerResolution(injectElement,
CDIConstants.INJECT_ANNOTATION_TYPE_NAME),
+ new DeleteAnnotationMarkerResolution(disposesElement,
CDIConstants.DISPOSES_ANNOTATION_TYPE_NAME)
+ };
+ }
+ }
+ }else if(messageId == CDIValidationErrorManager.PRODUCER_ANNOTATED_INJECT_ID){
+ IJavaElement element = findJavaElement(file, start);
+ if(element != null){
+ IJavaElement injectElement = findJavaElementByAnnotation(element,
CDIConstants.INJECT_ANNOTATION_TYPE_NAME);
+ IJavaElement produsesElement = findJavaElementByAnnotation(element,
CDIConstants.PRODUCES_ANNOTATION_TYPE_NAME);
+ if(injectElement != null && produsesElement != null){
+ return new IMarkerResolution[] {
+ new DeleteAnnotationMarkerResolution(injectElement,
CDIConstants.INJECT_ANNOTATION_TYPE_NAME),
+ new DeleteAnnotationMarkerResolution(produsesElement,
CDIConstants.PRODUCES_ANNOTATION_TYPE_NAME)
+ };
+ }
+ }
+ }else if(messageId == CDIValidationErrorManager.OBSERVER_ANNOTATED_INJECT_ID){
+ IJavaElement element = findJavaElement(file, start);
+ if(element != null){
+ IJavaElement injectElement = findJavaElementByAnnotation(element,
CDIConstants.INJECT_ANNOTATION_TYPE_NAME);
+ IJavaElement observerElement = findJavaElementByAnnotation(element,
CDIConstants.OBSERVERS_ANNOTATION_TYPE_NAME);
+ if(injectElement != null && observerElement != null){
+ return new IMarkerResolution[] {
+ new DeleteAnnotationMarkerResolution(injectElement,
CDIConstants.INJECT_ANNOTATION_TYPE_NAME),
+ new DeleteAnnotationMarkerResolution(observerElement,
CDIConstants.OBSERVERS_ANNOTATION_TYPE_NAME)
+ };
+ }
+ }
}
}
return new IMarkerResolution[] {};
@@ -502,4 +539,26 @@
return null;
}
+ private IJavaElement findJavaElementByAnnotation(IJavaElement element, String
qualifiedName) throws JavaModelException{
+ IAnnotation annotation = getAnnotation(element, qualifiedName);
+ if(annotation != null)
+ return element;
+
+ if(element instanceof IMethod){
+ for(ILocalVariable parameter : ((IMethod)element).getParameters()){
+ annotation = getAnnotation(parameter, qualifiedName);
+ if(annotation != null)
+ return parameter;
+ }
+ }else if(element instanceof ILocalVariable){
+ IJavaElement parent = element.getParent();
+ if(parent != null){
+ annotation = getAnnotation(parent, qualifiedName);
+ if(annotation != null)
+ return parent;
+ }
+ }
+ return null;
+ }
+
}
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAnnotationMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAnnotationMarkerResolution.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAnnotationMarkerResolution.java 2011-07-21
23:12:46 UTC (rev 33124)
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * 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 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.IField;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.ILocalVariable;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.osgi.util.NLS;
+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;
+
+public class DeleteAnnotationMarkerResolution implements
+ IMarkerResolution2 {
+ private IJavaElement element;
+ private String qualifiedName;
+ private String label;
+
+ public DeleteAnnotationMarkerResolution(IJavaElement element, String qualifiedName){
+ this.element = element;
+ this.qualifiedName = qualifiedName;
+ String shortName = MarkerResolutionUtils.getShortName(qualifiedName);
+ String type = "";
+ if(element instanceof IType){
+ type = "class";
+ }else if(element instanceof IMethod){
+ type = "method";
+ }else if(element instanceof IField){
+ type = "field";
+ }else if(element instanceof ILocalVariable && ((ILocalVariable)
element).isParameter()){
+ type = "parameter";
+ }
+
+ label = NLS.bind(CDIUIMessages.DELETE_ANNOTATION_MARKER_RESOLUTION_TITLE, new
String[]{shortName, element.getElementName(), type});
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void run(IMarker marker) {
+ try{
+ ICompilationUnit original =
MarkerResolutionUtils.getJavaMember(element).getCompilationUnit();
+ ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+
+ MarkerResolutionUtils.deleteAnnotation(qualifiedName, compilationUnit, element);
+
+ compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
+ compilationUnit.discardWorkingCopy();
+ }catch(CoreException ex){
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ }
+
+ public String getDescription() {
+ return label;
+ }
+
+ public Image getImage() {
+ return null;
+ }
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAnnotationMarkerResolution.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
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-07-21
22:25:52 UTC (rev 33123)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MarkerResolutionUtils.java 2011-07-21
23:12:46 UTC (rev 33124)
@@ -15,6 +15,8 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
@@ -25,6 +27,7 @@
import org.eclipse.jdt.core.IBuffer;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IImportContainer;
import org.eclipse.jdt.core.IImportDeclaration;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.ILocalVariable;
@@ -157,15 +160,20 @@
return false;
}
- public static void addAnnotation(String qualifiedName, ICompilationUnit compilationUnit,
IMember element) throws JavaModelException{
+ public static void addAnnotation(String qualifiedName, ICompilationUnit compilationUnit,
IJavaElement element) throws JavaModelException{
addAnnotation(qualifiedName, compilationUnit, element, "");
}
- public static void addAnnotation(String qualifiedName, ICompilationUnit compilationUnit,
IMember element, String params) throws JavaModelException{
- IMember workingCopyMember = findWorkingCopy(compilationUnit, element);
- if(workingCopyMember == null)
+ public static void addAnnotation(String qualifiedName, ICompilationUnit compilationUnit,
IJavaElement element, String params) throws JavaModelException{
+ IJavaElement workingCopyElement = findWorkingCopy(compilationUnit, element);
+ if(workingCopyElement == null)
return;
+ if(!(workingCopyElement instanceof IMember))
+ return;
+
+ IMember workingCopyMember = (IMember) workingCopyElement;
+
IAnnotation annotation = getAnnotation(workingCopyMember, qualifiedName);
if(annotation != null && annotation.exists())
return;
@@ -261,6 +269,8 @@
member = (IMember)element;
}else if(element instanceof ITypeParameter){
member = ((ITypeParameter)element).getDeclaringMember();
+ }else if(element instanceof ILocalVariable){
+ member = ((ILocalVariable)element).getDeclaringMember();
}
if (member != null && annotation != null &&
qualifiedName.equals(EclipseJavaUtil.resolveType(member.getDeclaringType(), name))) {
return annotation;
@@ -501,6 +511,14 @@
return (T)a;
}
}
+ }else if(element instanceof ILocalVariable && ((ILocalVariable)
element).isParameter()){
+ IJavaElement parent = findWorkingCopy(compilationUnit, element.getParent());
+ if(parent instanceof IMethod){
+ for(ILocalVariable parameter : ((IMethod)parent).getParameters()){
+ if(parameter.getElementName().equals(element.getElementName()) &&
parameter.getTypeSignature().equals(((ILocalVariable)element).getTypeSignature()))
+ return (T)parameter;
+ }
+ }
}else{
IJavaElement[] elements = compilationUnit.findElements(element);
if(elements != null){
@@ -513,4 +531,56 @@
return null;
}
+ public static void deleteAnnotation(String qualifiedName, ICompilationUnit
compilationUnit, IJavaElement element) throws JavaModelException{
+ IJavaElement workingCopyElement = findWorkingCopy(compilationUnit, element);
+ if(workingCopyElement == null)
+ return;
+
+ IAnnotation annotation = getAnnotation(workingCopyElement, qualifiedName);
+ if(annotation != null){
+ IBuffer buffer = compilationUnit.getBuffer();
+
+ int position = annotation.getSourceRange().getOffset() +
annotation.getSourceRange().getLength();
+ int numberOfSpaces = 0;
+ if(position < buffer.getLength()-1){
+ char c = buffer.getChar(position);
+ while(c == ' ' && position < buffer.getLength()-1){
+ numberOfSpaces++;
+ position++;
+ c = buffer.getChar(position);
+ }
+ }
+
+ // delete annotation
+ buffer.replace(annotation.getSourceRange().getOffset(),
annotation.getSourceRange().getLength()+numberOfSpaces, "");
+
+ // check and delete import
+ IImportDeclaration importDeclaration = compilationUnit.getImport(qualifiedName);
+ IImportContainer importContainer = compilationUnit.getImportContainer();
+ 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))
+ importDeclaration.delete(false, new NullProgressMonitor());
+ }
+ }
+ }
+
+ private static boolean checkImport(String text, String qualifiedName){
+ String name = getShortName(qualifiedName);
+
+ Pattern p = Pattern.compile(".*\\W"+name+"\\W.*",Pattern.DOTALL);
//$NON-NLS-1$ //$NON-NLS-2$
+ Matcher m = p.matcher(text);
+ return !m.matches();
+ }
+
+ public static IMember getJavaMember(IJavaElement element){
+ while(element != null){
+ if(element instanceof IMember)
+ return (IMember)element;
+ element = element.getParent();
+ }
+ return null;
+ }
+
}
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 2011-07-21
22:25:52 UTC (rev 33123)
+++
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIMarkerResolutionTest.java 2011-07-21
23:12:46 UTC (rev 33124)
@@ -27,8 +27,8 @@
import org.jboss.tools.cdi.core.test.tck.validation.ValidationTest;
import org.jboss.tools.cdi.internal.core.validation.CDICoreValidator;
import org.jboss.tools.cdi.internal.core.validation.CDIValidationErrorManager;
+import org.jboss.tools.cdi.ui.marker.AddAnnotationMarkerResolution;
import org.jboss.tools.cdi.ui.marker.AddLocalBeanMarkerResolution;
-import org.jboss.tools.cdi.ui.marker.AddNonbindingAnnotationMarkerResolution;
import org.jboss.tools.cdi.ui.marker.AddRetentionAnnotationMarkerResolution;
import org.jboss.tools.cdi.ui.marker.AddSerializableInterfaceMarkerResolution;
import org.jboss.tools.cdi.ui.marker.AddTargetAnnotationMarkerResolution;
@@ -561,7 +561,7 @@
CDICoreValidator.PROBLEM_TYPE,
CDIValidationErrorManager.MESSAGE_ID_ATTRIBUTE_NAME,
CDIValidationErrorManager.MISSING_NONBINDING_FOR_ANNOTATION_VALUE_IN_QUALIFIER_TYPE_MEMBER_ID,
- AddNonbindingAnnotationMarkerResolution.class);
+ AddAnnotationMarkerResolution.class);
}
public void testAddNonbindingToArrayMemberOfQualifierResolution() throws CoreException{
@@ -575,7 +575,7 @@
CDICoreValidator.PROBLEM_TYPE,
CDIValidationErrorManager.MESSAGE_ID_ATTRIBUTE_NAME,
CDIValidationErrorManager.MISSING_NONBINDING_FOR_ARRAY_VALUE_IN_QUALIFIER_TYPE_MEMBER_ID,
- AddNonbindingAnnotationMarkerResolution.class);
+ AddAnnotationMarkerResolution.class);
}
public void testAddNonbindingToAnnotationMemberOfInterceptorResolution() throws
CoreException{
@@ -589,7 +589,7 @@
CDICoreValidator.PROBLEM_TYPE,
CDIValidationErrorManager.MESSAGE_ID_ATTRIBUTE_NAME,
CDIValidationErrorManager.MISSING_NONBINDING_FOR_ANNOTATION_VALUE_IN_INTERCEPTOR_BINDING_TYPE_MEMBER_ID,
- AddNonbindingAnnotationMarkerResolution.class);
+ AddAnnotationMarkerResolution.class);
}
public void testAddNonbindingToArrayMemberOfInterceptorResolution() throws
CoreException{
@@ -603,7 +603,7 @@
CDICoreValidator.PROBLEM_TYPE,
CDIValidationErrorManager.MESSAGE_ID_ATTRIBUTE_NAME,
CDIValidationErrorManager.MISSING_NONBINDING_FOR_ARRAY_VALUE_IN_INTERCEPTOR_BINDING_TYPE_MEMBER_ID,
- AddNonbindingAnnotationMarkerResolution.class);
+ AddAnnotationMarkerResolution.class);
}
}
\ No newline at end of file