use of org.eclipse.jface.text.reconciler.IReconcileResult in project webtools.sourceediting by eclipse.
the class ReconcileStepForValidator method createAnnotations.
protected IReconcileResult[] createAnnotations(AnnotationInfo[] infos) {
List annotations = new ArrayList();
for (int i = 0; i < infos.length; i++) {
AnnotationInfo info = infos[i];
IMessage validationMessage = info.getMessage();
int offset = validationMessage.getOffset();
if (offset < 0)
continue;
String messageText = null;
try {
messageText = validationMessage.getText(validationMessage.getClass().getClassLoader());
} catch (Exception t) {
// $NON-NLS-1$
Logger.logException("exception reporting message from validator", t);
continue;
}
String type = getSeverity(validationMessage);
// this position seems like it would be possibly be the wrong
// length
int length = validationMessage.getLength();
if (length >= 0) {
Position p = new Position(offset, length);
ReconcileAnnotationKey key = createKey(getPartitionType(getDocument(), offset), getScope());
// create an annotation w/ problem ID and fix info
TemporaryAnnotation annotation = new TemporaryAnnotation(p, type, messageText, key);
Object extraInfo = info.getAdditionalFixInfo();
// add quick fix information
if (extraInfo == null) {
extraInfo = validationMessage.getAttribute(QUICKASSISTPROCESSOR);
}
annotation.setAdditionalFixInfo(extraInfo);
annotation.setAttributes(validationMessage.getAttributes());
annotations.add(annotation);
}
}
return (IReconcileResult[]) annotations.toArray(new IReconcileResult[annotations.size()]);
}
use of org.eclipse.jface.text.reconciler.IReconcileResult in project webtools.sourceediting by eclipse.
the class ValidatorStrategy method reconcile.
/**
* @param tr
* Partition of the region to reconcile.
* @param dr
* Dirty region representation of the typed region
*/
public void reconcile(ITypedRegion tr, DirtyRegion dr) {
/*
* Abort if no workspace file is known (new validation framework does
* not support that scenario) or no validators have been specified
*/
if (isCanceled() || fMetaData.isEmpty() || fValidatorsSuspended)
return;
IDocument doc = getDocument();
// for external files, this can be null
if (doc == null)
return;
String partitionType = tr.getType();
ValidatorMetaData vmd = null;
List annotationsToAdd = new ArrayList();
List stepsRanOnThisDirtyRegion = new ArrayList(1);
/*
* Keep track of the disabled validators by source id for the V2
* validators.
*/
Set disabledValsBySourceId = new HashSet(20);
/*
* Keep track of the disabled validators by class id for the v1
* validators.
*/
Set disabledValsByClass = new HashSet(20);
IFile file = getFile();
if (file != null) {
if (!file.isAccessible())
return;
Collection disabledValidators = null;
try {
/*
* Take extra care when calling this external code, as it
* can indirectly cause bundles to start
*/
disabledValidators = ValidationFramework.getDefault().getDisabledValidatorsFor(file);
} catch (Exception e) {
Logger.logException(e);
}
if (disabledValidators != null) {
for (Iterator it = disabledValidators.iterator(); it.hasNext(); ) {
Validator v = (Validator) it.next();
Validator.V1 v1 = null;
try {
v1 = v.asV1Validator();
} catch (Exception e) {
Logger.logException(e);
}
if (v1 != null)
disabledValsByClass.add(v1.getId());
else // not a V1 validator
if (v.getSourceId() != null) {
// could be more then one sourceid per batch validator
String[] sourceIDs = StringUtils.unpack(v.getSourceId());
disabledValsBySourceId.addAll(Arrays.asList(sourceIDs));
}
}
}
}
/*
* Loop through all of the relevant validator meta data to find
* supporting validators for this partition type. Don't check
* this.canHandlePartition() before-hand since it just loops through
* and calls vmd.canHandlePartitionType()...which we're already doing
* here anyway to find the right vmd.
*/
for (int i = 0; i < fMetaData.size() && !isCanceled(); i++) {
vmd = (ValidatorMetaData) fMetaData.get(i);
if (vmd.canHandlePartitionType(getContentTypeIds(), partitionType)) {
/*
* Check if validator is enabled according to validation
* preferences before attempting to create/use it
*/
if (!disabledValsBySourceId.contains(vmd.getValidatorId()) && !disabledValsByClass.contains(vmd.getValidatorClass())) {
if (DEBUG_VALIDATION_UNSUPPORTED) {
Logger.log(Logger.INFO, "Source validator " + vmd.getValidatorId() + " handling (content types:[" + StringUtils.pack(getContentTypeIds()) + "] partition type:" + partitionType);
}
int validatorScope = vmd.getValidatorScope();
ReconcileStepForValidator validatorStep = null;
// get step for partition type
Object o = fVidToVStepMap.get(vmd.getValidatorId());
if (o != null) {
validatorStep = (ReconcileStepForValidator) o;
} else {
// if doesn't exist, create one
IValidator validator = vmd.createValidator();
validatorStep = new ReconcileStepForValidator(validator, validatorScope);
validatorStep.setInputModel(new DocumentAdapter(doc));
fVidToVStepMap.put(vmd.getValidatorId(), validatorStep);
}
if (!fTotalScopeValidatorsAlreadyRun.contains(vmd) && !fIsCancelled) {
annotationsToAdd.addAll(Arrays.asList(validatorStep.reconcile(dr, dr)));
stepsRanOnThisDirtyRegion.add(validatorStep);
if (validatorScope == ReconcileAnnotationKey.TOTAL) {
// mark this validator as "run"
fTotalScopeValidatorsAlreadyRun.add(vmd);
}
}
} else if (DEBUG_VALIDATION_CAPABLE_BUT_DISABLED) {
String message = "Source validator able (id:" + vmd.getValidatorId() + " class:" + vmd.getValidatorClass() + " but skipped because it was reported as disabled";
Logger.log(Logger.INFO, message);
}
} else if (DEBUG_VALIDATION_UNSUPPORTED) {
Logger.log(Logger.INFO, "Source validator " + vmd.getValidatorId() + " can not handle (content types:[" + StringUtils.pack(getContentTypeIds()) + "] partition type:" + partitionType);
}
}
TemporaryAnnotation[] annotationsToRemove = getAnnotationsToRemove(dr, stepsRanOnThisDirtyRegion);
if (annotationsToRemove.length + annotationsToAdd.size() > 0 && !fIsCancelled)
smartProcess(annotationsToRemove, (IReconcileResult[]) annotationsToAdd.toArray(new IReconcileResult[annotationsToAdd.size()]));
}
use of org.eclipse.jface.text.reconciler.IReconcileResult in project webtools.sourceediting by eclipse.
the class ReconcileStepForValidator method validate.
protected IReconcileResult[] validate(DirtyRegion dirtyRegion, IRegion subRegion) {
IReconcileResult[] results = EMPTY_RECONCILE_RESULT_SET;
IFile file = getFile();
try {
IncrementalHelper helper = getHelper(file != null ? file.getProject() : null);
/*
* Setting the URI isn't necessary for all source validators, we
* can still continue without it
*/
if (file != null && file.exists()) {
helper.setURI(file.getFullPath().toString());
}
if (fValidator instanceof ISourceValidator) {
IncrementalReporter reporter = getReporter();
if (getScope() == IReconcileAnnotationKey.PARTIAL)
((ISourceValidator) fValidator).validate(dirtyRegion, helper, reporter);
else
((ISourceValidator) fValidator).validate(new Region(0, getDocument().getLength()), helper, reporter);
/*
* call IValidator.cleanup() during release() because this
* validator might be called again on a different region
*/
results = createAnnotations(reporter.getAnnotationInfo());
reporter.removeAllMessages(fValidator);
}
} catch (Exception e) {
Logger.logException(e);
}
return results;
}
use of org.eclipse.jface.text.reconciler.IReconcileResult in project webtools.sourceediting by eclipse.
the class ReconcileStepForValidator method validate.
protected IReconcileResult[] validate() {
IReconcileResult[] results = EMPTY_RECONCILE_RESULT_SET;
IFile file = getFile();
IncrementalReporter reporter = null;
try {
IncrementalHelper helper = getHelper(file != null ? file.getProject() : null);
if (file != null && file.isAccessible()) {
helper.setURI(file.getFullPath().toString());
} else {
String uri = getURI();
if (uri != null) {
helper.setURI(uri);
}
}
reporter = getReporter();
fValidator.validate(helper, reporter);
results = createAnnotations(reporter.getAnnotationInfo());
reporter.removeAllMessages(fValidator);
} catch (Exception e) {
Logger.logException(e);
} finally {
fValidator.cleanup(reporter);
}
return results;
}
use of org.eclipse.jface.text.reconciler.IReconcileResult in project webtools.sourceediting by eclipse.
the class StructuredReconcileStep method merge.
/**
* Removes duplicates.
*
* @param results1
* @param results2
* @return
*/
protected IReconcileResult[] merge(IReconcileResult[] results1, IReconcileResult[] results2) {
if (results1 == null)
return results2;
if (results2 == null)
return results1;
List results = new ArrayList();
results.addAll(Arrays.asList(results1));
for (int i = 0; i < results2.length; i++) {
results.add(results2[i]);
}
return (IReconcileResult[]) results.toArray(new IReconcileResult[results.size()]);
}
Aggregations