Search in sources :

Example 1 with ValidatorMetaData

use of org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorMetaData in project webtools.sourceediting by eclipse.

the class DocumentRegionProcessor method getValidatorStrategy.

/**
 * @return Returns the ValidatorStrategy.
 */
protected ValidatorStrategy getValidatorStrategy() {
    ValidatorStrategy validatorStrategy = null;
    if (fValidatorStrategy == null && fValidationEnabled) {
        if (getTextViewer() instanceof ISourceViewer) {
            ISourceViewer viewer = (ISourceViewer) getTextViewer();
            String contentTypeId = null;
            IDocument doc = viewer.getDocument();
            contentTypeId = getContentType(doc);
            if (contentTypeId != null) {
                validatorStrategy = new ValidatorStrategy(viewer, contentTypeId);
                ValidatorBuilder vBuilder = new ValidatorBuilder();
                ValidatorMetaData[] vmds = vBuilder.getValidatorMetaData(SSE_UI_ID);
                List enabledValidators = new ArrayList(1);
                /* if any "must" handle this content type, just add them */
                boolean foundSpecificContentTypeValidators = false;
                for (int i = 0; i < vmds.length; i++) {
                    if (vmds[i].mustHandleContentType(contentTypeId)) {
                        if (DEBUG_VALIDATORS)
                            // $NON-NLS-1$
                            Logger.log(Logger.INFO, contentTypeId + " using specific validator " + vmds[i].getValidatorId());
                        foundSpecificContentTypeValidators = true;
                        enabledValidators.add(vmds[i]);
                    }
                }
                if (!foundSpecificContentTypeValidators) {
                    for (int i = 0; i < vmds.length; i++) {
                        if (vmds[i].canHandleContentType(contentTypeId)) {
                            if (DEBUG_VALIDATORS)
                                // $NON-NLS-1$
                                Logger.log(Logger.INFO, contentTypeId + " using inherited(?) validator " + vmds[i].getValidatorId());
                            enabledValidators.add(vmds[i]);
                        }
                    }
                }
                for (int i = 0; i < enabledValidators.size(); i++) {
                    validatorStrategy.addValidatorMetaData((ValidatorMetaData) enabledValidators.get(i));
                }
            }
        }
        fValidatorStrategy = validatorStrategy;
    } else if (fValidatorStrategy != null && fValidationEnabled) {
        validatorStrategy = fValidatorStrategy;
    }
    return validatorStrategy;
}
Also used : ArrayList(java.util.ArrayList) ValidatorMetaData(org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorMetaData) ArrayList(java.util.ArrayList) List(java.util.List) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) ValidatorStrategy(org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorStrategy) ValidatorBuilder(org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorBuilder) IDocument(org.eclipse.jface.text.IDocument)

Example 2 with ValidatorMetaData

use of org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorMetaData in project webtools.sourceediting by eclipse.

the class JavascriptValidationStrategy method getValidatorStrategy.

/**
 * @return Returns the ValidatorStrategy.
 */
protected ValidatorStrategy getValidatorStrategy() {
    ValidatorStrategy validatorStrategy = null;
    if (fValidatorStrategy == null && fValidationEnabled) {
        if (getTextViewer() instanceof ISourceViewer) {
            ISourceViewer viewer = (ISourceViewer) getTextViewer();
            String contentTypeId = getContentType();
            if (contentTypeId != null) {
                validatorStrategy = new ValidatorStrategy(viewer, contentTypeId);
                ValidatorBuilder vBuilder = new ValidatorBuilder();
                ValidatorMetaData[] vmds = vBuilder.getValidatorMetaData(SSE_UI_ID);
                List enabledValidators = new ArrayList(1);
                /* if any "must" handle this content type, just add them */
                boolean foundSpecificContentTypeValidators = false;
                for (int i = 0; i < vmds.length; i++) {
                    if (vmds[i].mustHandleContentType(contentTypeId)) {
                        if (DEBUG_VALIDATORS) {
                            // $NON-NLS-1$
                            String info = contentTypeId + " using specific validator " + vmds[i].getValidatorId();
                            IStatus status = new Status(IStatus.INFO, JavaScriptUI.ID_PLUGIN, info);
                            JavaScriptPlugin.getDefault().getLog().log(status);
                        }
                        foundSpecificContentTypeValidators = true;
                        enabledValidators.add(vmds[i]);
                    }
                }
                if (!foundSpecificContentTypeValidators) {
                    for (int i = 0; i < vmds.length; i++) {
                        if (vmds[i].canHandleContentType(contentTypeId)) {
                            if (DEBUG_VALIDATORS) {
                                // $NON-NLS-1$
                                String info = contentTypeId + " using inherited(?) validator " + vmds[i].getValidatorId();
                                IStatus status = new Status(IStatus.INFO, JavaScriptUI.ID_PLUGIN, info);
                                JavaScriptPlugin.getDefault().getLog().log(status);
                            }
                            enabledValidators.add(vmds[i]);
                        }
                    }
                }
                for (int i = 0; i < enabledValidators.size(); i++) {
                    validatorStrategy.addValidatorMetaData((ValidatorMetaData) enabledValidators.get(i));
                }
            }
        }
        fValidatorStrategy = validatorStrategy;
    } else if (fValidatorStrategy != null && fValidationEnabled) {
        validatorStrategy = fValidatorStrategy;
    }
    return validatorStrategy;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ArrayList(java.util.ArrayList) ValidatorMetaData(org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorMetaData) ArrayList(java.util.ArrayList) List(java.util.List) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) ValidatorStrategy(org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorStrategy) ValidatorBuilder(org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorBuilder)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)2 ValidatorBuilder (org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorBuilder)2 ValidatorMetaData (org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorMetaData)2 ValidatorStrategy (org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorStrategy)2 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IDocument (org.eclipse.jface.text.IDocument)1