org.netbeans.modules.parsing.spi.ParseException Java Examples

The following examples show how to use org.netbeans.modules.parsing.spi.ParseException. 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: Utilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Returns {@code CssParserResult}s (including the embedded ones) that
 * correspond to the given {@code ResultIterator}.
 * 
 * @param resultIterator {@code ResultIterator} to process.
 * @return {@code CssParserResult}s contained in the given {@code ResultIterator}.
 * @throws ParseException when there is a parsing problem.
 */
public static List<CssParserResult> cssParserResults(ResultIterator resultIterator)
        throws ParseException {
    List<ResultIterator> resultIterators = new ArrayList<ResultIterator>();
    resultIterators.add(resultIterator);
    for (Embedding embedding : resultIterator.getEmbeddings()) {
        String mimeType = embedding.getMimeType();
        if ("text/css".equals(mimeType)) { // NOI18N
            resultIterators.add(resultIterator.getResultIterator(embedding));
        }
    }
    List<CssParserResult> parserResults = new ArrayList<CssParserResult>(resultIterators.size());
    for (ResultIterator iterator : resultIterators) {
        Parser.Result parserResult = iterator.getParserResult();
        if (parserResult instanceof CssParserResult) {
            parserResults.add((CssParserResult)parserResult);
        }
    }
    return parserResults;
}
 
Example #2
Source File: HtmlCompletionQueryTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testEndTagsCompletionOfUndeclaredTagsMixedWithHtml() throws BadLocationException, ParseException {
        //including html content
//        assertItems("<div><x:out></|", arr("x:out"), Match.CONTAINS);
        assertItems("<div><x:out></x| </div>", arr("x:out"), Match.CONTAINS);
        assertItems("<div><x:out></x:|", arr("x:out"), Match.CONTAINS);
        assertItems("<p><x:out></x:ou| </p>", arr("x:out"), Match.CONTAINS);
        assertItems("<div><div><x:out></x:out|", arr("x:out"), Match.CONTAINS);

        //nested - the tags needs to be close, so only the closest unclosed tag is offered
        assertItems("<div><x:out><div><x:in></|", arr("x:in"), Match.CONTAINS);
        assertItems("<div><x:out><div><x:in></x:| </div></div>", arr("x:in"), Match.CONTAINS);
        assertItems("<p><x:out><x:in></|", arr("x:out"), Match.DOES_NOT_CONTAIN);
        assertItems("<p><x:out><x:in></x:|", arr("x:out"), Match.DOES_NOT_CONTAIN);

        assertItems("<x:out><div><x:in></x:in></div></|", arr("x:out"), Match.CONTAINS);
        assertItems("<x:out><div><x:in></div></x:in></x|", arr("x:out"), Match.CONTAINS); //crossed
        assertItems("<div><x:out><div><x:in></x:in></div></x:| </div>", arr("x:out"), Match.CONTAINS);
        assertItems("<p><x:out><x:in></x:in></|", arr("x:in"), Match.DOES_NOT_CONTAIN);
    }
 
Example #3
Source File: EditorSupportImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Collection<PhpType> getTypes(FileObject fo) {
    final List<PhpType> retval = new ArrayList<>();
    Source source = Source.create(fo);
    if (source != null) {
        try {
            ParserManager.parse(Collections.singleton(source), new UserTask() {
                @Override
                public void run(ResultIterator resultIterator) throws Exception {
                    Parser.Result pr = resultIterator.getParserResult();
                    if (pr != null && pr instanceof PHPParseResult) {
                        Model model = ModelFactory.getModel((PHPParseResult) pr);
                        FileScope fileScope = model.getFileScope();
                        Collection<? extends TypeScope> allTypes = ModelUtils.getDeclaredTypes(fileScope);
                        for (TypeScope typeScope : allTypes) {
                            retval.add((PhpType) getPhpType(typeScope));
                        }
                    }
                }
            });
        } catch (ParseException ex) {
            LOGGER.log(Level.WARNING, null, ex);
        }
    }
    return retval;
}
 
Example #4
Source File: CGSInfo.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Extract attributes and methods from caret enclosing class and initialize list of properties.
 */
