use of net.sourceforge.pmd.lang.ast.ParseException in project pmd by pmd.
the class ViewerModel method evaluateXPathExpression.
/**
* Evaluates the given XPath expression against the current tree.
*
* @param xPath
* XPath expression to be evaluated
* @param evaluator
* object which requests the evaluation
*/
public void evaluateXPathExpression(String xPath, Object evaluator) throws ParseException, JaxenException {
try {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("xPath=" + xPath);
LOGGER.finest("evaluator=" + evaluator);
}
XPath xpath = new BaseXPath(xPath, new DocumentNavigator());
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("xpath=" + xpath);
LOGGER.finest("rootNode=" + rootNode);
}
try {
evaluationResults = xpath.selectNodes(rootNode);
} catch (Exception e) {
LOGGER.finest("selectNodes problem:");
e.printStackTrace(System.err);
}
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("evaluationResults=" + evaluationResults);
}
fireViewerModelEvent(new ViewerModelEvent(evaluator, ViewerModelEvent.PATH_EXPRESSION_EVALUATED));
} catch (JaxenException je) {
je.printStackTrace(System.err);
throw je;
}
}
use of net.sourceforge.pmd.lang.ast.ParseException in project pmd by pmd.
the class EcmascriptParser method parse.
public EcmascriptNode<AstRoot> parse(final Reader reader) {
try {
final List<ParseProblem> parseProblems = new ArrayList<>();
final String sourceCode = IOUtils.toString(reader);
final AstRoot astRoot = parseEcmascript(sourceCode, parseProblems);
final EcmascriptTreeBuilder treeBuilder = new EcmascriptTreeBuilder(sourceCode, parseProblems);
EcmascriptNode<AstRoot> tree = treeBuilder.build(astRoot);
suppressMap = new HashMap<>();
if (astRoot.getComments() != null) {
for (Comment comment : astRoot.getComments()) {
int nopmd = comment.getValue().indexOf(suppressMarker);
if (nopmd > -1) {
String suppression = comment.getValue().substring(nopmd + suppressMarker.length());
EcmascriptNode<Comment> node = treeBuilder.build(comment);
suppressMap.put(node.getBeginLine(), suppression);
}
}
}
return tree;
} catch (IOException e) {
throw new ParseException(e);
}
}
use of net.sourceforge.pmd.lang.ast.ParseException in project pmd by pmd.
the class ApexParser method parse.
public ApexNode<Compilation> parse(final Reader reader) {
try {
final String sourceCode = IOUtils.toString(reader);
final Compilation astRoot = parseApex(sourceCode);
final ApexTreeBuilder treeBuilder = new ApexTreeBuilder(sourceCode);
suppressMap = new HashMap<>();
if (astRoot == null) {
throw new ParseException("Couldn't parse the source - there is not root node - Syntax Error??");
}
return treeBuilder.build(astRoot);
} catch (IOException e) {
throw new ParseException(e);
}
}
use of net.sourceforge.pmd.lang.ast.ParseException in project pmd by pmd.
the class XmlParser method parseDocument.
protected Document parseDocument(Reader reader) throws ParseException {
nodeCache.clear();
try {
String xmlData = IOUtils.toString(reader);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(parserOptions.isNamespaceAware());
dbf.setValidating(parserOptions.isValidating());
dbf.setIgnoringComments(parserOptions.isIgnoringComments());
dbf.setIgnoringElementContentWhitespace(parserOptions.isIgnoringElementContentWhitespace());
dbf.setExpandEntityReferences(parserOptions.isExpandEntityReferences());
dbf.setCoalescing(parserOptions.isCoalescing());
dbf.setXIncludeAware(parserOptions.isXincludeAware());
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
DocumentBuilder documentBuilder = dbf.newDocumentBuilder();
documentBuilder.setEntityResolver(parserOptions.getEntityResolver());
Document document = documentBuilder.parse(new InputSource(new StringReader(xmlData)));
DOMLineNumbers lineNumbers = new DOMLineNumbers(document, xmlData);
lineNumbers.determine();
return document;
} catch (ParserConfigurationException | SAXException | IOException e) {
throw new ParseException(e);
}
}
Aggregations