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;
}
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;
}
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();
}
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);
}
}
}
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;
}
Aggregations