org.netbeans.modules.csl.spi.ParserResult Java Examples
The following examples show how to use
org.netbeans.modules.csl.spi.ParserResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ElementScanningTask.java From netbeans with Apache License 2.0 | 6 votes |
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; }
Example #2
Source File: PhpCommentGenerator.java From netbeans with Apache License 2.0 | 6 votes |
public ScannerImpl(ParserResult info, FunctionDeclaration decl) { if (info instanceof PHPParseResult) { PHPParseResult parseResult = (PHPParseResult) info; Model model = parseResult.getModel(); final VariableScope variableScope = model.getVariableScope(decl.getEndOffset() - 1); NamespaceScope namespaceScope = ModelUtils.getNamespaceScope(model.getFileScope(), decl.getEndOffset() - 1); if (namespaceScope != null) { declaredUses = namespaceScope.getAllDeclaredSingleUses(); } if (variableScope instanceof FunctionScope) { fnc = (FunctionScope) variableScope; declaredVariables.addAll(fnc.getDeclaredVariables()); } else { fnc = null; } } else { fnc = null; } this.decl = decl; }
Example #3
Source File: JQueryCodeCompletion.java From netbeans with Apache License 2.0 | 6 votes |
private Collection<String> getCSSClasses(String classPrefix, ParserResult parserResult) { FileObject fo = parserResult.getSnapshot().getSource().getFileObject(); if(fo == null) { return Collections.emptyList(); } Project project = FileOwnerQuery.getOwner(fo); HashSet<String> unique = new HashSet<String>(); try { CssIndex cssIndex = CssIndex.create(project); Map<FileObject, Collection<String>> findIdsByPrefix = cssIndex.findClassesByPrefix(classPrefix); for (Collection<String> ids : findIdsByPrefix.values()) { for (String id : ids) { unique.add(id); } } } catch (IOException ex) { Exceptions.printStackTrace(ex); } return unique; }
Example #4
Source File: YamlKeystrokeHandler.java From netbeans with Apache License 2.0 | 6 votes |
@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; }
Example #5
Source File: JQueryCodeCompletion.java From netbeans with Apache License 2.0 | 6 votes |
private String findFunctionName(ParserResult parserResult, int offset) { TokenSequence<? extends JsTokenId> ts = LexUtilities.getJsTokenSequence(parserResult.getSnapshot().getTokenHierarchy(), offset); if (ts == null) { return null; } ts.move(offset); if (!(ts.moveNext() && ts.movePrevious())) { return null; } Token<? extends JsTokenId> token = LexUtilities.findNext(ts, Arrays.asList(JsTokenId.WHITESPACE)); while(token.id() != JsTokenId.EOL && token.id() != JsTokenId.BRACKET_LEFT_PAREN) { if (token.id() == JsTokenId.OPERATOR_DOT) { // we are not inside () return null; } token = LexUtilities.findNext(ts, Arrays.asList(JsTokenId.WHITESPACE)); } if (token.id() == JsTokenId.BRACKET_LEFT_PAREN && ts.movePrevious()) { token = LexUtilities.findNext(ts, Arrays.asList(JsTokenId.WHITESPACE)); if (token.id() == JsTokenId.IDENTIFIER){ return token.text().toString(); } } return null; }
Example #6
Source File: GsfHintsProvider.java From netbeans with Apache License 2.0 | 6 votes |
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); } }
Example #7
Source File: GsfHintsManager.java From netbeans with Apache License 2.0 | 6 votes |
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; }
Example #8
Source File: CslTestBase.java From netbeans with Apache License 2.0 | 6 votes |
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"); } }); }
Example #9
Source File: HtmlRenameHandler.java From netbeans with Apache License 2.0 | 5 votes |
@Override public boolean isRenameAllowed(ParserResult info, int caretOffset, String[] explanationRetValue) { int astCaretOffset = info.getSnapshot().getEmbeddedOffset(caretOffset); if (astCaretOffset == -1) { return false; } HtmlParserResult result = (HtmlParserResult) info; Element node = result.findByPhysicalRange(astCaretOffset, true); if (node == null) { return false; } switch (node.type()) { case OPEN_TAG: OpenTag ot = (OpenTag)node; //enable only if the caret is in the tag name int from = node.from(); int to = from + 1 + ot.name().length() ; //"<" + "body" length return astCaretOffset >= from && astCaretOffset <= to; case CLOSE_TAG: return true; } return false; }
Example #10
Source File: InstantRenamerImpl.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Set<OffsetRange> getRenameRegions(ParserResult info, int caretOffset) { Set<OffsetRange> retval = new HashSet<>(); for (Occurence occurence : allOccurences) { retval.add(occurence.getOccurenceRange()); } allOccurences.clear(); return retval; }
Example #11
Source File: TwigCompletionHandler.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Documentation documentElement(ParserResult parserResult, ElementHandle elementHandle, Callable<Boolean> cancel) { Documentation result = null; if (elementHandle instanceof TwigElement) { result = Documentation.create(((TwigElement) elementHandle).getDocumentation().asText(), documentationUrl); } return result; }
Example #12
Source File: CompletionContext.java From netbeans with Apache License 2.0 | 5 votes |
private AstPath getPath(ParserResult parseResult, BaseDocument doc, int astOffset) { ASTNode root = ASTUtils.getRoot(parseResult); // in some cases we can not repair the code, therefore root == null // therefore we can not complete. See # 131317 if (root == null) { return null; } return new AstPath(root, astOffset, doc); }
Example #13
Source File: BreadCrumbsTask.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void run(final ParserResult result, final SchedulerEvent event) { runWithCancelService(new Runnable() { @Override public void run() { resume(); final long id = requestId.incrementAndGet(); final Document doc = result.getSnapshot().getSource().getDocument(false); if (doc == null || !BreadcrumbsController.areBreadCrumsEnabled(doc)) return ; final int caret; if (event instanceof CursorMovedSchedulerEvent) { caret = ((CursorMovedSchedulerEvent) event).getCaretOffset(); } else { //XXX: outside AWT! JTextComponent c = EditorRegistry.focusedComponent(); if (c != null && c.getDocument() == doc) caret = c.getCaretPosition(); else caret = (-1); } if (caret == (-1)) return ; final StructureItem structureRoot = computeStructureRoot(result.getSnapshot().getSource()); if (structureRoot == null) return ; WORKER.post(new Runnable() { @Override public void run() { selectNode(doc, structureRoot, id, caret); } }); } }); }
Example #14
Source File: SemiAttribute.java From netbeans with Apache License 2.0 | 5 votes |
public static SemiAttribute semiAttribute(ParserResult info, int stopOffset) { SemiAttribute a = new SemiAttribute(info, stopOffset); try { a.scan(Utils.getRoot(info)); } catch (Stop s) { } return a; }
Example #15
Source File: JadeCodeCompletion.java From netbeans with Apache License 2.0 | 5 votes |
@Override public String getPrefix(ParserResult info, int caretOffset, boolean upToOffset) { String prefix = null; BaseDocument doc = (BaseDocument) info.getSnapshot().getSource().getDocument(false); if (doc == null) { return null; } //caretOffset = info.getSnapshot().getEmbeddedOffset(caretOffset); TokenSequence<? extends JadeTokenId> ts = info.getSnapshot().getTokenHierarchy().tokenSequence(JadeTokenId.jadeLanguage()); if (ts == null) { return null; } int offset = info.getSnapshot().getEmbeddedOffset(caretOffset); ts.move(offset); if (!ts.moveNext() && !ts.movePrevious()) { return null; } if (ts.offset() == offset) { // We're looking at the offset to the RIGHT of the caret // and here I care about what's on the left ts.movePrevious(); } Token<? extends JadeTokenId> token = ts.token(); if (token.id() == JadeTokenId.TAG || token.id().isKeyword()) { prefix = token.text().toString(); if (upToOffset) { if (offset - ts.offset() >= 0) { prefix = prefix.substring(0, offset - ts.offset()); } } } return prefix; }
Example #16
Source File: DeclarationFinderImpl.java From netbeans with Apache License 2.0 | 5 votes |
public static DeclarationLocation findDeclarationImpl(ParserResult info, int caretOffset) { if (!(info instanceof PHPParseResult)) { return DeclarationLocation.NONE; } PHPParseResult result = (PHPParseResult) info; final Model model = result.getModel(Model.Type.COMMON); OccurencesSupport occurencesSupport = model.getOccurencesSupport(caretOffset); Occurence underCaret = occurencesSupport.getOccurence(); return findDeclarationImpl(underCaret, info); }
Example #17
Source File: OverridingMethodsImpl.java From netbeans with Apache License 2.0 | 5 votes |
/** * @return the inheritedByTypes */ private Set<TypeElement> getInheritedByTypes(final ParserResult info, final TypeScope type) { final String signature = type.getIndexSignature(); if (signature != null && !signature.equals(classSignatureForInheritedByTypes)) { Index index = ElementQueryFactory.getIndexQuery(info); inheritedByTypes = index.getInheritedByTypes(type); } classSignatureForInheritedByTypes = signature; return inheritedByTypes; }
Example #18
Source File: YamlScanner.java From netbeans with Apache License 2.0 | 5 votes |
@Override public List<? extends StructureItem> scan(ParserResult info) { YamlParserResult result = (YamlParserResult) info; if (result != null) { return result.getItems(); } return Collections.emptyList(); }
Example #19
Source File: PHPCodeCompletion.java From netbeans with Apache License 2.0 | 5 votes |
@Override public ParameterInfo parameters(final ParserResult info, final int caretOffset, CompletionProposal proposal) { final org.netbeans.modules.php.editor.model.Model model = ((PHPParseResult) info).getModel(); ParameterInfoSupport infoSupport = model.getParameterInfoSupport(caretOffset); ParameterInfo parameterInfo = infoSupport.getParameterInfo(); return parameterInfo == null ? ParameterInfo.NONE : parameterInfo; }
Example #20
Source File: OverridingMethodsImpl.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Collection<? extends AlternativeLocation> overrides(ParserResult info, ElementHandle handle) { assert handle instanceof ModelElement; if (handle instanceof MethodScope) { MethodScope method = (MethodScope) handle; final ElementFilter methodNameFilter = ElementFilter.forName(NameKind.exact(method.getName())); final Set<MethodElement> overridenMethods = methodNameFilter.filter(getInheritedMethods(info, method)); List<AlternativeLocation> retval = new ArrayList<>(); for (MethodElement methodElement : overridenMethods) { retval.add(MethodLocation.newInstance(methodElement)); } return retval; } return null; }
Example #21
Source File: SanitizeSourceTest.java From netbeans with Apache License 2.0 | 5 votes |
protected String getTestResult(String filename, String caretLine) throws Exception { FileObject testFile = getTestFile("testfiles/" + filename + ".php"); Source testSource = getTestSource(testFile); final int caretOffset; if (caretLine != null) { caretOffset = getCaretOffset(testSource.createSnapshot().getText().toString(), caretLine); enforceCaretOffset(testSource, caretOffset); } else { caretOffset = -1; } final StringBuffer textresult = new StringBuffer(); ParserManager.parse(Collections.singleton(testSource), new UserTask() { public @Override void run(ResultIterator resultIterator) throws Exception { Parser.Result r = caretOffset == -1 ? resultIterator.getParserResult() : resultIterator.getParserResult(caretOffset); if (r != null) { assertTrue(r instanceof ParserResult); PHPParseResult phpResult = (PHPParseResult)r; Program program = phpResult.getProgram(); if (program != null) { textresult.append((new PrintASTVisitor()).printTree(program, 0)); } else { textresult.append("Program is null"); } } } }); return textresult.toString(); }
Example #22
Source File: TableGenerator.java From netbeans with Apache License 2.0 | 5 votes |
private String findConnVariableInScope() { final List<String> connVariables = new ArrayList<>(); try { ParserManager.parse(Collections.singleton(Source.create(component.getDocument())), new UserTask() { @Override public void run(ResultIterator resultIterator) throws Exception { ParserResult info = (ParserResult) resultIterator.getParserResult(); if (info != null) { ASTNodeUtilities.getVariablesInScope(info, component.getCaretPosition(), new VariableAcceptor() { @Override public boolean acceptVariable(String variableName) { if (variableName.contains("conn")) { // NOI18N connVariables.add(variableName); } return false; } }); } } }); } catch (ParseException ex) { Exceptions.printStackTrace(ex); return null; } if (connVariables.contains("conn")) { // NOI18N return "conn"; // NOI18N } if (connVariables.contains("connection")) { // NOI18N return "connection"; // NOI18N } for (String connVariable : connVariables) { return connVariable; } return null; }
Example #23
Source File: JadeStructureScanner.java From netbeans with Apache License 2.0 | 5 votes |
private void appendFold(ParserResult info, Map<String, List<OffsetRange>> folds, String kind, int startOffset, int endOffset) { if (startOffset >= 0 && endOffset >= startOffset) { if (info.getSnapshot().getText().subSequence(startOffset, endOffset).toString().indexOf('\n') > -1) { getRanges(folds, kind).add(new OffsetRange(startOffset, endOffset)); } } }
Example #24
Source File: PHPCodeCompletion.java From netbeans with Apache License 2.0 | 5 votes |
private int findBaseNamespaceEnd(ParserResult info, int caretOffset) { TokenHierarchy<?> th = info.getSnapshot().getTokenHierarchy(); assert th != null; TokenSequence<PHPTokenId> tokenSequence = LexUtilities.getPHPTokenSequence(th, caretOffset); assert tokenSequence != null; tokenSequence.move(caretOffset); final boolean moveNextSucces = tokenSequence.moveNext(); if (!moveNextSucces && !tokenSequence.movePrevious()) { assert false; return caretOffset; } boolean hasCurly = false; while (tokenSequence.movePrevious()) { if (!hasCurly) { if (tokenSequence.token().id() == PHPTokenId.PHP_CURLY_OPEN) { hasCurly = true; } } else { // possibly some whitespace before curly open? if (tokenSequence.token().id() != PHPTokenId.WHITESPACE) { tokenSequence.moveNext(); break; } } } if (hasCurly) { return tokenSequence.offset(); } assert false; return caretOffset; }
Example #25
Source File: ClassMemberNavigatorSourceFactory.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void run(ParserResult result, SchedulerEvent event) { SpiSupportAccessor.getInstance().setCancelSupport(cancel); try { final ElementScanningTask t = getTask(); if (t != null) { t.run(result, event); } } finally { SpiSupportAccessor.getInstance().removeCancelSupport(cancel); } }
Example #26
Source File: GroovyInstantRenamer.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Set<OffsetRange> getRenameRegions(ParserResult info, int caretOffset) { LOG.log(Level.FINEST, "getRenameRegions()"); //NOI18N GroovyParserResult gpr = ASTUtils.getParseResult(info); BaseDocument doc = LexUtilities.getDocument(gpr, false); if (doc == null) { return Collections.emptySet(); } AstPath path = getPathUnderCaret(gpr, caretOffset); return markOccurences(path, doc, caretOffset); }
Example #27
Source File: LatteCompletionHandler.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Documentation documentElement(ParserResult info, ElementHandle element, Callable<Boolean> cancel) { Documentation result = null; if (element instanceof LatteElement) { result = Documentation.create(((LatteElement) element).getDocumentationText(), documentationUrl); } return result; }
Example #28
Source File: JsCodeCompletion.java From netbeans with Apache License 2.0 | 5 votes |
@Override public String document(ParserResult info, ElementHandle element) { Documentation doc = documentElement(info, element, new Callable<Boolean>() { @Override public Boolean call() throws Exception { return false; } }); if (doc != null) { return doc.getContent(); } return null; }
Example #29
Source File: CslTestBase.java From netbeans with Apache License 2.0 | 5 votes |
protected void initializeTypeNodes(ParserResult info, List<Object> nodes, Map<Object,OffsetRange> positions, Map<Object,String> types) throws Exception { // Override in your test // Associate type descriptions with a bunch of nodes. // For every node that has an associated type, add position and description information about it. // This will then be used to generate type hints in the source }
Example #30
Source File: LatteCompletionHandler.java From netbeans with Apache License 2.0 | 4 votes |
@Override public String document(ParserResult info, ElementHandle element) { return null; }