Search in sources :

Example 6 with RegionParser

use of org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser in project webtools.sourceediting by eclipse.

the class CSSModelImpl method createDocument.

private CSSDocumentImpl createDocument() {
    CSSDocumentImpl doc = null;
    int parserMode = CSSSourceParser.MODE_STYLESHEET;
    if (ownerNode == null) {
        // this case is external CSS file
        // parameters
        doc = (CSSStyleSheetImpl) DOMCSSImpl.createCSSStyleSheet(null, null);
        // are
        // for
        // STYLE-tag
        parserMode = CSSSourceParser.MODE_STYLESHEET;
    } else if (ownerNode instanceof org.w3c.dom.Element && ((Element) ownerNode).getTagName().toUpperCase().equals("STYLE")) {
        // $NON-NLS-1$
        // this case is STYLE-tag
        Element style = (Element) ownerNode;
        doc = (CSSStyleSheetImpl) // $NON-NLS-1$
        DOMCSSImpl.createCSSStyleSheet(// $NON-NLS-1$
        style.getAttribute("TITLE"), // $NON-NLS-1$
        style.getAttribute("MEDIA"));
        parserMode = CSSSourceParser.MODE_STYLESHEET;
    } else if (ownerNode instanceof org.w3c.dom.Element || ownerNode instanceof org.w3c.dom.Attr) {
        // Inline attributes
        doc = (CSSStyleDeclarationImpl) DOMCSSImpl.createCSSStyleDeclaration();
        parserMode = CSSSourceParser.MODE_DECLARATION;
    }
    RegionParser regionParser = getStructuredDocument().getParser();
    if (regionParser instanceof CSSSourceParser) {
        ((CSSSourceParser) regionParser).setParserMode(parserMode);
    }
    return doc;
}
Also used : Element(org.w3c.dom.Element) Element(org.w3c.dom.Element) CSSSourceParser(org.eclipse.wst.css.core.internal.parser.CSSSourceParser) RegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser)

Example 7 with RegionParser

use of org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser in project webtools.sourceediting by eclipse.

the class ScanningTests method parse.

public static Vector parse(String stringdata, boolean useXML) {
    if (Debug.perfTest) {
        startTime = System.currentTimeMillis();
    }
    RegionParser parser = null;
    if (useXML)
        parser = newXMLParser();
    else
        parser = newParser();
    if (Debug.perfTest) {
        stopTime = System.currentTimeMillis();
        System.out.println("ScanningTests spent " + (stopTime - startTime) + " (msecs) creating a " + parser.getClass().getName());
    }
    // Caution: cast
    parser.reset(new StringReader(stringdata));
    IStructuredDocumentRegion aNode = setNodeDocument(parser.getDocumentRegions());
    if (Debug.perfTest) {
        startTime = System.currentTimeMillis();
    }
    textStore = StructuredDocumentFactory.getNewStructuredDocumentInstance(parser);
    textStore.setText(null, stringdata);
    StructuredDocumentRegionIterator.setParentDocument(aNode, textStore);
    Vector v = new Vector();
    while (aNode != null) {
        v.addElement(aNode);
        aNode = aNode.getNext();
    }
    if (Debug.perfTest) {
        stopTime = System.currentTimeMillis();
        System.out.println("ScanningTests spent " + (stopTime - startTime) + " (msecs) setting text and storing nodes");
    }
    return v;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) StringReader(java.io.StringReader) RegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser) Vector(java.util.Vector)

Example 8 with RegionParser

use of org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser in project webtools.sourceediting by eclipse.

the class StructuredFileTaskScanner method findTasks.

