Author: dazarov
Date: 2011-07-19 19:41:22 -0400 (Tue, 19 Jul 2011)
New Revision: 33062
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddTargetAnnotationMarkerResolution.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/ChangeTargetAnnotationMarkerResolution.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/AnnotationValidationDelegate.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-7632,
https://issues.jboss.org/browse/JBIDE-7633,
https://issues.jboss.org/browse/JBIDE-7630
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 2011-07-19
22:26:25 UTC (rev 33061)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java 2011-07-19
23:41:22 UTC (rev 33062)
@@ -97,4 +97,9 @@
public String SEAM_FACES_INPUT_FIELD_TYPE_NAME =
"org.jboss.seam.faces.validation.InputField";
public String SEAM_FACES_INPUT_ELEMENT_TYPE_NAME =
"org.jboss.seam.faces.validation.InputElement";
+
+ public String ELEMENT_TYPE_TYPE_NAME =
"java.lang.annotation.ElementType.TYPE";
+ public String ELEMENT_TYPE_METHOD_NAME =
"java.lang.annotation.ElementType.METHOD";
+ public String ELEMENT_TYPE_FIELD_NAME =
"java.lang.annotation.ElementType.FIELD";
+ public String ELEMENT_TYPE_PARAMETER_NAME =
"java.lang.annotation.ElementType.PARAMETER";
}
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/AnnotationValidationDelegate.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/AnnotationValidationDelegate.java 2011-07-19
22:26:25 UTC (rev 33061)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/AnnotationValidationDelegate.java 2011-07-19
23:41:22 UTC (rev 33062)
@@ -65,7 +65,7 @@
* Stereotype annotation type should be annotated with @Target with correct targets
[JSR-299 §2.7.1]
* Stereotype annotation type should be annotated with @Retention(RUNTIME)
*/
- validateTargetAnnotation(stereotype, STEREOTYPE_GENERAL_TARGET_VARAINTS,
CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_STEREOTYPE_TYPE, resource);
+ validateTargetAnnotation(stereotype, STEREOTYPE_GENERAL_TARGET_VARAINTS,
CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_STEREOTYPE_TYPE, resource,
CDIValidationErrorManager.MISSING_TARGET_ANNOTATION_IN_STEREOTYPE_TYPE_ID);
/*
* Stereotype annotation type should be annotated with @Retention(RUNTIME)
@@ -177,7 +177,7 @@
/*
* Scope annotation type should be annotated with @Target({TYPE, METHOD, FIELD})
*/
- validateTargetAnnotation(scope, SCOPE_GENERAL_TARGET_VARIANTS,
CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_SCOPE_TYPE, resource);
+ validateTargetAnnotation(scope, SCOPE_GENERAL_TARGET_VARIANTS,
CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_SCOPE_TYPE, resource,
CDIValidationErrorManager.MISSING_TARGET_ANNOTATION_IN_SCOPE_TYPE_ID);
/*
* Scope annotation type should be annotated with @Retention(RUNTIME)
@@ -210,7 +210,7 @@
* Qualifier annotation type should be annotated with @Target({METHOD, FIELD,
PARAMETER, TYPE}) or @Target({"FIELD", "PARAMETER"})
* Qualifier annotation type should be annotated with @Retention(RUNTIME)
*/
- validateTargetAnnotation(qualifier, QUALIFIER_GENERAL_TARGET_VARIANTS,
CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE, resource);
+ validateTargetAnnotation(qualifier, QUALIFIER_GENERAL_TARGET_VARIANTS,
CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE, resource,
CDIValidationErrorManager.MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE_ID);
/*
* Qualifier annotation type should be annotated with @Retention(RUNTIME)
@@ -218,12 +218,12 @@
validateRetentionAnnotation(qualifier,
CDIValidationMessages.MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE, resource,
CDIValidationErrorManager.MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE_ID);
}
- private void validateTargetAnnotation(ICDIAnnotation annotationType, String[][]
variants, String message, IResource resource) throws JavaModelException {
+ private void validateTargetAnnotation(ICDIAnnotation annotationType, String[][]
variants, String message, IResource resource, int message_id) throws JavaModelException {
IAnnotationDeclaration target =
annotationType.getAnnotationDeclaration(CDIConstants.TARGET_ANNOTATION_TYPE_NAME);
if(target==null) {
- validator.addError(message,
CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE,
CDIUtil.convertToSourceReference(annotationType.getSourceType().getNameRange(), resource),
resource);
+ validator.addError(message,
CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE,
CDIUtil.convertToSourceReference(annotationType.getSourceType().getNameRange(), resource),
resource, message_id);
} else if(!CDIUtil.checkTargetAnnotation(target, variants)) {
- validator.addError(message,
CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE, target,
resource);
+ validator.addError(message,
CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE, target,
resource, message_id);
}
}
}
\ No newline at end of file
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-19
22:26:25 UTC (rev 33061)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationErrorManager.java 2011-07-19
23:41:22 UTC (rev 33062)
@@ -32,6 +32,9 @@
public static final int MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE_ID = 11;
public static final int MISSING_RETENTION_ANNOTATION_IN_STEREOTYPE_TYPE_ID = 12;
public static final int MISSING_RETENTION_ANNOTATION_IN_SCOPE_TYPE_ID = 13;
+ public static final int MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE_ID = 14;
+ public static final int MISSING_TARGET_ANNOTATION_IN_STEREOTYPE_TYPE_ID = 15;
+ public static final int MISSING_TARGET_ANNOTATION_IN_SCOPE_TYPE_ID = 16;
/*
* (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-07-19
22:26:25 UTC (rev 33061)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java 2011-07-19
23:41:22 UTC (rev 33062)
@@ -105,6 +105,8 @@
public static String MAKE_FIELD_PROTECTED_MARKER_RESOLUTION_TITLE;
public static String ADD_RETENTION_MARKER_RESOLUTION_TITLE;
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 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-19
22:26:25 UTC (rev 33061)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2011-07-19
23:41:22 UTC (rev 33062)
@@ -89,6 +89,8 @@
MAKE_FIELD_PROTECTED_MARKER_RESOLUTION_TITLE=Make ''{0}'' field
protected
ADD_RETENTION_MARKER_RESOLUTION_TITLE=Add @Retention(RUNTIME) annotation to
''{0}'' class
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})
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/AddTargetAnnotationMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddTargetAnnotationMarkerResolution.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddTargetAnnotationMarkerResolution.java 2011-07-19
23:41:22 UTC (rev 33062)
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * 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.IType;
+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 AddTargetAnnotationMarkerResolution implements
+ IMarkerResolution2 {
+ private IType type;
+ private String label;
+ private String[] qualifiedNames;
+ private String[] shortNames;
+ private String totalList;
+
+ public AddTargetAnnotationMarkerResolution(IType type, String[] typeNames){
+ this.qualifiedNames = typeNames;
+ this.type = type;
+ shortNames = MarkerResolutionUtils.getShortNames(qualifiedNames);
+ totalList =
"{"+MarkerResolutionUtils.getTotalList(shortNames)+"}";
+ label = NLS.bind(CDIUIMessages.ADD_TARGET_MARKER_RESOLUTION_TITLE, totalList,
type.getElementName());
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void run(IMarker marker) {
+ try{
+ ICompilationUnit original = type.getCompilationUnit();
+ ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+
+ for(String qualifiedName : qualifiedNames){
+ MarkerResolutionUtils.addImport(qualifiedName, compilationUnit, true);
+ }
+
+ IType workingCopyType = MarkerResolutionUtils.findWorkingCopyType(compilationUnit,
type);
+
+ MarkerResolutionUtils.addAnnotation(CDIConstants.TARGET_ANNOTATION_TYPE_NAME,
compilationUnit, workingCopyType, "("+totalList+")");
+
+ 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/AddTargetAnnotationMarkerResolution.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-07-19
22:26:25 UTC (rev 33061)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java 2011-07-19
23:41:22 UTC (rev 33062)
@@ -191,7 +191,7 @@
messageId == CDIValidationErrorManager.MISSING_RETENTION_ANNOTATION_IN_SCOPE_TYPE_ID
||
messageId ==
CDIValidationErrorManager.MISSING_RETENTION_ANNOTATION_IN_STEREOTYPE_TYPE_ID){
- TypeAndAnnotation ta = findTypeOrRetentionAnnotation(file, start);
+ TypeAndAnnotation ta = findTypeAndAnnotation(file, start,
CDIConstants.RETENTION_ANNOTATION_TYPE_NAME);
if(ta != null){
if(ta.annotation == null){
return new IMarkerResolution[] {
@@ -204,6 +204,58 @@
}
}
+ }else if(messageId ==
CDIValidationErrorManager.MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE_ID){
+ TypeAndAnnotation ta = findTypeAndAnnotation(file, start,
CDIConstants.TARGET_ANNOTATION_TYPE_NAME);
+ if(ta != null){
+ if(ta.annotation == null){
+ return new IMarkerResolution[] {
+ new AddTargetAnnotationMarkerResolution(ta.type, new
String[]{CDIConstants.ELEMENT_TYPE_TYPE_NAME, CDIConstants.ELEMENT_TYPE_METHOD_NAME,
CDIConstants.ELEMENT_TYPE_FIELD_NAME, CDIConstants.ELEMENT_TYPE_PARAMETER_NAME}),
+ new AddTargetAnnotationMarkerResolution(ta.type, new
String[]{CDIConstants.ELEMENT_TYPE_FIELD_NAME, CDIConstants.ELEMENT_TYPE_PARAMETER_NAME})
+ };
+ }else{
+ return new IMarkerResolution[] {
+ new ChangeTargetAnnotationMarkerResolution(ta.type, ta.annotation, new
String[]{CDIConstants.ELEMENT_TYPE_TYPE_NAME, CDIConstants.ELEMENT_TYPE_METHOD_NAME,
CDIConstants.ELEMENT_TYPE_FIELD_NAME, CDIConstants.ELEMENT_TYPE_PARAMETER_NAME}),
+ new ChangeTargetAnnotationMarkerResolution(ta.type, ta.annotation, new
String[]{CDIConstants.ELEMENT_TYPE_FIELD_NAME, CDIConstants.ELEMENT_TYPE_PARAMETER_NAME})
+ };
+
+ }
+ }
+ }else if(messageId ==
CDIValidationErrorManager.MISSING_TARGET_ANNOTATION_IN_STEREOTYPE_TYPE_ID){
+ TypeAndAnnotation ta = findTypeAndAnnotation(file, start,
CDIConstants.TARGET_ANNOTATION_TYPE_NAME);
+ if(ta != null){
+ if(ta.annotation == null){
+ return new IMarkerResolution[] {
+ new AddTargetAnnotationMarkerResolution(ta.type, new
String[]{CDIConstants.ELEMENT_TYPE_TYPE_NAME, CDIConstants.ELEMENT_TYPE_METHOD_NAME,
CDIConstants.ELEMENT_TYPE_FIELD_NAME}),
+ new AddTargetAnnotationMarkerResolution(ta.type, new
String[]{CDIConstants.ELEMENT_TYPE_METHOD_NAME, CDIConstants.ELEMENT_TYPE_FIELD_NAME}),
+ new AddTargetAnnotationMarkerResolution(ta.type, new
String[]{CDIConstants.ELEMENT_TYPE_TYPE_NAME}),
+ new AddTargetAnnotationMarkerResolution(ta.type, new
String[]{CDIConstants.ELEMENT_TYPE_METHOD_NAME}),
+ new AddTargetAnnotationMarkerResolution(ta.type, new
String[]{CDIConstants.ELEMENT_TYPE_FIELD_NAME})
+ };
+ }else{
+ return new IMarkerResolution[] {
+ new ChangeTargetAnnotationMarkerResolution(ta.type, ta.annotation, new
String[]{CDIConstants.ELEMENT_TYPE_TYPE_NAME, CDIConstants.ELEMENT_TYPE_METHOD_NAME,
CDIConstants.ELEMENT_TYPE_FIELD_NAME}),
+ new ChangeTargetAnnotationMarkerResolution(ta.type, ta.annotation, new
String[]{CDIConstants.ELEMENT_TYPE_METHOD_NAME, CDIConstants.ELEMENT_TYPE_FIELD_NAME}),
+ new ChangeTargetAnnotationMarkerResolution(ta.type, ta.annotation, new
String[]{CDIConstants.ELEMENT_TYPE_TYPE_NAME}),
+ new ChangeTargetAnnotationMarkerResolution(ta.type, ta.annotation, new
String[]{CDIConstants.ELEMENT_TYPE_METHOD_NAME}),
+ new ChangeTargetAnnotationMarkerResolution(ta.type, ta.annotation, new
String[]{CDIConstants.ELEMENT_TYPE_FIELD_NAME})
+ };
+
+ }
+ }
+ }else if(messageId ==
CDIValidationErrorManager.MISSING_TARGET_ANNOTATION_IN_SCOPE_TYPE_ID){
+ TypeAndAnnotation ta = findTypeAndAnnotation(file, start,
CDIConstants.TARGET_ANNOTATION_TYPE_NAME);
+ if(ta != null){
+ if(ta.annotation == null){
+ return new IMarkerResolution[] {
+ new AddTargetAnnotationMarkerResolution(ta.type, new
String[]{CDIConstants.ELEMENT_TYPE_TYPE_NAME, CDIConstants.ELEMENT_TYPE_METHOD_NAME,
CDIConstants.ELEMENT_TYPE_FIELD_NAME})
+ };
+ }else{
+ return new IMarkerResolution[] {
+ new ChangeTargetAnnotationMarkerResolution(ta.type, ta.annotation, new
String[]{CDIConstants.ELEMENT_TYPE_TYPE_NAME, CDIConstants.ELEMENT_TYPE_METHOD_NAME,
CDIConstants.ELEMENT_TYPE_FIELD_NAME})
+ };
+
+ }
+ }
}
}
return new IMarkerResolution[] {};
@@ -318,15 +370,15 @@
}
}
- private TypeAndAnnotation findTypeOrRetentionAnnotation(IFile file, int start) throws
JavaModelException{
+ private TypeAndAnnotation findTypeAndAnnotation(IFile file, int start, String
annotationQualifiedName) throws JavaModelException{
IJavaElement javaElement = findJavaElement(file, start);
if(javaElement != null && javaElement instanceof IType){
IType type = (IType)javaElement;
if(!type.isBinary()){
- String shortName =
MarkerResolutionUtils.getShortName(CDIConstants.RETENTION_ANNOTATION_TYPE_NAME);
+ String shortName = MarkerResolutionUtils.getShortName(annotationQualifiedName);
IAnnotation[] annotations = type.getAnnotations();
for(IAnnotation annotation : annotations){
- if(annotation.getElementName().equals(CDIConstants.RETENTION_ANNOTATION_TYPE_NAME)
||
+ if(annotation.getElementName().equals(annotationQualifiedName) ||
annotation.getElementName().equals(shortName))
return new TypeAndAnnotation(type, annotation);
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/ChangeTargetAnnotationMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/ChangeTargetAnnotationMarkerResolution.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/ChangeTargetAnnotationMarkerResolution.java 2011-07-19
23:41:22 UTC (rev 33062)
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * 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.IAnnotation;
+import org.eclipse.jdt.core.IBuffer;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+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 ChangeTargetAnnotationMarkerResolution implements
+ IMarkerResolution2 {
+ private String label=null;
+ private IType type;
+ private IAnnotation annotation;
+ private String[] qualifiedNames;
+ private String[] shortNames;
+ private String totalList;
+
+
+ public ChangeTargetAnnotationMarkerResolution(IType type, IAnnotation annotation,
String[] typeNames){
+ this.type = type;
+ this.annotation = annotation;
+ this.qualifiedNames = typeNames;
+ shortNames = MarkerResolutionUtils.getShortNames(qualifiedNames);
+ totalList =
"{"+MarkerResolutionUtils.getTotalList(shortNames)+"}";
+
+ try {
+ label = NLS.bind(CDIUIMessages.CHANGE_TARGET_MARKER_RESOLUTION_TITLE,
annotation.getSource(), totalList);
+ } catch (JavaModelException e) {
+ CDIUIPlugin.getDefault().logError(e);
+ }
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void run(IMarker marker) {
+ try{
+ ICompilationUnit original = type.getCompilationUnit();
+ ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+
+ for(String qualifiedName : qualifiedNames){
+ MarkerResolutionUtils.addImport(qualifiedName, compilationUnit, true);
+ }
+
+ IAnnotation workingCopyAnnotation =
MarkerResolutionUtils.findWorkingCopyAnnotation(compilationUnit, type, annotation);
+
+ IBuffer buffer = compilationUnit.getBuffer();
+ String shortName =
MarkerResolutionUtils.getShortName(CDIConstants.TARGET_ANNOTATION_TYPE_NAME);
+
+ buffer.replace(workingCopyAnnotation.getSourceRange().getOffset(),
workingCopyAnnotation.getSourceRange().getLength(),
MarkerResolutionUtils.AT+shortName+"("+totalList+")");
+
+ 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/ChangeTargetAnnotationMarkerResolution.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-19
22:26:25 UTC (rev 33061)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MarkerResolutionUtils.java 2011-07-19
23:41:22 UTC (rev 33062)
@@ -221,6 +221,24 @@
return name;
}
+ public static String[] getShortNames(String[] qualifiedNames){
+ String[] shortNames = new String[qualifiedNames.length];
+ for(int i = 0; i < qualifiedNames.length; i++){
+ shortNames[i] = getShortName(qualifiedNames[i]);
+ }
+ return shortNames;
+ }
+
+ public static String getTotalList(String[] names){
+ String list = "";
+ for(int i = 0; i < names.length; i++){
+ if(i != 0)
+ list += ", ";
+ list += names[i];
+ }
+ return list;
+ }
+
public static IAnnotation getAnnotation(IJavaElement element, String qualifiedName){
if(element instanceof IAnnotatable){
String name = getShortName(qualifiedName);