本文整理汇总了Java中org.netbeans.modules.csl.spi.ParserResult类的典型用法代码示例。如果您正苦于以下问题:Java ParserResult类的具体用法?Java ParserResult怎么用?Java ParserResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParserResult类属于org.netbeans.modules.csl.spi包,在下文中一共展示了ParserResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRuleContext
import org.netbeans.modules.csl.spi.ParserResult; //导入依赖的package包/类
public RuleContext createRuleContext (ParserResult parserResult, Language language, int caretOffset, int selectionStart, int selectionEnd) {
RuleContext context = provider.createRuleContext();
context.manager = this;
context.parserResult = parserResult;
context.caretOffset = caretOffset;
context.selectionStart = selectionStart;
context.selectionEnd = selectionEnd;
context.doc = (BaseDocument) parserResult.getSnapshot().getSource().getDocument(false);
if (context.doc == null) {
// Document closed
return null;
}
// XXX: parsingapi
// Collection<? extends ParserResult> embeddedResults = info.getEmbeddedResults(language.getMimeType());
// context.parserResults = embeddedResults != null ? embeddedResults : Collections.EMPTY_LIST;
// if (context.parserResults.size() > 0) {
// context.parserResult = embeddedResults.iterator().next();
// }
return context;
}
示例2: run
import org.netbeans.modules.csl.spi.ParserResult; //导入依赖的package包/类
public @Override void run(ParserResult result, SchedulerEvent event) {
final Document doc = getDocument();
if (doc == null) {
LOG.log(Level.INFO, "SemanticHighlighter: Cannot get document!");
return ;
}
SpiSupportAccessor.getInstance().setCancelSupport(cancel);
try {
ParserManager.parse(Collections.singleton(result.getSnapshot().getSource()), new UserTask() {
public @Override void run(ResultIterator resultIterator) throws ParseException {
refreshErrors(resultIterator);
}
});
} catch (ParseException e) {
LOG.log(Level.WARNING, null, e);
} finally {
SpiSupportAccessor.getInstance().removeCancelSupport(cancel);
}
}
示例3: findCachedStructure
import org.netbeans.modules.csl.spi.ParserResult; //导入依赖的package包/类
public static List<? extends StructureItem> findCachedStructure(Snapshot s, Parser.Result r) {
if (!(r instanceof ParserResult)) {
return null;
}
Reference<ResultStructure> previousRef;
previousRef = lastResults.get(s);
if (previousRef == null) {
return null;
}
ResultStructure cached = previousRef.get();
if (cached == null || cached.result != r) {
// remove from cache:
lastResults.remove(s);
return null;
}
return cached.structure;
}
示例4: run
import org.netbeans.modules.csl.spi.ParserResult; //导入依赖的package包/类
public @Override void run(ParserResult result, SchedulerEvent event) {
boolean navigatorShouldUpdate = ClassMemberPanel.getInstance() != null; // XXX set by navigator visible
if (cancel.isCancelled() || (!navigatorShouldUpdate) || !(event instanceof CursorMovedSchedulerEvent)) {
return;
}
SpiSupportAccessor.getInstance().setCancelSupport(cancel);
try {
int offset = ((CursorMovedSchedulerEvent) event).getCaretOffset();
if (offset != -1) {
ClassMemberPanel.getInstance().selectElement(result, offset);
}
} finally {
SpiSupportAccessor.getInstance().removeCancelSupport(cancel);
}
}
示例5: selectElementNode
import org.netbeans.modules.csl.spi.ParserResult; //导入依赖的package包/类
public void selectElementNode(final ParserResult info, final int offset) {
final ElementNode root = getRootNode();
if ( root == null ) {
return;
}
FileObject rootFo = root.getFileObject();
FileObject sourceFo = info.getSnapshot().getSource().getFileObject();
if (sourceFo != null && !sourceFo.equals(rootFo)) {
// switching files; refresh should be fired by periodic scheduler
synchronized (this) {
positionRequests.put(sourceFo, offset);
}
} else {
doSelectNodes(info, null, offset);
}
}
示例6: doSelectNodes0
import org.netbeans.modules.csl.spi.ParserResult; //导入依赖的package包/类
private void doSelectNodes0(ParserResult info, BaseDocument bd, int offset) {
ElementNode node;
final ElementNode rootNode = getRootNode();
if (info != null && rootNode != null) {
node = rootNode.getMimeRootNodeForOffset(info, offset);
} else if (bd != null && rootNode != null) {
node = rootNode.getMimeRootNodeForOffset(bd, offset);
} else {
return;
}
Node[] selectedNodes = manager.getSelectedNodes();
if (!(selectedNodes != null && selectedNodes.length == 1 && selectedNodes[0] == node)) {
try {
manager.setSelectedNodes(new Node[]{ node == null ? getRootNode() : node });
} catch (PropertyVetoException propertyVetoException) {
Exceptions.printStackTrace(propertyVetoException);
}
}
}
示例7: scan
import org.netbeans.modules.csl.spi.ParserResult; //导入依赖的package包/类
private void scan(final ParserResult info,
final Collection<FoldInfo> folds, final Document doc, final
StructureScanner scanner) {
// #217322, disabled folding -> no folds will be created
String mime = info.getSnapshot().getMimeType();
if (!FoldUtilities.isFoldingEnabled(mime)) {
LOG.log(Level.FINER, "Folding is not enabled for MIME: {0}", mime);
return;
}
final Map<String,List<OffsetRange>> collectedFolds = scanner.folds(info);
final Collection<? extends FoldType> ftypes = FoldUtilities.getFoldTypes(mime).values();
doc.render(new Runnable() {
@Override
public void run() {
addTree(folds, info, collectedFolds, ftypes);
}
});
}
示例8: checkErrors
import org.netbeans.modules.csl.spi.ParserResult; //导入依赖的package包/类
protected void checkErrors(final String relFilePath) throws Exception {
Source testSource = getTestSource(getTestFile(relFilePath));
ParserManager.parse(Collections.singleton(testSource), new UserTask() {
public @Override void run(ResultIterator resultIterator) throws Exception {
Parser.Result r = resultIterator.getParserResult();
assertNotNull(r);
assertTrue(r instanceof ParserResult);
ParserResult pr = (ParserResult) r;
List<? extends Error> diagnostics = pr.getDiagnostics();
String annotatedSource = annotateErrors(diagnostics);
assertDescriptionMatches(relFilePath, annotatedSource, false, ".errors");
}
});
}
示例9: checkOffsets
import org.netbeans.modules.csl.spi.ParserResult; //导入依赖的package包/类
protected void checkOffsets(final String relFilePath, final String caretLine) throws Exception {
Source testSource = getTestSource(getTestFile(relFilePath));
if (caretLine != null) {
int caretOffset = getCaretOffset(testSource.createSnapshot().getText().toString(), caretLine);
enforceCaretOffset(testSource, caretOffset);
}
ParserManager.parse(Collections.singleton(testSource), new UserTask() {
public @Override void run(ResultIterator resultIterator) throws Exception {
Parser.Result r = resultIterator.getParserResult();
assertTrue(r instanceof ParserResult);
ParserResult pr = (ParserResult) r;
List<Object> validNodes = new ArrayList<Object>();
List<Object> invalidNodes = new ArrayList<Object>();
Map<Object,OffsetRange> positions = new HashMap<Object,OffsetRange>();
initializeNodes(pr, validNodes, positions, invalidNodes);
String annotatedSource = annotateOffsets(validNodes, positions, invalidNodes, pr);
assertDescriptionMatches(relFilePath, annotatedSource, false, ".offsets");
}
});
}
示例10: checkTypes
import org.netbeans.modules.csl.spi.ParserResult; //导入依赖的package包/类
protected void checkTypes(final String relFilePath, final String caretLine) throws Exception {
Source testSource = getTestSource(getTestFile(relFilePath));
if (caretLine != null) {
int caretOffset = getCaretOffset(testSource.createSnapshot().getText().toString(), caretLine);
enforceCaretOffset(testSource, caretOffset);
}
ParserManager.parse(Collections.singleton(testSource), new UserTask() {
public @Override void run(ResultIterator resultIterator) throws Exception {
Parser.Result r = resultIterator.getParserResult();
assertTrue(r instanceof ParserResult);
ParserResult pr = (ParserResult) r;
List<Object> nodes = new ArrayList<Object>();
Map<Object,String> types = new HashMap<Object,String>();
Map<Object,OffsetRange> positions = new HashMap<Object,OffsetRange>();
initializeTypeNodes(pr, nodes, positions, types);
String annotatedSource = annotateTypes(nodes, positions, types, pr);
assertDescriptionMatches(relFilePath, annotatedSource, false, ".types");
}
});
}
示例11: findLogicalRanges
import org.netbeans.modules.csl.spi.ParserResult; //导入依赖的package包/类
@Override
public List<OffsetRange> findLogicalRanges(ParserResult info, int caretOffset) {
YamlParserResult result = (YamlParserResult) info;
if (result == null) {
return Collections.emptyList();
}
List<? extends StructureItem> items = result.getItems();
if (items.isEmpty()) {
return Collections.emptyList();
}
List<OffsetRange> ranges = new ArrayList<OffsetRange>();
for (StructureItem item : items) {
addRanges(ranges, caretOffset, item);
}
Collections.reverse(ranges);
Document doc = info.getSnapshot().getSource().getDocument(false);
if (doc != null) {
ranges.add(new OffsetRange(0, doc.getLength()));
}
return ranges;
}
示例12: getPrefix
import org.netbeans.modules.csl.spi.ParserResult; //导入依赖的package包/类
@Override
public String getPrefix(ParserResult info, int caretOffset, boolean upToOffset) {
if (caretOffset > 0) {
try {
Document doc = ((YamlParserResult) info).getSnapshot().getSource().getDocument(false);
if (doc != null) {
return doc.getText(caretOffset - 1, 1);
} else {
return null;
}
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
return null;
}
示例13: getOffsetRange
import org.netbeans.modules.csl.spi.ParserResult; //导入依赖的package包/类
@Override
public OffsetRange getOffsetRange(ParserResult result) {
Snapshot s = result.getSnapshot();
if(s.getText().length() == 0) {
return null;
}
//check the boundaries bacause of (I)
int origFrom = from > s.getText().length() ? 0 : s.getOriginalOffset(from);
int origTo = to > s.getText().length() ? 0 : s.getOriginalOffset(to);
if(origFrom == -1 || origTo == -1 || origFrom == origTo || origTo == 0) {
return null;
}
return new OffsetRange(origFrom, origTo);
}
示例14: documentElement
import org.netbeans.modules.csl.spi.ParserResult; //导入依赖的package包/类
@Override
public Documentation documentElement(
@NonNull final ParserResult info,
@NonNull final ElementHandle element,
@NonNull final Callable<Boolean> cancel) {
switch (element.getKind()) {
case KEYWORD:
return Optional.ofNullable(Command.forHandle(element))
.map((cmd) -> cmd.getDocumentation(cancel))
.orElse(null);
case OTHER:
try {
final URL url = ((DocHandle)element).getURI().toURL();
final Future<String> becomesContent = DocDownloader.download(url, cancel);
String content = null;
while (cancel.call() != Boolean.TRUE) {
try {
content = becomesContent.get(250, TimeUnit.MILLISECONDS);
break;
} catch (TimeoutException timeout) {
//retry
}
}
return content == null ?
null :
DocDownloader.parseSection(content, url);
} catch (Exception e) {
return null;
}
default:
return null;
}
}
示例15: processErrorsRecursive
import org.netbeans.modules.csl.spi.ParserResult; //导入依赖的package包/类
private void processErrorsRecursive(final ResultIterator resultIterator,
Document doc,
final List<ErrorDescription> descriptions,
Snapshot topLevelSnapshot) throws ParseException {
if (resultIterator == null) {
return;
}
if (doc == null) {
doc = getDocument();
}
for(Embedding e : resultIterator.getEmbeddings()) {
try {
if (cancel.isCancelled()) {
return;
}
} catch (Exception ex) {
// should never happen, but log:
LOG.log(Level.WARNING, "Unexpected error", ex);
}
processErrorsRecursive(resultIterator.getResultIterator(e), doc, descriptions, topLevelSnapshot);
}
if (!(resultIterator.getParserResult() instanceof ParserResult)) {
return;
}
processErrors(resultIterator.getSnapshot(), (ParserResult)resultIterator.getParserResult(),
doc, descriptions, topLevelSnapshot);
}