private void findPropertyInScope() {
    FileObject file = NavUtils.getFile(textComp.getDocument());
    if (file == null) {
        return;
    }
    try {
        ParserManager.parse(Collections.singleton(Source.create(textComp.getDocument())), new UserTask() {

            @Override
            public void run(ResultIterator resultIterator) throws Exception {
                initProperties(resultIterator);
            }
        });
    } catch (ParseException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example #5
Source File: LatteVariableCompletionProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void parsePresenter(FileObject presenterFile) throws ParseException {
    ParserManager.parse(Collections.singleton(Source.create(presenterFile)), new UserTask() {

        @Override
        public void run(ResultIterator resultIterator) throws Exception {
            PHPParseResult parseResult = (PHPParseResult) resultIterator.getParserResult();
            PresenterVisitor presenterVisitor = new PresenterVisitor(templateFile);
            presenterVisitor.scan(parseResult.getProgram());
            for (MethodDeclaration methodToScan : presenterVisitor.getMethodsToScan()) {
                VariableVisitor variableVisitor = new VariableVisitor(parseResult.getModel(), variablePrefix);
                methodToScan.accept(variableVisitor);
                result.addAll(variableVisitor.getVariables());
            }
        }
    });
}
 
Example #6
Source File: JavaSource.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static long createTaggedController(final FileObject fo, int position, final long timestamp, final Object[] controller) throws IOException {
    ClasspathInfo cpi = ClasspathInfo.create(fo);
    Collection<Source> sources = Collections.singleton(Source.create(fo));
    CompilationController cc = (CompilationController) controller[0];
    final NewComilerTask _task = new NewComilerTask(cpi, position, cc, timestamp);
    try {
        ParserManager.parse(sources, _task);
        controller[0] = _task.getCompilationController();
        return _task.getTimeStamp();
    } catch (final ParseException pe) {
        final Throwable rootCase = pe.getCause();
        if (rootCase instanceof CompletionFailure) {
            throw new IOException (rootCase);
        } else if (rootCase instanceof RuntimeException) {
            throw (RuntimeException) rootCase;
        } else {
            throw new IOException (rootCase);
        }
    }
}
 
Example #7
Source File: RefactoringTask.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        if (!cancelled) {
            future = ParserManager.parseWhenScanFinished(Collections.singleton(source), userTask);
        }
    } catch (ParseException e) {
        LOG.log(Level.WARNING, null, e);
    }
}
 
Example #8
Source File: W3CSelectorsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void tests_css3_modsel_49_xml() throws BadLocationException, ParseException {
    String code = "@namespace html url(http://www.w3.org/1999/xhtml);"
            + "@namespace a url(http://www.example.org/a);"
            + "@namespace b url(http://www.example.org/b);"
            + "div.stub > *|* { background-color : lime ; display : block ;"
            + "                 margin-bottom : 1em }"
            + "div.stub > *|*:not() { background-color : red }"
            + "/* yes, the rule just above selects nothing... That's the point */"
            + "";
    assertResultOK(TestUtil.parse(code));
}
 
Example #9
Source File: W3CSelectorsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void tests_css3_modsel_74b_xml() throws BadLocationException, ParseException {
    String code = ".green { background-color : lime ! important; }"
            + "ul > li:not(:nth-last-child(odd)) { background-color : red }"
            + "ol > li:not(:nth-last-child(even)) { background-color : red }"
            + "table.t1 tr:not(:nth-last-child(-n+4)) { background-color : red }"
            + "table.t2 td:not(:nth-last-child(3n+1)) { background-color : red }"
            + "table.t1 td, table.t2 td { border : thin black solid }"
            + "";
    assertResultOK(TestUtil.parse(code));
}
 
Example #10
Source File: ScssCompletionTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testPseudoForParentSelectorNoPrefix() throws ParseException {
    assertCompletion("#main {\n"
            + "    &:|\n"
            + "\n"
            + "}", Match.CONTAINS, "hover");

    //pseudo element w/o prefix
    assertCompletion("#main {\n"
            + "    &::|\n"
            + "\n"
            + "}", Match.CONTAINS, "first-line");

}
 
Example #11
Source File: W3CSelectorsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void tests_css3_modsel_104b_xml() throws BadLocationException, ParseException {
    String code = "@namespace a url(http://www.example.org/a);"
            + "@namespace b url(http://www.example.org/b);"
            + "@namespace html url(http://www.w3.org/1999/xhtml);"
            + "*|p, *|q, *|r, *|s { display : block ; margin-bottom : 1em }"
            + "*|p, *|r, *|s { background-color : lime ! important }"
            + "*|*[*|title] { background-color : red }"
            + "";
    assertResultOK(TestUtil.parse(code));
}
 
Example #12
Source File: GoToSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static String getGoToElementTooltip(final Document doc, final int offset, final boolean goToSource, final HyperlinkType type) {
    try {
        final FileObject fo = getFileObject(doc);

        if (fo == null) {
            return null;
        }

        final String[] result = new String[1];

        ParserManager.parse(Collections.singleton (Source.create(doc)), new UserTask() {
            @Override
            public void run(ResultIterator resultIterator) throws Exception {
                Result res = resultIterator.getParserResult (offset);
                CompilationController controller = res != null ? CompilationController.get(res) : null;
                if (controller == null || controller.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) {
                    return;
                }

                Context resolved = resolveContext(controller, doc, offset, goToSource, true);

                if (resolved != null) {
                    result[0] = computeTooltip(controller, doc, resolved, type);
                }
            }
        });

        return result[0];
    } catch (ParseException ex) {
        throw new IllegalStateException(ex);
    }
}
 
