[plsql] Move ParsingExclusion to internal package

This commit is contained in:
Andreas Dangel
2021-03-25 16:26:38 +01:00
parent 595ab39015
commit 90675d9df0
4 changed files with 69 additions and 51 deletions

View File

@ -164,6 +164,7 @@ import java.util.ArrayList;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.SimpleCharStream;
import net.sourceforge.pmd.lang.ast.TokenMgrError;
import net.sourceforge.pmd.lang.plsql.ast.internal.ParsingExclusion;
public class PLSQLParser {
@ -249,7 +250,7 @@ PARSER_END(PLSQLParser)
TOKEN_MGR_DECLS : {
public List<ParsingExclusion> exclusions = new ArrayList<ParsingExclusion>();
List<ParsingExclusion> exclusions = new ArrayList<ParsingExclusion>();
}
@ -292,19 +293,19 @@ ASTInput Input(String sourcecode) :
("/")*
)*
<EOF>
{ jjtThis.setSourcecode(sourcecode);
{
jjtThis.setSourcecode(sourcecode);
List<ParsingExclusion> exclusions = token_source.exclusions;
if (exclusions != null) {
// System.err.println("ParsingExclusions:");
for (int i=0; i<exclusions.size(); i++) {
ParsingExclusion ex = exclusions.get(i);
// System.err.print(" Lines " + ex.beginLine + " - " + ex.endLine);
// if (ex.reason != null) {
// System.err.println(": " + ex.reason);
for (ParsingExclusion ex : exclusions) {
// System.err.print(" Lines " + ex.getBeginLine() + " - " + ex.getEndLine());
// if (ex.getReason() != null) {
// System.err.println(": " + ex.getReason());
// } else {
// System.err.println("");
// }
jjtThis.addExcludedLineRange(ex.beginLine, ex.endLine);
jjtThis.addExcludedLineRange(ex.getBeginLine(), ex.getEndLine());
}
}
return jjtThis ;

View File

@ -39,9 +39,10 @@ public class ASTInput extends net.sourceforge.pmd.lang.plsql.ast.AbstractPLSQLNo
private int excludedLinesCount = 0;
/**
Let the user know that a range of lines were excluded from parsing.
@param first First line of the exlucded line range (1-based).
@param last Last line of the exlucded line range (1-based).
* Let the user know that a range of lines were excluded from parsing.
*
* @param first First line of the excluded line range (1-based).
* @param last Last line of the excluded line range (1-based).
*/
void addExcludedLineRange(int first, int last) {
excludedLinesCount += last - first + 1;

View File

@ -1,40 +0,0 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.plsql.ast;
import java.util.Locale;
/**
* This represents an exclusion of a line range from parsing.
*/
public final class ParsingExclusion {
public static final String BEGIN_MARKER = "PMD-EXCLUDE-BEGIN";
public static final String END_MARKER = "PMD-EXCLUDE-END";
public static final int LEN_BEGIN_MARKER = BEGIN_MARKER.length();
public int beginLine;
public int endLine;
public String source = null;
/**
* The reason is the comment text in the first line after the beginMarker.
*/
public String reason = null;
public ParsingExclusion(int beginLine, int endLine, String source) {
this.beginLine = beginLine;
this.endLine = endLine;
this.source = source;
final String sourceUpper = source.toUpperCase(Locale.US);
int i1 = sourceUpper.indexOf(BEGIN_MARKER);
int i2 = sourceUpper.indexOf("\n");
this.reason = source.substring(i1 + LEN_BEGIN_MARKER, i2).trim();
if (this.reason.startsWith(":")) {
this.reason = this.reason.substring(2).trim();
}
}
}

View File

@ -0,0 +1,56 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.plsql.ast.internal;
import java.util.Locale;
/**
* This represents an exclusion of a line range from parsing.
*/
public final class ParsingExclusion {
private static final String BEGIN_MARKER = "PMD-EXCLUDE-BEGIN";
private static final String END_MARKER = "PMD-EXCLUDE-END";
private static final int LEN_BEGIN_MARKER = BEGIN_MARKER.length();
private final int beginLine;
private final int endLine;
private final String excludedSource;
private final String reason;
public ParsingExclusion(int beginLine, int endLine, String source) {
this.beginLine = beginLine;
this.endLine = endLine;
this.excludedSource = source;
final String sourceUpper = source.toUpperCase(Locale.ROOT);
int i1 = sourceUpper.indexOf(BEGIN_MARKER);
int i2 = sourceUpper.indexOf("\n");
String reason = source.substring(i1 + LEN_BEGIN_MARKER, i2).trim();
if (reason.startsWith(":")) {
this.reason = reason.substring(2).trim();
} else {
this.reason = null;
}
}
public String getExcludedSource() {
return excludedSource;
}
public int getBeginLine() {
return beginLine;
}
public int getEndLine() {
return endLine;
}
/**
* The reason is the comment text in the first line after the beginMarker.
*/
public String getReason() {
return reason;
}
}