[jbosstools-commits] JBoss Tools SVN: r43506 - trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/java.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Fri Sep 7 10:51:49 EDT 2012
Author: vrubezhny
Date: 2012-09-07 10:51:49 -0400 (Fri, 07 Sep 2012)
New Revision: 43506
Modified:
trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/java/JavaDirtyRegionProcessor.java
Log:
JBIDE-12418
Sometimes As-You-Type validation isn't invoked after a Java-String that contains EL is Copy-Pasted in Java editor
Issue is fixed
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-09-07 12:57:01 UTC (rev 43505)
+++ trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/java/JavaDirtyRegionProcessor.java 2012-09-07 14:51:49 UTC (rev 43506)
@@ -12,6 +12,8 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -52,6 +54,7 @@
import org.jboss.tools.common.log.LogHelper;
import org.jboss.tools.common.validation.AsYouTypeValidatorManager;
import org.jboss.tools.common.validation.CommonValidationPlugin;
+import org.jboss.tools.common.validation.ITypedReporter;
import org.jboss.tools.common.validation.TempMarkerManager;
import org.jboss.tools.common.validation.ValidationMessage;
import org.jboss.tools.common.validation.java.xpl.DirtyRegionProcessor;
@@ -82,7 +85,7 @@
private int fStartRegionToProcess = -1;
private int fEndRegionToProcess = -1;
- public final class JavaProblemReporter implements IReporter {
+ public final class JavaProblemReporter implements IReporter, ITypedReporter {
private List<IMessage> messages = new ArrayList<IMessage>();
private IFile fFile;
private ICompilationUnit fCompilationUnit;
@@ -179,6 +182,8 @@
return;
String editorInputName = editorInput.getName();
+ Collection<String> regionTypes = getTypesForRegion();
+ Collection<String> fileTypes = getTypesForFile();
Annotation[] annotations = fAnnotations.toArray(new Annotation[0]);
List<Annotation> annotationsToRemove = new ArrayList<Annotation>();
@@ -190,6 +195,11 @@
TempJavaProblemAnnotation jpAnnotation = (TempJavaProblemAnnotation)annotation;
Position position = getAnnotationModel().getPosition(jpAnnotation);
+ Map attributes = jpAnnotation.getAttributes();
+ Object typeOfAnnotation = attributes == null ? null : attributes.get(TempMarkerManager.MESSAGE_TYPE_ATTRIBUTE_NAME);
+ boolean isRegionWideAnnotationType = regionTypes.contains(typeOfAnnotation);
+ boolean isFileWideAnnotationType = fileTypes.contains(typeOfAnnotation);
+ IRegion regionOfAnnotation = position == null ? null : findRegion(position.getOffset());
// Find a validation message for the annotation
boolean existing = false;
@@ -221,8 +231,10 @@
}
// This is an annotation to remove (no message found for the annotation)
- if (!existing)
- annotationsToRemove.add(annotation);
+ if (!existing) {
+ if (isFileWideAnnotationType || (isRegionWideAnnotationType && regionOfAnnotation != null))
+ annotationsToRemove.add(annotation);
+ }
}
Map<Annotation, Position> annotationsToAdd = new HashMap<Annotation, Position>();
@@ -250,7 +262,55 @@
fAnnotationModel.addAnnotation(a, p);
}
removeAllMessages();
+ clearRegions();
}
+
+ private List<String> fTypesForFileValidation = new ArrayList<String>();
+ private List<String> fTypesForRegionValidatoin = new ArrayList<String>();
+
+ @Override
+ public void addTypeForFile(String type) {
+ if (!fTypesForFileValidation.contains(type)) {
+ fTypesForFileValidation.add(type);
+ }
+ }
+
+ @Override
+ public Collection<String> getTypesForFile() {
+ return Collections.unmodifiableList(fTypesForFileValidation);
+ }
+
+ @Override
+ public void addTypeForRegion(String type) {
+ if (!fTypesForRegionValidatoin.contains(type)) {
+ fTypesForRegionValidatoin.add(type);
+ }
+ }
+
+ @Override
+ public Collection<String> getTypesForRegion() {
+ return Collections.unmodifiableList(fTypesForRegionValidatoin);
+ }
+
+ private List<IRegion> fRegions;
+ public void setRegions(List<IRegion> regions) {
+ this.fRegions = regions;
+ }
+
+ public void clearRegions() {
+ this.fRegions = null;
+ }
+
+ private IRegion findRegion(int position) {
+ if (fRegions != null) {
+ for (IRegion region : fRegions) {
+ if (region.getOffset() <= position && region.getOffset() + region.getLength() > position)
+ return region;
+ }
+ }
+
+ return null;
+ }
}
class DocumentRewriteSessionListener implements IDocumentRewriteSessionListener {
@@ -428,9 +488,12 @@
if (fValidatorManager == null || fReporter == null || fStartPartitionsToProcess == -1 || fEndPartitionsToProcess == -1)
return;
+ fReporter.clearRegions();
if (fPartitionsToProcess != null && !fPartitionsToProcess.isEmpty()) {
+ List<IRegion> regions = Arrays.asList(fPartitionsToProcess.toArray(new IRegion[fPartitionsToProcess.size()]));
+ fReporter.setRegions(regions);
fValidatorManager.validateString(
- Arrays.asList(fPartitionsToProcess.toArray(new IRegion[fPartitionsToProcess.size()])),
+ regions,
fHelper, fReporter);
fReporter.finishReporting();
} else if (isJavaElementValidationRequired()) {
More information about the jbosstools-commits
mailing list