[jbosstools-commits] JBoss Tools SVN: r43017 - in trunk: common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation and 2 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Mon Aug 13 21:06:06 EDT 2012


Author: akazakov
Date: 2012-08-13 21:06:06 -0400 (Mon, 13 Aug 2012)
New Revision: 43017

Modified:
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
   trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/TempMarkerManager.java
   trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/java/JavaDirtyRegionProcessor.java
   trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ELValidator.java
Log:
https://issues.jboss.org/browse/JBIDE-10611 As-you-type CDI validation

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	2012-08-13 23:45:06 UTC (rev 43016)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java	2012-08-14 01:06:06 UTC (rev 43017)
@@ -498,6 +498,7 @@
 		setAsYouTypeValidation(true);
 		this.document = validationContext.getDocument();
 		rootCdiProject = new CDIProjectAsYouType(rootCdiProject, file);
+		validateResource(file);
 		disableProblemAnnotations(new ITextSourceReference() {
 			@Override
 			public int getStartPosition() {
@@ -513,8 +514,7 @@
 			public int getLength() {
 				return document.getLength();
 			}
-		});
-		validateResource(file);
+		}, reporter);
 	}
 
 	/**

Modified: trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/TempMarkerManager.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/TempMarkerManager.java	2012-08-13 23:45:06 UTC (rev 43016)
+++ trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/TempMarkerManager.java	2012-08-14 01:06:06 UTC (rev 43017)
@@ -14,6 +14,7 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -53,6 +54,8 @@
 	protected boolean asYouTypeValidation;
 	protected int messageCounter;
 
+	private static final IMessage[] EMPTY_MESSAGE_ARRAY = new IMessage[0];
+
 	protected abstract String getMessageBundleName();
 
 	/*
@@ -218,7 +221,42 @@
 		return message;
 	}
 
-	protected void disableProblemAnnotations(final ITextSourceReference reference) {
+	private static class SimpleReference implements ITextSourceReference {
+		int start;
+		int length;
+		IResource resource;
+
+		public SimpleReference(int start, int length, IResource resource) {
+			this.start = start;
+			this.length = length;
+			this.resource = resource;
+		}
+
+		@Override
+		public int getStartPosition() {
+			return start;
+		}
+
+		@Override
+		public int getLength() {
+			return length;
+		}
+
+		@Override
+		public IResource getResource() {
+			return resource;
+		}
+	};
+
+	protected void disableProblemAnnotations(ITextSourceReference region, IReporter reporter) {
+		List messages = reporter.getMessages();
+		IMessage[] msgs = EMPTY_MESSAGE_ARRAY;
+		if(messages!=null) {
+			msgs = (IMessage[])messages.toArray(new IMessage[messages.size()]);
+		}
+		final ITextSourceReference reference = new SimpleReference(region.getStartPosition(), region.getLength(), region.getResource());
+
+		final IMessage[] messageArray = msgs;
         UIJob job = new UIJob("As-you-type JBT validation. Disabling the marker annotations.") {
 			public IStatus runInUIThread(IProgressMonitor monitor) {
 				if(EclipseUIUtil.isActiveEditorDirty()) {
@@ -241,11 +279,23 @@
 										try {
 											String type = marker.getType();
 											if(getMarkerType().equals(type)) {
-												Annotation newAnnotation = new DisabledAnnotation(annotation.getType(), false, annotation.getText(), marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING) == IMarker.SEVERITY_WARNING);
 												int offset = marker.getAttribute(IMarker.CHAR_START, 0);
-												int length = 0; // marker.getAttribute(IMarker.CHAR_END, 0) - offset;
-												Position p = new Position(offset, length);
-												newAnnotations.put(newAnnotation, p);
+												int originalMarkerEnd = marker.getAttribute(IMarker.CHAR_END, -1);
+												String markerMessage = marker.getAttribute(IMarker.MESSAGE, "");
+												boolean removedProblem = true;
+												for (Object object : messageArray) {
+													IMessage message = (IMessage)object;
+													if(message.getOffset() == offset && message.getLength() == originalMarkerEnd - offset && markerMessage.equals(message.getText())) {
+														removedProblem = false;
+														break;
+													}
+												}
+												if(removedProblem) {
+													Annotation newAnnotation = new DisabledAnnotation(annotation.getType(), false, annotation.getText(), marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING) == IMarker.SEVERITY_WARNING);
+													int length = 0; // marker.getAttribute(IMarker.CHAR_END, 0) - offset;
+													Position p = new Position(offset, length);
+													newAnnotations.put(newAnnotation, p);
+												}
 												annotationsToRemove.add(annotation);
 											} else if("org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor".equals(e.getClass().getName()) && "org.eclipse.jst.jsf.facelet.ui.FaceletValidationMarker".equals(type)) {
 												// Remove WTP's annotations for JBT JSP/XHTML editors.

Modified: trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/java/JavaDirtyRegionProcessor.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/java/JavaDirtyRegionProcessor.java	2012-08-13 23:45:06 UTC (rev 43016)
+++ trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/java/JavaDirtyRegionProcessor.java	2012-08-14 01:06:06 UTC (rev 43017)
@@ -42,7 +42,6 @@
 import org.eclipse.ui.IFileEditorInput;
 import org.eclipse.ui.texteditor.IDocumentProvider;
 import org.eclipse.ui.texteditor.ITextEditor;
-import org.jboss.tools.common.validation.java.xpl.DirtyRegionProcessor;
 import org.eclipse.wst.validation.internal.provisional.core.IMessage;
 import org.eclipse.wst.validation.internal.provisional.core.IReporter;
 import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;
@@ -53,6 +52,7 @@
 import org.jboss.tools.common.validation.CommonValidationPlugin;
 import org.jboss.tools.common.validation.TempMarkerManager;
 import org.jboss.tools.common.validation.ValidationMessage;
+import org.jboss.tools.common.validation.java.xpl.DirtyRegionProcessor;
 
 /**
  * As-You-Type validation Java files
@@ -67,7 +67,7 @@
 	private ITextEditor fEditor;
 	private IDocument fDocument;
 	private IValidationContext fHelper;
-	private JavaELProblemReporter fReporter;
+	private JavaProblemReporter fReporter;
 	private AsYouTypeValidatorManager fValidatorManager;
 
 	private boolean fDocumentJustSetup = false;
@@ -80,7 +80,8 @@
 	private int fStartRegionToProcess = -1;
 	private int fEndRegionToProcess = -1;
 
-	public final class JavaELProblemReporter implements IReporter {
+	public final class JavaProblemReporter implements IReporter {
+		private List<IMessage> messages = new ArrayList<IMessage>();
 		private IFile fFile;
 		private ICompilationUnit fCompilationUnit;
 		private IAnnotationModel fAnnotationModel;
@@ -113,7 +114,7 @@
 		@SuppressWarnings("rawtypes")
 		@Override
 		public List getMessages() {
-			return null;
+			return messages;
 		}
 
 		@Override
@@ -227,6 +228,7 @@
 
 		@Override
 		public void addMessage(IValidator origin, IMessage message) {
+			messages.add(message);
 			if (isCancelled()) {
 				return;
 			}
@@ -280,8 +282,8 @@
 		};
 	}
 
-	private JavaELProblemReporter createProblemReporter() {
-		JavaELProblemReporter reporter = new JavaELProblemReporter();
+	private JavaProblemReporter createProblemReporter() {
+		JavaProblemReporter reporter = new JavaProblemReporter();
 		reporter.update();
 		return reporter; 
 	}

Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ELValidator.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ELValidator.java	2012-08-13 23:45:06 UTC (rev 43016)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ELValidator.java	2012-08-14 01:06:06 UTC (rev 43017)
@@ -296,8 +296,6 @@
 			displaySubtask(ELValidationMessages.VALIDATING_EL_FILE, new String[]{el.getResource().getProject().getName(), el.getResource().getName()});
 			if(!asYouType) {
 				el.deleteMarkers();
-			} else {
-				disableProblemAnnotations(el);
 			}
 
 			if(context!=null && !el.getSyntaxErrors().isEmpty() && !isDollarExpressionInXML(el)) {
@@ -322,6 +320,9 @@
 			for (ELExpression expresion : el.getEl()) {
 				validateELExpression(el, expresion, asYouType, context);
 			}
+			if(asYouType) {
+				disableProblemAnnotations(el, reporter);
+			}
 		}
 	}
 



More information about the jbosstools-commits mailing list