public boolean reportAnalysisError(RecognitionException re, File file) { reportAnalysisError(file, re.getMessage()); return isSonarLintContext(); }
public boolean reportAnalysisError(RecognitionException re, File file) { reportAnalysisError(file, re.getMessage()); return isSonarLintContext(); }
@Override public void visitFile(@Nullable AstNode astNode) { RecognitionException parsingException = getContext().parsingException(); if (parsingException != null) { addIssueAtLine(parsingException.getMessage(), parsingException.getLine()); } }
@Override public void processRecognitionException(RecognitionException e) { getContext().createLineViolation(this, e.getMessage(), e.getLine()); }
@Override public void processRecognitionException(RecognitionException e) { getContext().createLineViolation(this, e.getMessage(), e.getLine()); }
@Override public void processRecognitionException(RecognitionException e) { getContext().createLineViolation(this, e.getMessage(), e.getLine()); }
@Override public void processRecognitionException(RecognitionException e) { getContext().createLineViolation(this, e.getMessage(), e.getLine()); }
@Override public void init() { RecognitionException parsingException = getContext().parsingException(); if (parsingException != null) { addLineIssue(parsingException.getMessage(), parsingException.getLine()); } }
@Override public void scanFile(PythonVisitorContext context) { super.scanFile(context); RecognitionException parsingException = context.parsingException(); if (parsingException != null) { addLineIssue(parsingException.getMessage(), parsingException.getLine()); } }
@Override public void scanFile(PythonVisitorContext context) { super.scanFile(context); RecognitionException parsingException = context.parsingException(); if (parsingException != null) { addLineIssue(parsingException.getMessage(), parsingException.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); } }
/** * 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 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<>(); }
/** * 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; }
public ParserAssert matches(String input) { isNotNull(); Preconditions.checkArgument(!hasTrailingWhitespaces(input), "Trailing whitespaces in input are not supported"); String expected = "Rule '" + getRuleName() + "' should match:\n" + input; try { parseTillEof(input); } catch (RecognitionException e) { String actual = e.getMessage(); throw new ParsingResultComparisonFailure(expected, actual); } return this; }
private void processRecognitionException(RecognitionException e, SensorContext sensorContext, InputFile inputFile) { if (parsingErrorRuleKey != null) { NewIssue newIssue = sensorContext.newIssue(); NewIssueLocation primaryLocation = newIssue.newLocation() .message(e.getMessage()) .on(inputFile) .at(inputFile.selectLine(e.getLine())); newIssue .forRule(parsingErrorRuleKey) .at(primaryLocation) .save(); } }
private void analyse(SensorContext sensorContext, InputFile inputFile, ProductDependentExecutor executor, List<TreeVisitor> visitors) { ActionParser<Tree> currentParser = this.parser; if (inputFile.filename().endsWith(".vue")) { currentParser = this.vueParser; } ScriptTree scriptTree; try { scriptTree = (ScriptTree) currentParser.parse(inputFile.contents()); scanFile(sensorContext, inputFile, executor, visitors, scriptTree); } catch (RecognitionException e) { checkInterrupted(e); LOG.error("Unable to parse file: " + inputFile.uri()); LOG.error(e.getMessage()); processRecognitionException(e, sensorContext, inputFile); } catch (Exception e) { checkInterrupted(e); processException(e, sensorContext, inputFile); LOG.error("Unable to analyse file: " + inputFile.uri(), e); } }
@VisibleForTesting protected void execute(SensorContext context, Checks<PhpIniCheck> checks) { PhpIniParser parser = new PhpIniParser(); FileSystem fs = context.fileSystem(); Iterable<InputFile> inputFiles = fs.inputFiles(fs.predicates().matchesPathPattern("**/php.ini")); for (InputFile inputFile : inputFiles) { PhpIniFile phpIni; try { phpIni = parser.parse(new PhpFileImpl(inputFile)); } catch (RecognitionException e) { LOG.error("Unable to parse file: " + inputFile.absolutePath()); LOG.error(e.getMessage()); continue; } for (PhpIniCheck check : checks.all()) { List<PhpIniIssue> issues = check.analyze(phpIni); saveIssues(context, inputFile, checks.ruleKey(check), issues); } } }
private PlSqlVisitorContext getPlSqlVisitorContext(InputFile inputFile) { PlSqlFile plSqlFile = SonarQubePlSqlFile.create(inputFile); PlSqlVisitorContext visitorContext; try { AstNode root = parser.parse(plSqlFile.content()); visitorContext = new PlSqlVisitorContext(root, plSqlFile, formsMetadata); } catch (RecognitionException e) { visitorContext = new PlSqlVisitorContext(plSqlFile, e, formsMetadata); LOG.error("Unable to parse file: " + inputFile.toString()); LOG.error(e.getMessage()); } catch (Exception e) { checkInterrupted(e); throw new AnalysisException("Unable to analyze file: " + inputFile.toString(), e); } catch (Throwable e) { throw new AnalysisException("Unable to analyze file: " + inputFile.toString(), e); } return visitorContext; }
private void processRecognitionException(RecognitionException e, SensorContext sensorContext, InputFile inputFile) { if (parsingErrorRuleKey != null) { NewIssue newIssue = sensorContext.newIssue(); NewIssueLocation primaryLocation = newIssue.newLocation() .message(ParsingErrorCheck.MESSAGE) .on(inputFile) .at(inputFile.selectLine(e.getLine())); newIssue .forRule(parsingErrorRuleKey) .at(primaryLocation) .save(); } sensorContext.newAnalysisError() .onFile(inputFile) .at(inputFile.newPointer(e.getLine(), 0)) .message(e.getMessage()) .save(); }