[jbosstools-commits] JBoss Tools SVN: r43493 - in trunk: common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test and 1 other directory.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Thu Sep 6 21:01:46 EDT 2012
Author: dazarov
Date: 2012-09-06 21:01:45 -0400 (Thu, 06 Sep 2012)
New Revision: 43493
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIQuickFixTest.java
trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/QuickFixTestUtil.java
Log:
Make CDI Quick Fixes work for As-You-Type validator annotations https://issues.jboss.org/browse/JBIDE-12328
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-07 00:37:29 UTC (rev 43492)
+++ trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIQuickFixTest.java 2012-09-07 01:01:45 UTC (rev 43493)
@@ -1,10 +1,6 @@
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;
@@ -40,6 +36,7 @@
util.checkProposal(tckProject,
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/MakeFieldStatic.java",
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/MakeFieldStatic.qfxresult",
+ "@Produces",
CDIValidationErrorManager.ILLEGAL_PRODUCER_FIELD_IN_SESSION_BEAN_ID,
MakeFieldStaticMarkerResolution.class, true);
}
@@ -48,6 +45,7 @@
util.checkProposal(tckProject,
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/AddLocalBean.java",
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/AddLocalBean.qfxresult",
+ "@Produces",
CDIValidationErrorManager.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN_ID,
AddLocalBeanMarkerResolution.class, true);
}
@@ -56,6 +54,7 @@
util.checkProposal(tckProject,
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/MakeMethodPublic.java",
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/MakeMethodPublic.qfxresult",
+ "@Produces",
CDIValidationErrorManager.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN_ID,
MakeMethodPublicMarkerResolution.class, true);
}
@@ -65,6 +64,7 @@
util.checkProposal(tckProject,
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/AddSerializable.java",
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/AddSerializable.qfxresult",
+ "AddSerializable",
CDIValidationErrorManager.NOT_PASSIVATION_CAPABLE_BEAN_ID,
AddSerializableInterfaceMarkerResolution.class, true);
}
@@ -73,6 +73,7 @@
util.checkProposal(tckProject,
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/AddRetention.java",
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/AddRetention.qfxresult",
+ "AddRetention",
CDIValidationErrorManager.MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE_ID,
AddRetentionAnnotationMarkerResolution.class, true);
}
@@ -81,6 +82,7 @@
util.checkProposal(tckProject,
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/ChangeAnnotation.java",
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/ChangeAnnotation.qfxresult",
+ "@Retention(value = null)",
CDIValidationErrorManager.MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE_ID,
ChangeAnnotationMarkerResolution.class, true);
}
@@ -89,6 +91,7 @@
util.checkProposal(tckProject,
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/AddTarget.java",
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/AddTarget.qfxresult",
+ "AddTarget",
CDIValidationErrorManager.MISSING_TARGET_ANNOTATION_IN_SCOPE_TYPE_ID,
AddTargetAnnotationMarkerResolution.class, true);
}
@@ -97,6 +100,7 @@
util.checkProposal(tckProject,
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/AddAnnotation.java",
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/AddAnnotation.qfxresult",
+ "abc",
CDIValidationErrorManager.MISSING_NONBINDING_FOR_ANNOTATION_VALUE_IN_QUALIFIER_TYPE_MEMBER_ID,
AddAnnotationMarkerResolution.class, true);
}
@@ -105,6 +109,7 @@
util.checkProposal(tckProject,
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/DeleteAnnotation.java",
"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/DeleteAnnotation.qfxresult",
+ "@Inject",
CDIValidationErrorManager.CONSTRUCTOR_PARAMETER_ANNOTATED_DISPOSES_ID,
DeleteAnnotationMarkerResolution.class, true);
}
@@ -113,6 +118,7 @@
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);
}
@@ -121,6 +127,7 @@
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);
}
@@ -129,6 +136,7 @@
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);
}
@@ -137,6 +145,7 @@
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/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-07 00:37:29 UTC (rev 43492)
+++ trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/QuickFixTestUtil.java 2012-09-07 01:01:45 UTC (rev 43493)
@@ -1,7 +1,6 @@
package org.jboss.tools.common.base.test;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import junit.framework.Assert;
@@ -10,18 +9,18 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
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;
@@ -30,9 +29,10 @@
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.ReconcileAnnotationKey;
import org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation;
-import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.editor.ObjectMultiPageEditor;
import org.jboss.tools.common.model.ui.editor.EditorPartWrapper;
import org.jboss.tools.common.quickfix.QuickFixManager;
@@ -41,9 +41,10 @@
import org.jboss.tools.common.ui.marker.AddSuppressWarningsMarkerResolution;
import org.jboss.tools.common.ui.marker.ConfigureProblemSeverityMarkerResolution;
import org.jboss.tools.common.util.FileUtil;
+import org.jboss.tools.common.validation.TempMarkerManager;
+import org.jboss.tools.common.validation.ValidationMessage;
import org.jboss.tools.common.validation.java.TempJavaProblem;
import org.jboss.tools.common.validation.java.TempJavaProblemAnnotation;
-import org.jboss.tools.test.util.JobUtils;
public class QuickFixTestUtil{
private static final int MAX_SECONDS_TO_WAIT = 3;
@@ -100,7 +101,7 @@
}
}
- public void checkProposal(IProject project, String fileName, String newFile, int id, Class<? extends IJavaCompletionProposal> proposalClass, boolean checkResult) throws CoreException {
+ public void checkProposal(IProject project, String fileName, String newFile, String str, int id, Class<? extends IJavaCompletionProposal> proposalClass, boolean checkResult) throws CoreException {
IFile file = project.getFile(fileName);
IFile nFile = project.getFile(newFile);
@@ -122,59 +123,42 @@
document.set(text);
- // Find annotation
- IAnnotationModel annotationModel = viewer.getAnnotationModel();
- Annotation[] annotations = waitForProblemAnnotationAppearance(annotationModel, id);
- //System.out.println("ANNOTATIONS Before...");
- //for(TempJavaProblemAnnotation a : annotations){
- // System.out.println(a.getText());
- //}
+ int offset = text.indexOf(str);
- Assert.assertTrue("No annotations found", annotations.length > 0);
+ Assert.assertTrue("String - "+str+" not found", offset > 0);
- 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());
- //}
+ int length = str.length();
+ Annotation annotation = createAnnotation(file, id, offset, length);
+
+ Position position = new Position(offset, length);
+ 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));
-
- Assert.assertTrue("Quick fix did not decrease number of problems. was: "+annotations.length+" now: "+newAnnotations.length, newAnnotations.length <= annotations.length);
-
- checkResults(file, document.get());
+ 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);
}
- return;
+
}
+ return;
}
}
@@ -204,52 +188,39 @@
Assert.assertEquals("Wrong result of resolution", fileContent, text);
}
- protected Annotation[] waitForProblemAnnotationAppearance(final IAnnotationModel annotationModel, final int problemId) {
- final ArrayList<Annotation> annotations = new ArrayList<Annotation>();
-
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- int secondsLeft = MAX_SECONDS_TO_WAIT;
- boolean isFirstPass = true;
- boolean found = false;
- while (secondsLeft-- > 0 && !found) {
- if (!isFirstPass) {
- JobUtils.delay(1000);
-
- // clean differed events
- while (Display.getCurrent().readAndDispatch())
- ;
- } else {
- secondsLeft++; // because the wait step was skipped
- }
-
- //boolean found = false;
-
- Iterator it = annotationModel.getAnnotationIterator();
- while (it.hasNext()) {
- Object o = it.next();
-
- if (o instanceof TempJavaProblemAnnotation){
- int id = ((TempJavaProblemAnnotation) o).getId() - TempJavaProblem.TEMP_PROBLEM_ID;
- if(id == problemId){
- 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;
- }
- }
-
- }
- isFirstPass = false;
+ protected Annotation createAnnotation(IFile file, int quickFixId, int offset, int length){
+ if("java".equals(file.getFileExtension())){
+ ICompilationUnit compilationUnit = EclipseUtil.getCompilationUnit(file);
+
+ synchronized(compilationUnit) {
+ try {
+ compilationUnit.reconcile(ICompilationUnit.NO_AST, true, null, null);
+ } catch (JavaModelException e) {
+ Assert.fail(e.getMessage());
}
}
- });
-
- return annotations.toArray(new Annotation[]{});
+ Assert.assertNotNull("Compilation unit not found for file - "+file.getName());
+
+ ValidationMessage message = new ValidationMessage(IMessage.NORMAL_SEVERITY, "Message", compilationUnit.getResource());
+ message.setOffset(offset);
+ message.setLength(length);
+ message.setLineNo(1);
+ message.setBundleName("org.jboss.tools.cdi.internal.core.validation.messages");
+ message.setAttribute(TempMarkerManager.AS_YOU_TYPE_VALIDATION_ANNOTATION_ATTRIBUTE, Boolean.TRUE);
+ message.setAttribute(TempMarkerManager.MESSAGE_ID_ATTRIBUTE_NAME, quickFixId);
+ message.setAttribute(TempMarkerManager.PREFERENCE_KEY_ATTRIBUTE_NAME, "preferenceKey");
+ message.setAttribute(TempMarkerManager.PREFERENCE_PAGE_ID_NAME, "pref_page_id");
+ message.setAttribute(TempMarkerManager.MESSAGE_TYPE_ATTRIBUTE_NAME, JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE);
+
+ TempJavaProblem problem = new TempJavaProblem(message, "origin");
+
+ TempJavaProblemAnnotation annotation = new TempJavaProblemAnnotation(problem, compilationUnit);
+
+ return annotation;
+ }else{
+ TemporaryAnnotation annotation = new TemporaryAnnotation(new Position(offset, length), "type", "message", null, quickFixId);
+
+ return annotation;
+ }
}
}
More information about the jbosstools-commits
mailing list