forked from jasder/antlr
refactor for reuse, make target check majorminor only.
This commit is contained in:
parent
b6311928c1
commit
4acb1091de
|
@ -231,32 +231,6 @@ public class RuntimeMetaData {
|
|||
|
||||
return getMajorMinorVersion(VERSION).equals(getMajorMinorVersion(ex.compileTimeRuntimeVersion));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the major and minor version numbers from a version string. For
|
||||
* details about the syntax of the input {@code version}, see the
|
||||
* documentation for {@link DefaultListener}.
|
||||
*
|
||||
* @param version The complete version string.
|
||||
* @return A string of the form <em>major</em>.<em>minor</em> containing
|
||||
* only the major and minor components of the version string.
|
||||
*/
|
||||
@NotNull
|
||||
protected String getMajorMinorVersion(@NotNull String version) {
|
||||
int firstDot = version.indexOf('.');
|
||||
int secondDot = firstDot >= 0 ? version.indexOf('.', firstDot + 1) : -1;
|
||||
int firstDash = version.indexOf('-');
|
||||
int referenceLength = version.length();
|
||||
if (secondDot >= 0) {
|
||||
referenceLength = Math.min(referenceLength, secondDot);
|
||||
}
|
||||
|
||||
if (firstDash >= 0) {
|
||||
referenceLength = Math.min(referenceLength, firstDash);
|
||||
}
|
||||
|
||||
return version.substring(0, referenceLength);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -400,4 +374,31 @@ public class RuntimeMetaData {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the major and minor version numbers from a version string. For
|
||||
* details about the syntax of the input {@code version}, see the
|
||||
* documentation for {@link org.antlr.v4.runtime.RuntimeMetaData.DefaultListener}.
|
||||
* E.g., from x.y.z return x.y.
|
||||
*
|
||||
* @param version The complete version string.
|
||||
* @return A string of the form <em>major</em>.<em>minor</em> containing
|
||||
* only the major and minor components of the version string.
|
||||
*/
|
||||
@NotNull
|
||||
public static String getMajorMinorVersion(@NotNull String version) {
|
||||
int firstDot = version.indexOf('.');
|
||||
int secondDot = firstDot >= 0 ? version.indexOf('.', firstDot + 1) : -1;
|
||||
int firstDash = version.indexOf('-');
|
||||
int referenceLength = version.length();
|
||||
if (secondDot >= 0) {
|
||||
referenceLength = Math.min(referenceLength, secondDot);
|
||||
}
|
||||
|
||||
if (firstDash >= 0) {
|
||||
referenceLength = Math.min(referenceLength, firstDash);
|
||||
}
|
||||
|
||||
return version.substring(0, referenceLength);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.antlr.v4.codegen.model.RuleFunction;
|
|||
import org.antlr.v4.codegen.model.SerializedATN;
|
||||
import org.antlr.v4.misc.Utils;
|
||||
import org.antlr.v4.parse.ANTLRParser;
|
||||
import org.antlr.v4.runtime.RuntimeMetaData;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.tool.ErrorType;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
|
@ -101,7 +102,9 @@ public abstract class Target {
|
|||
public STGroup getTemplates() {
|
||||
if (templates == null) {
|
||||
String version = getVersion();
|
||||
if (version == null || !version.equals(Tool.VERSION)) {
|
||||
if ( version==null ||
|
||||
!RuntimeMetaData.getMajorMinorVersion(version).equals(RuntimeMetaData.getMajorMinorVersion(Tool.VERSION)))
|
||||
{
|
||||
gen.tool.errMgr.toolError(ErrorType.INCOMPATIBLE_TOOL_AND_TEMPLATES, version, Tool.VERSION, language);
|
||||
}
|
||||
templates = loadTemplates();
|
||||
|
|
Loading…
Reference in New Issue