Author: dazarov
Date: 2011-07-26 18:40:11 -0400 (Tue, 26 Jul 2011)
New Revision: 33218
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/ChangeAnnotationMarkerResolution.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/TestStereotype5.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/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIMarkerResolutionTest.java
Log:
https://issues.jboss.org/browse/JBIDE-7634
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-26
22:22:39 UTC (rev 33217)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2011-07-26
22:40:11 UTC (rev 33218)
@@ -2271,7 +2271,7 @@
Object name = nameDeclaration.getMemberValue(null);
if (name != null && name.toString().length() > 0) {
ITextSourceReference location = nameDeclaration;
- addError(CDIValidationMessages.STEREOTYPE_DECLARES_NON_EMPTY_NAME,
CDIPreferences.STEREOTYPE_DECLARES_NON_EMPTY_NAME, location, resource);
+ addError(CDIValidationMessages.STEREOTYPE_DECLARES_NON_EMPTY_NAME,
CDIPreferences.STEREOTYPE_DECLARES_NON_EMPTY_NAME, location, resource,
STEREOTYPE_DECLARES_NON_EMPTY_NAME_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-07-26
22:22:39 UTC (rev 33217)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationErrorManager.java 2011-07-26
22:40:11 UTC (rev 33218)
@@ -48,6 +48,7 @@
public static final int PRODUCER_IN_DECORATOR_ID = 27;
public static final int DISPOSER_IN_INTERCEPTOR_ID = 28;
public static final int DISPOSER_IN_DECORATOR_ID = 29;
+ public static final int STEREOTYPE_DECLARES_NON_EMPTY_NAME_ID = 30;
/*
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-26
22:22:39 UTC (rev 33217)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java 2011-07-26
22:40:11 UTC (rev 33218)
@@ -109,6 +109,7 @@
public static String CHANGE_TARGET_MARKER_RESOLUTION_TITLE;
public static String ADD_ANNOTATION_MARKER_RESOLUTION_TITLE;
public static String DELETE_ANNOTATION_MARKER_RESOLUTION_TITLE;
+ public static String CHANGE_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-26
22:22:39 UTC (rev 33217)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2011-07-26
22:40:11 UTC (rev 33218)
@@ -93,6 +93,7 @@
CHANGE_TARGET_MARKER_RESOLUTION_TITLE=Change ''{0}'' annotation to
@Target({1})
ADD_ANNOTATION_MARKER_RESOLUTION_TITLE=Add @{0} annotation to ''{1}''
{2}
DELETE_ANNOTATION_MARKER_RESOLUTION_TITLE=Delete @{0} annotation from
''{1}'' {2}
+CHANGE_ANNOTATION_MARKER_RESOLUTION_TITLE=Change ''{0}'' annotation to
{1}
QUESTION=Question
DECREASING_FIELD_VISIBILITY_MAY_CAUSE_COMPILATION_PROBLEMS=Decreasing field visibility
may cause compilation problems. Do you want to continue?
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-26
22:22:39 UTC (rev 33217)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java 2011-07-26
22:40:11 UTC (rev 33218)
@@ -368,6 +368,14 @@
};
}
}
+ }else if(messageId ==
CDIValidationErrorManager.STEREOTYPE_DECLARES_NON_EMPTY_NAME_ID){
+ TypeAndAnnotation ta = findTypeAndAnnotation(file, start,
CDIConstants.NAMED_QUALIFIER_TYPE_NAME);
+ if(ta != null && ta.annotation != null && ta.type != null){
+ return new IMarkerResolution[] {
+ new ChangeAnnotationMarkerResolution(ta.annotation),
+ new DeleteAnnotationMarkerResolution(ta.type,
CDIConstants.NAMED_QUALIFIER_TYPE_NAME)
+ };
+ }
}
}
return new IMarkerResolution[] {};
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/ChangeAnnotationMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/ChangeAnnotationMarkerResolution.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/ChangeAnnotationMarkerResolution.java 2011-07-26
22:40:11 UTC (rev 33218)
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * 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.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 ChangeAnnotationMarkerResolution implements
+ IMarkerResolution2 {
+ private IAnnotation annotation;
+
+ private String sourceString = "";
+ private String changeString = MarkerResolutionUtils.AT;
+ private boolean useBraces = true;
+
+ private String[] qualifiedNames = new String[0];
+
+ public ChangeAnnotationMarkerResolution(IAnnotation annotation){
+ this.annotation = annotation;
+
+ changeString += annotation.getElementName();
+
+ try {
+ sourceString = annotation.getSource();
+ } catch (JavaModelException e) {
+ CDIUIPlugin.getDefault().logError(e);
+ }
+ }
+
+ public ChangeAnnotationMarkerResolution(IAnnotation annotation, String parameter){
+ this(annotation);
+
+ qualifiedNames = new String[]{parameter};
+ String shortName = MarkerResolutionUtils.getShortName(parameter);
+
+ changeString += "("+shortName+")";
+ }
+
+ public ChangeAnnotationMarkerResolution(IAnnotation annotation, String[] typeNames){
+ this(annotation);
+
+ this.qualifiedNames = typeNames;
+ String[] shortNames = MarkerResolutionUtils.getShortNames(qualifiedNames);
+ String totalList = MarkerResolutionUtils.getTotalList(shortNames);
+ if(useBraces)
+ totalList =
MarkerResolutionUtils.OPEN_BRACE+totalList+MarkerResolutionUtils.CLOSE_BRACE;
+
+ changeString += "("+totalList+")";
+ }
+
+ public ChangeAnnotationMarkerResolution(IAnnotation annotation, String[] typeNames,
boolean useBraces){
+ this(annotation, typeNames);
+ this.useBraces = useBraces;
+ }
+
+ public String getLabel() {
+ return NLS.bind(CDIUIMessages.CHANGE_ANNOTATION_MARKER_RESOLUTION_TITLE, sourceString,
changeString);
+ }
+
+ public void run(IMarker marker) {
+ try{
+ ICompilationUnit original =
MarkerResolutionUtils.getJavaMember(annotation).getCompilationUnit();
+ ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+
+ MarkerResolutionUtils.addImport(CDIConstants.TARGET_ANNOTATION_TYPE_NAME,
compilationUnit);
+
+ for(String qualifiedName : qualifiedNames){
+ MarkerResolutionUtils.addImport(qualifiedName, compilationUnit, true);
+ }
+
+ IAnnotation workingCopyAnnotation =
MarkerResolutionUtils.findWorkingCopy(compilationUnit, annotation);
+
+ IBuffer buffer = compilationUnit.getBuffer();
+
+ buffer.replace(workingCopyAnnotation.getSourceRange().getOffset(),
workingCopyAnnotation.getSourceRange().getLength(), changeString);
+
+ compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
+ compilationUnit.discardWorkingCopy();
+ }catch(CoreException ex){
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ }
+
+ public String getDescription() {
+ return NLS.bind(CDIUIMessages.CHANGE_ANNOTATION_MARKER_RESOLUTION_TITLE, sourceString,
changeString);
+ }
+
+ public Image getImage() {
+ return null;
+ }
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/ChangeAnnotationMarkerResolution.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/TestStereotype5.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/TestStereotype5.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/TestStereotype5.java 2011-07-26
22:40:11 UTC (rev 33218)
@@ -0,0 +1,21 @@
+package org.jboss.jsr299.tck.tests.jbt.quickfixes;
+
+import java.lang.annotation.Target;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Stereotype;
+import javax.inject.Named;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.FIELD;
+
+@Retention(RUNTIME)
+@Stereotype
+@Target({TYPE, METHOD, FIELD})
+@ApplicationScoped
+@Named("a")
+public @interface TestStereotype5 {
+
+}
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/TestStereotype5.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
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-26
22:22:39 UTC (rev 33217)
+++
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIMarkerResolutionTest.java 2011-07-26
22:40:11 UTC (rev 33218)
@@ -32,6 +32,7 @@
import org.jboss.tools.cdi.ui.marker.AddRetentionAnnotationMarkerResolution;
import org.jboss.tools.cdi.ui.marker.AddSerializableInterfaceMarkerResolution;
import org.jboss.tools.cdi.ui.marker.AddTargetAnnotationMarkerResolution;
+import org.jboss.tools.cdi.ui.marker.ChangeAnnotationMarkerResolution;
import org.jboss.tools.cdi.ui.marker.ChangeRetentionAnnotationMarkerResolution;
import org.jboss.tools.cdi.ui.marker.ChangeTargetAnnotationMarkerResolution;
import org.jboss.tools.cdi.ui.marker.DeleteAllDisposerDuplicantMarkerResolution;
@@ -735,4 +736,26 @@
DeleteAnnotationMarkerResolution.class);
}
+ public void testNonEmptyNamedInStereotypeResolution() throws CoreException{
+ checkResolution(tckProject,
+ new String[]{
+ "JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/TestStereotype5.java"
+ },
+ CDICoreValidator.PROBLEM_TYPE,
+ CDIValidationErrorManager.MESSAGE_ID_ATTRIBUTE_NAME,
+ CDIValidationErrorManager.STEREOTYPE_DECLARES_NON_EMPTY_NAME_ID,
+ DeleteAnnotationMarkerResolution.class);
+ }
+
+ public void testNonEmptyNamedInStereotypeResolution2() throws CoreException{
+ checkResolution(tckProject,
+ new String[]{
+ "JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/TestStereotype5.java"
+ },
+ CDICoreValidator.PROBLEM_TYPE,
+ CDIValidationErrorManager.MESSAGE_ID_ATTRIBUTE_NAME,
+ CDIValidationErrorManager.STEREOTYPE_DECLARES_NON_EMPTY_NAME_ID,
+ ChangeAnnotationMarkerResolution.class);
+ }
+
}
\ No newline at end of file