/** * Run any IJPTreeParser against the AST. This will call parse() if the JPNode AST has not already been built. */ public void treeParser(IJPTreeParser tp) throws ANTLRException { LOGGER.trace("Entering ParseUnit#treeParser()"); if (this.getTopNode() == null) parse(); tp.program(getTopNode()); LOGGER.trace("Exiting ParseUnit#treeParser()"); }
/** * Run any IJPTreeParser against the AST. This will call parse() if the JPNode AST has not already been built. */ public void treeParser(IJPTreeParser tp) throws ANTLRException { LOGGER.trace("Entering ParseUnit#treeParser()"); if (this.getTopNode() == null) parse(); tp.program(getTopNode()); LOGGER.trace("Exiting ParseUnit#treeParser()"); }
/** * Run TreeParser01. Takes care of calling parse() first, if that has not already been done. */ public void treeParser01() throws ANTLRException { LOGGER.trace("Entering ParseUnit#treeParser01()"); if (this.getTopNode() == null) parse(); ITreeParserAction action = new TP01Support(session, this); TreeParser01 tp = new TreeParser01(action); treeParser(tp); LOGGER.trace("Exiting ParseUnit#treeParser01()"); }
private void generateProparseDebugFile(InputFile file, ParseUnit unit) { String fileName = ".proparse/" + file.relativePath() + ".json"; File dbgFile = new File(fileName); dbgFile.getParentFile().mkdirs(); try (PrintWriter writer = new PrintWriter(dbgFile)) { JsonNodeLister nodeLister = new JsonNodeLister(unit.getTopNode(), writer, ABLNodeType.LEFTPAREN, ABLNodeType.RIGHTPAREN, ABLNodeType.COMMA, ABLNodeType.PERIOD, ABLNodeType.LEXCOLON, ABLNodeType.OBJCOLON, ABLNodeType.THEN, ABLNodeType.END); nodeLister.print(); debugFiles.add(file.relativePath() + ".json"); } catch (IOException caught) { LOG.error("Unable to write proparse debug file", caught); } }
/** * Run TreeParser01. Takes care of calling parse() first, if that has not already been done. */ public void treeParser01() throws ANTLRException { LOGGER.trace("Entering ParseUnit#treeParser01()"); if (this.getTopNode() == null) parse(); ITreeParserAction action = new TP01Support(session, this); TreeParser01 tp = new TreeParser01(action); treeParser(tp); LOGGER.trace("Exiting ParseUnit#treeParser01()"); }
/** * Run TreeParser01 with any TP01Action object. Takes care of calling parse() first, if that has not already been * done. */ public void treeParser01(ITreeParserAction action) throws ANTLRException { if (this.getTopNode() == null) parse(); TreeParser01 tp = new TreeParser01(action); treeParser(tp); }
/** * Run TreeParser01 with any TP01Action object. Takes care of calling parse() first, if that has not already been * done. */ public void treeParser01(ITreeParserAction action) throws ANTLRException { if (this.getTopNode() == null) parse(); TreeParser01 tp = new TreeParser01(action); treeParser(tp); }
private void computeCpd(SensorContext context, InputFile file, ParseUnit unit) { CPDCallback cpdCallback = new CPDCallback(context, file, settings, unit); unit.getTopNode().walk(cpdCallback); cpdCallback.getResult().save(); }
@Override public void execute(InputFile file, ParseUnit unit) { if (unit.getTransactionBlocks() == null) return; for (JPNode node : unit.getTopNode().queryStateHead(ABLNodeType.TRIGGER)) { if (node.getFirstChild().getNodeType() == ABLNodeType.PROCEDURE) { return; } } for (Integer line : unit.getTransactionBlocks()) { if (line == 0) { reportIssue(file, "Transaction scope of main block spans the entire procedure"); } } }
@SuppressWarnings({"unchecked", "rawtypes"}) private void computeComplexity(SensorContext context, InputFile file, ParseUnit unit) { // Interfaces don't contribute to complexity if (unit.getRootScope().isInterface()) return; int complexity = 0; int complexityWithInc = 0; // Procedure has a main block, so starting at 1 if (!unit.getRootScope().isClass()) { complexity++; complexityWithInc++; } complexity += unit.getTopNode().queryMainFile(ABLNodeType.IF, ABLNodeType.REPEAT, ABLNodeType.FOR, ABLNodeType.WHEN, ABLNodeType.AND, ABLNodeType.OR, ABLNodeType.RETURN, ABLNodeType.PROCEDURE, ABLNodeType.FUNCTION, ABLNodeType.METHOD, ABLNodeType.ENUM).size(); complexityWithInc += unit.getTopNode().query(ABLNodeType.IF, ABLNodeType.REPEAT, ABLNodeType.FOR, ABLNodeType.WHEN, ABLNodeType.AND, ABLNodeType.OR, ABLNodeType.RETURN, ABLNodeType.PROCEDURE, ABLNodeType.FUNCTION, ABLNodeType.METHOD, ABLNodeType.ENUM).size(); context.newMeasure().on(file).forMetric((Metric) CoreMetrics.COMPLEXITY).withValue(complexity).save(); context.newMeasure().on(file).forMetric((Metric) OpenEdgeMetrics.COMPLEXITY).withValue(complexityWithInc).save(); }
@Override public void execute(InputFile file, ParseUnit unit) { if (unit.getRootScope().isInterface() || unit.getRootScope().isAbstractClass()) { for (JPNode node : unit.getTopNode().queryStateHead(ABLNodeType.METHOD)) { JPNode lastChild = node.getLastDescendant(); if (lastChild.getNodeType() == ABLNodeType.LEXCOLON) { reportIssue(file, node, "METHOD ending with colon instead of period"); } } } }
generateProparseFlatFiles(unit.getTopNode(), unit.getSupport(), false, InputFileUtils.getRelativePath(file, context.fileSystem()));
@SuppressWarnings({"unchecked", "rawtypes"}) private void computeCommonMetrics(SensorContext context, InputFile file, ParseUnit unit) { context.newMeasure().on(file).forMetric((Metric) CoreMetrics.STATEMENTS).withValue( unit.getTopNode().queryStateHead().size()).save(); int numProcs = 0; int numFuncs = 0;