Example #13
Source File: Css3ParserScssTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testSassInclude() throws ParseException, BadLocationException {
    assertParses(".clz { @include extjs-button-ui(\n"
            + "    $ui: 'default-small',\n"
            + "\n"
            + "    $border-radius: $button-small-border-radius,\n"
            + "    $border-width: $button-small-border-width); }");
}
 
Example #14
Source File: W3CSelectorsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void tests_css3_modsel_139_xml() throws BadLocationException, ParseException {
    String code = "@namespace a url(http://www.example.org/a);"
            + "@namespace b url(http://www.example.org/b);"
            + "@namespace html url(http://www.w3.org/1999/xhtml);"
            + "*|p, *|address, *|q, *|r { display : block ; margin-bottom : 1em }"
            + "*|address, *|r { background-color : red }"
            + "div.stub *|*:not([|class~=\"foo\"]) { background-color : lime }";
    assertResultOK(TestUtil.parse(code));
}
 
Example #15
Source File: W3CSelectorsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void tests_css3_modsel_96b_xml() throws BadLocationException, ParseException {
    String code = "@namespace a url(http://www.example.org/a);"
            + "@namespace b url(http://www.example.org/b);"
            + "div.green * { background-color : lime ! important }"
            + "div.test * { display : block ; margin-bottom : 1em }"
            + "div.test |* { background-color : red }";
    assertResultOK(TestUtil.parse(code));
}
 
Example #16
Source File: TableStatus.java    From cakephp3-netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void scan(PhpModule phpModule, FileObject fileObject, int offset) {
    clear();
    TableVisitor tableVisitor = new TableVisitor(phpModule);
    try {
        scan(tableVisitor, fileObject);
    } catch (ParseException ex) {
        Exceptions.printStackTrace(ex);
    }
    addTables(tableVisitor.getTables());
    addBehaviors(tableVisitor.getBehaviors());

}
 
Example #17
Source File: CssCompletionTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testAtRules() throws ParseException {
    checkCC("|", AT_RULES, Match.CONTAINS);
    checkCC("@| ", AT_RULES, Match.CONTAINS);
    checkCC("@pa| ", new String[]{"@page"}, Match.EXACT);

    checkCC("|  h1 { }", AT_RULES, Match.CONTAINS);
    checkCC("@| h1 { }", AT_RULES, Match.CONTAINS);
    checkCC("@pa| h1 { }", new String[]{"@page"}, Match.CONTAINS);
}
 
Example #18
Source File: W3CSelectorsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void tests_css3_modsel_18_xml() throws BadLocationException, ParseException {
    String code = "p:hover { background-color : lime }"
            + "a:hover { background-color : lime }"
            + ""
            + "tr:hover { background-color : green }"
            + "td:hover { background-color : lime }"
            + ""
            + "table { border-spacing: 5px; }";
    assertResultOK(TestUtil.parse(code));
}
 
Example #19
Source File: W3CSelectorsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void tests_css3_modsel_127b_xml() throws BadLocationException, ParseException {
    String code = "@namespace a url(http://www.example.org/a);"
            + "@namespace b url(http://www.example.org/b);"
            + "@namespace html url(http://www.w3.org/1999/xhtml);"
            + "*|p, *|q, *|r, *|s { display : block ; margin-bottom : 1em }"
            + "*|q, *|s { background-color : lime ! important }"
            + "div.stub *|*:not([a|title^=\"si on\"]) { background-color : red }"
            + "";
    assertResultOK(TestUtil.parse(code));
}
 
Example #20
Source File: W3CSelectorsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void tests_css3_modsel_106_xml() throws BadLocationException, ParseException {
    String code = "@namespace a url(http://www.example.org/a);"
            + "@namespace b url(http://www.example.org/b);"
            + "@namespace html url(http://www.w3.org/1999/xhtml);"
            + "*|p, *|q, *|r, *|s { display : block ; margin-bottom : 1em }"
            + "*|p, *|r, *|s { background-color : red }"
            + "*|*[*|class~=\"deux\"], *|*[*|foo~=\"deux\"] { background-color : lime }"
            + "";
    assertResultOK(TestUtil.parse(code));
}
 
Example #21
Source File: W3CSelectorsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void tests_css3_modsel_149_xml() throws BadLocationException, ParseException {
    String code = ""
            + " address:empty { background: lime; }"
            + " address { background: red; margin: 0; height: 1em; }"
            + " .text { margin: -1em 0 0 0; }"
            + "";
    assertResultOK(TestUtil.parse(code));
}
 
