Search in sources :

Example 1 with ValidatorStrategy

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

the class DocumentRegionProcessor method endProcessing.

protected void endProcessing() {
    super.endProcessing();
    ValidatorStrategy validatorStrategy = getValidatorStrategy();
    if (validatorStrategy != null) {
        validatorStrategy.endProcessing();
    }
    /* single spell-check for everything to ensure that SpellingProblem offsets are correct */
    IReconcilingStrategy spellingStrategy = getSpellcheckStrategy();
    IDocument document = getDocument();
    if (spellingStrategy != null && document != null) {
        spellingStrategy.reconcile(new Region(0, document.getLength()));
    }
    IReconcilingStrategy semanticHighlightingStrategy = getSemanticHighlightingStrategy();
    if (semanticHighlightingStrategy != null && document != null) {
        semanticHighlightingStrategy.reconcile(new Region(0, document.getLength()));
    }
    if ((getTextViewer() instanceof ISourceViewer)) {
        ISourceViewer sourceViewer = (ISourceViewer) getTextViewer();
        IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
        for (int i = 0; i < fReconcileListeners.length; i++) {
            fReconcileListeners[i].reconciled(document, annotationModel, false, new NullProgressMonitor());
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IReconcilingStrategy(org.eclipse.jface.text.reconciler.IReconcilingStrategy) Region(org.eclipse.jface.text.Region) ITypedRegion(org.eclipse.jface.text.ITypedRegion) DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) ValidatorStrategy(org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorStrategy) IDocument(org.eclipse.jface.text.IDocument)

Example 2 with ValidatorStrategy

use of org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorStrategy 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 3 with ValidatorStrategy

use of org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorStrategy 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)

Example 4 with ValidatorStrategy

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

the class TestSourceValidationFramework method getSourceValidatorIDs.

private List getSourceValidatorIDs(String fileName) throws Exception {
    List validatorIds = new ArrayList(1);
    IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IWorkbenchPage page = workbenchWindow.getActivePage();
    IFile file = ensureFileIsAccessible(PROJECT_NAME + SEPARATOR + fileName, null);
    IEditorPart editor = IDE.openEditor(page, file, TestStructuredTextEditor.class.getName(), true);
    ITextEditor textEditor = editor.getAdapter(ITextEditor.class);
    TestStructuredTextEditor testTextEditor = (TestStructuredTextEditor) textEditor;
    IReconciler reconciler = testTextEditor.textViewerConfiguration.getReconciler(testTextEditor.getTextViewer());
    assertNotNull(reconciler);
    assertTrue("unexpected IReconciler implementation: " + reconciler.getClass(), reconciler instanceof DocumentRegionProcessor);
    Class reconcilerClass = reconciler.getClass();
    Method method = null;
    while (reconcilerClass != Object.class && method == null) {
        Method[] methods = reconcilerClass.getDeclaredMethods();
        for (int i = 0; i < methods.length; i++) {
            if (methods[i].getName().equals("getValidatorStrategy")) {
                method = methods[i];
            }
        }
        reconcilerClass = reconcilerClass.getSuperclass();
    }
    assertNotNull("no getValidatorStrategy method found on " + reconciler.getClass(), method);
    method.setAccessible(true);
    ValidatorStrategy strategy = (ValidatorStrategy) method.invoke(reconciler, new Object[0]);
    assertNotNull(strategy);
    Field fMetaData = strategy.getClass().getDeclaredField("fMetaData");
    assertNotNull("validator metadata field \"fMetaData\" not found on strategy " + strategy.getClass(), fMetaData);
    fMetaData.setAccessible(true);
    List metadata = (List) fMetaData.get(strategy);
    assertNotNull(metadata);
    for (int i = 0; i < metadata.size(); i++) {
        validatorIds.add(((ValidatorMetaData) metadata.get(i)).getValidatorId());
    }
    page.closeEditor(editor, false);
    return validatorIds;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) Method(java.lang.reflect.Method) Field(java.lang.reflect.Field) IReconciler(org.eclipse.jface.text.reconciler.IReconciler) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ArrayList(java.util.ArrayList) List(java.util.List) ValidatorStrategy(org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorStrategy) DocumentRegionProcessor(org.eclipse.wst.sse.ui.internal.reconcile.DocumentRegionProcessor)

Example 5 with ValidatorStrategy

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

the class DocumentRegionProcessor method beginProcessing.

protected void beginProcessing() {
    super.beginProcessing();
    ValidatorStrategy validatorStrategy = getValidatorStrategy();
    if (validatorStrategy != null) {
        validatorStrategy.beginProcessing();
    }
    if ((getTextViewer() instanceof ISourceViewer)) {
        for (int i = 0; i < fReconcileListeners.length; i++) {
            fReconcileListeners[i].aboutToBeReconciled();
        }
    }
}
Also used : ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) ValidatorStrategy(org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorStrategy)

Aggregations

ValidatorStrategy (org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorStrategy)5 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IDocument (org.eclipse.jface.text.IDocument)2 ValidatorBuilder (org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorBuilder)2 ValidatorMetaData (org.eclipse.wst.sse.ui.internal.reconcile.validator.ValidatorMetaData)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 IFile (org.eclipse.core.resources.IFile)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Status (org.eclipse.core.runtime.Status)1 ITypedRegion (org.eclipse.jface.text.ITypedRegion)1 Region (org.eclipse.jface.text.Region)1 DirtyRegion (org.eclipse.jface.text.reconciler.DirtyRegion)1 IReconciler (org.eclipse.jface.text.reconciler.IReconciler)1 IReconcilingStrategy (org.eclipse.jface.text.reconciler.IReconcilingStrategy)1 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)1 IEditorPart (org.eclipse.ui.IEditorPart)1