[core] Consolidate internal api in LexException

This commit is contained in:
Andreas Dangel
2024-02-10 10:05:34 +01:00
parent 7c5bf74402
commit 2cc9ae9d7e
4 changed files with 33 additions and 4 deletions

View File

@ -314,6 +314,8 @@ package or made (package) private and are _not accessible_ anymore.
* Method `loadRuleSetsWithoutException(java.util.List)` is now package private.
* {%jdoc !!core::lang.rule.RuleSetLoadException %}
* All constructors are package private now.
* {%jdoc !!core::lang.ast.LexException %} - the constructor `LexException(boolean, String, int, int, String, char)` is now package private.
It is only used by JavaCC-generated token managers.
* pmd-ant
* {%jdoc !!ant::ant.Formatter %}
* Method `getRenderer()` has been removed.

View File

@ -283,7 +283,7 @@
<!-- Use own LexException instead of JavaCC's TokenMgrError -->
<replaceregexp>
<regexp pattern='throw new TokenMgrError\(EOFSeen' />
<substitution expression='throw new net.sourceforge.pmd.lang.ast.LexException(EOFSeen' />
<substitution expression='throw net.sourceforge.pmd.lang.ast.InternalApiBridge.newLexException(EOFSeen' />
<file name="${tokenmgr-file}" />
</replaceregexp>

View File

@ -0,0 +1,27 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ast;
import net.sourceforge.pmd.annotation.InternalApi;
/**
* Internal API.
*
* <p>Acts as a bridge between outer parts of PMD and the restricted access
* internal API of this package.
*
* <p><b>None of this is published API, and compatibility can be broken anytime!</b>
* Use this only at your own risk.
*
* @apiNote Internal API
*/
@InternalApi
public final class InternalApiBridge {
private InternalApiBridge() {}
public static LexException newLexException(boolean eofSeen, String lexStateName, int errorLine, int errorColumn, String errorAfter, char curChar) {
return new LexException(eofSeen, lexStateName, errorLine, errorColumn, errorAfter, curChar);
}
}

View File

@ -9,7 +9,6 @@ import static java.lang.Math.max;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import net.sourceforge.pmd.annotation.InternalApi;
import net.sourceforge.pmd.lang.document.FileId;
import net.sourceforge.pmd.lang.document.FileLocation;
import net.sourceforge.pmd.util.StringUtil;
@ -44,9 +43,10 @@ public final class LexException extends FileAnalysisException {
/**
* Constructor called by JavaCC.
*
* @apiNote Internal API.
*/
@InternalApi
public LexException(boolean eofSeen, String lexStateName, int errorLine, int errorColumn, String errorAfter, char curChar) {
LexException(boolean eofSeen, String lexStateName, int errorLine, int errorColumn, String errorAfter, char curChar) {
super(makeReason(eofSeen, lexStateName, errorAfter, curChar));
line = max(errorLine, 1);
column = max(errorColumn, 1);