Search in sources :

Example 1 with IReconcileResult

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()]);
}
Also used : Position(org.eclipse.jface.text.Position) IReconcileResult(org.eclipse.jface.text.reconciler.IReconcileResult) IReconcileAnnotationKey(org.eclipse.wst.sse.ui.internal.reconcile.IReconcileAnnotationKey) ReconcileAnnotationKey(org.eclipse.wst.sse.ui.internal.reconcile.ReconcileAnnotationKey) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TemporaryAnnotation(org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation)

Example 2 with IReconcileResult

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()]));
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) DocumentAdapter(org.eclipse.wst.sse.ui.internal.reconcile.DocumentAdapter) IValidator(org.eclipse.wst.validation.internal.provisional.core.IValidator) IReconcileResult(org.eclipse.jface.text.reconciler.IReconcileResult) Iterator(java.util.Iterator) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) TemporaryAnnotation(org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation) IDocument(org.eclipse.jface.text.IDocument) IValidator(org.eclipse.wst.validation.internal.provisional.core.IValidator) Validator(org.eclipse.wst.validation.Validator) HashSet(java.util.HashSet)

Example 3 with IReconcileResult

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) IReconcileResult(org.eclipse.jface.text.reconciler.IReconcileResult) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion)

Example 4 with IReconcileResult

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) IReconcileResult(org.eclipse.jface.text.reconciler.IReconcileResult)

Example 5 with IReconcileResult

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()]);
}
Also used : IReconcileResult(org.eclipse.jface.text.reconciler.IReconcileResult) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

IReconcileResult (org.eclipse.jface.text.reconciler.IReconcileResult)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IFile (org.eclipse.core.resources.IFile)3 TemporaryAnnotation (org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 IDocument (org.eclipse.jface.text.IDocument)1 IRegion (org.eclipse.jface.text.IRegion)1 Position (org.eclipse.jface.text.Position)1 Region (org.eclipse.jface.text.Region)1 DirtyRegion (org.eclipse.jface.text.reconciler.DirtyRegion)1 DocumentAdapter (org.eclipse.wst.sse.ui.internal.reconcile.DocumentAdapter)1 IReconcileAnnotationKey (org.eclipse.wst.sse.ui.internal.reconcile.IReconcileAnnotationKey)1 ReconcileAnnotationKey (org.eclipse.wst.sse.ui.internal.reconcile.ReconcileAnnotationKey)1 Validator (org.eclipse.wst.validation.Validator)1 IMessage (org.eclipse.wst.validation.internal.provisional.core.IMessage)1 IValidator (org.eclipse.wst.validation.internal.provisional.core.IValidator)1