private void findTasks(IFile file, final TaskTag[] taskTags, final IProgressMonitor monitor) {
    try {
        IModelHandler handler = ModelHandlerRegistry.getInstance().getHandlerFor(file);
        // records if the optimized streamish parse was possible
        boolean didStreamParse = false;
        final IEncodedDocument defaultDocument = handler.getDocumentLoader().createNewStructuredDocument();
        if (defaultDocument instanceof IStructuredDocument) {
            RegionParser parser = ((IStructuredDocument) defaultDocument).getParser();
            if (parser instanceof StructuredDocumentRegionParser) {
                didStreamParse = true;
                String charset = detectCharset(file);
                StructuredDocumentRegionParser documentParser = (StructuredDocumentRegionParser) parser;
                final IDocument textDocument = new Document();
                setDocumentContent(textDocument, file.getContents(true), charset);
                monitor.beginTask("", textDocument.getLength());
                documentParser.reset(new DocumentReader(textDocument));
                documentParser.addStructuredDocumentRegionHandler(new StructuredDocumentRegionHandler() {

                    public void nodeParsed(IStructuredDocumentRegion documentRegion) {
                        ITextRegionList regions = documentRegion.getRegions();
                        for (int j = 0; j < regions.size(); j++) {
                            ITextRegion comment = regions.get(j);
                            findTasks(textDocument, taskTags, documentRegion, comment);
                        }
                        // disconnect the document regions
                        if (documentRegion.getPrevious() != null) {
                            documentRegion.getPrevious().setPrevious(null);
                            documentRegion.getPrevious().setNext(null);
                        }
                        if (monitor.isCanceled()) {
                            // $NON-NLS-1$
                            textDocument.set("");
                        }
                        monitor.worked(documentRegion.getLength());
                    }

                    public void resetNodes() {
                    }
                });
                documentParser.getDocumentRegions();
            }
        }
        if (!didStreamParse) {
            // Use a StructuredDocument
            IEncodedDocument document = handler.getDocumentLoader().createNewStructuredDocument(file);
            monitor.beginTask("", document.getLength());
            if (document instanceof IStructuredDocument) {
                IStructuredDocumentRegion documentRegion = ((IStructuredDocument) document).getFirstStructuredDocumentRegion();
                while (documentRegion != null) {
                    ITextRegionList regions = documentRegion.getRegions();
                    for (int j = 0; j < regions.size(); j++) {
                        ITextRegion comment = regions.get(j);
                        findTasks(document, taskTags, documentRegion, comment);
                    }
                    monitor.worked(documentRegion.getLength());
                    documentRegion = documentRegion.getNext();
                }
            }
        }
    } catch (CoreException e) {
        // $NON-NLS-1$
        Logger.logException("Exception with " + file.getFullPath().toString(), e);
    } catch (CharacterCodingException e) {
        // $NON-NLS-1$
        Logger.log(Logger.INFO, "StructuredFileTaskScanner encountered CharacterCodingException reading " + file.getFullPath());
    } catch (Exception e) {
        // $NON-NLS-1$
        Logger.logException("Exception with " + file.getFullPath().toString(), e);
    }
    monitor.done();
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) StructuredDocumentRegionHandler(org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionHandler) DocumentReader(org.eclipse.wst.sse.core.internal.document.DocumentReader) CharacterCodingException(java.nio.charset.CharacterCodingException) StructuredDocumentRegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser) RegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IEncodedDocument(org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler) CharacterCodingException(java.nio.charset.CharacterCodingException) CoreException(org.eclipse.core.runtime.CoreException) BadLocationException(org.eclipse.jface.text.BadLocationException) IOException(java.io.IOException) StructuredDocumentRegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) CoreException(org.eclipse.core.runtime.CoreException) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IEncodedDocument(org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument) IDocument(org.eclipse.jface.text.IDocument)

Example 9 with RegionParser

use of org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser in project webtools.sourceediting by eclipse.

the class DocumentRegionProcessor method setDocument.

public void setDocument(IDocument doc) {
    if (getDocument() instanceof IStructuredDocument) {
        RegionParser parser = ((IStructuredDocument) getDocument()).getParser();
        if (parser instanceof StructuredDocumentRegionParser) {
            ((StructuredDocumentRegionParser) parser).removeStructuredDocumentRegionHandler(fResetHandler);
        }
    }
    super.setDocument(doc);
    IReconcilingStrategy validatorStrategy = getValidatorStrategy();
    if (validatorStrategy != null) {
        validatorStrategy.setDocument(doc);
    }
    if (fSemanticHighlightingStrategy != null) {
        fSemanticHighlightingStrategy.setDocument(doc);
    }
    fSpellcheckStrategy = null;
    if (fFoldingStrategy != null) {
        fFoldingStrategy.uninstall();
    }
    fFoldingStrategy = null;
    if (getDocument() instanceof IStructuredDocument) {
        RegionParser parser = ((IStructuredDocument) doc).getParser();
        if (parser instanceof StructuredDocumentRegionParser) {
            ((StructuredDocumentRegionParser) parser).addStructuredDocumentRegionHandler(fResetHandler);
        }
    }
}
Also used : IReconcilingStrategy(org.eclipse.jface.text.reconciler.IReconcilingStrategy) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) StructuredDocumentRegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser) RegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser) StructuredDocumentRegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser)

Example 10 with RegionParser

use of org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser in project webtools.sourceediting by eclipse.

the class ScanningTests method tokenizeFile.

public static List tokenizeFile(String fileName) {
    List v = null;
    StringBuffer buff = new StringBuffer();
    try {
        // char[] input = loadChars(fileName);
        Reader input = new FileReader(fileName);
        RegionParser parser = newParser();
        // parser must be given input, before tokenizer is valid
        parser.reset(input);
        int c = 0;
        parser.getDocumentRegions();
        v = parser.getRegions();
        input.reset();
        while ((c = input.read()) >= 0) {
            buff.append((char) c);
        }
        textStore = StructuredDocumentFactory.getNewStructuredDocumentInstance(parser);
        textStore.setText(null, buff.toString());
    } catch (FileNotFoundException e) {
        System.out.println("File not found : \"" + fileName + "\"");
    } catch (IOException e) {
    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println("Usage : java JSPLexer3 <inputfile>");
    }
    return v;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) Reader(java.io.Reader) StringReader(java.io.StringReader) FileReader(java.io.FileReader) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) List(java.util.List) FileReader(java.io.FileReader) IOException(java.io.IOException) RegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser)

Aggregations

RegionParser (org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser)13 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)6 StructuredDocumentRegionParser (org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser)4 List (java.util.List)3 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)3 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 IReconcilingStrategy (org.eclipse.jface.text.reconciler.IReconcilingStrategy)2 CSSSourceParser (org.eclipse.wst.css.core.internal.parser.CSSSourceParser)2 BlockMarker (org.eclipse.wst.sse.core.internal.ltk.parser.BlockMarker)2 BlockTagParser (org.eclipse.wst.sse.core.internal.ltk.parser.BlockTagParser)2 StructuredDocumentRegionHandler (org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionHandler)2 IEncodedDocument (org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)2 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)2 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)2 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 Reader (java.io.Reader)1