@Override public void processRecognitionException(RecognitionException e) { getContext().createLineViolation(this, e.getMessage(), e.getLine()); }
private static void checkState(boolean condition, int lineNumber, String line) { if (!condition) { throw new RecognitionException(lineNumber, "Cannot parse directive at line " + lineNumber + ":\n" + line); } }
public boolean reportAnalysisError(RecognitionException re, File file) { reportAnalysisError(file, re.getMessage()); return isSonarLintContext(); }
/** * Verifies that the actual <code>{@link com.sonar.sslr.api.Rule}</code> partially matches a given input. * * @param prefixToBeMatched the prefix that must be fully matched * @param remainingInput the remainder of the input, which is not to be matched * @return this assertion object. */ public ParserAssert matchesPrefix(String prefixToBeMatched, String remainingInput) { isNotNull(); try { PHPTree tree = (PHPTree)actual.parse(prefixToBeMatched + remainingInput); SyntaxToken lastToken = tree.getLastToken(); if (prefixToBeMatched.length() != lastToken.column() + lastToken.text().length()) { throw new RecognitionException(0, "Rule '" + getRuleName() + "' should match:\n" + prefixToBeMatched + "\nwhen followed by:\n" + remainingInput); } } catch (RecognitionException e) { throw new RecognitionException(0, e.getMessage() + "\n" + "Rule '" + getRuleName() + "' should match:\n" + prefixToBeMatched + "\nwhen followed by:\n" + remainingInput); } return this; }
@Override public void processRecognitionException(RecognitionException e) { context.addIssue(e.getLine(), this, "Parse error"); }
public boolean reportAnalysisError(RecognitionException re, File file) { reportAnalysisError(file, re.getMessage()); return isSonarLintContext(); }
@Override public void processRecognitionException(RecognitionException e) { context.addIssue(e.getLine(), this, "Parse error"); }
@Override public void processRecognitionException(RecognitionException e) { getContext().createLineViolation(this, e.getMessage(), e.getLine()); }
private void simpleScan(File file) { visitor.setCurrentFile(file); try { Tree ast = parser.parse(file); visitor.visitFile(ast); } catch (RecognitionException e) { checkInterrrupted(e); LOG.error("Unable to parse source file : " + file.getAbsolutePath()); LOG.error(e.getMessage()); parseErrorWalkAndVisit(e, file); } catch (Exception e) { checkInterrrupted(e); throw new AnalysisException(getAnalyisExceptionMessage(file), e); } }
private static void checkState(boolean condition, int lineNumber, String line) { if (!condition) { throw new RecognitionException(lineNumber, "Cannot parse directive at line " + lineNumber + ":\n" + line); } }
@Override public void processRecognitionException(RecognitionException e) { getContext().createLineViolation(this, "Parse error", e.getLine()); }
@Override public void processRecognitionException(RecognitionException e) { getContext().createLineViolation(this, e.getMessage(), e.getLine()); }
private List<Issue> analyzeFile(SensorContext sensorContext, InputFile inputFile, List<TreeVisitor> visitors) { try { TreeImpl cssTree = (TreeImpl) parser.parse(new File(inputFile.absolutePath())); return scanFile(inputFile, cssTree, visitors); } catch (RecognitionException e) { checkInterrupted(e); LOG.error("Unable to parse file: " + inputFile.absolutePath()); LOG.error(e.getMessage()); processRecognitionException(e, sensorContext, inputFile); } catch (Exception e) { checkInterrupted(e); throw new AnalysisException("Unable to analyze file: " + inputFile.absolutePath(), e); } return new ArrayList<>(); }
private static char[] fileToCharArray(File file, Charset charset) { try { return Files.toString(file, charset).toCharArray(); } catch (IOException e) { throw new RecognitionException(0, e.getMessage(), e); } }
@Override public void processRecognitionException(RecognitionException e) { getContext().createLineViolation(this, e.getMessage(), e.getLine()); }
/** * Verifies that the actual <code>{@link Parser}</code> fully matches a given input. * @return this assertion object. */ public ParserAssert matches(String input) { isNotNull(); hasRootRule(); Parser parser = createParserWithEofMatcher(); String expected = "Rule '" + getRuleName() + "' should match:\n" + input; try { parser.parse(input); } catch (RecognitionException e) { String actual = e.getMessage(); throw new ParsingResultComparisonFailure(expected, actual); } return this; }
private static char[] fileToCharArray(File file, Charset charset) { try { return new String(Files.readAllBytes(Paths.get(file.getPath())), charset).toCharArray(); } catch (IOException e) { throw new RecognitionException(0, e.getMessage(), e); } }
@Override public void visitFile(@Nullable AstNode astNode) { RecognitionException parsingException = getContext().parsingException(); if (parsingException != null) { addIssueAtLine(parsingException.getMessage(), parsingException.getLine()); } }
parseException = e; LOG.error("Unable to parse file: " + file.getAbsolutePath()); LOG.error(e.getMessage()); } catch (Exception e) { parseException = e;
private static char[] fileToCharArray(File file, Charset charset) { try { return new String(Files.readAllBytes(Paths.get(file.getPath())), charset).toCharArray(); } catch (IOException e) { throw new RecognitionException(0, e.getMessage(), e); } }