Example #22
Source File: LessCompletionTest2.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testImportCompletion() throws ParseException {
    FileObject cssFile = getTestFile("testProject/public_html/test.less");
    Document document = getDocumentForFileObject(cssFile);
    
    setDocumentContent(document, "@import |");
    assertCompletion(document, Match.CONTAINS, "\"test1.scss\";");
    
    setDocumentContent(document, "@import | ");
    assertCompletion(document, Match.CONTAINS, "\"test1.scss\";");
    
}
 
Example #23
Source File: W3CSelectorsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void tests_css3_modsel_173a_xml() throws BadLocationException, ParseException {
    String code = ""
            + " tests, tests * { display: block; color: red; }"
            + " testA[*|attribute] { color: green; }"
            + " testB[*|attribute=\"pass\"] { color: green; }"
            + " testC[*|attribute~=\"pass\"] { color: green; }"
            + " testD[*|attribute^=\"pass\"] { color: green; }"
            + " testE[*|attribute*=\"pass\"] { color: green; }"
            + " testF[*|attribute$=\"pass\"] { color: green; }"
            + " testG[*|attribute|=\"pass\"] { color: green; }"
            + "";
    assertResultOK(TestUtil.parse(code));
}
 
Example #24
Source File: W3CSelectorsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void tests_css3_modsel_172a_xml() throws BadLocationException, ParseException {
    String code = ""
            + " tests, tests * { display: block; color: green; }"
            + " testA[|attribute] { color: red; }"
            + " testB[|attribute=\"fail\"] { color: red; }"
            + " testC[|attribute~=\"fail\"] { color: red; }"
            + " testD[|attribute^=\"fail\"] { color: red; }"
            + " testE[|attribute*=\"fail\"] { color: red; }"
            + " testF[|attribute$=\"fail\"] { color: red; }"
            + " testG[|attribute|=\"fail\"] { color: red; }"
            + "";
    assertResultOK(TestUtil.parse(code));
}
 
Example #25
Source File: W3CSelectorsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void tests_css3_modsel_172b_xml() throws BadLocationException, ParseException {
    String code = ""
            + " @namespace url(http://css.example.net/);"
            + " tests, tests * { display: block; color: green; }"
            + " testA[|attribute] { color: red; }"
            + " testB[|attribute=\"fail\"] { color: red; }"
            + " testC[|attribute~=\"fail\"] { color: red; }"
            + " testD[|attribute^=\"fail\"] { color: red; }"
            + " testE[|attribute*=\"fail\"] { color: red; }"
            + " testF[|attribute$=\"fail\"] { color: red; }"
            + " testG[|attribute|=\"fail\"] { color: red; }"
            + "";
    assertResultOK(TestUtil.parse(code));
}
 
Example #26
Source File: PropertiesATest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testCursorNewProperties() throws ParseException {
    String code = "span.wait {\n"
            + "    cursor:url(smiley.gif),url(myBall.cur),auto;\n"
            + "    cursor: zoom-in;\n"
            + "    cursor: zoom-out;\n"
            + "    cursor: grab;\n"
            + "    cursor: grabbing;\n"
            + "}";
    assertCssCode(code);
}
 
Example #27
Source File: CssCompletionTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testCompletionInURL() throws ParseException {
    FileObject cssFile = getTestFile("testfiles/testHtmlApplication/public_html/style.css");
    Document document = getDocumentForFileObject(cssFile);
    
    setDocumentContent(document, "div {\n"
            + "    content: u|rl(\"image.png\");\n"
            + "}");
    assertCompletion(document, Match.EMPTY);
}
 
Example #28
Source File: W3CSelectorsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void tests_css3_modsel_32_xml() throws BadLocationException, ParseException {
    String code = ".red { background-color : red }"
            + ".t1 td:first-child { background-color : lime }"
            + "p > *:first-child { background-color : lime }"
            + "";
    assertResultOK(TestUtil.parse(code));
}
 
Example #29
Source File: Css3ParserTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testErrorRecoveryBetweenrules() throws ParseException, BadLocationException {
        String content = "h1 { color: red} ; h2 { color: blue }";
        //                                 ^ -- semicolon not allowed here

        CssParserResult result = TestUtil.parse(content);
//        TestUtil.dumpResult(result);

        //commented out since it currently fails
        //assertResult(result, 0);
    }
 
Example #30
Source File: W3CSelectorsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void tests_css3_modsel_135b_xml() throws BadLocationException, ParseException {
    String code = "@namespace a url(http://www.example.org/a);"
            + "@namespace b url(http://www.example.org/b);"
            + "@namespace html url(http://www.w3.org/1999/xhtml);"
            + "*|p, *|q, *|r, *|s, *|t{ display : block ; margin-bottom : 1em }"
            + "*|p.red, *|q, *|t { background-color : lime ! important }"
            + "div.stub *|*:not([*|title$=\"tait\"]) { background-color : red }";
    assertResultOK(TestUtil.parse(code));
}