[jbosstools-commits] JBoss Tools SVN: r43472 - in trunk: cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes and 8 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Thu Sep 6 13:54:33 EDT 2012
Author: dazarov
Date: 2012-09-06 13:54:33 -0400 (Thu, 06 Sep 2012)
New Revision: 43472
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonExistingAlternative.qfxresult
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonExistingDecorator.qfxresult
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonExistingInterceptor.qfxresult
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonExistingStereotype.qfxresult
Modified:
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/CDIQuickFixTest.java
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/marker/ConfigureProblemSeverityResolutionGenerator.java
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/quickfix/BaseJavaHover.java
trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/java/TempJavaProblemAnnotation.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/quickfix/IQuickFixGenerator.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/quickfix/MarkerAnnotationInfo.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/quickfix/QuickFixManager.java
trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/MarkerResolutionTestUtil.java
trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/QuickFixTestUtil.java
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/JSPProblemMarkerResolutionTest.java
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/action/JSPProblemMarkerResolutionGenerator.java
Log:
Make CDI Quick Fixes work for As-You-Type validator annotations https://issues.jboss.org/browse/JBIDE-12328
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 2012-09-06 16:20:55 UTC (rev 43471)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java 2012-09-06 17:54:33 UTC (rev 43472)
@@ -33,6 +33,7 @@
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IMarkerResolutionGenerator2;
@@ -1038,7 +1039,7 @@
}
@Override
- public boolean hasProposals(Annotation annotation) {
+ public boolean hasProposals(Annotation annotation, Position position) {
if(annotation instanceof TempJavaProblemAnnotation || annotation instanceof TemporaryAnnotation){
return true;
}
@@ -1046,14 +1047,14 @@
}
@Override
- public IJavaCompletionProposal[] getProposals(Annotation annotation) {
+ public IJavaCompletionProposal[] getProposals(Annotation annotation, Position position) {
if(annotation instanceof TempJavaProblemAnnotation){
TempJavaProblemAnnotation javaAnnotation = (TempJavaProblemAnnotation) annotation;
int messageId = javaAnnotation.getId() - TempJavaProblem.TEMP_PROBLEM_ID;
ICompilationUnit compilationUnit = javaAnnotation.getCompilationUnit();
if(compilationUnit != null){
- int start = javaAnnotation.getPosition();
+ int start = position.getOffset();
ICDIMarkerResolutionGeneratorExtension[] extensions = CDIQuickFixExtensionManager.getInstances();
Added: trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonExistingAlternative.qfxresult
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonExistingAlternative.qfxresult (rev 0)
+++ trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonExistingAlternative.qfxresult 2012-09-06 17:54:33 UTC (rev 43472)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd">
+ <alternatives>
+ <class>
+ org.jboss.jsr299.tck.tests.policy.broken.incorrect.name.NonExistingClass
+ </class>
+ </alternatives>
+</beans>
\ No newline at end of file
Added: trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonExistingDecorator.qfxresult
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonExistingDecorator.qfxresult (rev 0)
+++ trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonExistingDecorator.qfxresult 2012-09-06 17:54:33 UTC (rev 43472)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd">
+ <decorators>
+ <class>com.acme.NonExistingDecoratorClass</class>
+ </decorators>
+</beans>
\ No newline at end of file
Added: trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonExistingInterceptor.qfxresult
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonExistingInterceptor.qfxresult (rev 0)
+++ trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonExistingInterceptor.qfxresult 2012-09-06 17:54:33 UTC (rev 43472)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd">
+ <interceptors>
+ <class>com.acme.NonExistingInterceptorClass</class>
+ </interceptors>
+</beans>
\ No newline at end of file
Added: trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonExistingStereotype.qfxresult
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonExistingStereotype.qfxresult (rev 0)
+++ trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonExistingStereotype.qfxresult 2012-09-06 17:54:33 UTC (rev 43472)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd">
+ <alternatives>
+ <stereotype>
+ <!-- Some comment -->
+ org.jboss.jsr299.tck.tests.policy.broken.not.policy.stereotype.NotExistingStereotype
+ </stereotype>
+ </alternatives>
+</beans>
\ No newline at end of file
Modified: trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIQuickFixTest.java
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIQuickFixTest.java 2012-09-06 16:20:55 UTC (rev 43471)
+++ trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIQuickFixTest.java 2012-09-06 17:54:33 UTC (rev 43472)
@@ -1,6 +1,10 @@
package org.jboss.tools.cdi.ui.test.marker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.wst.validation.ValidationFramework;
import org.jboss.tools.cdi.core.test.tck.TCKTest;
import org.jboss.tools.cdi.internal.core.validation.CDIValidationErrorManager;
import org.jboss.tools.cdi.ui.marker.AddAnnotationMarkerResolution;
@@ -9,6 +13,7 @@
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.CreateCDIElementMarkerResolution;
import org.jboss.tools.cdi.ui.marker.DeleteAnnotationMarkerResolution;
import org.jboss.tools.cdi.ui.marker.MakeFieldStaticMarkerResolution;
import org.jboss.tools.cdi.ui.marker.MakeMethodPublicMarkerResolution;
@@ -17,77 +22,122 @@
public class CDIQuickFixTest extends TCKTest {
private QuickFixTestUtil util = new QuickFixTestUtil();
+// private static boolean isSuspendedValidationDefaultValue;
+// public void setUp() throws Exception {
+// super.setUp();
+// isSuspendedValidationDefaultValue = ValidationFramework.getDefault().isSuspended();
+// ValidationFramework.getDefault().suspendAllValidation(false);
+// tckProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+// tckProject.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
+// }
+//
+// public void tearDown() throws Exception {
+// ValidationFramework.getDefault().suspendAllValidation(isSuspendedValidationDefaultValue);
+// super.tearDown();
+// }
+
public void testMakeFieldStatic() throws CoreException {
- util.checkPrpposal(tckProject,
+ util.checkProposal(tckProject,
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/MakeFieldStatic.java",
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/MakeFieldStatic.qfxresult",
CDIValidationErrorManager.ILLEGAL_PRODUCER_FIELD_IN_SESSION_BEAN_ID,
- MakeFieldStaticMarkerResolution.class);
+ MakeFieldStaticMarkerResolution.class, true);
}
public void testAddLocalBeanResolution() throws CoreException {
- util.checkPrpposal(tckProject,
+ util.checkProposal(tckProject,
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/AddLocalBean.java",
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/AddLocalBean.qfxresult",
CDIValidationErrorManager.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN_ID,
- AddLocalBeanMarkerResolution.class);
+ AddLocalBeanMarkerResolution.class, true);
}
public void testMakeProducerMethodPublicResolution() throws CoreException {
- util.checkPrpposal(tckProject,
+ util.checkProposal(tckProject,
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/MakeMethodPublic.java",
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/MakeMethodPublic.qfxresult",
CDIValidationErrorManager.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN_ID,
- MakeMethodPublicMarkerResolution.class);
+ MakeMethodPublicMarkerResolution.class, true);
}
public void testAddSerializableInterfaceResolution() throws CoreException{
- util.checkPrpposal(tckProject,
+ util.checkProposal(tckProject,
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/AddSerializable.java",
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/AddSerializable.qfxresult",
CDIValidationErrorManager.NOT_PASSIVATION_CAPABLE_BEAN_ID,
- AddSerializableInterfaceMarkerResolution.class);
+ AddSerializableInterfaceMarkerResolution.class, true);
}
public void testAddRetentionToQualifierResolution() throws CoreException{
- util.checkPrpposal(tckProject,
+ util.checkProposal(tckProject,
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/AddRetention.java",
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/AddRetention.qfxresult",
CDIValidationErrorManager.MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE_ID,
- AddRetentionAnnotationMarkerResolution.class);
+ AddRetentionAnnotationMarkerResolution.class, true);
}
public void testChangeRetentionToQualifierResolution() throws CoreException{
- util.checkPrpposal(tckProject,
+ util.checkProposal(tckProject,
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/ChangeAnnotation.java",
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/ChangeAnnotation.qfxresult",
CDIValidationErrorManager.MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE_ID,
- ChangeAnnotationMarkerResolution.class);
+ ChangeAnnotationMarkerResolution.class, true);
}
public void testAddTargetToScopeResolution() throws CoreException{
- util.checkPrpposal(tckProject,
+ util.checkProposal(tckProject,
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/AddTarget.java",
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/AddTarget.qfxresult",
CDIValidationErrorManager.MISSING_TARGET_ANNOTATION_IN_SCOPE_TYPE_ID,
- AddTargetAnnotationMarkerResolution.class);
+ AddTargetAnnotationMarkerResolution.class, true);
}
public void testAddNonbindingToAnnotationMemberOfQualifierResolution() throws CoreException{
- util.checkPrpposal(tckProject,
+ util.checkProposal(tckProject,
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/AddAnnotation.java",
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/AddAnnotation.qfxresult",
CDIValidationErrorManager.MISSING_NONBINDING_FOR_ANNOTATION_VALUE_IN_QUALIFIER_TYPE_MEMBER_ID,
- AddAnnotationMarkerResolution.class);
+ AddAnnotationMarkerResolution.class, true);
}
public void testDeleteDisposesAnnotationFromParameterResolution() throws CoreException{
- util.checkPrpposal(tckProject,
+ util.checkProposal(tckProject,
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/DeleteAnnotation.java",
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/DeleteAnnotation.qfxresult",
CDIValidationErrorManager.CONSTRUCTOR_PARAMETER_ANNOTATED_DISPOSES_ID,
- DeleteAnnotationMarkerResolution.class);
+ DeleteAnnotationMarkerResolution.class, true);
}
+ public void _testCreateBeanClassResolution() throws CoreException{
+ util.checkProposal(tckProject,
+ "WebContent/WEB-INF/beans.xml",
+ "JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/NonExistingAlternative.qfxresult",
+ CDIValidationErrorManager.UNKNOWN_ALTERNATIVE_BEAN_CLASS_NAME_ID,
+ CreateCDIElementMarkerResolution.class, false);
+ }
+
+ public void _testCreateStereotypeResolution() throws CoreException{
+ util.checkProposal(tckProject,
+ "WebContent/WEB-INF/beans.xml",
+ "JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/NonExistingStereotype.qfxresult",
+ CDIValidationErrorManager.UNKNOWN_ALTERNATIVE_ANNOTATION_NAME_ID,
+ CreateCDIElementMarkerResolution.class, false);
+ }
+
+ public void _testCreateDecoratorResolution() throws CoreException{
+ util.checkProposal(tckProject,
+ "WebContent/WEB-INF/beans.xml",
+ "JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/NonExistingDecorator.qfxresult",
+ CDIValidationErrorManager.UNKNOWN_DECORATOR_BEAN_CLASS_NAME_ID,
+ CreateCDIElementMarkerResolution.class, false);
+ }
+
+ public void _testCreateInterceptorResolution() throws CoreException{
+ util.checkProposal(tckProject,
+ "WebContent/WEB-INF/beans.xml",
+ "JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/NonExistingInterceptor.qfxresult",
+ CDIValidationErrorManager.UNKNOWN_INTERCEPTOR_CLASS_NAME_ID,
+ CreateCDIElementMarkerResolution.class, false);
+ }
}
Modified: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/quickfix/IQuickFixGenerator.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/quickfix/IQuickFixGenerator.java 2012-09-06 16:20:55 UTC (rev 43471)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/quickfix/IQuickFixGenerator.java 2012-09-06 17:54:33 UTC (rev 43472)
@@ -11,6 +11,7 @@
package org.jboss.tools.common.quickfix;
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
+import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;
public interface IQuickFixGenerator {
@@ -22,7 +23,7 @@
* @return <code>true</code> if there are proposals for the given annotation,
* <code>false</code> if not
*/
- public boolean hasProposals(Annotation annotation);
+ public boolean hasProposals(Annotation annotation, Position position);
/**
* Returns array of proposals for the given annotation (may
@@ -31,5 +32,5 @@
* @param annotation the annotation
* @return list of proposals for the given annotation
*/
- public IJavaCompletionProposal[] getProposals(Annotation annotation);
+ public IJavaCompletionProposal[] getProposals(Annotation annotation, Position position);
}
Modified: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/quickfix/MarkerAnnotationInfo.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/quickfix/MarkerAnnotationInfo.java 2012-09-06 16:20:55 UTC (rev 43471)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/quickfix/MarkerAnnotationInfo.java 2012-09-06 17:54:33 UTC (rev 43472)
@@ -82,9 +82,9 @@
// get all relevant quick fixes for this annotation
- if(isDirty() && QuickFixManager.getInstance().hasProposals(annotation)){
+ if(isDirty() && QuickFixManager.getInstance().hasProposals(annotation, info.position)){
annotation.setAdditionalFixInfo(viewer.getDocument());
- List<IJavaCompletionProposal> proposals = QuickFixManager.getInstance().getProposals(annotation);
+ List<IJavaCompletionProposal> proposals = QuickFixManager.getInstance().getProposals(annotation, info.position);
allProposals.addAll(proposals);
}
Modified: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/quickfix/QuickFixManager.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/quickfix/QuickFixManager.java 2012-09-06 16:20:55 UTC (rev 43471)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/quickfix/QuickFixManager.java 2012-09-06 17:54:33 UTC (rev 43472)
@@ -15,6 +15,7 @@
import java.util.List;
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
+import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;
public class QuickFixManager {
@@ -49,19 +50,19 @@
generators.remove(generator);
}
- public boolean hasProposals(Annotation annotation){
+ public boolean hasProposals(Annotation annotation, Position position){
for(IQuickFixGenerator generator : generators.values()){
- if(generator.hasProposals(annotation)){
+ if(generator.hasProposals(annotation, position)){
return true;
}
}
return false;
}
- public List<IJavaCompletionProposal> getProposals(Annotation annotation){
+ public List<IJavaCompletionProposal> getProposals(Annotation annotation, Position position){
ArrayList<IJavaCompletionProposal> proposals = new ArrayList<IJavaCompletionProposal>();
for(IQuickFixGenerator generator : generators.values()){
- IJavaCompletionProposal[] pp = generator.getProposals(annotation);
+ IJavaCompletionProposal[] pp = generator.getProposals(annotation, position);
for(IJavaCompletionProposal p : pp){
proposals.add(p);
}
Modified: trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/marker/ConfigureProblemSeverityResolutionGenerator.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/marker/ConfigureProblemSeverityResolutionGenerator.java 2012-09-06 16:20:55 UTC (rev 43471)
+++ trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/marker/ConfigureProblemSeverityResolutionGenerator.java 2012-09-06 17:54:33 UTC (rev 43472)
@@ -22,6 +22,7 @@
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.ui.javaeditor.JavaMarkerAnnotation;
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
+import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IMarkerResolutionGenerator2;
@@ -157,12 +158,12 @@
}
@Override
- public boolean hasProposals(Annotation annotation) {
+ public boolean hasProposals(Annotation annotation, Position position) {
return getPreferenceKey(annotation) != null && getPreferencePageId(annotation) != null;
}
@Override
- public IJavaCompletionProposal[] getProposals(Annotation annotation) {
+ public IJavaCompletionProposal[] getProposals(Annotation annotation, Position position) {
ArrayList<IJavaCompletionProposal> proposals = new ArrayList<IJavaCompletionProposal>();
String preferenceKey = getPreferenceKey(annotation);
String preferencePageId = getPreferencePageId(annotation);
@@ -170,14 +171,14 @@
if(annotation instanceof TempJavaProblemAnnotation){
TempJavaProblemAnnotation tAnnotation = (TempJavaProblemAnnotation)annotation;
if(JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE.equals(tAnnotation.getType())){
- int position = getPosition(tAnnotation);
+ int offset = position.getOffset();
IFile file = getFile(tAnnotation);
if(file != null){
- IJavaElement element = findJavaElement(tAnnotation, position);
+ IJavaElement element = findJavaElement(tAnnotation, offset);
if(element != null){
if(element instanceof IMethod){
try{
- ILocalVariable parameter = findParameter((IMethod)element, position);
+ ILocalVariable parameter = findParameter((IMethod)element, offset);
if(parameter != null){
proposals.add(new AddSuppressWarningsMarkerResolution(file, parameter, preferenceKey, tAnnotation.getCompilationUnit()));
}
@@ -195,9 +196,6 @@
return proposals.toArray(new IJavaCompletionProposal[]{});
}
- private int getPosition(TempJavaProblemAnnotation annotation){
- return annotation.getPosition();
- }
private IFile getFile(TempJavaProblemAnnotation annotation){
if(annotation.getCompilationUnit() != null){
Modified: trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/quickfix/BaseJavaHover.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/quickfix/BaseJavaHover.java 2012-09-06 16:20:55 UTC (rev 43471)
+++ trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/quickfix/BaseJavaHover.java 2012-09-06 17:54:33 UTC (rev 43472)
@@ -51,8 +51,8 @@
if(propArray == null){
ArrayList<IJavaCompletionProposal> proposals= new ArrayList<IJavaCompletionProposal>();
- if(QuickFixManager.getInstance().hasProposals(annotation)){
- List<IJavaCompletionProposal> pp = QuickFixManager.getInstance().getProposals(annotation);
+ if(QuickFixManager.getInstance().hasProposals(annotation, position)){
+ List<IJavaCompletionProposal> pp = QuickFixManager.getInstance().getProposals(annotation, position);
proposals.addAll(pp);
}
propArray = proposals.toArray(new ICompletionProposal[proposals.size()]);
Modified: trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/java/TempJavaProblemAnnotation.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/java/TempJavaProblemAnnotation.java 2012-09-06 16:20:55 UTC (rev 43471)
+++ trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/java/TempJavaProblemAnnotation.java 2012-09-06 17:54:33 UTC (rev 43472)
@@ -30,8 +30,4 @@
public Map getAttributes() {
return problem.getAttributes();
}
-
- public int getPosition(){
- return problem.getSourceStart();
- }
}
\ No newline at end of file
Modified: trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/MarkerResolutionTestUtil.java
===================================================================
--- trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/MarkerResolutionTestUtil.java 2012-09-06 16:20:55 UTC (rev 43471)
+++ trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/MarkerResolutionTestUtil.java 2012-09-06 17:54:33 UTC (rev 43472)
@@ -134,7 +134,7 @@
}
}
- private static void copyFiles(IProject project, String[] fileNames) throws CoreException{
+ public static void copyFiles(IProject project, String[] fileNames) throws CoreException{
for(String fileName : fileNames){
IFile file = project.getFile(fileName);
IFile copyFile = project.getFile(fileName+".copy");
@@ -158,7 +158,7 @@
}
}
- private static void restoreFiles(IProject project, String[] fileNames) throws CoreException {
+ public static void restoreFiles(IProject project, String[] fileNames) throws CoreException {
for(String fileName : fileNames){
IFile file = project.getFile(fileName);
IFile copyFile = project.getFile(fileName+".copy");
Modified: trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/QuickFixTestUtil.java
===================================================================
--- trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/QuickFixTestUtil.java 2012-09-06 16:20:55 UTC (rev 43471)
+++ trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/QuickFixTestUtil.java 2012-09-06 17:54:33 UTC (rev 43472)
@@ -14,16 +14,27 @@
import org.eclipse.jdt.internal.ui.javaeditor.JavaMarkerAnnotation;
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.ltk.core.refactoring.CompositeChange;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorRegistry;
+import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation;
+import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart;
+import org.jboss.tools.common.editor.ObjectMultiPageEditor;
+import org.jboss.tools.common.model.ui.editor.EditorPartWrapper;
import org.jboss.tools.common.quickfix.QuickFixManager;
import org.jboss.tools.common.refactoring.TestableResolutionWithDialog;
import org.jboss.tools.common.refactoring.TestableResolutionWithRefactoringProcessor;
@@ -40,14 +51,32 @@
protected ISourceViewer getViewer(IEditorPart editor){
if(editor instanceof JavaEditor){
return ((JavaEditor)editor).getViewer();
+ }else if(editor instanceof EditorPartWrapper){
+ IEditorPart ed = ((EditorPartWrapper)editor).getEditor();
+
+ if(ed instanceof ObjectMultiPageEditor){
+ ((ObjectMultiPageEditor)ed).selectPageByName("Source");
+ return ((ObjectMultiPageEditor)ed).getSourceEditor().getTextViewer();
+ }else {
+ Assert.fail("Editor must be ObjectMultiPageEditor, was - "+ed.getClass());
+ }
}else{
- Assert.fail("editor must be instanceof JavaEditor");
+ Assert.fail("editor must be instanceof JavaEditor or EditorPartWrapper, but was "+editor.getClass());
}
return null;
}
- protected String getEditorID(){
- return "org.eclipse.jdt.ui.CompilationUnitEditor";
+ protected String getEditorId(String filename) {
+ if(filename.endsWith(".xml")){
+ return "org.jboss.tools.common.model.ui.editor.EditorPartWrapper";
+ }
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ IEditorRegistry editorRegistry = workbench.getEditorRegistry();
+ IEditorDescriptor descriptor = editorRegistry
+ .getDefaultEditor(filename);
+ if (descriptor != null)
+ return descriptor.getId();
+ return EditorsUI.DEFAULT_TEXT_EDITOR_ID;
}
private void checkForConfigureProblemSeverity(IJavaCompletionProposal[] proposals){
@@ -58,18 +87,20 @@
Assert.fail("Configure Problem Severity quick fix not found");
}
- private void checkForAddSuppressWarnings(IFile file, TempJavaProblemAnnotation annotation, IJavaCompletionProposal[] proposals){
- String severity = annotation.getMarkerType();
- if(file.getFileExtension().equals("java") && severity.equals(JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE)){
- for(IJavaCompletionProposal proposal : proposals){
- if(proposal.getClass().equals(AddSuppressWarningsMarkerResolution.class))
- return;
+ private void checkForAddSuppressWarnings(IFile file, Annotation annotation, IJavaCompletionProposal[] proposals){
+ if(annotation instanceof TempJavaProblemAnnotation){
+ String severity = ((TempJavaProblemAnnotation)annotation).getMarkerType();
+ if(file.getFileExtension().equals("java") && severity.equals(JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE)){
+ for(IJavaCompletionProposal proposal : proposals){
+ if(proposal.getClass().equals(AddSuppressWarningsMarkerResolution.class))
+ return;
+ }
+ Assert.fail("Add @SuppressWarnings marker resolution not found");
}
- Assert.fail("Add @SuppressWarnings marker resolution not found");
}
}
- public void checkPrpposal(IProject project, String fileName, String newFile, int id, Class<? extends IJavaCompletionProposal> proposalClass) throws CoreException {
+ public void checkProposal(IProject project, String fileName, String newFile, int id, Class<? extends IJavaCompletionProposal> proposalClass, boolean checkResult) throws CoreException {
IFile file = project.getFile(fileName);
IFile nFile = project.getFile(newFile);
@@ -78,9 +109,11 @@
IEditorInput input = new FileEditorInput(file);
- IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, getEditorID(), true);
+ IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, getEditorId(file.getName()), true);
ISourceViewer viewer = getViewer(editor);
+ MarkerResolutionTestUtil.copyFiles(project, new String[]{fileName});
+
try{
// change file
IDocument document = viewer.getDocument();
@@ -90,7 +123,8 @@
document.set(text);
// Find annotation
- TempJavaProblemAnnotation[] annotations = waitForProblemAnnotationAppearance(viewer, id);
+ IAnnotationModel annotationModel = viewer.getAnnotationModel();
+ Annotation[] annotations = waitForProblemAnnotationAppearance(annotationModel, id);
//System.out.println("ANNOTATIONS Before...");
//for(TempJavaProblemAnnotation a : annotations){
// System.out.println(a.getText());
@@ -98,46 +132,47 @@
Assert.assertTrue("No annotations found", annotations.length > 0);
- for(TempJavaProblemAnnotation annotation : annotations){
- IJavaCompletionProposal[] proposals = getCompletionProposals(annotation);
+ for(Annotation annotation : annotations){
+ Position position = annotationModel.getPosition(annotation);
+ IJavaCompletionProposal[] proposals = getCompletionProposals(annotation, position);
checkForConfigureProblemSeverity(proposals);
checkForAddSuppressWarnings(file, annotation, proposals);
for(IJavaCompletionProposal proposal : proposals){
if (proposal.getClass().equals(proposalClass)) {
+ if(checkResult){
+ if(proposal instanceof TestableResolutionWithRefactoringProcessor){
+ RefactoringProcessor processor = ((TestableResolutionWithRefactoringProcessor)proposal).getRefactoringProcessor();
+
+ RefactoringStatus status = processor.checkInitialConditions(new NullProgressMonitor());
+
+ Assert.assertNull("Rename processor returns fatal error", status.getEntryMatchingSeverity(RefactoringStatus.FATAL));
+
+ status = processor.checkFinalConditions(new NullProgressMonitor(), null);
+
+ Assert.assertNull("Rename processor returns fatal error", status.getEntryMatchingSeverity(RefactoringStatus.FATAL));
+
+ CompositeChange rootChange = (CompositeChange)processor.createChange(new NullProgressMonitor());
+
+ rootChange.perform(new NullProgressMonitor());
+ } else if(proposal instanceof TestableResolutionWithDialog){
+ ((TestableResolutionWithDialog) proposal).runForTest(null);
+ } else {
+ proposal.apply(document);
+ }
+
+ //TestUtil.validate(file);
+
+ Annotation[] newAnnotations = waitForProblemAnnotationAppearance(annotationModel, id);
+ //System.out.println("ANNOTATIONS After...");
+ //for(TempJavaProblemAnnotation a : newAnnotations){
+ // System.out.println(a.getText());
+ //}
- if(proposal instanceof TestableResolutionWithRefactoringProcessor){
- RefactoringProcessor processor = ((TestableResolutionWithRefactoringProcessor)proposal).getRefactoringProcessor();
-
- RefactoringStatus status = processor.checkInitialConditions(new NullProgressMonitor());
-
- Assert.assertNull("Rename processor returns fatal error", status.getEntryMatchingSeverity(RefactoringStatus.FATAL));
-
- status = processor.checkFinalConditions(new NullProgressMonitor(), null);
-
- Assert.assertNull("Rename processor returns fatal error", status.getEntryMatchingSeverity(RefactoringStatus.FATAL));
-
- CompositeChange rootChange = (CompositeChange)processor.createChange(new NullProgressMonitor());
-
- rootChange.perform(new NullProgressMonitor());
- } else if(proposal instanceof TestableResolutionWithDialog){
- ((TestableResolutionWithDialog) proposal).runForTest(null);
- } else {
- proposal.apply(document);
+
+ Assert.assertTrue("Quick fix did not decrease number of problems. was: "+annotations.length+" now: "+newAnnotations.length, newAnnotations.length <= annotations.length);
+
+ checkResults(file, document.get());
}
-
- //TestUtil.validate(file);
-
- TempJavaProblemAnnotation[] newAnnotations = waitForProblemAnnotationAppearance(viewer, id);
- //System.out.println("ANNOTATIONS After...");
- //for(TempJavaProblemAnnotation a : newAnnotations){
- // System.out.println(a.getText());
- //}
-
-
- Assert.assertTrue("Quick fix did not decrease number of problems. was: "+annotations.length+" now: "+newAnnotations.length, newAnnotations.length <= annotations.length);
-
- checkResults(file, document.get());
-
return;
}
}
@@ -148,14 +183,15 @@
if(editor.isDirty()){
editor.doSave(new NullProgressMonitor());
}
+ MarkerResolutionTestUtil.restoreFiles(project, new String[]{fileName});
}
}
- public static IJavaCompletionProposal[] getCompletionProposals(TempJavaProblemAnnotation annotation){
+ public static IJavaCompletionProposal[] getCompletionProposals(Annotation annotation, Position position){
ArrayList<IJavaCompletionProposal> proposals = new ArrayList<IJavaCompletionProposal>();
- if(QuickFixManager.getInstance().hasProposals(annotation)){
- List<IJavaCompletionProposal> list = QuickFixManager.getInstance().getProposals(annotation);
+ if(QuickFixManager.getInstance().hasProposals(annotation, position)){
+ List<IJavaCompletionProposal> list = QuickFixManager.getInstance().getProposals(annotation, position);
proposals.addAll(list);
}
@@ -168,8 +204,8 @@
Assert.assertEquals("Wrong result of resolution", fileContent, text);
}
- protected TempJavaProblemAnnotation[] waitForProblemAnnotationAppearance(final ISourceViewer viewer, final int problemId) {
- final ArrayList<TempJavaProblemAnnotation> annotations = new ArrayList<TempJavaProblemAnnotation>();
+ protected Annotation[] waitForProblemAnnotationAppearance(final IAnnotationModel annotationModel, final int problemId) {
+ final ArrayList<Annotation> annotations = new ArrayList<Annotation>();
Display.getDefault().syncExec(new Runnable() {
public void run() {
@@ -188,7 +224,7 @@
}
//boolean found = false;
- IAnnotationModel annotationModel = viewer.getAnnotationModel();
+
Iterator it = annotationModel.getAnnotationIterator();
while (it.hasNext()) {
Object o = it.next();
@@ -199,6 +235,13 @@
annotations.add((TempJavaProblemAnnotation) o);
found = true;
}
+ }else if(o instanceof TemporaryAnnotation){
+ Integer attribute = ((Integer) ((TemporaryAnnotation)o).getAttributes().get("Message_id"));
+ int id = attribute.intValue();
+ if(id == problemId){
+ annotations.add((TemporaryAnnotation) o);
+ found = true;
+ }
}
}
@@ -207,6 +250,6 @@
}
});
- return annotations.toArray(new TempJavaProblemAnnotation[]{});
+ return annotations.toArray(new Annotation[]{});
}
}
Modified: trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/JSPProblemMarkerResolutionTest.java
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/JSPProblemMarkerResolutionTest.java 2012-09-06 16:20:55 UTC (rev 43471)
+++ trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/JSPProblemMarkerResolutionTest.java 2012-09-06 17:54:33 UTC (rev 43472)
@@ -15,6 +15,7 @@
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jst.jsp.ui.internal.validation.JSPContentSourceValidator;
@@ -243,13 +244,15 @@
document.replace(region.getOffset(), region.getLength(), "");
// Find annotation
- TemporaryAnnotation problemAnnotation = waitForProblemAnnotationAppearance(viewer, "Unknown tag (", MAX_SECONDS_TO_WAIT);
+ IAnnotationModel annotationModel = viewer.getAnnotationModel();
+ TemporaryAnnotation problemAnnotation = waitForProblemAnnotationAppearance(annotationModel, "Unknown tag (", MAX_SECONDS_TO_WAIT);
+ Position position = annotationModel.getPosition(problemAnnotation);
assertNotNull("No Unknown tag TemporaryAnnotation found", problemAnnotation);
problemAnnotation.setAdditionalFixInfo(document);
// get all relevant quick fixes for this annotation
- if(QuickFixManager.getInstance().hasProposals(problemAnnotation)){
- List<IJavaCompletionProposal> proposals = QuickFixManager.getInstance().getProposals(problemAnnotation);
+ if(QuickFixManager.getInstance().hasProposals(problemAnnotation, position)){
+ List<IJavaCompletionProposal> proposals = QuickFixManager.getInstance().getProposals(problemAnnotation, position);
assertTrue("No quick fixes found", proposals.size() > 0);
assertEquals("Add tag library definition quick fix not found", AddTLDMarkerResolution.class, proposals.get(0).getClass());
}else{
@@ -261,7 +264,7 @@
}
private TemporaryAnnotation waitForProblemAnnotationAppearance(
- final SourceViewer viewer, final String name, final int seconds) {
+ final IAnnotationModel annotationModel, final String name, final int seconds) {
final TemporaryAnnotation[] result = new TemporaryAnnotation[]{null};
Display.getDefault().syncExec(new Runnable() {
@@ -280,7 +283,7 @@
}
//boolean found = false;
- IAnnotationModel annotationModel = viewer.getAnnotationModel();
+ //IAnnotationModel annotationModel = viewer.getAnnotationModel();
Iterator it = annotationModel.getAnnotationIterator();
while (it.hasNext()) {
Object o = it.next();
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/action/JSPProblemMarkerResolutionGenerator.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/action/JSPProblemMarkerResolutionGenerator.java 2012-09-06 16:20:55 UTC (rev 43471)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/action/JSPProblemMarkerResolutionGenerator.java 2012-09-06 17:54:33 UTC (rev 43472)
@@ -20,6 +20,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IMarkerResolutionGenerator2;
@@ -98,7 +99,7 @@
return true;
}
- private IJavaCompletionProposal[] isOurCase(Annotation annotation){
+ private IJavaCompletionProposal[] isOurCase(Annotation annotation, Position position){
ArrayList<IJavaCompletionProposal> proposals = new ArrayList<IJavaCompletionProposal>();
if(!(annotation instanceof TemporaryAnnotation)){
return new IJavaCompletionProposal[]{};
@@ -109,9 +110,9 @@
if(ta.getPosition() == null)
return new IJavaCompletionProposal[]{};
- final int start = ta.getPosition().getOffset();
+ final int start = position.getOffset();
- final int end = ta.getPosition().getOffset()+ta.getPosition().getLength();
+ final int end = position.getOffset()+position.getLength();
if(!message.startsWith(UNKNOWN_TAG))
return new IJavaCompletionProposal[]{};
@@ -292,13 +293,13 @@
}
@Override
- public boolean hasProposals(Annotation annotation) {
+ public boolean hasProposals(Annotation annotation, Position position) {
String message = annotation.getText();
return message.startsWith(UNKNOWN_TAG);
}
@Override
- public IJavaCompletionProposal[] getProposals(Annotation annotation) {
- return isOurCase(annotation);
+ public IJavaCompletionProposal[] getProposals(Annotation annotation, Position position) {
+ return isOurCase(annotation, position);
}
}
\ No newline at end of file
More information about the jbosstools-commits
mailing list