diff --git a/.github/workflows/gradle-release-manual.yml b/.github/workflows/gradle-release-manual.yml index c9effb7c8a6..fb7294d2834 100644 --- a/.github/workflows/gradle-release-manual.yml +++ b/.github/workflows/gradle-release-manual.yml @@ -160,8 +160,10 @@ jobs: cache-read-only: false cache-overwrite-existing: true - # Cache cross-platform JDK and JavaFX jmod archives downloaded by - # downloadJdk_* / downloadJavaFXMods_* tasks. These are pinned by + # Cache the host-platform JDK and JavaFX jmod archives downloaded by + # the downloadJdk / downloadJfxMods tasks. Filenames are stamped with + # ${hostOs}_${hostArch}, so each runner OS gets its own cache bucket + # via the runner-keyed actions/cache key. These are pinned by # javaVersion (gradle.properties) and the URL templates (build.gradle), # so keying on those file hashes invalidates correctly when we bump # the JDK or JavaFX version. We cache only the archives (.tar.gz / .zip) diff --git a/.github/workflows/gradle-release.yml b/.github/workflows/gradle-release.yml index 704e4656018..5d92dcb5aac 100644 --- a/.github/workflows/gradle-release.yml +++ b/.github/workflows/gradle-release.yml @@ -130,8 +130,10 @@ jobs: cache-read-only: false cache-overwrite-existing: true - # Cache cross-platform JDK and JavaFX jmod archives downloaded by - # downloadJdk_* / downloadJavaFXMods_* tasks. These are pinned by + # Cache the host-platform JDK and JavaFX jmod archives downloaded by + # the downloadJdk / downloadJfxMods tasks. Filenames are stamped with + # ${hostOs}_${hostArch}, so each runner OS gets its own cache bucket + # via the runner-keyed actions/cache key. These are pinned by # javaVersion (gradle.properties) and the URL templates (build.gradle), # so keying on those file hashes invalidates correctly when we bump # the JDK or JavaFX version. We cache only the archives (.tar.gz / .zip) diff --git a/.github/workflows/gradle-test.yml b/.github/workflows/gradle-test.yml index acc144d5617..5ec5a2d03f7 100644 --- a/.github/workflows/gradle-test.yml +++ b/.github/workflows/gradle-test.yml @@ -42,6 +42,12 @@ jobs: build/test-results/**/*.xml build/test-results/**/*.trx build/test-results/**/*.json + PCGen-base/build/test-results/**/*.xml + PCGen-base/build/test-results/**/*.trx + PCGen-base/build/test-results/**/*.json + PCGen-Formula/build/test-results/**/*.xml + PCGen-Formula/build/test-results/**/*.trx + PCGen-Formula/build/test-results/**/*.json - name: Run Coverage run: ./gradlew testCoverage diff --git a/AGENTS.md b/AGENTS.md index 31e14aac133..631746d751c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -65,8 +65,7 @@ Always use the wrapper (./gradlew). Java 25 is required; Gradle will fetch depen - ./gradlew clean (also triggers cleanPlugins, cleanOutput, cleanJdks, cleanMods, cleanMasterSheets) Notes -- Some tasks trigger downloads of JDKs/JavaFX for all platforms (downloadJDKs, extractJDKs, downloadJavaFXMods) or host SDK (downloadJavaFXLocal/extractJavaFXLocal). CI caches build/jre and build/libs. -- The `jre` task prepares all platform JDKs with JavaFX modules for runtime image creation. +- jlink/jpackage build only the host platform. The download/extract tasks (downloadJdk, extractJdk, downloadJfxMods, extractJfxMods) target the host OS/arch automatically; the host SDK helper for local dev is downloadJavaFXLocal/extractJavaFXLocal. CI caches build/jre and build/libs. - Runtime bundles expect assets in data/, system/, outputsheets/, preview/, vendordata/, homebrewdata/. ## Running From Source diff --git a/PCGen-Formula/build.gradle b/PCGen-Formula/build.gradle index 1d9dcf1bf90..3181f872868 100644 --- a/PCGen-Formula/build.gradle +++ b/PCGen-Formula/build.gradle @@ -1,186 +1,93 @@ -/* - * PCGen formula component build using the Gradle tool. This file specifies the - * core build tasks and refers to other files in the code/gradle directory for - * additional tasks for specific output. - * - * Developer build: gradle - * Incremental dev build: gradle build - * Full build: gradle all - */ - plugins { - id "ca.coglinc2.javacc" version "3.0.0" - id 'java' - id 'eclipse' - id 'jacoco' - id 'ivy-publish' - id 'checkstyle' - id 'pmd' - id 'com.github.ben-manes.versions' version '0.39.0' - id 'com.github.spotbugs' version '4.7.5' + id 'java-library' } group = 'net.sourceforge.pcgen' -description = """PCGen formula library""" - -defaultTasks 'clean', 'build' - -sourceCompatibility = 1.11 -targetCompatibility = 1.11 - -ext { - majorVersion = 1 - minorVersion = 0 -} +description = 'PCGen formula library - generic expression parser and solver system' -repositories { - mavenCentral() - ivy { - name "Pcgen Repo" - url 'http://pc-gen.org/librepo' - allowInsecureProtocol true +java { + toolchain { + languageVersion = JavaLanguageVersion.of(25) } + modularity.inferModulePath = true } -dependencies { - // Use this if you want to reference your own local pcgen base, alter the - // relative path to what you need. - //compile files("../../pcgen-base/PCGen-base/build/libs/PCgen-base-1.0.jar") - - implementation group: 'net.sourceforge.pcgen', name: 'PCGen-base', version:'1.0.220' - testImplementation group: 'org.junit.platform', name: 'junit-platform-runner', version: '1.8.0' - testImplementation group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.7.2' - testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.8.0' - testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.8.0' - testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.8.0' -} +def generatedJjtreeDir = layout.buildDirectory.dir('generated/sources/jjtree').get().asFile +def generatedJavaccDir = layout.buildDirectory.dir('generated/sources/javacc').get().asFile sourceSets { main { - java { - srcDirs 'code/src/java' - } - } - javacc { - java { - srcDirs 'code/src/javacc' - } + java { srcDirs = ['code/src/java', generatedJjtreeDir, generatedJavaccDir] } } test { - java { - srcDirs 'code/src/test' - } - } -} - -test { - useJUnitPlatform() - reports { - junitXml.enabled = true - html.enabled = false + java { srcDirs = ['code/src/test'] } } - systemProperties 'property': 'value' } -jacocoTestReport { - reports { - xml { - enabled true // coveralls plugin depends on xml format report - } - - html { - enabled true - } - } - - afterEvaluate { - getClassDirectories().from(files(classDirectories.files.collect { - fileTree(dir: it, exclude: ['**/testsupport/**', '**/Abstract**TestCase', '**/**Test', 'pcgen/base/formula/parse/FormulaParser**', 'pcgen/base/formula/parse/AST**', 'pcgen/base/formula/parse/JJT**', 'pcgen/base/formula/parse/Node**', 'pcgen/base/formula/parse/ParseException**', 'pcgen/base/formula/parse/SimpleCharStream**', 'pcgen/base/formula/parse/Token**']) - })) - } -} - -compileJjtree { - inputDirectory = file('code/src/jjtree') - // We consciously choose to put the output in the main repo tree so that - // SimpleNode only exists once... - outputDirectory = file('code/src/javacc/') - include '**/*.java' +repositories { + mavenCentral() } -compileJavacc { - inputDirectory = file('code/src/javacc/') - outputDirectory = file('code/src/java/') +configurations { + javacc } -// Calculate the version number - runs in the parse phase -allprojects { - ext.buildTimestamp = new Date().format('yyyy-MM-dd HH:mm:ss Z') - if (System.env.BUILD_NUMBER) { - project.version = "$majorVersion.$minorVersion.$System.env.BUILD_NUMBER" +dependencies { + api project(':PCGen-base') + + javacc 'net.java.dev.javacc:javacc:7.0.13' + + testImplementation platform('org.junit:junit-bom:5.11.4') + testImplementation 'org.junit.jupiter:junit-jupiter-api' + testImplementation 'org.junit.jupiter:junit-jupiter-params' + testImplementation 'junit:junit:4.13.2' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' +} + +// SimpleNode.java and Operator.java in code/src/java are hand-maintained; everything +// else in pcgen/base/formula/parse is generated at build time. JJTree produces the AST +// classes, the visitor interfaces, and an annotated .jj grammar; JavaCC then turns the +// .jj into the parser and token classes. +tasks.register('jjtree', JavaExec) { + def src = file('code/src/jjtree/pcgen/base/formula/parse/formula.jjt') + def outDir = new File(generatedJjtreeDir, 'pcgen/base/formula/parse') + inputs.file(src) + outputs.dir(generatedJjtreeDir) + classpath = configurations.javacc + mainClass = 'jjtree' + args "-OUTPUT_DIRECTORY=${outDir}", src.absolutePath + doFirst { + generatedJjtreeDir.deleteDir() + outDir.mkdirs() } - else { - project.version = "$majorVersion.$minorVersion" + doLast { + // SimpleNode is hand-maintained in code/src/java; drop JJTree's stub so the + // two don't collide on the source path. + new File(outDir, 'SimpleNode.java').delete() } } -task echoVer() doLast { - println "${project.name} Version: ${project.version} (${buildTimestamp})" -} - -jar { - manifest { - attributes 'Implementation-Title': 'PCGenFormulaLibrary', 'Implementation-Version': project.version, - 'Built-On': buildTimestamp +tasks.register('javacc', JavaExec) { + dependsOn 'jjtree' + def jjFile = new File(generatedJjtreeDir, 'pcgen/base/formula/parse/formula.jj') + def outDir = new File(generatedJavaccDir, 'pcgen/base/formula/parse') + inputs.file(jjFile) + outputs.dir(generatedJavaccDir) + classpath = configurations.javacc + mainClass = 'javacc' + args "-OUTPUT_DIRECTORY=${outDir}", jjFile.absolutePath + doFirst { + generatedJavaccDir.deleteDir() + outDir.mkdirs() } } -task sourceJar(type: Jar) { - from sourceSets.main.java - classifier "sources" +tasks.named('compileJava') { + dependsOn 'javacc' } -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir +tasks.named('test') { + useJUnitPlatform() } - -// Rules for how we publish our artifacts in ivy compliant format -publishing { - repositories { - ivy { - name "fileRepo" - url '/var/www/librepo' - } - } - publications { - ivy(IvyPublication) { - from components.java - configurations { - sources {} - javadoc {} - } - artifact(sourceJar) { - type "sources" - conf "sources" - } - artifact(javadocJar) { - type "javadoc" - conf "javadoc" - } - descriptor.withXml { - asNode().info[0].appendNode('description', description) - } - } - } -} - -//We end up with an unneeded task with SpotBugs and JavaCC that causes a failure -//see: https://github.com/spotbugs/spotbugs-gradle-plugin/issues/70 -tasks.whenTaskAdded {task -> - if(task.name.contains("spotbugsJavacc")) { - task.enabled = false - } -} - -apply from: 'gradle/reporting.gradle' diff --git a/PCGen-Formula/code/src/java/module-info.java b/PCGen-Formula/code/src/java/module-info.java new file mode 100644 index 00000000000..d5c73237997 --- /dev/null +++ b/PCGen-Formula/code/src/java/module-info.java @@ -0,0 +1,20 @@ +module pcgen.formula { + requires transitive pcgen.base; + + exports pcgen.base.formula; + exports pcgen.base.formula.analysis; + exports pcgen.base.formula.base; + exports pcgen.base.formula.exception; + exports pcgen.base.formula.factory; + exports pcgen.base.formula.function; + exports pcgen.base.formula.inst; + exports pcgen.base.formula.library; + exports pcgen.base.formula.operator.array; + exports pcgen.base.formula.operator.bool; + exports pcgen.base.formula.operator.generic; + exports pcgen.base.formula.operator.number; + exports pcgen.base.formula.operator.string; + exports pcgen.base.formula.parse; + exports pcgen.base.formula.visitor; + exports pcgen.base.solver; +} diff --git a/code/src/java/pcgen/base/formula/AddingFormula.java b/PCGen-Formula/code/src/java/pcgen/base/formula/AddingFormula.java similarity index 100% rename from code/src/java/pcgen/base/formula/AddingFormula.java rename to PCGen-Formula/code/src/java/pcgen/base/formula/AddingFormula.java diff --git a/code/src/java/pcgen/base/formula/DividingFormula.java b/PCGen-Formula/code/src/java/pcgen/base/formula/DividingFormula.java similarity index 100% rename from code/src/java/pcgen/base/formula/DividingFormula.java rename to PCGen-Formula/code/src/java/pcgen/base/formula/DividingFormula.java diff --git a/code/src/java/pcgen/base/formula/MultiplyingFormula.java b/PCGen-Formula/code/src/java/pcgen/base/formula/MultiplyingFormula.java similarity index 100% rename from code/src/java/pcgen/base/formula/MultiplyingFormula.java rename to PCGen-Formula/code/src/java/pcgen/base/formula/MultiplyingFormula.java diff --git a/code/src/java/pcgen/base/formula/ReferenceFormula.java b/PCGen-Formula/code/src/java/pcgen/base/formula/ReferenceFormula.java similarity index 100% rename from code/src/java/pcgen/base/formula/ReferenceFormula.java rename to PCGen-Formula/code/src/java/pcgen/base/formula/ReferenceFormula.java diff --git a/code/src/java/pcgen/base/formula/SubtractingFormula.java b/PCGen-Formula/code/src/java/pcgen/base/formula/SubtractingFormula.java similarity index 100% rename from code/src/java/pcgen/base/formula/SubtractingFormula.java rename to PCGen-Formula/code/src/java/pcgen/base/formula/SubtractingFormula.java diff --git a/PCGen-Formula/code/src/java/pcgen/base/formula/inst/ImplementedScopeLibrary.java b/PCGen-Formula/code/src/java/pcgen/base/formula/inst/ImplementedScopeLibrary.java index d0ff82f3c04..f56c1cce028 100644 --- a/PCGen-Formula/code/src/java/pcgen/base/formula/inst/ImplementedScopeLibrary.java +++ b/PCGen-Formula/code/src/java/pcgen/base/formula/inst/ImplementedScopeLibrary.java @@ -15,6 +15,7 @@ */ package pcgen.base.formula.inst; +import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -70,4 +71,13 @@ public boolean isRelated(ImplementedScope scope1, ImplementedScope scope2) || scope2.drawsFrom().contains(scope1); } + /** + * Returns a Collection of all ImplementedScope objects in this library. + * + * @return A Collection of all ImplementedScope objects + */ + public Collection getScopes() + { + return scopeCache.values(); + } } diff --git a/PCGen-Formula/code/src/java/pcgen/base/formula/parse/.gitignore b/PCGen-Formula/code/src/java/pcgen/base/formula/parse/.gitignore index e741072ad3e..9fb4c6a7efc 100644 --- a/PCGen-Formula/code/src/java/pcgen/base/formula/parse/.gitignore +++ b/PCGen-Formula/code/src/java/pcgen/base/formula/parse/.gitignore @@ -1,3 +1,12 @@ +# Generated by JJTree from code/src/jjtree/.../formula.jjt at build time. +/AST*.java +/FormulaParserDefaultVisitor.java +/FormulaParserTreeConstants.java +/FormulaParserVisitor.java +/JJTFormulaParserState.java +/Node.java + +# Generated by JavaCC from the JJTree-produced .jj at build time. /formula.jj /FormulaParser.java /FormulaParserConstants.java diff --git a/PCGen-Formula/code/src/java/pcgen/base/formula/parse/SimpleNode.java b/PCGen-Formula/code/src/java/pcgen/base/formula/parse/SimpleNode.java new file mode 100644 index 00000000000..db0ed3af9d0 --- /dev/null +++ b/PCGen-Formula/code/src/java/pcgen/base/formula/parse/SimpleNode.java @@ -0,0 +1,207 @@ +/* Generated By:JJTree: Do not edit this line. SimpleNode.java */ + +/* + * Copyright (c) Andrew Wilson, 2010. + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +package pcgen.base.formula.parse; + +/** + * SimpleNode is the base AST node class for the formula parser. JJTree would + * normally generate this class itself from formula.jjt, but the PCGen formula + * domain needs every node to carry an Operator (for arithmetic/relational/ + * logical nodes) and a text token (for variables, function names, numeric + * literals, etc.). The fields and accessors for those — setOperator/getOperator, + * setToken/getText, and the getId override — are added below the standard + * JJTree boilerplate. + * + * Because these PCGen-specific accessors are called on receivers typed as + * SimpleNode from roughly fifty call sites across the formula visitors, + * library functions, the grammar actions in formula.jjt, and the main pcgen + * tree (UserFunction, InputFunction), they must live on a class literally + * named SimpleNode. JJTree's own SimpleNode generation is suppressed by the + * `jjtree` Gradle task, which deletes the generated stub before compileJava. + * + * The cleaner alternative would be to set NODE_CLASS=PCGenBaseNode in + * formula.jjt, move the PCGen-specific extensions into a new PCGenBaseNode + * class, let JJTree regenerate SimpleNode from scratch, and rename every + * external reference. That is the idiomatic JJTree pattern for this kind of + * customization, but it would touch around fifty call sites for no functional + * benefit, so the current shape is preserved. + */ +public class SimpleNode implements Node +{ + private Node parent; + private Node[] children; + private int id; + private FormulaParser parser; + + public SimpleNode(int i) + { + id = i; + } + + public SimpleNode(FormulaParser p, int i) + { + this(i); + parser = p; + } + + public void jjtOpen() + { + } + + public void jjtClose() + { + } + + public void jjtSetParent(Node n) + { + parent = n; + } + + public Node jjtGetParent() + { + return parent; + } + + public void jjtAddChild(Node n, int i) + { + if (children == null) + { + children = new Node[i + 1]; + } + else if (i >= children.length) + { + Node[] c = new Node[i + 1]; + System.arraycopy(children, 0, c, 0, children.length); + children = c; + } + children[i] = n; + } + + public Node jjtGetChild(int i) + { + return children[i]; + } + + public int jjtGetNumChildren() + { + return (children == null) ? 0 : children.length; + } + + public Object jjtAccept(FormulaParserVisitor visitor, Object data) + { + return visitor.visit(this, data); + } + + public Object childrenAccept(FormulaParserVisitor visitor, Object data) + { + if (children != null) + { + for (Node aChildren : children) + { + aChildren.jjtAccept(visitor, data); + } + } + return data; + } + + /* + * Items below this point are not auto-generated by javacc, but content + * unique to this implementation. + */ + /** + * The Operator for this node, if any. This is only loaded for relations, + * arithmetic calculations and other "operations" in a formula. + * + * Generally nodes that have a text String will not have an operator. + */ + private Operator operator; + + /** + * The String containing the text for the node, if any. This is only loaded + * for text-related nodes (variables, formula names, etc.). This does + * include numerical nodes, as they are stored as a String until the formula + * is visited. + */ + private String text; + + /** + * Sets the Operator for this Node. Under normal circumstances, this method + * should only be called by the parser, not by any method at runtime. + * + * @param operator + * The Operator for this Node + */ + public void setOperator(Operator operator) + { + this.operator = operator; + } + + /** + * Sets the text String contained by the node. Under normal circumstances, + * this method should only be called by the parser, not by any method at + * runtime. + * + * @param s + * The text String contained by the node + */ + public void setToken(String s) + { + text = s; + } + + /** + * Returns the ID of this node. The ID is a numerical representation of the + * type of node in the tree. It is arguably redundant information to the + * class of the node, but is nonetheless useful for accessing the array in + * pcgen.base.formula.parse.FormulaParserTreeConstants in order to get a + * String representation of the node type. + * + * @return The ID of this node. + */ + @Override + public int getId() + { + return id; + } + + /** + * Returns the Operator for this node, if any. Null may be returned if no + * operator has been set. + * + * @return The Operator for this node, if any. Null is a legal return value + * if no operator is set. + */ + public Operator getOperator() + { + return operator; + } + + /** + * Returns the text representation of this node, if any. Null may be + * returned if no text representation has been set. + * + * @return The text representation of this node, if any. Null is a legal + * return value if text representation has been set. + */ + public String getText() + { + return text; + } +} diff --git a/PCGen-Formula/code/src/jjtree/pcgen/base/formula/parse/formula.jjt b/PCGen-Formula/code/src/jjtree/pcgen/base/formula/parse/formula.jjt index 9ab91a8bfbd..9b390955a99 100644 --- a/PCGen-Formula/code/src/jjtree/pcgen/base/formula/parse/formula.jjt +++ b/PCGen-Formula/code/src/jjtree/pcgen/base/formula/parse/formula.jjt @@ -20,6 +20,7 @@ options { STATIC=false; VISITOR=true; MULTI=true; + UNICODE_INPUT=true; } PARSER_BEGIN( FormulaParser ) diff --git a/PCGen-Formula/settings.gradle b/PCGen-Formula/settings.gradle deleted file mode 100644 index e64944b26e7..00000000000 --- a/PCGen-Formula/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'pcgen' diff --git a/PCGen-base/build.gradle b/PCGen-base/build.gradle index 684daefa378..1cc5deeb0b8 100644 --- a/PCGen-base/build.gradle +++ b/PCGen-base/build.gradle @@ -1,148 +1,38 @@ -/* - * PCGen base build using the Gradle tool. This file specifies the core build tasks - * and refers to other files in the code/gradle directory for additional tasks - * for specific output. - * - * Developer build: gradle - * Incremental dev build: gradle build - * Full build: gradle all - */ - plugins { - id 'java' - id 'eclipse' - id "jacoco" - id 'ivy-publish' - id 'checkstyle' - id 'pmd' - id "com.github.spotbugs" version '4.7.5' - id 'com.github.ben-manes.versions' version '0.39.0' + id 'java-library' } group = 'net.sourceforge.pcgen' -description = """PCGen base library""" - -defaultTasks 'clean', 'build' - -sourceCompatibility = "1.11" -targetCompatibility = "1.11" - -ext { - majorVersion = 1 - minorVersion = 0 -} - -repositories { - mavenCentral() -} +description = 'PCGen base library - stable value-semantic utilities' -dependencies { - testImplementation group: 'org.junit.platform', name: 'junit-platform-runner', version: '1.8.0' - testImplementation group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.8.0' - testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.8.0' - testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.8.0' - testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.8.0' +java { + toolchain { + languageVersion = JavaLanguageVersion.of(25) + } + modularity.inferModulePath = true } sourceSets { main { - java { - srcDirs 'code/src/java' - } + java { srcDirs = ['code/src/java'] } } test { - java { - srcDirs 'code/src/test' - } - } -} - -def testSources = ['**/testsupport/**', '**/Abstract**TestCase', '**/*Test'] - -test { - useJUnitPlatform() - reports { - junitXml.enabled = true - html.enabled = false - } - systemProperties 'property': 'value' -} - -jacocoTestReport { - afterEvaluate { - getSourceDirectories().setFrom(files(classDirectories.files.collect {fileTree(dir: it, exclude: testSources)})) + java { srcDirs = ['code/src/test'] } } - reports { - html { - enabled true - } - } -} - -// Calculate the version number - runs in the parse phase -allprojects { - ext.buildTimestamp = new Date().format('yyyy-MM-dd HH:mm:ss Z') - if (System.env.BUILD_NUMBER) { - project.version = "$majorVersion.$minorVersion.$System.env.BUILD_NUMBER" - } - else { - project.version = "$majorVersion.$minorVersion" - } -} - -task echoVer() doLast { - println "${project.name} Version: ${project.version} (${buildTimestamp})" -} - -jar { - manifest { - attributes 'Implementation-Title': 'PCGenBaseLibrary', 'Implementation-Version': project.version, - 'Built-On': buildTimestamp - } -} - -task sourceJar(type: Jar) { - from sourceSets.main.java - classifier "sources" } -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir +repositories { + mavenCentral() } -// Rules for how we publish our artifacts in ivy compliant format -publishing { - repositories { - ivy { - name "fileRepo" - url '/var/www/librepo' - } - } - publications { - ivy(IvyPublication) { - from components.java - configurations { - sources {} - javadoc {} - } - artifact(sourceJar) { - type "sources" - conf "sources" - } - artifact(javadocJar) { - type "javadoc" - conf "javadoc" - } - descriptor.withXml { - asNode().info[0].appendNode('description', description) - } - } - } +dependencies { + testImplementation platform('org.junit:junit-bom:5.11.4') + testImplementation 'org.junit.jupiter:junit-jupiter-api' + testImplementation 'org.junit.jupiter:junit-jupiter-params' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } -wrapper { - distributionType = Wrapper.DistributionType.ALL +tasks.named('test') { + useJUnitPlatform() } - -apply from: 'gradle/reporting.gradle' diff --git a/PCGen-base/code/src/java/module-info.java b/PCGen-base/code/src/java/module-info.java new file mode 100644 index 00000000000..dae47aec8cc --- /dev/null +++ b/PCGen-base/code/src/java/module-info.java @@ -0,0 +1,21 @@ +module pcgen.base { + requires java.desktop; + + exports pcgen.base.enumeration; + exports pcgen.base.format; + exports pcgen.base.format.compound; + exports pcgen.base.format.dice; + exports pcgen.base.formatmanager; + exports pcgen.base.graph.base; + exports pcgen.base.graph.inst; + exports pcgen.base.graph.search; + exports pcgen.base.graph.util; + exports pcgen.base.lang; + exports pcgen.base.logging; + exports pcgen.base.math; + exports pcgen.base.proxy; + exports pcgen.base.spotbugs; + exports pcgen.base.test; + exports pcgen.base.text; + exports pcgen.base.util; +} diff --git a/code/src/java/pcgen/base/format/dice/Dice.java b/PCGen-base/code/src/java/pcgen/base/format/dice/Dice.java similarity index 100% rename from code/src/java/pcgen/base/format/dice/Dice.java rename to PCGen-base/code/src/java/pcgen/base/format/dice/Dice.java diff --git a/code/src/java/pcgen/base/format/dice/DiceFormat.java b/PCGen-base/code/src/java/pcgen/base/format/dice/DiceFormat.java similarity index 100% rename from code/src/java/pcgen/base/format/dice/DiceFormat.java rename to PCGen-base/code/src/java/pcgen/base/format/dice/DiceFormat.java diff --git a/code/src/java/pcgen/base/format/dice/Die.java b/PCGen-base/code/src/java/pcgen/base/format/dice/Die.java similarity index 100% rename from code/src/java/pcgen/base/format/dice/Die.java rename to PCGen-base/code/src/java/pcgen/base/format/dice/Die.java diff --git a/PCGen-base/code/src/java/pcgen/base/lang/CaseInsensitiveString.java b/PCGen-base/code/src/java/pcgen/base/lang/CaseInsensitiveString.java index 8544dd75faa..ce221778bf4 100644 --- a/PCGen-base/code/src/java/pcgen/base/lang/CaseInsensitiveString.java +++ b/PCGen-base/code/src/java/pcgen/base/lang/CaseInsensitiveString.java @@ -72,8 +72,6 @@ public boolean equals(Object obj) { CaseInsensitiveString cis = (CaseInsensitiveString) obj; return (string == cis.string) || string.equalsIgnoreCase(cis.string); - } else if (obj instanceof String) { - return string.equalsIgnoreCase(obj.toString()); } return false; } diff --git a/code/src/java/pcgen/base/test/InequalityTester.java b/PCGen-base/code/src/java/pcgen/base/test/InequalityTester.java similarity index 100% rename from code/src/java/pcgen/base/test/InequalityTester.java rename to PCGen-base/code/src/java/pcgen/base/test/InequalityTester.java diff --git a/PCGen-base/settings.gradle b/PCGen-base/settings.gradle deleted file mode 100644 index e64944b26e7..00000000000 --- a/PCGen-base/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'pcgen' diff --git a/README.md b/README.md index 668778cdcc9..0af6a02d4e0 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ It supports numerous game systems, most notably: 1. Install Java. - JDK 11 is recommended and has long term support, later versions should also work. 10 and below are not supported. - To check if you have Java installed, see [Install Java](#install-java) - - If you don't have it already, you can get it from [AdoptOpenJDK](https://adoptopenjdk.net/installation.html?variant=openjdk11&jvmVariant=hotspot). + - If you don't have it already, you can get it from [Eclipse Temurin](https://adoptium.net/temurin/releases/?version=11). 2. Download and extract the full zip file from https://github.com/PCGen/pcgen/releases/latest. @@ -113,7 +113,7 @@ Check the installed version with: For 6.08 development you will want Java with a minimum version of 11. For 6.09 development you will want Java with a minimum version of 25. -You can install the latest version from [AdoptOpenJDK](https://adoptopenjdk.net) regardless of your OS, please see instructions there. +You can install the latest version from [Eclipse Temurin](https://adoptium.net) regardless of your OS, please see instructions there. ### Install Git Check the installed version with: @@ -150,7 +150,7 @@ Run the following command: This sets up the project for upstream rebasing to keep you level with changes. You can rebase the master with the latest changes with the following. It can be done from GUI as well. - git checkout master && git fetch upstream && git rebase master + git fetch upstream && git checkout master && git rebase upstream/master ### Get an IDE This step is optional. You are free to program in what you prefer, these are several popular IDEs for Java. @@ -206,6 +206,19 @@ This mirrors what GitHub Actions runs to verify a PR; if it fails locally your C ### Generate IntelliJ IDEA Project ./gradlew idea +### Build Native Application Bundle (jpackage) +Produces a self-contained native app with a bundled JVM for the current platform. +**Always use `fullJpackage`** — not `jpackageImage` directly. `jpackageImage` only builds +the JVM runtime; `fullJpackage` also copies the required `data`, `plugins`, `preview`, and +`outputsheets` folders into the bundle. + + ./gradlew fullJpackage + +The output is placed in `build/jpackage/`. + +> **macOS note:** If the build fails with `Unable to delete directory 'build/jpackage'` due +> to a `.DS_Store` file, run `rm -f build/jpackage/.DS_Store` and retry. + ## Troubleshooting #### If you have an error stating `Task :run FAILED Error: --module-path requires module path specification` in Intellij, diff --git a/build.gradle b/build.gradle index e4f392e4278..108be993871 100644 --- a/build.gradle +++ b/build.gradle @@ -235,22 +235,11 @@ dependencies { implementation 'org.freemarker:freemarker:2.3.34' implementation 'org.jdom:jdom2:2.0.6.1' implementation 'net.sourceforge.argparse4j:argparse4j:0.9.0' - implementation 'org.xmlunit:xmlunit-core:2.11.0' implementation 'org.controlsfx:controlsfx:11.2.3' - implementation 'net.sourceforge.pcgen:PCGen-base:1.0.170' - // The latest Base, but pcgen core would need refactoring to support it. - //implementation group: 'net.sourceforge.pcgen', name: 'PCGen-base', version:'1.0.237' - // Use this if you're working from your local PCGen Base - //implementation files("../pcgen-base/PCGen-base/build/libs/PCgen-base-1.0.jar") - - implementation 'net.sourceforge.pcgen:PCGen-Formula:1.0.200' - // The latest Formula, but pcgen core would need refactoring to support it. - //implementation group: 'net.sourceforge.pcgen', name: 'PCGen-Formula', version:'1.0.266' - // Use if you're working from your local PCGen Formula - //implementation files("../pcgen-formula/PCGen-formula/build/libs/PCgen-formula-1.0.jar") + implementation project(':PCGen-base') + implementation project(':PCGen-Formula') compileOnly 'org.jetbrains:annotations:26.1.0' - compileOnly 'com.yuvimasory:orange-extensions:1.3.0' compileOnly 'com.github.spotbugs:spotbugs-annotations:4.9.8' testImplementation platform('org.junit:junit-bom:6.0.3') @@ -268,6 +257,7 @@ dependencies { testImplementation 'org.testfx:openjfx-monocle:21.0.2' testImplementation 'org.xmlunit:xmlunit-matchers:2.11.0' + testImplementation 'org.xmlunit:xmlunit-core:2.11.0' spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.14.0' @@ -301,9 +291,28 @@ jar { /** * Create a Java runtime built from Java modules using jlink */ +// Host platform detection. jpackage shells out to native OS tooling and the +// jlink mergedModule step invokes the target JDK's native javac, so cross- +// platform images cannot be built from a single host. Compute host once and +// reuse from jlink {}, jpackage {}, and the JDK/JFX download tasks below. +def supportedHostOs = [ + (Os.FAMILY_MAC) : "mac", + (Os.FAMILY_UNIX) : "linux", + (Os.FAMILY_WINDOWS): "windows", +] +def hostOs = supportedHostOs.find { Os.isFamily(it.key) }?.value +if (hostOs == null) { + throw new GradleException("Unsupported host OS: '${System.getProperty("os.name")}'. Supported families: ${supportedHostOs.values().join(", ")}") +} +def hostArch = (System.getProperty("os.arch") == "aarch64") ? "aarch64" : "x64" +def hostJdkExt = (hostOs == "windows") ? "zip" : "tar.gz" +def hostJfxOsPackage = (hostOs == "mac") ? "osx" : hostOs +def hostJfxArchSuffix = (hostArch == "x64") ? "-x64" : "-aarch64" + jlink { options = ['--strip-debug', '--no-header-files', '--no-man-pages'] - forceMerge('PCGen-base', 'PCGen-Formula', 'jep', 'fop', 'Saxon-HE', + addExtraDependencies('javafx') + forceMerge('jep', 'fop', 'Saxon-HE', 'commons-lang3', 'commons-io', 'spring', 'freemarker', 'jdom2', 'argparse4j', 'xmlunit', 'controlsfx', 'annotations', 'spotbugs', 'xmlresolver') @@ -335,53 +344,25 @@ jlink { excludeProvides(service: 'org.apache.fop.fo.FOEventHandler') } - // Cross-platform images: only register platforms whose JDK javac can run on this host. - // CI sets PCGEN_ALL_PLATFORMS=true to build all targets (using platform-specific runners). - def hostArch = System.getProperty("os.arch") - def allPlatforms = System.getenv("PCGEN_ALL_PLATFORMS") == "true" - - def platformDefs = [ - 'linux-x64' : jdksDir.dir("jdk_linux_x64").asFile.absolutePath, - 'linux-aarch64' : jdksDir.dir("jdk_linux_aarch64").asFile.absolutePath, - 'windows-x64' : jdksDir.dir("jdk_windows_x64").asFile.absolutePath, - 'mac-x64' : jdksDir.dir("jdk_mac_x64/Contents/Home").asFile.absolutePath, - 'mac-aarch64' : jdksDir.dir("jdk_mac_aarch64/Contents/Home").asFile.absolutePath, - ] - - if (allPlatforms) { - platformDefs.each { name, jdk -> targetPlatform(name, jdk) } - } else if (Os.isFamily(Os.FAMILY_MAC)) { - def macPlatform = (hostArch == "aarch64") ? 'mac-aarch64' : 'mac-x64' - targetPlatform(macPlatform, platformDefs[macPlatform]) - } else if (Os.isFamily(Os.FAMILY_UNIX)) { - def linuxPlatform = (hostArch == "aarch64") ? 'linux-aarch64' : 'linux-x64' - targetPlatform(linuxPlatform, platformDefs[linuxPlatform]) - } else if (Os.isFamily(Os.FAMILY_WINDOWS)) { - targetPlatform('windows-x64', platformDefs['windows-x64']) - } + def hostJdkPath = (hostOs == "mac") + ? jdksDir.dir("jdk_${hostOs}_${hostArch}/Contents/Home").asFile.absolutePath + : jdksDir.dir("jdk_${hostOs}_${hostArch}").asFile.absolutePath + targetPlatform("${hostOs}-${hostArch}", hostJdkPath) // Use the jpackage tool that comes with Java to build native installers jpackage { def licenseFile = layout.projectDirectory.file("code/LICENSE") - def hostArchitecture = System.getProperty("os.arch") - def osFamily = - Os.isFamily(Os.FAMILY_MAC) ? "mac" : - Os.isFamily(Os.FAMILY_UNIX) ? "linux" : - Os.isFamily(Os.FAMILY_WINDOWS) ? "windows" : "unknown" - def targetPlatform = ["x86_64" : "x64", - "amd64" : "x64", - "aarch64" : "aarch64"] - targetPlatformName = "${osFamily}-${targetPlatform.get(hostArchitecture, "NOT SUPPORTED")}" + targetPlatformName = "${hostOs}-${hostArch}" def appVersionStr = version.replaceAll('-SNAPSHOT', '').replaceAll(/[^0-9.].*/, '').replaceAll(/\.$/, '') appVersion = appVersionStr def opts = ["--license-file", licenseFile.asFile.absolutePath] - if (osFamily == "mac") { + if (hostOs == "mac") { opts += ["--mac-package-identifier", "PcGen", "--mac-package-name", "PcGen"] resourceDir = layout.projectDirectory.dir("installers/mac-installer").asFile } - else if (osFamily == "linux") { + else if (hostOs == "linux") { opts += ['--linux-shortcut'] } @@ -396,7 +377,7 @@ tasks.named("jpackageImage") { } tasks.named("jlink") { - dependsOn "downloadJavaFXMods" + dependsOn "extractJfxMods" } tasks.register("assembleJpackageImage", Copy) { @@ -477,17 +458,20 @@ tasks.register("copyToLibs", Copy) { from configurations.runtimeClasspath } -// Fix implicit dependency issues with distribution tasks -distZip.dependsOn copyToLibs -distTar.dependsOn copyToLibs +// distZip/distTar are unused: CI publishes the custom buildDist zips +// (see code/gradle/distribution.gradle) and the jpackage native installers, +// not the built-in distribution-plugin archives. Disable them so they don't +// materialize ~150 runtime JARs into build/distributions/ on every build. +tasks.named("distZip") { enabled = false } +tasks.named("distTar") { enabled = false } +// jlink's prepareMergedJarsDir reads from build/libs, which copyToLibs populates. +tasks.named("prepareMergedJarsDir").configure { + dependsOn copyToLibs +} tasks.register("copyToOutput", Copy) { dependsOn copyToLibs, converterJar, jar - doFirst { - println("IN copyToOutput") - } - from layout.buildDirectory.file("libs/pcgen-${version}.jar"), layout.buildDirectory.file("libs/pcgen-${version}-batch-convert.jar"), layout.projectDirectory.file("code/pcgen.bat") @@ -528,120 +512,71 @@ tasks.register("cleanMods", Delete) { delete modsDir } -// Alias tasks -tasks.register("buildonly") { - doFirst { - println("IN buildonly") - } - dependsOn copyToOutput -} - -tasks.register("quickbuild") { - dependsOn copyToOutput, test -} - tasks.named("build") { - // TODO reverts the commit f00f99c, because we don't have to generate all artifacts during the build - // dependsOn copyToOutput - - // Ensures that clean is never run after build and when clean is called it is - // run before build so it doesn't delete the new build folder. + // Ensures clean runs before build (not after) when both are invoked, + // so it doesn't delete the freshly-built artifacts. mustRunAfter clean } -ext { - platforms = [ - [os: 'linux', arch: 'x64', ext: 'tar.gz'], - [os: 'linux', arch: 'aarch64', ext: 'tar.gz'], - [os: 'mac', arch: 'x64', ext: 'tar.gz'], - [os: 'mac', arch: 'aarch64', ext: 'tar.gz'], - [os: 'windows', arch: 'x64', ext: 'zip'], - ] -} - -platforms.each { p -> - tasks.register("downloadJdk_${p.os}_${p.arch}", Download) { - description = "Downloads JDK for ${p.os} ${p.arch}" - src "https://api.adoptium.net/v3/binary/latest/${javaVersion}/ga/${p.os}/${p.arch}/jdk/hotspot/normal/eclipse" - dest jdksDir.file("jdk_${p.os}_${p.arch}.${p.ext}") - onlyIfModified true - overwrite false - useETag true - tempAndMove true - } -} - -tasks.register("downloadJDKs") { - description = "Downloads JDKs for all supported platforms" - dependsOn platforms.collect { "downloadJdk_${it.os}_${it.arch}" } +tasks.register("downloadJdk", Download) { + description = "Downloads JDK for the host platform (${hostOs} ${hostArch})" + src "https://api.adoptium.net/v3/binary/latest/${javaVersion}/ga/${hostOs}/${hostArch}/jdk/hotspot/normal/eclipse" + dest jdksDir.file("jdk_${hostOs}_${hostArch}.${hostJdkExt}") + onlyIfModified true + overwrite false + useETag true + tempAndMove true } -platforms.each { p -> - tasks.register("extractJdk_${p.os}_${p.arch}", Copy) { - description = "Extracts JDK archive for ${p.os} ${p.arch}" - dependsOn "downloadJdk_${p.os}_${p.arch}" +tasks.register("extractJdk", Copy) { + description = "Extracts the host-platform JDK archive" + dependsOn "downloadJdk" - def archiveFile = jdksDir.file("jdk_${p.os}_${p.arch}.${p.ext}") - def outDir = jdksDir.dir("jdk_${p.os}_${p.arch}") + def archiveFile = jdksDir.file("jdk_${hostOs}_${hostArch}.${hostJdkExt}") + def outDir = jdksDir.dir("jdk_${hostOs}_${hostArch}") - from(p.ext == 'zip' ? zipTree(archiveFile) : tarTree(archiveFile)) - into outDir + from(hostJdkExt == 'zip' ? zipTree(archiveFile) : tarTree(archiveFile)) + into outDir - eachFile { FileCopyDetails fcd -> - def segments = fcd.relativePath.segments - if (segments.length > 1) { - fcd.relativePath = new RelativePath(!fcd.isDirectory(), segments[1..-1] as String[]) - } + eachFile { FileCopyDetails fcd -> + def segments = fcd.relativePath.segments + if (segments.length > 1) { + fcd.relativePath = new RelativePath(!fcd.isDirectory(), segments[1..-1] as String[]) } - includeEmptyDirs = false - - onlyIf { !outDir.asFile.directory } } -} + includeEmptyDirs = false -tasks.register("extractJDKs") { - description = "Extracts all downloaded JDK archives" - dependsOn platforms.collect { "extractJdk_${it.os}_${it.arch}" } + onlyIf { !outDir.asFile.directory } } -platforms.each { p -> - def osPackage = (p.os == 'mac') ? 'osx' : p.os - def archSuffix = (p.arch == 'x64') ? '-x64' : '-aarch64' - def fileName = "openjfx-${latestJavaVersion}_${osPackage}${archSuffix}_bin-jmods.zip" - - tasks.register("downloadJfxMods_${p.os}_${p.arch}", Download) { - description = "Downloads JavaFX jmods for ${p.os} ${p.arch}" - dependsOn "extractJdk_${p.os}_${p.arch}" - src "https://download2.gluonhq.com/openjfx/${latestJavaVersion}/${fileName}" - dest jdksDir.file("jfx_jmods_${p.os}_${p.arch}.zip") - overwrite false - useETag true - tempAndMove true - } - - tasks.register("extractJfxMods_${p.os}_${p.arch}", Copy) { - description = "Extracts JavaFX jmods into JDK for ${p.os} ${p.arch}" - dependsOn "downloadJfxMods_${p.os}_${p.arch}" +tasks.register("downloadJfxMods", Download) { + description = "Downloads JavaFX jmods for the host platform" + dependsOn "extractJdk" + def fileName = "openjfx-${latestJavaVersion}_${hostJfxOsPackage}${hostJfxArchSuffix}_bin-jmods.zip" + src "https://download2.gluonhq.com/openjfx/${latestJavaVersion}/${fileName}" + dest jdksDir.file("jfx_jmods_${hostOs}_${hostArch}.zip") + overwrite false + useETag true + tempAndMove true +} - def jmodsTarget = (p.os == 'mac') - ? jdksDir.dir("jdk_${p.os}_${p.arch}/Contents/Home/jmods") - : jdksDir.dir("jdk_${p.os}_${p.arch}/jmods") +tasks.register("extractJfxMods", Copy) { + description = "Extracts JavaFX jmods into the host-platform JDK" + dependsOn "downloadJfxMods" - from zipTree(jdksDir.file("jfx_jmods_${p.os}_${p.arch}.zip")) - into jmodsTarget - eachFile { fcd -> - def segments = fcd.relativePath.segments - fcd.relativePath = new RelativePath(!fcd.isDirectory(), segments[1..-1] as String[]) - } - includeEmptyDirs = false + def jmodsTarget = (hostOs == 'mac') + ? jdksDir.dir("jdk_${hostOs}_${hostArch}/Contents/Home/jmods") + : jdksDir.dir("jdk_${hostOs}_${hostArch}/jmods") - onlyIf { !jmodsTarget.asFile.directory || jmodsTarget.asFile.list()?.length == 0 } + from zipTree(jdksDir.file("jfx_jmods_${hostOs}_${hostArch}.zip")) + into jmodsTarget + eachFile { fcd -> + def segments = fcd.relativePath.segments + fcd.relativePath = new RelativePath(!fcd.isDirectory(), segments[1..-1] as String[]) } -} + includeEmptyDirs = false -tasks.register("downloadJavaFXMods") { - description = "Downloads and extracts JavaFX jmods into each platform JDK" - dependsOn platforms.collect { "extractJfxMods_${it.os}_${it.arch}" } + onlyIf { !jmodsTarget.asFile.directory || jmodsTarget.asFile.list()?.length == 0 } } tasks.register("downloadJavaFXLocal", Download) { @@ -703,11 +638,6 @@ tasks.named("compileJava") { dependsOn copyMasterSheets } -tasks.register("jre") { - description = "Prepares all platform JDKs with JavaFX modules for runtime image creation" - dependsOn downloadJavaFXMods -} - tasks.register("testCoverage", JacocoReport) { dependsOn test group = "Reporting" @@ -814,42 +744,8 @@ allprojects { exceptionFormat = 'full' events 'failed', 'skipped' } - jvmArgs += [ - '-Djava.awt.headless=true', - '-Djavafx.macosx.embedded=true', - '-Djava.security.manager=disallow', - - "--module-path", layout.projectDirectory.dir("mods/lib"), - "--add-modules", "javafx.controls,javafx.web,javafx.swing,javafx.fxml,javafx.graphics", - - '--enable-native-access=javafx.graphics', - ] - } - - tasks.withType(JavaCompile).configureEach { - dependsOn extractJavaFXLocal - options.fork = true - options.release = project.ext.javaVersion - - def modsLibPath = layout.projectDirectory.dir("mods/lib").asFile.absolutePath - def depJars = configurations.runtimeClasspath.files.findAll { - !it.name.startsWith('javafx-') - }.collect { it.absolutePath }.join(File.pathSeparator) - def compileOnlyJars = configurations.compileClasspath.files.findAll { - it.name.contains('annotations') || it.name.contains('spotbugs') - }.collect { it.absolutePath }.join(File.pathSeparator) - - doFirst { - if (name.toLowerCase().contains("test")) { - options.compilerArgs << "--module-path" << modsLibPath - options.compilerArgs << "--add-modules" << "javafx.controls,javafx.web,javafx.swing,javafx.fxml,javafx.graphics" - } else if (name == "compileJava") { - def modulePath = [modsLibPath, depJars, compileOnlyJars].findAll { it }.join(File.pathSeparator) - options.compilerArgs << "--module-path" << modulePath - } - println "Args for for $name are $options.allCompilerArgs" - } } + // https://youtrack.jetbrains.com/issue/KT-46165 tasks.withType(Jar).configureEach { duplicatesStrategy = DuplicatesStrategy.EXCLUDE @@ -859,6 +755,56 @@ allprojects { } } +// Root-project tests need JavaFX on the module path. Subproject tests +// (PCGen-base, PCGen-Formula) don't, and don't have a mods/lib dir. +tasks.withType(Test).configureEach { + jvmArgs += [ + '-Djava.awt.headless=true', + '-Dtestfx.robot=glass', + '-Dtestfx.headless=true', + '-Dprism.order=sw', + '-Dprism.verbose=true', + '-Djavafx.macosx.embedded=true', + '-Djava.security.manager=disallow', + + "--module-path", layout.projectDirectory.dir("mods/lib"), + "--add-modules", "javafx.controls,javafx.web,javafx.swing,javafx.fxml,javafx.graphics", + + // Needed to fix issue with testfx test crashing due to issue with modularity of whole program. Slightly related issue. https://github.com/TestFX/TestFX/issues/638 + '--add-exports', 'javafx.graphics/com.sun.javafx.application=ALL-UNNAMED', + // Next two needed to support monocle testing + '--add-exports', 'javafx.graphics/com.sun.javafx.util=ALL-UNNAMED', + '--add-exports', 'javafx.base/com.sun.javafx.logging=ALL-UNNAMED', + '--add-opens', 'javafx.graphics/com.sun.glass.ui=ALL-UNNAMED', + '--enable-native-access=javafx.graphics', + ] +} + +tasks.withType(JavaCompile).configureEach { + dependsOn extractJavaFXLocal + options.fork = true + options.release = project.ext.javaVersion + + def modsLibPath = layout.projectDirectory.dir("mods/lib").asFile.absolutePath + def depJars = configurations.runtimeClasspath.files.findAll { + !it.name.startsWith('javafx-') + }.collect { it.absolutePath }.join(File.pathSeparator) + def compileOnlyJars = configurations.compileClasspath.files.findAll { + it.name.contains('annotations') || it.name.contains('spotbugs') + }.collect { it.absolutePath }.join(File.pathSeparator) + + doFirst { + if (name.toLowerCase().contains("test")) { + options.compilerArgs << "--module-path" << modsLibPath + options.compilerArgs << "--add-modules" << "javafx.controls,javafx.web,javafx.swing,javafx.fxml,javafx.graphics" + } else if (name == "compileJava") { + def modulePath = [modsLibPath, depJars, compileOnlyJars].findAll { it }.join(File.pathSeparator) + options.compilerArgs << "--module-path" << modulePath + } + println "Args for for $name are $options.allCompilerArgs" + } +} + tasks.named("dependencyUpdates") { revision = 'release' diff --git a/code/gradle/release.gradle b/code/gradle/release.gradle index 8b1079210d6..b7a63a8c1d5 100644 --- a/code/gradle/release.gradle +++ b/code/gradle/release.gradle @@ -32,7 +32,7 @@ ext { } tasks.register("sourcesJar", Jar) { - dependsOn classes, copyToOutput, distTar, distZip, startScripts + dependsOn classes, copyToOutput, startScripts duplicatesStrategy = DuplicatesStrategy.INCLUDE description = "build source jar file" archiveClassifier.set('sources') diff --git a/code/src/itest/tokencontent/GlobalModifyTest.java b/code/src/itest/tokencontent/GlobalModifyTest.java index c9524663dd8..b33e6fc5bda 100644 --- a/code/src/itest/tokencontent/GlobalModifyTest.java +++ b/code/src/itest/tokencontent/GlobalModifyTest.java @@ -98,11 +98,10 @@ protected int targetFacetCount() try { List list = sm.diagnose(varID); - size = list.size() - 1; + size = list.isEmpty() ? 0 : list.size() - 1; } catch (IllegalArgumentException e) { - //Really, SolverManager should have isChannel(varID) to avoid diagnose complaining if something doesn't exist size = 0; } return size; diff --git a/code/src/java/module-info.java b/code/src/java/module-info.java index e9d1e15e877..6a75e5bcbb1 100644 --- a/code/src/java/module-info.java +++ b/code/src/java/module-info.java @@ -19,8 +19,8 @@ requires javafx.swing; requires javafx.web; - requires PCGen.base; - requires PCGen.Formula; + requires pcgen.base; + requires pcgen.formula; requires org.apache.commons.lang3; requires org.apache.commons.io; @@ -28,7 +28,6 @@ requires org.jdom2; requires net.sourceforge.argparse4j; requires org.controlsfx.controls; - requires org.xmlunit; requires org.apache.xmlgraphics.fop.core; requires org.apache.xmlgraphics.fop.events; requires org.apache.xmlgraphics.commons; @@ -50,6 +49,8 @@ exports pcgen.system; exports pcgen.util; + opens pcgen.cdom.base to pcgen.base; + opens pcgen.system; opens pcgen.pluginmgr; opens pcgen.core.bonus; diff --git a/code/src/java/pcgen/base/enumeration/TypeSafeConstant.java b/code/src/java/pcgen/base/enumeration/TypeSafeConstant.java deleted file mode 100644 index c2a72c985d9..00000000000 --- a/code/src/java/pcgen/base/enumeration/TypeSafeConstant.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2006 Tom Parker - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2.1 of the License, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - * - */ -package pcgen.base.enumeration; - -/** - * A TypeSafeConstant is an object which will provide a unique integer - * identifier to every instance of that class (not unique to every - * TypeSafeConstant). - * - * As an example, If Classes A and B both extend TypeSafeConstant, then there - * may be an instance of Class A that has ordinal 1 and an instance of Class B - * that has ordinal 1, but only one instance of each class may have any ordinal. - * (Two instances of Class A may not share ordinal 1 and still respect the - * TypeSafeConstant interface) - * - * This emulates behavior by the enum system in Java 1.5+. Note that the - * identifier should be unique per virtual machine; thus serialization and other - * forms of persistence of classes must ensure the uniqueness of identifiers of - * a TypeSafeConstant. - * - * It is considered good behavior for a TypeSafeConstant to begin the ordinal - * count at zero. There may be an expectation by classes that use - * TypeSafeConstants that expect this behavior. In that case, such behavioral - * limitations should be documented in the TypeSafeConstant-using class. - * - */ -@FunctionalInterface -public interface TypeSafeConstant -{ - - /** - * Returns the unique ordinal for the instance of the TypeSafeConstant - * class. - * - * @return An integer identifier unique to this instance of the class. - */ - public int getOrdinal(); - -} diff --git a/code/src/java/pcgen/cdom/base/CDOMObject.java b/code/src/java/pcgen/cdom/base/CDOMObject.java index 43824565d27..fdf8c70fca9 100644 --- a/code/src/java/pcgen/cdom/base/CDOMObject.java +++ b/code/src/java/pcgen/cdom/base/CDOMObject.java @@ -35,7 +35,8 @@ import java.util.Set; import org.jetbrains.annotations.NotNull; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; +import pcgen.base.formula.base.ImplementedScope; import pcgen.base.formula.base.VarScoped; import pcgen.base.lang.StringUtil; import pcgen.base.util.DoubleKeyMapToList; @@ -1232,20 +1233,38 @@ public CDOMObject getCDOMObject() return this; } - @Override public Optional getLocalScopeName() { //I don't have one return Optional.empty(); } - @Override public Optional getVariableParent() { //Fall back to Global return Optional.empty(); } + @Override + public VarScoped getProviderFor(ImplementedScope implScope) + { + if (implScope.isGlobal()) + { + return this; + } + Optional localName = getLocalScopeName(); + if (localName.isPresent() && localName.get().equals(implScope.getName())) + { + return this; + } + Optional parent = getVariableParent(); + if (parent.isPresent()) + { + return parent.get().getProviderFor(implScope); + } + return this; + } + @Override public boolean hasPrerequisites() { diff --git a/code/src/java/pcgen/cdom/base/ChooseDriver.java b/code/src/java/pcgen/cdom/base/ChooseDriver.java index 0b107e92070..e4113bfbf55 100644 --- a/code/src/java/pcgen/cdom/base/ChooseDriver.java +++ b/code/src/java/pcgen/cdom/base/ChooseDriver.java @@ -19,7 +19,7 @@ import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; public interface ChooseDriver { diff --git a/code/src/java/pcgen/cdom/base/ConcretePersistentTransitionChoice.java b/code/src/java/pcgen/cdom/base/ConcretePersistentTransitionChoice.java index 1870520caa7..6a5066345a2 100644 --- a/code/src/java/pcgen/cdom/base/ConcretePersistentTransitionChoice.java +++ b/code/src/java/pcgen/cdom/base/ConcretePersistentTransitionChoice.java @@ -19,7 +19,7 @@ import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.enumeration.AssociationListKey; import pcgen.core.PlayerCharacter; import pcgen.rules.context.LoadContext; diff --git a/code/src/java/pcgen/cdom/base/ConcreteTransitionChoice.java b/code/src/java/pcgen/cdom/base/ConcreteTransitionChoice.java index e18c9408d8a..da353856f5e 100644 --- a/code/src/java/pcgen/cdom/base/ConcreteTransitionChoice.java +++ b/code/src/java/pcgen/cdom/base/ConcreteTransitionChoice.java @@ -23,7 +23,7 @@ import java.util.List; import java.util.Set; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.enumeration.AssociationListKey; import pcgen.core.PlayerCharacter; import pcgen.core.chooser.CDOMChooserFacadeImpl; diff --git a/code/src/java/pcgen/cdom/base/FormulaFactory.java b/code/src/java/pcgen/cdom/base/FormulaFactory.java index 6ea551f6476..cd94d705835 100644 --- a/code/src/java/pcgen/cdom/base/FormulaFactory.java +++ b/code/src/java/pcgen/cdom/base/FormulaFactory.java @@ -20,17 +20,16 @@ import java.util.Objects; import java.util.Optional; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.formula.base.DependencyManager; import pcgen.base.formula.base.EvaluationManager; -import pcgen.base.formula.base.FormulaManager; import pcgen.base.formula.base.FormulaSemantics; +import pcgen.base.formula.base.ImplementedScope; import pcgen.base.formula.base.ManagerFactory; import pcgen.base.formula.exception.SemanticsException; import pcgen.base.formula.inst.ComplexNEPFormula; import pcgen.base.formula.inst.NEPFormula; import pcgen.base.util.FormatManager; -import pcgen.cdom.formula.scope.PCGenScope; import pcgen.core.Equipment; import pcgen.core.PlayerCharacter; @@ -281,7 +280,7 @@ public boolean equals(Object obj) } @Override - public void getDependencies(DependencyManager fdm) + public void captureDependencies(DependencyManager fdm) { //None } @@ -344,22 +343,20 @@ public static NEPFormula getNEPFormulaFor(FormatManager fmtManager, St /** * Returns a "valid" NEPFormula for the given expression. - * + * * If the given expression does not represent a valid formula, then this * will throw an IllegalArgumentException. - * + * * If the given expression does not return an object of the type in the * given FormatManager, then this will throw an IllegalArgumentException. - * + * * @param expression * The String representation of the formula to be converted to a * NEPFormula * @param managerFactory * The ManagerFactory to be used for building the FormulaSemantics - * @param formulaManager - * The FormulaManager to be used for validating the NEPFormula * @param varScope - * The PCGenScope in which the NEPFormula is established and + * The scope in which the NEPFormula is established and * checked * @param formatManager * The FormatManager in which the NEPFormula is established and @@ -367,10 +364,10 @@ public static NEPFormula getNEPFormulaFor(FormatManager fmtManager, St * @return a "valid" NEPFormula for the given expression */ public static NEPFormula getValidFormula(String expression, ManagerFactory managerFactory, - FormulaManager formulaManager, PCGenScope varScope, FormatManager formatManager) + ImplementedScope varScope, FormatManager formatManager) { NEPFormula formula = getNEPFormulaFor(formatManager, expression); - FormulaSemantics semantics = managerFactory.generateFormulaSemantics(formulaManager, varScope); + FormulaSemantics semantics = managerFactory.generateFormulaSemantics(varScope); semantics = semantics.getWith(FormulaSemantics.INPUT_FORMAT, Optional.of(formatManager)); try { diff --git a/code/src/java/pcgen/cdom/base/JEPFormula.java b/code/src/java/pcgen/cdom/base/JEPFormula.java index c3ceb88544a..e2296f77b39 100644 --- a/code/src/java/pcgen/cdom/base/JEPFormula.java +++ b/code/src/java/pcgen/cdom/base/JEPFormula.java @@ -17,7 +17,7 @@ */ package pcgen.cdom.base; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.core.Equipment; import pcgen.core.PlayerCharacter; diff --git a/code/src/java/pcgen/cdom/base/TransitionChoice.java b/code/src/java/pcgen/cdom/base/TransitionChoice.java index 46d9cfb9e20..c40fe33af38 100644 --- a/code/src/java/pcgen/cdom/base/TransitionChoice.java +++ b/code/src/java/pcgen/cdom/base/TransitionChoice.java @@ -19,7 +19,7 @@ import java.util.Collection; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.core.PlayerCharacter; /** diff --git a/code/src/java/pcgen/base/calculation/AbstractNEPCalculation.java b/code/src/java/pcgen/cdom/calculation/AbstractNEPCalculation.java similarity index 98% rename from code/src/java/pcgen/base/calculation/AbstractNEPCalculation.java rename to code/src/java/pcgen/cdom/calculation/AbstractNEPCalculation.java index e5765887d33..d64d4d049dc 100644 --- a/code/src/java/pcgen/base/calculation/AbstractNEPCalculation.java +++ b/code/src/java/pcgen/cdom/calculation/AbstractNEPCalculation.java @@ -15,7 +15,7 @@ * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -package pcgen.base.calculation; +package pcgen.cdom.calculation; import java.util.Objects; diff --git a/code/src/java/pcgen/base/calculation/AbstractPCGenModifier.java b/code/src/java/pcgen/cdom/calculation/AbstractPCGenModifier.java similarity index 98% rename from code/src/java/pcgen/base/calculation/AbstractPCGenModifier.java rename to code/src/java/pcgen/cdom/calculation/AbstractPCGenModifier.java index 95f9bc46bed..f420bdf23a5 100644 --- a/code/src/java/pcgen/base/calculation/AbstractPCGenModifier.java +++ b/code/src/java/pcgen/cdom/calculation/AbstractPCGenModifier.java @@ -13,7 +13,7 @@ * this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA */ -package pcgen.base.calculation; +package pcgen.cdom.calculation; import java.util.Collection; import java.util.Collections; diff --git a/code/src/java/pcgen/base/calculation/BasicCalculation.java b/code/src/java/pcgen/cdom/calculation/BasicCalculation.java similarity index 98% rename from code/src/java/pcgen/base/calculation/BasicCalculation.java rename to code/src/java/pcgen/cdom/calculation/BasicCalculation.java index 91aa55ee1e0..9ac952c7511 100644 --- a/code/src/java/pcgen/base/calculation/BasicCalculation.java +++ b/code/src/java/pcgen/cdom/calculation/BasicCalculation.java @@ -15,7 +15,7 @@ * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -package pcgen.base.calculation; +package pcgen.cdom.calculation; /** * A BasicCalculation is a calculation performed on two objects of the same diff --git a/code/src/java/pcgen/base/calculation/CalculationInfo.java b/code/src/java/pcgen/cdom/calculation/CalculationInfo.java similarity index 98% rename from code/src/java/pcgen/base/calculation/CalculationInfo.java rename to code/src/java/pcgen/cdom/calculation/CalculationInfo.java index c21ec5f6d3a..ca442f12a75 100644 --- a/code/src/java/pcgen/base/calculation/CalculationInfo.java +++ b/code/src/java/pcgen/cdom/calculation/CalculationInfo.java @@ -15,7 +15,7 @@ * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -package pcgen.base.calculation; +package pcgen.cdom.calculation; /** * CalculationInfo is a shared interface used to collect common information diff --git a/code/src/java/pcgen/base/calculation/CalculationModifier.java b/code/src/java/pcgen/cdom/calculation/CalculationModifier.java similarity index 99% rename from code/src/java/pcgen/base/calculation/CalculationModifier.java rename to code/src/java/pcgen/cdom/calculation/CalculationModifier.java index dd8a326c1fc..86e3c46b1b4 100644 --- a/code/src/java/pcgen/base/calculation/CalculationModifier.java +++ b/code/src/java/pcgen/cdom/calculation/CalculationModifier.java @@ -15,7 +15,7 @@ * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -package pcgen.base.calculation; +package pcgen.cdom.calculation; import java.util.Objects; diff --git a/code/src/java/pcgen/base/calculation/FormulaCalculation.java b/code/src/java/pcgen/cdom/calculation/FormulaCalculation.java similarity index 98% rename from code/src/java/pcgen/base/calculation/FormulaCalculation.java rename to code/src/java/pcgen/cdom/calculation/FormulaCalculation.java index 943b1300863..2e2a842b094 100644 --- a/code/src/java/pcgen/base/calculation/FormulaCalculation.java +++ b/code/src/java/pcgen/cdom/calculation/FormulaCalculation.java @@ -15,7 +15,7 @@ * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -package pcgen.base.calculation; +package pcgen.cdom.calculation; import java.util.Objects; @@ -85,7 +85,7 @@ public T process(EvaluationManager evalManager) @Override public void getDependencies(DependencyManager fdm) { - formula.getDependencies(fdm); + formula.captureDependencies(fdm); } @Override diff --git a/code/src/java/pcgen/base/calculation/FormulaModifier.java b/code/src/java/pcgen/cdom/calculation/FormulaModifier.java similarity index 99% rename from code/src/java/pcgen/base/calculation/FormulaModifier.java rename to code/src/java/pcgen/cdom/calculation/FormulaModifier.java index e7b3e50e5af..337bf1e1a85 100644 --- a/code/src/java/pcgen/base/calculation/FormulaModifier.java +++ b/code/src/java/pcgen/cdom/calculation/FormulaModifier.java @@ -15,7 +15,7 @@ * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -package pcgen.base.calculation; +package pcgen.cdom.calculation; import java.util.Collection; diff --git a/code/src/java/pcgen/base/calculation/IgnoreVariables.java b/code/src/java/pcgen/cdom/calculation/IgnoreVariables.java similarity index 74% rename from code/src/java/pcgen/base/calculation/IgnoreVariables.java rename to code/src/java/pcgen/cdom/calculation/IgnoreVariables.java index 4ff00ced8aa..9fa92385e64 100644 --- a/code/src/java/pcgen/base/calculation/IgnoreVariables.java +++ b/code/src/java/pcgen/cdom/calculation/IgnoreVariables.java @@ -13,20 +13,20 @@ * this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA */ -package pcgen.base.calculation; +package pcgen.cdom.calculation; import pcgen.base.formula.base.DependencyManager; -import pcgen.base.formula.base.VariableStrategy; +import pcgen.base.formula.base.DependencyStrategy; /** - * IgnoreVariables is a VariableStrategy for a DependencyManager indicating that variables + * IgnoreVariables is a DependencyStrategy for a DependencyManager indicating that variables * are to be ignored */ -public class IgnoreVariables implements VariableStrategy +public class IgnoreVariables implements DependencyStrategy { @Override - public void addVariable(DependencyManager mgr, String varName) + public void addVariable(DependencyManager depManager, String varName) { //ignore } diff --git a/code/src/java/pcgen/base/calculation/NEPCalculation.java b/code/src/java/pcgen/cdom/calculation/NEPCalculation.java similarity index 99% rename from code/src/java/pcgen/base/calculation/NEPCalculation.java rename to code/src/java/pcgen/cdom/calculation/NEPCalculation.java index 83b10d22acd..323f2a2a7fe 100644 --- a/code/src/java/pcgen/base/calculation/NEPCalculation.java +++ b/code/src/java/pcgen/cdom/calculation/NEPCalculation.java @@ -15,7 +15,7 @@ * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -package pcgen.base.calculation; +package pcgen.cdom.calculation; import pcgen.base.formula.base.DependencyManager; import pcgen.base.formula.base.EvaluationManager; diff --git a/code/src/java/pcgen/base/calculation/package-info.java b/code/src/java/pcgen/cdom/calculation/package-info.java similarity index 97% rename from code/src/java/pcgen/base/calculation/package-info.java rename to code/src/java/pcgen/cdom/calculation/package-info.java index ce69c840384..9a7c39d55a2 100644 --- a/code/src/java/pcgen/base/calculation/package-info.java +++ b/code/src/java/pcgen/cdom/calculation/package-info.java @@ -20,4 +20,4 @@ * Formula. This is usually one "step" in a calculation (where a step can be * much more than just addition or subtraction, it can be a full equation). */ -package pcgen.base.calculation; +package pcgen.cdom.calculation; diff --git a/code/src/java/pcgen/cdom/content/CNAbility.java b/code/src/java/pcgen/cdom/content/CNAbility.java index f95adc2f659..bc7ff290d3e 100644 --- a/code/src/java/pcgen/cdom/content/CNAbility.java +++ b/code/src/java/pcgen/cdom/content/CNAbility.java @@ -20,7 +20,7 @@ import java.util.List; import java.util.Objects; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.Category; import pcgen.cdom.base.ChooseDriver; diff --git a/code/src/java/pcgen/cdom/content/ChallengeRating.java b/code/src/java/pcgen/cdom/content/ChallengeRating.java index 8c00d341ef2..f9e4d0adc33 100644 --- a/code/src/java/pcgen/cdom/content/ChallengeRating.java +++ b/code/src/java/pcgen/cdom/content/ChallengeRating.java @@ -17,7 +17,7 @@ */ package pcgen.cdom.content; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.ConcretePrereqObject; import pcgen.cdom.base.FormulaFactory; import pcgen.core.SettingsHandler; diff --git a/code/src/java/pcgen/cdom/content/DamageReduction.java b/code/src/java/pcgen/cdom/content/DamageReduction.java index 9536d465a08..792b4c0a838 100644 --- a/code/src/java/pcgen/cdom/content/DamageReduction.java +++ b/code/src/java/pcgen/cdom/content/DamageReduction.java @@ -25,7 +25,7 @@ import java.util.Set; import java.util.StringTokenizer; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.ConcretePrereqObject; import pcgen.cdom.base.QualifyingObject; diff --git a/code/src/java/pcgen/cdom/content/IndirectCalculation.java b/code/src/java/pcgen/cdom/content/IndirectCalculation.java index ae8c3645d89..da7e414530c 100644 --- a/code/src/java/pcgen/cdom/content/IndirectCalculation.java +++ b/code/src/java/pcgen/cdom/content/IndirectCalculation.java @@ -17,8 +17,8 @@ import java.util.Objects; -import pcgen.base.calculation.AbstractNEPCalculation; -import pcgen.base.calculation.BasicCalculation; +import pcgen.cdom.calculation.AbstractNEPCalculation; +import pcgen.cdom.calculation.BasicCalculation; import pcgen.base.formula.base.DependencyManager; import pcgen.base.formula.base.EvaluationManager; import pcgen.base.formula.base.FormulaSemantics; diff --git a/code/src/java/pcgen/cdom/content/LevelCommandFactory.java b/code/src/java/pcgen/cdom/content/LevelCommandFactory.java index d0f10733f7f..c8792b09e77 100644 --- a/code/src/java/pcgen/cdom/content/LevelCommandFactory.java +++ b/code/src/java/pcgen/cdom/content/LevelCommandFactory.java @@ -19,7 +19,7 @@ import java.util.Objects; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.ConcretePrereqObject; import pcgen.cdom.reference.CDOMSingleRef; import pcgen.cdom.reference.ReferenceUtilities; diff --git a/code/src/java/pcgen/cdom/content/ProcessCalculation.java b/code/src/java/pcgen/cdom/content/ProcessCalculation.java index 37b721fcac8..aab990e71de 100644 --- a/code/src/java/pcgen/cdom/content/ProcessCalculation.java +++ b/code/src/java/pcgen/cdom/content/ProcessCalculation.java @@ -19,8 +19,8 @@ import java.util.Objects; -import pcgen.base.calculation.AbstractNEPCalculation; -import pcgen.base.calculation.BasicCalculation; +import pcgen.cdom.calculation.AbstractNEPCalculation; +import pcgen.cdom.calculation.BasicCalculation; import pcgen.base.formula.base.DependencyManager; import pcgen.base.formula.base.EvaluationManager; import pcgen.base.formula.base.FormulaSemantics; diff --git a/code/src/java/pcgen/cdom/content/SpellLikeAbility.java b/code/src/java/pcgen/cdom/content/SpellLikeAbility.java index 3cba91b9833..956028fe55e 100644 --- a/code/src/java/pcgen/cdom/content/SpellLikeAbility.java +++ b/code/src/java/pcgen/cdom/content/SpellLikeAbility.java @@ -17,7 +17,7 @@ */ package pcgen.cdom.content; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.ConcretePrereqObject; import pcgen.cdom.base.QualifyingObject; import pcgen.core.spell.Spell; diff --git a/code/src/java/pcgen/cdom/content/SpellResistance.java b/code/src/java/pcgen/cdom/content/SpellResistance.java index 9dbb9035544..9a1d0ad8300 100644 --- a/code/src/java/pcgen/cdom/content/SpellResistance.java +++ b/code/src/java/pcgen/cdom/content/SpellResistance.java @@ -17,7 +17,7 @@ */ package pcgen.cdom.content; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.ConcretePrereqObject; import pcgen.cdom.base.FormulaFactory; diff --git a/code/src/java/pcgen/cdom/content/VarModifier.java b/code/src/java/pcgen/cdom/content/VarModifier.java index 131a3ec6e59..cfd57239136 100644 --- a/code/src/java/pcgen/cdom/content/VarModifier.java +++ b/code/src/java/pcgen/cdom/content/VarModifier.java @@ -19,8 +19,7 @@ import java.util.Objects; -import pcgen.base.calculation.FormulaModifier; -import pcgen.base.formula.base.LegalScope; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.cdom.formula.scope.PCGenScope; /** @@ -140,7 +139,7 @@ public boolean equals(Object o) */ public String getFullLegalScopeName() { - return LegalScope.getFullName(getLegalScope()); + return getLegalScope().getName(); } @Override diff --git a/code/src/java/pcgen/cdom/enumeration/AssociationKey.java b/code/src/java/pcgen/cdom/enumeration/AssociationKey.java index e1a59ba89bb..cb5a3f437d7 100644 --- a/code/src/java/pcgen/cdom/enumeration/AssociationKey.java +++ b/code/src/java/pcgen/cdom/enumeration/AssociationKey.java @@ -21,7 +21,7 @@ import java.lang.reflect.Modifier; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.lang.UnreachableError; import pcgen.base.util.CaseInsensitiveMap; import pcgen.cdom.base.CDOMObject; diff --git a/code/src/java/pcgen/cdom/enumeration/FormulaKey.java b/code/src/java/pcgen/cdom/enumeration/FormulaKey.java index b6818faa635..f24f6a8ffa7 100644 --- a/code/src/java/pcgen/cdom/enumeration/FormulaKey.java +++ b/code/src/java/pcgen/cdom/enumeration/FormulaKey.java @@ -22,7 +22,7 @@ import java.util.Objects; import pcgen.base.enumeration.TypeSafeConstant; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.util.CaseInsensitiveMap; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.formula.FixedSizeFormula; diff --git a/code/src/java/pcgen/cdom/enumeration/ListKey.java b/code/src/java/pcgen/cdom/enumeration/ListKey.java index 8e4263f1715..1d731e82704 100644 --- a/code/src/java/pcgen/cdom/enumeration/ListKey.java +++ b/code/src/java/pcgen/cdom/enumeration/ListKey.java @@ -22,7 +22,7 @@ import java.util.HashSet; import java.util.Map; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.lang.UnreachableError; import pcgen.base.util.CaseInsensitiveMap; import pcgen.cdom.base.CDOMReference; diff --git a/code/src/java/pcgen/cdom/enumeration/ObjectKey.java b/code/src/java/pcgen/cdom/enumeration/ObjectKey.java index 479cd832c77..15160571126 100644 --- a/code/src/java/pcgen/cdom/enumeration/ObjectKey.java +++ b/code/src/java/pcgen/cdom/enumeration/ObjectKey.java @@ -26,7 +26,7 @@ import java.util.HashSet; import java.util.Map; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.lang.UnreachableError; import pcgen.base.util.CaseInsensitiveMap; import pcgen.cdom.base.CDOMListObject; diff --git a/code/src/java/pcgen/cdom/facet/ActiveSpellsFacet.java b/code/src/java/pcgen/cdom/facet/ActiveSpellsFacet.java index 6ddf2aa86e3..9d4e9f96ee8 100644 --- a/code/src/java/pcgen/cdom/facet/ActiveSpellsFacet.java +++ b/code/src/java/pcgen/cdom/facet/ActiveSpellsFacet.java @@ -21,7 +21,7 @@ import java.util.Set; import java.util.TreeMap; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.content.SpellLikeAbility; import pcgen.cdom.enumeration.CharID; diff --git a/code/src/java/pcgen/cdom/facet/AddLevelFacet.java b/code/src/java/pcgen/cdom/facet/AddLevelFacet.java index ba3f3c9f7c8..bf4755f00a9 100644 --- a/code/src/java/pcgen/cdom/facet/AddLevelFacet.java +++ b/code/src/java/pcgen/cdom/facet/AddLevelFacet.java @@ -19,7 +19,7 @@ import java.util.List; import java.util.ListIterator; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.Constants; import pcgen.cdom.content.LevelCommandFactory; import pcgen.cdom.enumeration.CharID; diff --git a/code/src/java/pcgen/cdom/facet/FormulaResolvingFacet.java b/code/src/java/pcgen/cdom/facet/FormulaResolvingFacet.java index 264a13bff8c..f338fe2e8ec 100644 --- a/code/src/java/pcgen/cdom/facet/FormulaResolvingFacet.java +++ b/code/src/java/pcgen/cdom/facet/FormulaResolvingFacet.java @@ -17,7 +17,7 @@ */ package pcgen.cdom.facet; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.enumeration.CharID; /** diff --git a/code/src/java/pcgen/cdom/facet/ModifierFacet.java b/code/src/java/pcgen/cdom/facet/ModifierFacet.java index 74d6d08a80b..10c9b04d7a4 100644 --- a/code/src/java/pcgen/cdom/facet/ModifierFacet.java +++ b/code/src/java/pcgen/cdom/facet/ModifierFacet.java @@ -19,7 +19,7 @@ import java.util.Optional; -import pcgen.base.calculation.FormulaModifier; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.base.formula.base.ScopeInstance; import pcgen.base.formula.base.VarScoped; import pcgen.base.solver.Modifier; @@ -73,7 +73,7 @@ private void processAddition(CharID id, VarScoped obj, VarModifier vm, Sc private Modifier getModifier(CharID id, ScopeInstance source, FormulaModifier modifier, VarScoped thisValue) { - PCGenScope legalScope = (PCGenScope) source.getLegalScope(); + PCGenScope legalScope = (PCGenScope) source.getImplementedScope(); LoadContext context = loadContextFacet.get(id.getDatasetID()).get(); Modifier returnValue; Optional> formatManager = legalScope.getFormatManager(context); diff --git a/code/src/java/pcgen/cdom/facet/RemoteModifierFacet.java b/code/src/java/pcgen/cdom/facet/RemoteModifierFacet.java index 5aed10d32c1..11760ce7b02 100644 --- a/code/src/java/pcgen/cdom/facet/RemoteModifierFacet.java +++ b/code/src/java/pcgen/cdom/facet/RemoteModifierFacet.java @@ -21,7 +21,7 @@ import java.util.Set; import java.util.function.Consumer; -import pcgen.base.calculation.FormulaModifier; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.base.formula.base.ScopeInstance; import pcgen.base.formula.base.VarScoped; import pcgen.base.solver.Modifier; @@ -106,10 +106,10 @@ varModifier, target, getModifier(id, formulaModifier, modSource, private Modifier getModifier(CharID id, FormulaModifier modifier, VarScoped source, ScopeInstance sourceInstance, VarScoped target, ScopeInstance targetInstance) { - PCGenScope sourceScope = (PCGenScope) sourceInstance.getLegalScope(); + PCGenScope sourceScope = (PCGenScope) sourceInstance.getImplementedScope(); LoadContext context = loadContextFacet.get(id.getDatasetID()).get(); Optional> sourceFormatManager = sourceScope.getFormatManager(context); - PCGenScope targetScope = (PCGenScope) targetInstance.getLegalScope(); + PCGenScope targetScope = (PCGenScope) targetInstance.getImplementedScope(); Optional> targetFormatManager = targetScope.getFormatManager(context); Modifier returnValue; if (sourceFormatManager.isPresent() && targetFormatManager.isPresent()) diff --git a/code/src/java/pcgen/cdom/facet/ScopeFacet.java b/code/src/java/pcgen/cdom/facet/ScopeFacet.java index 68f66552b3a..09d84371e2d 100644 --- a/code/src/java/pcgen/cdom/facet/ScopeFacet.java +++ b/code/src/java/pcgen/cdom/facet/ScopeFacet.java @@ -1,23 +1,24 @@ /* * Copyright (c) Thomas Parker, 2015. - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ package pcgen.cdom.facet; -import java.util.Optional; +import java.util.HashMap; +import java.util.Map; import pcgen.base.formula.base.ScopeInstance; import pcgen.base.formula.base.ScopeInstanceFactory; @@ -25,6 +26,7 @@ import pcgen.cdom.enumeration.CharID; import pcgen.cdom.facet.base.AbstractItemFacet; import pcgen.cdom.formula.scope.GlobalPCScope; +import pcgen.cdom.formula.scope.GlobalPCVarScoped; /** * ScopeFacet stores the relationship from a Character, LegalScope, and @@ -32,10 +34,39 @@ */ public class ScopeFacet extends AbstractItemFacet { + private final Map globalVarScopedMap = new HashMap<>(); + + @Override + public boolean set(CharID id, ScopeInstanceFactory factory) + { + boolean result = super.set(id, factory); + GlobalPCVarScoped globalVS = new GlobalPCVarScoped(GlobalPCScope.GLOBAL_SCOPE_NAME); + globalVarScopedMap.put(id, globalVS); + return result; + } + + @Override + public void copyContents(CharID source, CharID copy) + { + super.copyContents(source, copy); + GlobalPCVarScoped globalVS = globalVarScopedMap.get(source); + if (globalVS != null) + { + globalVarScopedMap.put(copy, globalVS); + } + } + + @Override + public ScopeInstanceFactory remove(CharID id) + { + globalVarScopedMap.remove(id); + return super.remove(id); + } + /** * Returns the Global ScopeInstance for the PlayerCharacter represented by * the given CharID. - * + * * @param id * The CharID representing the PlayerCharacter for which the * Global ScopeInstance should be returned @@ -44,45 +75,43 @@ public class ScopeFacet extends AbstractItemFacet */ public ScopeInstance getGlobalScope(CharID id) { - return get(id).getGlobalInstance(GlobalPCScope.GLOBAL_SCOPE_NAME); + return get(id).get(GlobalPCScope.GLOBAL_SCOPE_NAME, globalVarScopedMap.get(id)); } /** - * Returns the ScopeInstance (within the given LegalScope and + * Returns the ScopeInstance (within the given scope name and * PlayerCharacter represented by the given CharID) for the given VarScoped * object. - * + * * @param id * The CharID representing the PlayerCharacter within which the * returned ScopeInstance exists - * @param legalScopeName - * The LegalScope name within which the returned ScopeInstance - * exists + * @param scopeName + * The scope name within which the returned ScopeInstance exists * @param scopedObject * The VarScoped object for which the ScopeInstance object should * be returned * @return The ScopeInstance for the CharID representing the PlayerCharacter - * and the given LegalScope and VarScoped objects + * and the given scope name and VarScoped objects */ - public ScopeInstance get(CharID id, String legalScopeName, VarScoped scopedObject) + public ScopeInstance get(CharID id, String scopeName, VarScoped scopedObject) { - return get(id).get(legalScopeName, Optional.of(scopedObject)); + return get(id).get(scopeName, scopedObject); } + /** + * Returns the ScopeInstance for the given VarScoped object within the PC identified + * by the given CharID. Uses the global scope name since VarScoped.getProviderFor + * will walk the hierarchy. + * + * @param id + * The CharID representing the PlayerCharacter + * @param vs + * The VarScoped object for which the ScopeInstance should be returned + * @return The ScopeInstance for the given VarScoped object + */ public ScopeInstance get(CharID id, VarScoped vs) { - Optional localName = vs.getLocalScopeName(); - VarScoped active = vs; - while (localName.isEmpty()) - { - Optional parent = active.getVariableParent(); - if (parent.isEmpty()) - { - return getGlobalScope(id); - } - active = parent.get(); - localName = active.getLocalScopeName(); - } - return get(id, localName.get(), vs); + return get(id).get(GlobalPCScope.GLOBAL_SCOPE_NAME, vs); } } diff --git a/code/src/java/pcgen/cdom/facet/SolverManagerFacet.java b/code/src/java/pcgen/cdom/facet/SolverManagerFacet.java index 1a315da46aa..cea4aa4bca3 100644 --- a/code/src/java/pcgen/cdom/facet/SolverManagerFacet.java +++ b/code/src/java/pcgen/cdom/facet/SolverManagerFacet.java @@ -28,6 +28,7 @@ import pcgen.cdom.content.VarModifier; import pcgen.cdom.enumeration.CharID; import pcgen.cdom.facet.base.AbstractItemFacet; +import pcgen.rules.context.VariableContext; /** * This stores the SolverManager for each PlayerCharacter. @@ -49,10 +50,13 @@ public List> diagnose(CharID id, VariableID varID) public boolean addModifier(CharID id, VarModifier vm, VarScoped thisValue, Modifier modifier, ScopeInstance source) { - ScopeInstance scope = scopeFacet.get(id, vm.getFullLegalScopeName(), thisValue); - VariableID varID = (VariableID) loadContextFacet.get(id.getDatasetID()).get().getVariableContext() - .getVariableID(scope, vm.getVarName()); - return get(id).addModifierAndSolve(varID, modifier, source); + VariableContext varContext = loadContextFacet.get(id.getDatasetID()).get().getVariableContext(); + ScopeInstance scope = resolveScope(id, vm, thisValue, varContext); + VariableID varID = (VariableID) varContext.getVariableID(scope, vm.getVarName()); + SolverManager sm = get(id); + sm.addModifier(varID, modifier, source); + sm.processSolver(varID); + return true; } /** @@ -61,10 +65,23 @@ public boolean addModifier(CharID id, VarModifier vm, VarScoped thisValue public void removeModifier(CharID id, VarModifier vm, VarScoped thisValue, Modifier modifier, ScopeInstance source) { - ScopeInstance scope = scopeFacet.get(id, vm.getFullLegalScopeName(), thisValue); - VariableID varID = (VariableID) loadContextFacet.get(id.getDatasetID()).get().getVariableContext() - .getVariableID(scope, vm.getVarName()); - get(id).removeModifier(varID, modifier, source); + VariableContext varContext = loadContextFacet.get(id.getDatasetID()).get().getVariableContext(); + ScopeInstance scope = resolveScope(id, vm, thisValue, varContext); + VariableID varID = (VariableID) varContext.getVariableID(scope, vm.getVarName()); + SolverManager sm = get(id); + sm.removeModifier(varID, modifier, source); + sm.processSolver(varID); + } + + private ScopeInstance resolveScope(CharID id, VarModifier vm, VarScoped thisValue, + VariableContext varContext) + { + if (vm.getLegalScope().isGlobal() + || varContext.isLegalVariableID(scopeFacet.getGlobalScope(id).getImplementedScope(), vm.getVarName())) + { + return scopeFacet.getGlobalScope(id); + } + return scopeFacet.get(id, vm.getFullLegalScopeName(), thisValue); } public void setScopeFacet(ScopeFacet scopeFacet) diff --git a/code/src/java/pcgen/cdom/facet/SpellsFacet.java b/code/src/java/pcgen/cdom/facet/SpellsFacet.java index 9b9c17d9fb5..097cb3a27b4 100644 --- a/code/src/java/pcgen/cdom/facet/SpellsFacet.java +++ b/code/src/java/pcgen/cdom/facet/SpellsFacet.java @@ -19,7 +19,7 @@ import java.util.Collection; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.AssociatedPrereqObject; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.CDOMReference; diff --git a/code/src/java/pcgen/cdom/facet/StatValueFacet.java b/code/src/java/pcgen/cdom/facet/StatValueFacet.java index d1f469249d5..5bee85d7c45 100644 --- a/code/src/java/pcgen/cdom/facet/StatValueFacet.java +++ b/code/src/java/pcgen/cdom/facet/StatValueFacet.java @@ -206,7 +206,7 @@ private VariableID getVarID(CharID id, PCStat stat, String channelName) String varName = ChannelUtilities.createVarName(channelName); ScopeInstanceFactory instFactory = SCOPE_FACET.get(id); Optional localScopeName = stat.getLocalScopeName(); - ScopeInstance scopeInst = instFactory.get(localScopeName.get(), Optional.of(stat)); + ScopeInstance scopeInst = instFactory.get(localScopeName.get(), stat); try { return (VariableID) loadContextFacet.get(id.getDatasetID()).get() diff --git a/code/src/java/pcgen/cdom/facet/analysis/ChallengeRatingFacet.java b/code/src/java/pcgen/cdom/facet/analysis/ChallengeRatingFacet.java index 110897f4656..0b1920a39ca 100644 --- a/code/src/java/pcgen/cdom/facet/analysis/ChallengeRatingFacet.java +++ b/code/src/java/pcgen/cdom/facet/analysis/ChallengeRatingFacet.java @@ -20,7 +20,7 @@ import java.util.List; import java.util.Map; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.content.ChallengeRating; import pcgen.cdom.content.LevelCommandFactory; diff --git a/code/src/java/pcgen/cdom/facet/analysis/CharacterSpellResistanceFacet.java b/code/src/java/pcgen/cdom/facet/analysis/CharacterSpellResistanceFacet.java index 2694fd52097..bbeea46b44b 100644 --- a/code/src/java/pcgen/cdom/facet/analysis/CharacterSpellResistanceFacet.java +++ b/code/src/java/pcgen/cdom/facet/analysis/CharacterSpellResistanceFacet.java @@ -20,7 +20,7 @@ import java.util.Map; import java.util.Set; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.content.SpellResistance; import pcgen.cdom.enumeration.CharID; diff --git a/code/src/java/pcgen/cdom/facet/analysis/InitiativeFacet.java b/code/src/java/pcgen/cdom/facet/analysis/InitiativeFacet.java index 192e448baed..f1bd4d49792 100644 --- a/code/src/java/pcgen/cdom/facet/analysis/InitiativeFacet.java +++ b/code/src/java/pcgen/cdom/facet/analysis/InitiativeFacet.java @@ -17,7 +17,7 @@ */ package pcgen.cdom.facet.analysis; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.enumeration.CharID; import pcgen.cdom.facet.BonusCheckingFacet; diff --git a/code/src/java/pcgen/cdom/facet/analysis/LevelFacet.java b/code/src/java/pcgen/cdom/facet/analysis/LevelFacet.java index dbc66e63772..dc20c41dd35 100644 --- a/code/src/java/pcgen/cdom/facet/analysis/LevelFacet.java +++ b/code/src/java/pcgen/cdom/facet/analysis/LevelFacet.java @@ -22,7 +22,7 @@ import javax.swing.event.EventListenerList; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.enumeration.CharID; import pcgen.cdom.enumeration.FormulaKey; import pcgen.cdom.facet.FormulaResolvingFacet; diff --git a/code/src/java/pcgen/cdom/facet/analysis/LevelTableFacet.java b/code/src/java/pcgen/cdom/facet/analysis/LevelTableFacet.java index f46579bbfc4..346470951af 100644 --- a/code/src/java/pcgen/cdom/facet/analysis/LevelTableFacet.java +++ b/code/src/java/pcgen/cdom/facet/analysis/LevelTableFacet.java @@ -17,7 +17,7 @@ */ package pcgen.cdom.facet.analysis; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.enumeration.CharID; import pcgen.cdom.facet.FormulaResolvingFacet; diff --git a/code/src/java/pcgen/cdom/facet/analysis/LoadFacet.java b/code/src/java/pcgen/cdom/facet/analysis/LoadFacet.java index 5ee32161756..ac9ba8816ad 100644 --- a/code/src/java/pcgen/cdom/facet/analysis/LoadFacet.java +++ b/code/src/java/pcgen/cdom/facet/analysis/LoadFacet.java @@ -19,7 +19,7 @@ import java.math.BigDecimal; import java.util.regex.Pattern; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.enumeration.CharID; import pcgen.cdom.facet.BonusCheckingFacet; diff --git a/code/src/java/pcgen/cdom/facet/analysis/VariableFacet.java b/code/src/java/pcgen/cdom/facet/analysis/VariableFacet.java index f54501699fb..a4ce89a48ac 100644 --- a/code/src/java/pcgen/cdom/facet/analysis/VariableFacet.java +++ b/code/src/java/pcgen/cdom/facet/analysis/VariableFacet.java @@ -24,7 +24,7 @@ import java.util.Map; import java.util.Set; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.enumeration.CharID; import pcgen.cdom.enumeration.VariableKey; diff --git a/code/src/java/pcgen/cdom/facet/analysis/VisionFacet.java b/code/src/java/pcgen/cdom/facet/analysis/VisionFacet.java index 9c694a42808..74e6b7a76fe 100644 --- a/code/src/java/pcgen/cdom/facet/analysis/VisionFacet.java +++ b/code/src/java/pcgen/cdom/facet/analysis/VisionFacet.java @@ -25,7 +25,7 @@ import java.util.Set; import java.util.TreeSet; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.AssociatedPrereqObject; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.CDOMReference; diff --git a/code/src/java/pcgen/cdom/facet/model/SizeFacet.java b/code/src/java/pcgen/cdom/facet/model/SizeFacet.java index e19af3ccdd6..bc4cdced9ed 100644 --- a/code/src/java/pcgen/cdom/facet/model/SizeFacet.java +++ b/code/src/java/pcgen/cdom/facet/model/SizeFacet.java @@ -19,7 +19,7 @@ import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.ItemFacet; import pcgen.cdom.enumeration.CharID; diff --git a/code/src/java/pcgen/cdom/format/table/ColumnFormatFactory.java b/code/src/java/pcgen/cdom/format/table/ColumnFormatFactory.java index 657d824a69b..54594c49f05 100644 --- a/code/src/java/pcgen/cdom/format/table/ColumnFormatFactory.java +++ b/code/src/java/pcgen/cdom/format/table/ColumnFormatFactory.java @@ -17,7 +17,7 @@ */ package pcgen.cdom.format.table; -import java.util.Objects; +import java.util.Optional; import java.util.regex.Pattern; import pcgen.base.formatmanager.FormatManagerFactory; @@ -56,9 +56,11 @@ public ColumnFormatFactory(FormatManager columnFormat) } @Override - public FormatManager build(String subFormatName, FormatManagerLibrary library) + public FormatManager build(Optional parentFormat, + Optional subFormat, FormatManagerLibrary library) { - Objects.requireNonNull(subFormatName, "Column Format cannot be built from no instructions"); + String subFormatName = subFormat.orElseThrow( + () -> new IllegalArgumentException("Column Format cannot be built from no instructions")); if (SUB_PATTERN.matcher(subFormatName).find()) { /* @@ -68,7 +70,7 @@ public FormatManager build(String subFormatName, FormatManagerLibra throw new IllegalArgumentException( "Column Subformat not supported: " + subFormatName + " may not contain COLUMN inside COLUMN"); } - FormatManager formatManager = library.getFormatManager(subFormatName); + FormatManager formatManager = library.getFormatManager(parentFormat, subFormatName); return proc(formatManager); } diff --git a/code/src/java/pcgen/cdom/format/table/TableFormatFactory.java b/code/src/java/pcgen/cdom/format/table/TableFormatFactory.java index bce06a3bc8c..9050b43a2b2 100644 --- a/code/src/java/pcgen/cdom/format/table/TableFormatFactory.java +++ b/code/src/java/pcgen/cdom/format/table/TableFormatFactory.java @@ -17,7 +17,7 @@ */ package pcgen.cdom.format.table; -import java.util.Objects; +import java.util.Optional; import java.util.regex.Pattern; import pcgen.base.formatmanager.FormatManagerFactory; @@ -56,9 +56,11 @@ public TableFormatFactory(FormatManager tableFormat) } @Override - public FormatManager build(String subFormatName, FormatManagerLibrary library) + public FormatManager build(Optional parentFormat, + Optional subFormat, FormatManagerLibrary library) { - Objects.requireNonNull(subFormatName, "Table Format cannot be built from no instructions"); + String subFormatName = subFormat.orElseThrow( + () -> new IllegalArgumentException("Table Format cannot be built from no instructions")); if (SUB_PATTERN.matcher(subFormatName).find()) { /* @@ -69,7 +71,7 @@ public FormatManager build(String subFormatName, FormatManagerLibrary throw new IllegalArgumentException( "Multidimensional Table format not supported: " + subFormatName + " may not contain brackets"); } - return new TableFormatManager(tableFormat, library.getFormatManager(subFormatName)); + return new TableFormatManager(tableFormat, library.getFormatManager(parentFormat, subFormatName)); } @Override diff --git a/code/src/java/pcgen/cdom/formula/FixedSizeFormula.java b/code/src/java/pcgen/cdom/formula/FixedSizeFormula.java index 84f2aec139f..f11b755d960 100644 --- a/code/src/java/pcgen/cdom/formula/FixedSizeFormula.java +++ b/code/src/java/pcgen/cdom/formula/FixedSizeFormula.java @@ -19,7 +19,6 @@ import java.util.Objects; -import pcgen.base.formula.Formula; import pcgen.cdom.enumeration.IntegerKey; import pcgen.cdom.reference.CDOMSingleRef; import pcgen.core.Equipment; diff --git a/code/src/java/pcgen/base/formula/Formula.java b/code/src/java/pcgen/cdom/formula/Formula.java similarity index 91% rename from code/src/java/pcgen/base/formula/Formula.java rename to code/src/java/pcgen/cdom/formula/Formula.java index bc9e2becefb..6c6de45b45b 100644 --- a/code/src/java/pcgen/base/formula/Formula.java +++ b/code/src/java/pcgen/cdom/formula/Formula.java @@ -15,14 +15,16 @@ * along with this library; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -package pcgen.base.formula; +package pcgen.cdom.formula; import pcgen.core.Equipment; import pcgen.core.PlayerCharacter; /** - * - * A Formula is a mathematical formula which requires a context to resolve. + * A legacy formula interface for PCGen's JEP-based formula resolution. Resolves formulas + * against a PlayerCharacter context. This is distinct from the generic formula parser + * system in module pcgen.formula ({@code pcgen.base.formula.parse}), which provides a + * context-free expression parser with visitor-based evaluation. */ public interface Formula { diff --git a/code/src/java/pcgen/cdom/formula/PCGenScoped.java b/code/src/java/pcgen/cdom/formula/PCGenScoped.java index eaffaa9ad9d..43339c06c29 100644 --- a/code/src/java/pcgen/cdom/formula/PCGenScoped.java +++ b/code/src/java/pcgen/cdom/formula/PCGenScoped.java @@ -18,6 +18,7 @@ package pcgen.cdom.formula; import java.util.List; +import java.util.Optional; import pcgen.base.formula.base.VarScoped; import pcgen.cdom.base.VarContainer; @@ -28,10 +29,17 @@ */ public interface PCGenScoped extends VarContainer, VarScoped { + /** + * Returns the name of the local scope for this object, if it has one. + * + * @return The name of the local scope, or empty if this object is in the global scope + */ + public Optional getLocalScopeName(); + /** * Returns the local child of the given child type and child name. Returns null if no * such type or no child of that type with the given name exists. - * + * * @param childType * The child type for which the child should be returned * @param childName @@ -42,10 +50,10 @@ public interface PCGenScoped extends VarContainer, VarScoped /** * Returns the List of child types that this PCGenScoped contains. - * + * * Contract for implementations of this method: Will not return null (return an empty * list instead). - * + * * @return The List of child types that this PCGenScoped contains */ public List getChildTypes(); @@ -53,7 +61,7 @@ public interface PCGenScoped extends VarContainer, VarScoped /** * Returns the List of children of the given child type. Returns null if this * PCGenScoped has no children of the given type. - * + * * @param childType * The child type for which the list of children should be returned * @return The List of children of the given child type diff --git a/code/src/java/pcgen/cdom/formula/VariableChannel.java b/code/src/java/pcgen/cdom/formula/VariableChannel.java index e8830ddd62d..226f24054e8 100644 --- a/code/src/java/pcgen/cdom/formula/VariableChannel.java +++ b/code/src/java/pcgen/cdom/formula/VariableChannel.java @@ -95,7 +95,7 @@ public T get() T value = varStore.get(varID); if (value == null) { - return manager.getDefaultValue(varID.getFormatManager()); + return manager.getDefault(varID.getFormatManager()); } return value; } @@ -106,7 +106,6 @@ public void set(T object) if (!checkForVeto(object)) { varStore.put(varID, object); - manager.solveChildren(varID); } } diff --git a/code/src/java/pcgen/cdom/formula/VariableUtilities.java b/code/src/java/pcgen/cdom/formula/VariableUtilities.java index 6042a5011a2..06c36b1fe32 100644 --- a/code/src/java/pcgen/cdom/formula/VariableUtilities.java +++ b/code/src/java/pcgen/cdom/formula/VariableUtilities.java @@ -17,7 +17,6 @@ */ package pcgen.cdom.formula; -import java.util.Optional; import pcgen.base.formula.base.ScopeInstance; import pcgen.base.formula.base.ScopeInstanceFactory; @@ -156,11 +155,11 @@ public static void forwardVariableChangeToDFCL(CharID id, * @return The VariableID for the variable with the given name on the local object * represented by the given ScopeInstance */ - public static VariableID getLocalVariableID(CharID id, + public static VariableID getLocalVariableID(CharID id, ScopeInstance scopeInst, String name) { LoadContext loadContext = LOAD_CONTEXT_FACET.get(id.getDatasetID()).get(); - return loadContext.getVariableContext().getVariableID(scopeInst, name); + return (VariableID) loadContext.getVariableContext().getVariableID(scopeInst, name); } /** @@ -176,13 +175,17 @@ public static VariableID getLocalVariableID(CharID id, * The name of the variable for which the VariableID should be returned * @return The VariableID for the variable with the given name on the given object */ - public static VariableID getLocalVariableID(CharID id, VarScoped owner, + public static VariableID getLocalVariableID(CharID id, VarScoped owner, String name) { ScopeInstanceFactory instFactory = SCOPE_FACET.get(id); - Optional localScopeName = owner.getLocalScopeName(); - ScopeInstance scopeInst = - instFactory.get(localScopeName.get(), Optional.of(owner)); + PCGenScoped pcGenOwner = (PCGenScoped) owner; + String localScopeName = pcGenOwner.getLocalScopeName().orElseThrow( + () -> new IllegalArgumentException( + "Cannot resolve local variable '" + name + "' on " + + owner.getClass().getSimpleName() + " '" + owner + + "': object has no local scope name")); + ScopeInstance scopeInst = instFactory.get(localScopeName, owner); return VariableUtilities.getLocalVariableID(id, scopeInst, name); } } diff --git a/code/src/java/pcgen/cdom/formula/VariableWrapper.java b/code/src/java/pcgen/cdom/formula/VariableWrapper.java index 938229ec848..128d8c1841c 100644 --- a/code/src/java/pcgen/cdom/formula/VariableWrapper.java +++ b/code/src/java/pcgen/cdom/formula/VariableWrapper.java @@ -84,7 +84,7 @@ public T get() T value = varStore.get(varID); if (value == null) { - return manager.getDefaultValue(varID.getFormatManager()); + return manager.getDefault(varID.getFormatManager()); } return value; } diff --git a/code/src/java/pcgen/cdom/formula/local/DefinedWrappingModifier.java b/code/src/java/pcgen/cdom/formula/local/DefinedWrappingModifier.java index 6aa49bee6d5..dd8b07feb4d 100644 --- a/code/src/java/pcgen/cdom/formula/local/DefinedWrappingModifier.java +++ b/code/src/java/pcgen/cdom/formula/local/DefinedWrappingModifier.java @@ -1,14 +1,14 @@ /* * Copyright 2018 (C) Tom Parker - * + * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License along with * this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA @@ -17,11 +17,12 @@ import java.util.Objects; -import pcgen.base.calculation.FormulaModifier; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.base.formula.base.DependencyManager; import pcgen.base.formula.base.EvaluationManager; -import pcgen.base.formula.base.FormulaManager; +import pcgen.base.formula.base.FormulaSemantics; import pcgen.base.formula.base.FunctionLibrary; +import pcgen.base.formula.exception.SemanticsException; import pcgen.base.solver.Modifier; import pcgen.base.util.FormatManager; @@ -29,7 +30,7 @@ * A DefinedWrappingModifier wraps a FormulaModifier and projects it to the formula system * as a Modifier, while also inserting any new formula system functions supported by the * given java.util.function.Function. - * + * * @param * The format that this DefinedWrappingModifier acts upon */ @@ -59,7 +60,7 @@ public class DefinedWrappingModifier implements Modifier /** * Constructs a new DefinedWrappingModifier for the given FormulaModifier and * Function. - * + * * @param modifier * The underlying FormulaModifier * @param definedName @@ -82,22 +83,25 @@ public DefinedWrappingModifier(FormulaModifier modifier, String definedName, @Override public T process(EvaluationManager manager) { - FormulaManager formulaManager = decorateFormulaManager(manager.get(EvaluationManager.FMANAGER)); - return modifier.process(manager.getWith(EvaluationManager.FMANAGER, formulaManager)); + FunctionLibrary functionLib = manager.get(EvaluationManager.FUNCTION); + functionLib = new DefinedWrappingLibrary(functionLib, definedName, definedValue, formatManager); + return modifier.process(manager.getWith(EvaluationManager.FUNCTION, functionLib)); } @Override - public void getDependencies(DependencyManager fdm) + public void captureDependencies(DependencyManager fdm) { - FormulaManager formulaManager = decorateFormulaManager(fdm.get(DependencyManager.FMANAGER)); - modifier.getDependencies(fdm.getWith(DependencyManager.FMANAGER, formulaManager)); + FunctionLibrary functionLib = fdm.get(DependencyManager.FUNCTION); + functionLib = new DefinedWrappingLibrary(functionLib, definedName, definedValue, formatManager); + modifier.getDependencies(fdm.getWith(DependencyManager.FUNCTION, functionLib)); } - private FormulaManager decorateFormulaManager(FormulaManager formulaManager) + @Override + public void isValid(FormulaSemantics semantics) throws SemanticsException { - FunctionLibrary functionManager = formulaManager.get(FormulaManager.FUNCTION); - functionManager = new DefinedWrappingLibrary(functionManager, definedName, definedValue, formatManager); - return formulaManager.getWith(FormulaManager.FUNCTION, functionManager); + FunctionLibrary functionLib = semantics.get(FormulaSemantics.FUNCTION); + functionLib = new DefinedWrappingLibrary(functionLib, definedName, definedValue, formatManager); + modifier.isValid(semantics.getWith(FormulaSemantics.FUNCTION, functionLib)); } @Override diff --git a/code/src/java/pcgen/cdom/formula/local/ModifierDecoration.java b/code/src/java/pcgen/cdom/formula/local/ModifierDecoration.java index b67ecafaf49..05c20c9d274 100644 --- a/code/src/java/pcgen/cdom/formula/local/ModifierDecoration.java +++ b/code/src/java/pcgen/cdom/formula/local/ModifierDecoration.java @@ -17,9 +17,11 @@ import java.util.Objects; -import pcgen.base.calculation.FormulaModifier; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.base.formula.base.DependencyManager; import pcgen.base.formula.base.EvaluationManager; +import pcgen.base.formula.base.FormulaSemantics; +import pcgen.base.formula.exception.SemanticsException; import pcgen.base.solver.Modifier; import pcgen.base.util.FormatManager; @@ -55,11 +57,17 @@ public T process(EvaluationManager manager) } @Override - public void getDependencies(DependencyManager fdm) + public void captureDependencies(DependencyManager fdm) { modifier.getDependencies(fdm); } + @Override + public void isValid(FormulaSemantics semantics) throws SemanticsException + { + modifier.isValid(semantics); + } + @Override public long getPriority() { diff --git a/code/src/java/pcgen/cdom/formula/local/RemoteWrappingModifier.java b/code/src/java/pcgen/cdom/formula/local/RemoteWrappingModifier.java index 7a17cb7f072..6836211001f 100644 --- a/code/src/java/pcgen/cdom/formula/local/RemoteWrappingModifier.java +++ b/code/src/java/pcgen/cdom/formula/local/RemoteWrappingModifier.java @@ -1,14 +1,14 @@ /* * Copyright 2018 (C) Tom Parker - * + * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License along with * this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA @@ -17,12 +17,13 @@ import java.util.Objects; -import pcgen.base.calculation.FormulaModifier; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.base.formula.base.DependencyManager; import pcgen.base.formula.base.EvaluationManager; -import pcgen.base.formula.base.FormulaManager; +import pcgen.base.formula.base.FormulaSemantics; import pcgen.base.formula.base.FunctionLibrary; import pcgen.base.formula.base.VarScoped; +import pcgen.base.formula.exception.SemanticsException; import pcgen.base.solver.Modifier; import pcgen.base.util.FormatManager; @@ -30,7 +31,7 @@ * A RemoteWrappingModifier wraps a FormulaModifier and projects it to the formula system * as a Modifier, while also inserting any new formula system functions supported by the * given java.util.function.Function. - * + * * @param * The format that this RemoteWrappingModifier acts upon */ @@ -65,7 +66,7 @@ public class RemoteWrappingModifier implements Modifier /** * Constructs a new RemoteWrappingModifier for the given FormulaModifier and Function. - * + * * @param modifier * The underlying FormulaModifier * @param sourceValue @@ -92,23 +93,28 @@ public RemoteWrappingModifier(FormulaModifier modifier, VarScoped sourceValue @Override public T process(EvaluationManager manager) { - FormulaManager formulaManager = decorateFormulaManager(manager.get(EvaluationManager.FMANAGER)); - return modifier.process(manager.getWith(EvaluationManager.FMANAGER, formulaManager)); + FunctionLibrary functionLib = manager.get(EvaluationManager.FUNCTION); + functionLib = new RemoteWrappingLibrary(functionLib, sourceValue, sourceFormatManager, targetValue, + targetFormatManager); + return modifier.process(manager.getWith(EvaluationManager.FUNCTION, functionLib)); } @Override - public void getDependencies(DependencyManager fdm) + public void captureDependencies(DependencyManager fdm) { - FormulaManager formulaManager = decorateFormulaManager(fdm.get(DependencyManager.FMANAGER)); - modifier.getDependencies(fdm.getWith(DependencyManager.FMANAGER, formulaManager)); + FunctionLibrary functionLib = fdm.get(DependencyManager.FUNCTION); + functionLib = new RemoteWrappingLibrary(functionLib, sourceValue, sourceFormatManager, targetValue, + targetFormatManager); + modifier.getDependencies(fdm.getWith(DependencyManager.FUNCTION, functionLib)); } - private FormulaManager decorateFormulaManager(FormulaManager formulaManager) + @Override + public void isValid(FormulaSemantics semantics) throws SemanticsException { - FunctionLibrary functionManager = formulaManager.get(FormulaManager.FUNCTION); - functionManager = new RemoteWrappingLibrary(functionManager, sourceValue, sourceFormatManager, targetValue, + FunctionLibrary functionLib = semantics.get(FormulaSemantics.FUNCTION); + functionLib = new RemoteWrappingLibrary(functionLib, sourceValue, sourceFormatManager, targetValue, targetFormatManager); - return formulaManager.getWith(FormulaManager.FUNCTION, functionManager); + modifier.isValid(semantics.getWith(FormulaSemantics.FUNCTION, functionLib)); } @Override diff --git a/code/src/java/pcgen/cdom/formula/scope/DynamicScope.java b/code/src/java/pcgen/cdom/formula/scope/DynamicScope.java index d3178a19258..e0cd1fbdd04 100644 --- a/code/src/java/pcgen/cdom/formula/scope/DynamicScope.java +++ b/code/src/java/pcgen/cdom/formula/scope/DynamicScope.java @@ -1,23 +1,25 @@ /* * Copyright 2018 (C) Tom Parker - * + * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License along with * this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA */ package pcgen.cdom.formula.scope; +import java.util.List; import java.util.Objects; import java.util.Optional; +import pcgen.base.formula.base.ImplementedScope; import pcgen.base.util.FormatManager; import pcgen.cdom.helper.SpringHelper; import pcgen.cdom.inst.Dynamic; @@ -32,7 +34,8 @@ public class DynamicScope implements PCGenScope /** * The parent PCGenScope for all DynamicScope objects is the GlobalPCScope. */ - private static final Optional PARENT_SCOPE = Optional.of(SpringHelper.getBean(GlobalPCScope.class)); + private static final List DRAWS_FROM = + List.of(SpringHelper.getBean(GlobalPCScope.class)); /** * The DynamicCategory indicating the objects contained by this DynamicScope. @@ -47,7 +50,7 @@ public class DynamicScope implements PCGenScope /** * Constructs a new DynamicScope for the given DynamicCategory and containing the * objects identified in the given FormatManager. - * + * * @param category * The DynamicCategory indicating the objects contained by this * DynamicScope @@ -63,13 +66,19 @@ public DynamicScope(DynamicCategory category, FormatManager formatManag @Override public String getName() { - return category.getName(); + return GlobalPCScope.GLOBAL_SCOPE_NAME + "." + category.getName(); } @Override - public Optional getParentScope() + public boolean isGlobal() { - return PARENT_SCOPE; + return false; + } + + @Override + public List drawsFrom() + { + return DRAWS_FROM; } @Override diff --git a/code/src/java/pcgen/cdom/formula/scope/EquipmentPartScope.java b/code/src/java/pcgen/cdom/formula/scope/EquipmentPartScope.java index 457f138df6c..5990853bda4 100644 --- a/code/src/java/pcgen/cdom/formula/scope/EquipmentPartScope.java +++ b/code/src/java/pcgen/cdom/formula/scope/EquipmentPartScope.java @@ -17,8 +17,11 @@ */ package pcgen.cdom.formula.scope; +import java.util.Collections; +import java.util.List; import java.util.Optional; +import pcgen.base.formula.base.ImplementedScope; import pcgen.base.util.FormatManager; import pcgen.rules.context.LoadContext; @@ -35,31 +38,37 @@ public class EquipmentPartScope implements PCGenScope public static final String PC_EQUIPMENT_PART = "PC.EQUIPMENT.PART"; /** - * The parent of this scope (once loaded) + * The scopes this scope draws from (once loaded) */ - private Optional parent; + private List drawsFrom = Collections.emptyList(); @Override public String getName() { - return "PART"; + return "PC.EQUIPMENT.PART"; } @Override - public Optional getParentScope() + public boolean isGlobal() { - return parent; + return false; + } + + @Override + public List drawsFrom() + { + return drawsFrom; } /** * Sets the parent PCGenScope for this EquipmentPartScope. - * + * * @param parent * The parent PCGenScope for this EquipmentPartScope */ public void setParent(PCGenScope parent) { - this.parent = Optional.of(parent); + this.drawsFrom = List.of(parent); } @Override diff --git a/code/src/java/pcgen/cdom/formula/scope/EquipmentScope.java b/code/src/java/pcgen/cdom/formula/scope/EquipmentScope.java index 798030150de..bc343a4856f 100644 --- a/code/src/java/pcgen/cdom/formula/scope/EquipmentScope.java +++ b/code/src/java/pcgen/cdom/formula/scope/EquipmentScope.java @@ -17,8 +17,11 @@ */ package pcgen.cdom.formula.scope; +import java.util.Collections; +import java.util.List; import java.util.Optional; +import pcgen.base.formula.base.ImplementedScope; import pcgen.base.util.FormatManager; import pcgen.rules.context.LoadContext; @@ -30,31 +33,37 @@ public class EquipmentScope implements PCGenScope { /** - * The parent of this scope (once loaded) + * The scopes this scope draws from (once loaded) */ - private Optional parent; + private List drawsFrom = Collections.emptyList(); @Override public String getName() { - return "EQUIPMENT"; + return "PC.EQUIPMENT"; } @Override - public Optional getParentScope() + public boolean isGlobal() { - return parent; + return false; + } + + @Override + public List drawsFrom() + { + return drawsFrom; } /** * Sets the parent PCGenScope for this EquipmentScope. - * + * * @param parent * The parent PCGenScope for this EquipmentScope */ public void setParent(PCGenScope parent) { - this.parent = Optional.of(parent); + this.drawsFrom = List.of(parent); } @Override diff --git a/code/src/java/pcgen/cdom/formula/scope/GlobalEQScope.java b/code/src/java/pcgen/cdom/formula/scope/GlobalEQScope.java index 6a45861a788..7f531bdef97 100644 --- a/code/src/java/pcgen/cdom/formula/scope/GlobalEQScope.java +++ b/code/src/java/pcgen/cdom/formula/scope/GlobalEQScope.java @@ -17,8 +17,11 @@ */ package pcgen.cdom.formula.scope; +import java.util.Collections; +import java.util.List; import java.util.Optional; +import pcgen.base.formula.base.ImplementedScope; import pcgen.base.util.FormatManager; import pcgen.rules.context.LoadContext; @@ -44,9 +47,15 @@ public String getName() } @Override - public Optional getParentScope() + public boolean isGlobal() { - return Optional.empty(); + return true; + } + + @Override + public List drawsFrom() + { + return Collections.emptyList(); } @Override diff --git a/code/src/java/pcgen/cdom/formula/scope/GlobalPCScope.java b/code/src/java/pcgen/cdom/formula/scope/GlobalPCScope.java index af221a90cde..7df7cc3045a 100644 --- a/code/src/java/pcgen/cdom/formula/scope/GlobalPCScope.java +++ b/code/src/java/pcgen/cdom/formula/scope/GlobalPCScope.java @@ -17,8 +17,11 @@ */ package pcgen.cdom.formula.scope; +import java.util.Collections; +import java.util.List; import java.util.Optional; +import pcgen.base.formula.base.ImplementedScope; import pcgen.base.util.FormatManager; import pcgen.rules.context.LoadContext; @@ -39,9 +42,15 @@ public String getName() } @Override - public Optional getParentScope() + public boolean isGlobal() { - return Optional.empty(); + return true; + } + + @Override + public List drawsFrom() + { + return Collections.emptyList(); } @Override diff --git a/code/src/java/pcgen/cdom/formula/scope/GlobalPCVarScoped.java b/code/src/java/pcgen/cdom/formula/scope/GlobalPCVarScoped.java new file mode 100644 index 00000000000..2ff72395aef --- /dev/null +++ b/code/src/java/pcgen/cdom/formula/scope/GlobalPCVarScoped.java @@ -0,0 +1,70 @@ +/* + * Copyright 2024 (C) PCGen Developers + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package pcgen.cdom.formula.scope; + +import pcgen.base.formula.base.ImplementedScope; +import pcgen.base.formula.base.VarScoped; + +/** + * A VarScoped sentinel representing the global PC scope for a character. + */ +public class GlobalPCVarScoped implements VarScoped +{ + private final String name; + + public GlobalPCVarScoped(String name) + { + this.name = name; + } + + @Override + public String getKeyName() + { + return name; + } + + @Override + public VarScoped getProviderFor(ImplementedScope implScope) + { + if (implScope.isGlobal()) + { + return this; + } + throw new IllegalArgumentException( + "GlobalPCVarScoped cannot provide for non-global scope: " + implScope.getName()); + } + + @Override + public String toString() + { + return "PC Global Scope (" + name + ")"; + } + + @Override + public boolean equals(Object obj) + { + return (obj instanceof GlobalPCVarScoped other) + && name.equals(other.name); + } + + @Override + public int hashCode() + { + return name.hashCode(); + } +} diff --git a/code/src/java/pcgen/cdom/formula/scope/LegalScopeUtilities.java b/code/src/java/pcgen/cdom/formula/scope/LegalScopeUtilities.java index 31377c5bbb4..c304bd13a7b 100644 --- a/code/src/java/pcgen/cdom/formula/scope/LegalScopeUtilities.java +++ b/code/src/java/pcgen/cdom/formula/scope/LegalScopeUtilities.java @@ -1,23 +1,23 @@ /* * Copyright 2015 (C) Tom Parker - * + * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. - * + * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package pcgen.cdom.formula.scope; -import pcgen.base.formula.inst.ScopeManagerInst; +import pcgen.base.formula.inst.ImplementedScopeLibrary; import pcgen.cdom.helper.SpringHelper; public final class LegalScopeUtilities @@ -28,15 +28,15 @@ private LegalScopeUtilities() //Do not construct utility class } - public static void loadLegalScopeLibrary(ScopeManagerInst library) + public static void loadLegalScopeLibrary(ImplementedScopeLibrary library) { - library.registerScope(SpringHelper.getBean(GlobalPCScope.class)); - library.registerScope(SpringHelper.getBean(EquipmentScope.class)); - library.registerScope(SpringHelper.getBean(EquipmentPartScope.class)); - library.registerScope(SpringHelper.getBean(RaceScope.class)); - library.registerScope(SpringHelper.getBean(SaveScope.class)); - library.registerScope(SpringHelper.getBean(SizeScope.class)); - library.registerScope(SpringHelper.getBean(SkillScope.class)); - library.registerScope(SpringHelper.getBean(StatScope.class)); + library.addScope(SpringHelper.getBean(GlobalPCScope.class)); + library.addScope(SpringHelper.getBean(EquipmentScope.class)); + library.addScope(SpringHelper.getBean(EquipmentPartScope.class)); + library.addScope(SpringHelper.getBean(RaceScope.class)); + library.addScope(SpringHelper.getBean(SaveScope.class)); + library.addScope(SpringHelper.getBean(SizeScope.class)); + library.addScope(SpringHelper.getBean(SkillScope.class)); + library.addScope(SpringHelper.getBean(StatScope.class)); } } diff --git a/code/src/java/pcgen/cdom/formula/scope/PCGenScope.java b/code/src/java/pcgen/cdom/formula/scope/PCGenScope.java index 6079f39450c..fa25f2806c7 100644 --- a/code/src/java/pcgen/cdom/formula/scope/PCGenScope.java +++ b/code/src/java/pcgen/cdom/formula/scope/PCGenScope.java @@ -17,22 +17,20 @@ import java.util.Optional; -import pcgen.base.formula.base.LegalScope; +import pcgen.base.formula.base.ImplementedScope; import pcgen.base.util.FormatManager; import pcgen.rules.context.LoadContext; /** - * A PCGenScope is an expanded LegalScope for use in PCGen that can also provide the + * A PCGenScope is an expanded ImplementedScope for use in PCGen that can also provide the * FormatManager related to the Scope. */ -public interface PCGenScope extends LegalScope +public interface PCGenScope extends ImplementedScope { - @Override - public Optional getParentScope(); /** * Returns the FormatManager used to process objects that are within this PCGenScope. - * + * * @param context * The LoadContext used to resolve the actual FormatManager * @return The FormatManager used to process objects that are within this PCGenScope diff --git a/code/src/java/pcgen/cdom/formula/scope/RaceScope.java b/code/src/java/pcgen/cdom/formula/scope/RaceScope.java index 3197c352bf9..a63d8a5d041 100644 --- a/code/src/java/pcgen/cdom/formula/scope/RaceScope.java +++ b/code/src/java/pcgen/cdom/formula/scope/RaceScope.java @@ -17,8 +17,11 @@ */ package pcgen.cdom.formula.scope; +import java.util.Collections; +import java.util.List; import java.util.Optional; +import pcgen.base.formula.base.ImplementedScope; import pcgen.base.util.FormatManager; import pcgen.core.Race; import pcgen.rules.context.LoadContext; @@ -30,31 +33,37 @@ public class RaceScope implements PCGenScope { /** - * The parent of this scope (once loaded) + * The scopes this scope draws from (once loaded) */ - private Optional parent; + private List drawsFrom = Collections.emptyList(); @Override public String getName() { - return "RACE"; + return "PC.RACE"; } @Override - public Optional getParentScope() + public boolean isGlobal() { - return parent; + return false; + } + + @Override + public List drawsFrom() + { + return drawsFrom; } /** * Sets the parent PCGenScope for this RaceScope. - * + * * @param parent * The parent PCGenScope for this RaceScope */ public void setParent(PCGenScope parent) { - this.parent = Optional.of(parent); + this.drawsFrom = List.of(parent); } @Override diff --git a/code/src/java/pcgen/cdom/formula/scope/SaveScope.java b/code/src/java/pcgen/cdom/formula/scope/SaveScope.java index 43531352f94..a92c95daf03 100644 --- a/code/src/java/pcgen/cdom/formula/scope/SaveScope.java +++ b/code/src/java/pcgen/cdom/formula/scope/SaveScope.java @@ -1,24 +1,27 @@ /* * Copyright 2016 (C) Tom Parker - * + * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. - * + * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package pcgen.cdom.formula.scope; +import java.util.Collections; +import java.util.List; import java.util.Optional; +import pcgen.base.formula.base.ImplementedScope; import pcgen.base.util.FormatManager; import pcgen.core.PCCheck; import pcgen.rules.context.LoadContext; @@ -30,31 +33,37 @@ public class SaveScope implements PCGenScope { /** - * The parent of this scope (once loaded) + * The scopes this scope draws from (once loaded) */ - private Optional parent; + private List drawsFrom = Collections.emptyList(); @Override public String getName() { - return "SAVE"; + return "PC.SAVE"; } @Override - public Optional getParentScope() + public boolean isGlobal() { - return parent; + return false; + } + + @Override + public List drawsFrom() + { + return drawsFrom; } /** * Sets the parent PCGenScope for this SaveScope. - * + * * @param parent * The parent PCGenScope for this SaveScope */ public void setParent(PCGenScope parent) { - this.parent = Optional.of(parent); + this.drawsFrom = List.of(parent); } @Override diff --git a/code/src/java/pcgen/cdom/formula/scope/SizeScope.java b/code/src/java/pcgen/cdom/formula/scope/SizeScope.java index 8eb0dd1f787..ce67bf0c1d6 100644 --- a/code/src/java/pcgen/cdom/formula/scope/SizeScope.java +++ b/code/src/java/pcgen/cdom/formula/scope/SizeScope.java @@ -1,24 +1,27 @@ /* * Copyright 2016 (C) Tom Parker - * + * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. - * + * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package pcgen.cdom.formula.scope; +import java.util.Collections; +import java.util.List; import java.util.Optional; +import pcgen.base.formula.base.ImplementedScope; import pcgen.base.util.FormatManager; import pcgen.core.SizeAdjustment; import pcgen.rules.context.LoadContext; @@ -30,31 +33,37 @@ public class SizeScope implements PCGenScope { /** - * The parent of this scope (once loaded) + * The scopes this scope draws from (once loaded) */ - private Optional parent; + private List drawsFrom = Collections.emptyList(); @Override public String getName() { - return "SIZE"; + return "PC.SIZE"; } @Override - public Optional getParentScope() + public boolean isGlobal() { - return parent; + return false; + } + + @Override + public List drawsFrom() + { + return drawsFrom; } /** * Sets the parent PCGenScope for this SizeAdjustmentScope. - * + * * @param parent * The parent PCGenScope for this SizeAdjustmentScope */ public void setParent(PCGenScope parent) { - this.parent = Optional.of(parent); + this.drawsFrom = List.of(parent); } @Override diff --git a/code/src/java/pcgen/cdom/formula/scope/SkillScope.java b/code/src/java/pcgen/cdom/formula/scope/SkillScope.java index e53f5743e94..1e838bff659 100644 --- a/code/src/java/pcgen/cdom/formula/scope/SkillScope.java +++ b/code/src/java/pcgen/cdom/formula/scope/SkillScope.java @@ -1,24 +1,27 @@ /* * Copyright 2015 (C) Tom Parker - * + * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. - * + * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package pcgen.cdom.formula.scope; +import java.util.Collections; +import java.util.List; import java.util.Optional; +import pcgen.base.formula.base.ImplementedScope; import pcgen.base.util.FormatManager; import pcgen.core.Skill; import pcgen.rules.context.LoadContext; @@ -30,31 +33,37 @@ public class SkillScope implements PCGenScope { /** - * The parent of this scope (once loaded) + * The scopes this scope draws from (once loaded) */ - private Optional parent; + private List drawsFrom = Collections.emptyList(); @Override public String getName() { - return "SKILL"; + return "PC.SKILL"; } @Override - public Optional getParentScope() + public boolean isGlobal() { - return parent; + return false; + } + + @Override + public List drawsFrom() + { + return drawsFrom; } /** * Sets the parent PCGenScope for this SkillScope. - * + * * @param parent * The parent PCGenScope for this SkillScope */ public void setParent(PCGenScope parent) { - this.parent = Optional.of(parent); + this.drawsFrom = List.of(parent); } @Override diff --git a/code/src/java/pcgen/cdom/formula/scope/StatScope.java b/code/src/java/pcgen/cdom/formula/scope/StatScope.java index 32a70be88a1..c39bf60a938 100644 --- a/code/src/java/pcgen/cdom/formula/scope/StatScope.java +++ b/code/src/java/pcgen/cdom/formula/scope/StatScope.java @@ -1,24 +1,27 @@ /* * Copyright 2016 (C) Tom Parker - * + * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. - * + * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package pcgen.cdom.formula.scope; +import java.util.Collections; +import java.util.List; import java.util.Optional; +import pcgen.base.formula.base.ImplementedScope; import pcgen.base.util.FormatManager; import pcgen.core.PCStat; import pcgen.rules.context.LoadContext; @@ -30,31 +33,37 @@ public class StatScope implements PCGenScope { /** - * The parent of this scope (once loaded) + * The scopes this scope draws from (once loaded) */ - private Optional parent; + private List drawsFrom = Collections.emptyList(); @Override public String getName() { - return "STAT"; + return "PC.STAT"; } @Override - public Optional getParentScope() + public boolean isGlobal() { - return parent; + return false; + } + + @Override + public List drawsFrom() + { + return drawsFrom; } /** * Sets the parent PCGenScope for this PCStatScope. - * + * * @param parent * The parent PCGenScope for this PCStatScope */ public void setParent(PCGenScope parent) { - this.parent = Optional.of(parent); + this.drawsFrom = List.of(parent); } @Override diff --git a/code/src/java/pcgen/cdom/grouping/GroupingInfoFactory.java b/code/src/java/pcgen/cdom/grouping/GroupingInfoFactory.java index ce9ea0e68de..e1121da130f 100644 --- a/code/src/java/pcgen/cdom/grouping/GroupingInfoFactory.java +++ b/code/src/java/pcgen/cdom/grouping/GroupingInfoFactory.java @@ -18,7 +18,6 @@ import java.util.Arrays; import java.util.Stack; -import pcgen.base.formula.base.LegalScope; import pcgen.cdom.formula.scope.PCGenScope; /** @@ -67,7 +66,7 @@ public class GroupingInfoFactory */ public GroupingInfo process(PCGenScope scope, String instructions) throws GroupingStateException { - String fullScopeName = LegalScope.getFullName(scope); + String fullScopeName = scope.getName(); this.scopeName = fullScopeName.split("\\."); depth = 0; expected.clear(); diff --git a/code/src/java/pcgen/cdom/grouping/GroupingScopeFilter.java b/code/src/java/pcgen/cdom/grouping/GroupingScopeFilter.java index dddf550ccd1..15039d060c4 100644 --- a/code/src/java/pcgen/cdom/grouping/GroupingScopeFilter.java +++ b/code/src/java/pcgen/cdom/grouping/GroupingScopeFilter.java @@ -19,7 +19,6 @@ import java.util.Optional; import java.util.function.Consumer; -import pcgen.base.formula.base.LegalScope; import pcgen.cdom.formula.PCGenScoped; import pcgen.cdom.formula.scope.PCGenScope; @@ -67,7 +66,7 @@ public class GroupingScopeFilter implements GroupingCollection */ public GroupingScopeFilter(PCGenScope scope, GroupingCollection grouping) { - this.scopeName = LegalScope.getFullName(scope); + this.scopeName = scope.getName(); this.underlying = Objects.requireNonNull(grouping); } diff --git a/code/src/java/pcgen/cdom/helper/FollowerLimit.java b/code/src/java/pcgen/cdom/helper/FollowerLimit.java index acb16f23b02..325e036d42c 100644 --- a/code/src/java/pcgen/cdom/helper/FollowerLimit.java +++ b/code/src/java/pcgen/cdom/helper/FollowerLimit.java @@ -19,7 +19,7 @@ import java.util.Objects; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.list.CompanionList; import pcgen.cdom.reference.CDOMSingleRef; diff --git a/code/src/java/pcgen/cdom/helper/OptionBound.java b/code/src/java/pcgen/cdom/helper/OptionBound.java index bbc8168e829..3f07832d63d 100644 --- a/code/src/java/pcgen/cdom/helper/OptionBound.java +++ b/code/src/java/pcgen/cdom/helper/OptionBound.java @@ -17,7 +17,7 @@ */ package pcgen.cdom.helper; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.core.PlayerCharacter; /** diff --git a/code/src/java/pcgen/cdom/helper/SpellLevelInfo.java b/code/src/java/pcgen/cdom/helper/SpellLevelInfo.java index e3f23fa6a96..3e3993afaf1 100644 --- a/code/src/java/pcgen/cdom/helper/SpellLevelInfo.java +++ b/code/src/java/pcgen/cdom/helper/SpellLevelInfo.java @@ -20,7 +20,7 @@ import java.util.Collection; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.Constants; import pcgen.cdom.base.Converter; import pcgen.cdom.base.PrimitiveCollection; diff --git a/code/src/java/pcgen/cdom/helper/StatLock.java b/code/src/java/pcgen/cdom/helper/StatLock.java index abaf85dcf63..ee92a93dc80 100644 --- a/code/src/java/pcgen/cdom/helper/StatLock.java +++ b/code/src/java/pcgen/cdom/helper/StatLock.java @@ -19,7 +19,7 @@ import java.util.Objects; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.reference.CDOMSingleRef; import pcgen.core.PCStat; diff --git a/code/src/java/pcgen/cdom/inst/Dynamic.java b/code/src/java/pcgen/cdom/inst/Dynamic.java index 144aaf021cf..74f289ccf3e 100644 --- a/code/src/java/pcgen/cdom/inst/Dynamic.java +++ b/code/src/java/pcgen/cdom/inst/Dynamic.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Optional; +import pcgen.base.formula.base.ImplementedScope; import pcgen.base.formula.base.VarScoped; import pcgen.cdom.base.Categorized; import pcgen.cdom.base.Category; @@ -123,12 +124,25 @@ public void setCDOMCategory(Category cat) } @Override + public VarScoped getProviderFor(ImplementedScope implScope) + { + if (implScope.isGlobal()) + { + return this; + } + String scopeName = implScope.getName(); + if (category != null && category.getKeyName().equals(scopeName)) + { + return this; + } + return this; + } + public Optional getLocalScopeName() { return Optional.of("PC." + category.getKeyName()); } - @Override public Optional getVariableParent() { return Optional.empty(); diff --git a/code/src/java/pcgen/core/AbilityCategory.java b/code/src/java/pcgen/core/AbilityCategory.java index e40877f9e52..8e3bddbcd67 100644 --- a/code/src/java/pcgen/core/AbilityCategory.java +++ b/code/src/java/pcgen/core/AbilityCategory.java @@ -29,7 +29,7 @@ import java.util.Set; import java.util.TreeSet; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.BasicClassIdentity; import pcgen.cdom.base.Category; import pcgen.cdom.base.ChooseInformation; diff --git a/code/src/java/pcgen/core/BonusManager.java b/code/src/java/pcgen/core/BonusManager.java index 1bff36ea64d..99f14f46c21 100644 --- a/code/src/java/pcgen/core/BonusManager.java +++ b/code/src/java/pcgen/core/BonusManager.java @@ -34,7 +34,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.BonusContainer; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.Constants; diff --git a/code/src/java/pcgen/core/Domain.java b/code/src/java/pcgen/core/Domain.java index 0869df0bff2..8c9a5171629 100644 --- a/code/src/java/pcgen/core/Domain.java +++ b/code/src/java/pcgen/core/Domain.java @@ -19,7 +19,7 @@ import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.ChooseDriver; import pcgen.cdom.base.ChooseInformation; import pcgen.cdom.base.ChooseSelectionActor; diff --git a/code/src/java/pcgen/core/Equipment.java b/code/src/java/pcgen/core/Equipment.java index 2e4c1195b5b..1cb99932c8f 100644 --- a/code/src/java/pcgen/core/Equipment.java +++ b/code/src/java/pcgen/core/Equipment.java @@ -40,7 +40,7 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.lang.StringUtil; import pcgen.base.util.FixedStringList; import pcgen.cdom.base.CDOMObject; diff --git a/code/src/java/pcgen/core/EquipmentModifier.java b/code/src/java/pcgen/core/EquipmentModifier.java index a2467203834..49737b6c0a4 100644 --- a/code/src/java/pcgen/core/EquipmentModifier.java +++ b/code/src/java/pcgen/core/EquipmentModifier.java @@ -22,7 +22,7 @@ import java.util.Optional; import java.util.regex.Pattern; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.formula.base.VarScoped; import pcgen.base.lang.StringUtil; import pcgen.cdom.base.CDOMObject; diff --git a/code/src/java/pcgen/core/Kit.java b/code/src/java/pcgen/core/Kit.java index d435d92cf35..5edffd43b68 100644 --- a/code/src/java/pcgen/core/Kit.java +++ b/code/src/java/pcgen/core/Kit.java @@ -24,7 +24,7 @@ import java.util.Comparator; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.lang.StringUtil; import pcgen.cdom.enumeration.KitApply; import pcgen.cdom.enumeration.ListKey; diff --git a/code/src/java/pcgen/core/PCTemplate.java b/code/src/java/pcgen/core/PCTemplate.java index 283b1a39fe9..62cc6c2e787 100644 --- a/code/src/java/pcgen/core/PCTemplate.java +++ b/code/src/java/pcgen/core/PCTemplate.java @@ -20,7 +20,7 @@ import java.util.ArrayList; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.ChooseDriver; import pcgen.cdom.base.ChooseInformation; import pcgen.cdom.base.ChooseSelectionActor; diff --git a/code/src/java/pcgen/core/PlayerCharacter.java b/code/src/java/pcgen/core/PlayerCharacter.java index 447da86e5d5..bf8a7ee3df5 100644 --- a/code/src/java/pcgen/core/PlayerCharacter.java +++ b/code/src/java/pcgen/core/PlayerCharacter.java @@ -32,8 +32,7 @@ import java.util.StringTokenizer; import java.util.TreeSet; -import pcgen.base.formula.Formula; -import pcgen.base.formula.base.FormulaManager; +import pcgen.cdom.formula.Formula; import pcgen.base.formula.inst.NEPFormula; import pcgen.base.solver.SolverManager; import pcgen.base.util.HashMapToList; @@ -608,9 +607,8 @@ private static void setProf(final Equipment equip, final Equipment eqm) private void doFormulaSetup(LoadContext context) { VariableContext variableContext = context.getVariableContext(); - FormulaManager formulaManager = variableContext.getPCFormulaManager(); MonitorableVariableStore varStore = new MonitorableVariableStore(); - scopeFacet.set(id, formulaManager.getScopeInstanceFactory()); + scopeFacet.set(id, variableContext.getScopeInstanceFactory()); variableStoreFacet.set(id, varStore); solverManagerFacet.set(id, variableContext.generateSolverManager(varStore)); ChannelUtilities.watchChannel(this, CControl.AGEINPUT, ageSetFacet); diff --git a/code/src/java/pcgen/core/Race.java b/code/src/java/pcgen/core/Race.java index 6346d426cd1..ebee93cb229 100644 --- a/code/src/java/pcgen/core/Race.java +++ b/code/src/java/pcgen/core/Race.java @@ -20,7 +20,7 @@ import java.util.List; import java.util.Optional; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.ChooseDriver; import pcgen.cdom.base.ChooseInformation; import pcgen.cdom.base.ChooseSelectionActor; diff --git a/code/src/java/pcgen/core/Skill.java b/code/src/java/pcgen/core/Skill.java index 8cc182fe275..08e6b781439 100644 --- a/code/src/java/pcgen/core/Skill.java +++ b/code/src/java/pcgen/core/Skill.java @@ -24,7 +24,7 @@ import java.util.List; import java.util.Optional; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.formula.base.VarScoped; import pcgen.cdom.base.ChooseDriver; import pcgen.cdom.base.ChooseInformation; diff --git a/code/src/java/pcgen/core/SpellProgressionCache.java b/code/src/java/pcgen/core/SpellProgressionCache.java index 50846f77b11..0cfcc6f4363 100644 --- a/code/src/java/pcgen/core/SpellProgressionCache.java +++ b/code/src/java/pcgen/core/SpellProgressionCache.java @@ -25,7 +25,7 @@ import java.util.Map.Entry; import java.util.TreeMap; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; /** * SpellProgressionInfo contains information about Spell Progression in support diff --git a/code/src/java/pcgen/core/SpellSupportForPCClass.java b/code/src/java/pcgen/core/SpellSupportForPCClass.java index 2e197009c35..f88b6ef35ee 100644 --- a/code/src/java/pcgen/core/SpellSupportForPCClass.java +++ b/code/src/java/pcgen/core/SpellSupportForPCClass.java @@ -24,7 +24,7 @@ import java.util.HashMap; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.Constants; import pcgen.cdom.content.BonusSpellInfo; import pcgen.cdom.content.KnownSpellIdentifier; diff --git a/code/src/java/pcgen/core/Vision.java b/code/src/java/pcgen/core/Vision.java index 9bba0c195f7..fcd01a92ff3 100644 --- a/code/src/java/pcgen/core/Vision.java +++ b/code/src/java/pcgen/core/Vision.java @@ -21,7 +21,7 @@ import java.util.Objects; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.CDOMReference; import pcgen.cdom.base.FormulaFactory; diff --git a/code/src/java/pcgen/core/analysis/DomainApplication.java b/code/src/java/pcgen/core/analysis/DomainApplication.java index 5ceb08aea42..c4a15fbce8a 100644 --- a/code/src/java/pcgen/core/analysis/DomainApplication.java +++ b/code/src/java/pcgen/core/analysis/DomainApplication.java @@ -22,7 +22,7 @@ import java.util.Collections; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.AssociatedPrereqObject; import pcgen.cdom.base.CDOMReference; import pcgen.cdom.enumeration.AssociationKey; diff --git a/code/src/java/pcgen/core/bonus/Bonus.java b/code/src/java/pcgen/core/bonus/Bonus.java index 52e492639f0..b05c91bce58 100644 --- a/code/src/java/pcgen/core/bonus/Bonus.java +++ b/code/src/java/pcgen/core/bonus/Bonus.java @@ -21,7 +21,7 @@ import java.util.Locale; import java.util.StringTokenizer; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.Constants; import pcgen.core.bonus.BonusObj.StackType; diff --git a/code/src/java/pcgen/core/bonus/BonusObj.java b/code/src/java/pcgen/core/bonus/BonusObj.java index 7812abc019f..c4370f92980 100644 --- a/code/src/java/pcgen/core/bonus/BonusObj.java +++ b/code/src/java/pcgen/core/bonus/BonusObj.java @@ -24,7 +24,7 @@ import java.util.Map; import java.util.StringTokenizer; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.ConcretePrereqObject; import pcgen.cdom.base.Constants; import pcgen.cdom.base.FormulaFactory; diff --git a/code/src/java/pcgen/core/bonus/BonusPair.java b/code/src/java/pcgen/core/bonus/BonusPair.java index d023bf7413f..d5823e3aebd 100644 --- a/code/src/java/pcgen/core/bonus/BonusPair.java +++ b/code/src/java/pcgen/core/bonus/BonusPair.java @@ -18,7 +18,7 @@ */ package pcgen.core.bonus; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.Constants; import pcgen.core.PlayerCharacter; diff --git a/code/src/java/pcgen/core/character/SpellBook.java b/code/src/java/pcgen/core/character/SpellBook.java index 7836d1cbaa5..94c5fd6bf17 100644 --- a/code/src/java/pcgen/core/character/SpellBook.java +++ b/code/src/java/pcgen/core/character/SpellBook.java @@ -17,7 +17,7 @@ */ package pcgen.core.character; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.Constants; import pcgen.cdom.enumeration.FormulaKey; import pcgen.cdom.enumeration.IntegerKey; diff --git a/code/src/java/pcgen/core/chooser/CDOMChoiceManager.java b/code/src/java/pcgen/core/chooser/CDOMChoiceManager.java index 3ea353312c2..d039f18f54f 100644 --- a/code/src/java/pcgen/core/chooser/CDOMChoiceManager.java +++ b/code/src/java/pcgen/core/chooser/CDOMChoiceManager.java @@ -20,7 +20,7 @@ import java.util.ArrayList; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.ChooseDriver; import pcgen.cdom.base.ChooseInformation; import pcgen.core.Globals; diff --git a/code/src/java/pcgen/core/chooser/ChooserUtilities.java b/code/src/java/pcgen/core/chooser/ChooserUtilities.java index 8871209e6b9..994d6930256 100644 --- a/code/src/java/pcgen/core/chooser/ChooserUtilities.java +++ b/code/src/java/pcgen/core/chooser/ChooserUtilities.java @@ -21,7 +21,7 @@ import java.util.ArrayList; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.ChooseDriver; import pcgen.cdom.base.ChooseInformation; import pcgen.cdom.content.CNAbility; diff --git a/code/src/java/pcgen/core/display/CharacterDisplay.java b/code/src/java/pcgen/core/display/CharacterDisplay.java index 4e544de7800..9b25d1f2071 100644 --- a/code/src/java/pcgen/core/display/CharacterDisplay.java +++ b/code/src/java/pcgen/core/display/CharacterDisplay.java @@ -31,7 +31,7 @@ import java.util.TreeSet; import java.util.stream.Collectors; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.util.NamedValue; import pcgen.cdom.base.CDOMList; import pcgen.cdom.base.CDOMObject; diff --git a/code/src/java/pcgen/core/kit/BaseKit.java b/code/src/java/pcgen/core/kit/BaseKit.java index a4ddbd81e07..480286e1e9e 100644 --- a/code/src/java/pcgen/core/kit/BaseKit.java +++ b/code/src/java/pcgen/core/kit/BaseKit.java @@ -24,7 +24,7 @@ import java.util.Collections; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.ConcretePrereqObject; import pcgen.cdom.base.Loadable; import pcgen.cdom.helper.OptionBound; diff --git a/code/src/java/pcgen/core/kit/KitClass.java b/code/src/java/pcgen/core/kit/KitClass.java index 6960e469588..c2577a65c8f 100644 --- a/code/src/java/pcgen/core/kit/KitClass.java +++ b/code/src/java/pcgen/core/kit/KitClass.java @@ -19,7 +19,7 @@ import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMReference; import pcgen.cdom.base.Constants; import pcgen.cdom.reference.CDOMSingleRef; diff --git a/code/src/java/pcgen/core/kit/KitDeity.java b/code/src/java/pcgen/core/kit/KitDeity.java index 35495bb7d70..7742282e5b8 100644 --- a/code/src/java/pcgen/core/kit/KitDeity.java +++ b/code/src/java/pcgen/core/kit/KitDeity.java @@ -22,7 +22,7 @@ import java.util.Iterator; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.reference.CDOMSingleRef; import pcgen.cdom.util.CControl; import pcgen.core.Deity; diff --git a/code/src/java/pcgen/core/kit/KitFunds.java b/code/src/java/pcgen/core/kit/KitFunds.java index 11216c36459..2f953cffe9f 100644 --- a/code/src/java/pcgen/core/kit/KitFunds.java +++ b/code/src/java/pcgen/core/kit/KitFunds.java @@ -20,7 +20,7 @@ import java.math.BigDecimal; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.util.CControl; import pcgen.core.Kit; import pcgen.core.PlayerCharacter; diff --git a/code/src/java/pcgen/core/kit/KitGear.java b/code/src/java/pcgen/core/kit/KitGear.java index 8a90e7cc996..1838f89273c 100644 --- a/code/src/java/pcgen/core/kit/KitGear.java +++ b/code/src/java/pcgen/core/kit/KitGear.java @@ -24,7 +24,7 @@ import java.util.LinkedList; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.util.NamedFormula; import pcgen.cdom.base.CDOMReference; import pcgen.cdom.base.Constants; diff --git a/code/src/java/pcgen/core/kit/KitSelect.java b/code/src/java/pcgen/core/kit/KitSelect.java index bb37e948dde..2e0b4dc4f3e 100644 --- a/code/src/java/pcgen/core/kit/KitSelect.java +++ b/code/src/java/pcgen/core/kit/KitSelect.java @@ -19,7 +19,7 @@ import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.core.Kit; import pcgen.core.PlayerCharacter; diff --git a/code/src/java/pcgen/core/kit/KitSpells.java b/code/src/java/pcgen/core/kit/KitSpells.java index 0c7e137d9fe..ef951a282f9 100644 --- a/code/src/java/pcgen/core/kit/KitSpells.java +++ b/code/src/java/pcgen/core/kit/KitSpells.java @@ -23,7 +23,7 @@ import java.util.List; import java.util.Set; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.util.DoubleKeyMap; import pcgen.cdom.base.CDOMList; import pcgen.cdom.content.KnownSpellIdentifier; diff --git a/code/src/java/pcgen/core/kit/KitStat.java b/code/src/java/pcgen/core/kit/KitStat.java index c1bd12a2c49..beeaecbdf90 100644 --- a/code/src/java/pcgen/core/kit/KitStat.java +++ b/code/src/java/pcgen/core/kit/KitStat.java @@ -24,7 +24,7 @@ import java.util.Set; import java.util.TreeSet; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.lang.StringUtil; import pcgen.cdom.base.Constants; import pcgen.cdom.reference.CDOMSingleRef; diff --git a/code/src/java/pcgen/core/kit/KitTable.java b/code/src/java/pcgen/core/kit/KitTable.java index a42a78ce07f..56c9f2296a8 100644 --- a/code/src/java/pcgen/core/kit/KitTable.java +++ b/code/src/java/pcgen/core/kit/KitTable.java @@ -21,7 +21,7 @@ import java.util.Collections; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.core.Kit; import pcgen.core.PlayerCharacter; diff --git a/code/src/java/pcgen/gui2/facade/Gui2InfoFactory.java b/code/src/java/pcgen/gui2/facade/Gui2InfoFactory.java index 90bf6346875..fa73a9e57c4 100644 --- a/code/src/java/pcgen/gui2/facade/Gui2InfoFactory.java +++ b/code/src/java/pcgen/gui2/facade/Gui2InfoFactory.java @@ -33,7 +33,7 @@ import java.util.TreeMap; import java.util.TreeSet; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.lang.StringUtil; import pcgen.base.util.Indirect; import pcgen.cdom.base.CDOMObject; diff --git a/code/src/java/pcgen/gui2/solverview/LegalScopeWrapper.java b/code/src/java/pcgen/gui2/solverview/LegalScopeWrapper.java index cb544c4641d..6441a76ab4e 100644 --- a/code/src/java/pcgen/gui2/solverview/LegalScopeWrapper.java +++ b/code/src/java/pcgen/gui2/solverview/LegalScopeWrapper.java @@ -17,10 +17,10 @@ */ package pcgen.gui2.solverview; -import pcgen.base.formula.base.LegalScope; +import pcgen.base.formula.base.ImplementedScope; /** - * An LegalScopeWrapper wraps a LegalScope in order to display an informative + * An LegalScopeWrapper wraps a ImplementedScope in order to display an informative * String from the toString() method. This allows the LegalScopeWrapper to be * directly used in the UI without worrying about the actual toString() behavior * of any given LegalScope. @@ -30,31 +30,31 @@ class LegalScopeWrapper /** * The underlying LegalScope. */ - private final LegalScope legalScope; + private final ImplementedScope legalScope; /** * Constructs a new LegalScopeWrapper with the given LegalScope * * @param legalScope - * The LegalScope that this LegalScopeWrapper will represent + * The ImplementedScope that this LegalScopeWrapper will represent */ - LegalScopeWrapper(LegalScope legalScope) + LegalScopeWrapper(ImplementedScope legalScope) { this.legalScope = legalScope; } /** - * Returns the LegalScope underlying this LegalScopeWrapper. + * Returns the ImplementedScope underlying this LegalScopeWrapper. * - * @return the LegalScope underlying this LegalScopeWrapper + * @return the ImplementedScope underlying this LegalScopeWrapper */ - public LegalScope getLegalScope() + public ImplementedScope getLegalScope() { return legalScope; } /** - * Returns an informative String identifying the LegalScope underlying this + * Returns an informative String identifying the ImplementedScope underlying this * LegalScopeWrapper */ @Override diff --git a/code/src/java/pcgen/gui2/solverview/SolverViewFrame.java b/code/src/java/pcgen/gui2/solverview/SolverViewFrame.java index 4e45a084d55..4abffd5ad30 100644 --- a/code/src/java/pcgen/gui2/solverview/SolverViewFrame.java +++ b/code/src/java/pcgen/gui2/solverview/SolverViewFrame.java @@ -38,7 +38,7 @@ import javax.swing.event.DocumentListener; import javax.swing.table.AbstractTableModel; -import pcgen.base.formula.base.LegalScope; +import pcgen.base.formula.base.ImplementedScope; import pcgen.base.formula.base.ScopeInstance; import pcgen.base.formula.base.VarScoped; import pcgen.base.formula.base.VariableID; @@ -65,7 +65,7 @@ public final class SolverViewFrame extends JFrame private final LoadContextFacet loadContextFacet = FacetLibrary.getFacet(LoadContextFacet.class); private final JComboBox scopeChooser; - private LegalScope selectedScope; + private ImplementedScope selectedScope; private final JTextField varName; private String varNameText = " "; @@ -111,7 +111,7 @@ public SolverViewFrame() private void update() { updateObjects(); - if ((activeObject == null) && (selectedScope.getParentScope().isPresent())) + if ((activeObject == null) && (!selectedScope.isGlobal())) { //scopeFacet will error if we continue... tableModel.setSteps(Collections.emptyList()); @@ -124,10 +124,10 @@ private void update() } else { - scope = scopeFacet.get(activeIdentifier, LegalScope.getFullName(selectedScope), activeObject); + scope = scopeFacet.get(activeIdentifier, selectedScope.getName(), activeObject); } if (loadContextFacet.get(activeIdentifier.getDatasetID()).get().getVariableContext() - .isLegalVariableID(scope.getLegalScope(), varNameText)) + .isLegalVariableID(scope.getImplementedScope(), varNameText)) { displayInfo(scope); } @@ -220,7 +220,7 @@ public void actionPerformed(ActionEvent e) Object item = identifierChooser.getSelectedItem(); activeIdentifier = ((PCRef) item).id; LoadContext loadContext = loadContextFacet.get(activeIdentifier.getDatasetID()).get(); - for (LegalScope lvs : loadContext.getVariableContext().getScopes()) + for (ImplementedScope lvs : loadContext.getVariableContext().getScopes()) { scopeChooser.addItem(new LegalScopeWrapper(lvs)); } @@ -235,8 +235,8 @@ private void updateObjects() { Collection objects = varScopedFacet.getSet(activeIdentifier); objectChooser.removeAllItems(); - String scopeName = LegalScope.getFullName(selectedScope); - for (VarScoped cdo : objects) + String scopeName = selectedScope.getName(); + for (PCGenScoped cdo : objects) { Optional localScopeName = cdo.getLocalScopeName(); if (localScopeName.isPresent() && scopeName.equals(localScopeName.get())) diff --git a/code/src/java/pcgen/output/channel/ChannelUtilities.java b/code/src/java/pcgen/output/channel/ChannelUtilities.java index 81c4f5d1a09..38ff524ce99 100644 --- a/code/src/java/pcgen/output/channel/ChannelUtilities.java +++ b/code/src/java/pcgen/output/channel/ChannelUtilities.java @@ -22,7 +22,6 @@ import pcgen.base.formula.base.VariableID; import pcgen.cdom.enumeration.CharID; import pcgen.cdom.facet.FacetLibrary; -import pcgen.cdom.facet.SolverManagerFacet; import pcgen.cdom.facet.VariableStoreFacet; import pcgen.cdom.facet.event.DataFacetChangeListener; import pcgen.cdom.formula.VariableListener; @@ -42,11 +41,6 @@ public final class ChannelUtilities * The VariableStoreFacet */ private static final VariableStoreFacet RESULT_FACET = FacetLibrary.getFacet(VariableStoreFacet.class); - - /** - * The SolverManagerFacet - */ - private static final SolverManagerFacet SOLVER_MANAGER_FACET = FacetLibrary.getFacet(SolverManagerFacet.class); private ChannelUtilities() { @@ -100,7 +94,6 @@ public static void setGlobalChannel(CharID id, String channelName, Object value) { VariableID varID = getChannelVariableID(id, channelName); RESULT_FACET.get(id).put(varID, value); - SOLVER_MANAGER_FACET.get(id).solveChildren(varID); } /** diff --git a/code/src/java/pcgen/persistence/SourceFileLoader.java b/code/src/java/pcgen/persistence/SourceFileLoader.java index 5068a3f7428..43c8a26a6e6 100644 --- a/code/src/java/pcgen/persistence/SourceFileLoader.java +++ b/code/src/java/pcgen/persistence/SourceFileLoader.java @@ -35,7 +35,7 @@ import java.util.stream.Stream; import pcgen.base.formatmanager.FormatUtilities; -import pcgen.base.formula.base.LegalScope; +import pcgen.base.formula.base.ImplementedScope; import pcgen.base.util.AbstractMapToList; import pcgen.base.util.FormatManager; import pcgen.base.util.HashMapToList; @@ -675,7 +675,7 @@ private static void enableBuiltInControl(LoadContext context, private static void defineVariable(VariableContext varContext, FormatManager formatManager, String varName) { - LegalScope varScope = varContext.getScope(GlobalPCScope.GLOBAL_SCOPE_NAME); + ImplementedScope varScope = varContext.getScope(GlobalPCScope.GLOBAL_SCOPE_NAME); varContext.assertLegalVariableID(varName, varScope, formatManager); } diff --git a/code/src/java/pcgen/rules/context/AbstractObjectContext.java b/code/src/java/pcgen/rules/context/AbstractObjectContext.java index 54f225023e0..47af1f00227 100644 --- a/code/src/java/pcgen/rules/context/AbstractObjectContext.java +++ b/code/src/java/pcgen/rules/context/AbstractObjectContext.java @@ -23,7 +23,7 @@ import java.util.Objects; import java.util.Set; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.util.DoubleKeyMap; import pcgen.base.util.DoubleKeyMapToList; import pcgen.base.util.HashMapToList; diff --git a/code/src/java/pcgen/rules/context/AbstractReferenceContext.java b/code/src/java/pcgen/rules/context/AbstractReferenceContext.java index 2a1a0961f2b..530f118ecc7 100644 --- a/code/src/java/pcgen/rules/context/AbstractReferenceContext.java +++ b/code/src/java/pcgen/rules/context/AbstractReferenceContext.java @@ -25,6 +25,7 @@ import java.util.Comparator; import java.util.HashSet; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.TreeSet; @@ -486,7 +487,7 @@ private List generateList(Class cl, Comparator getFormatManager(String clName) { - return fmtLibrary.getFormatManager(clName); + return fmtLibrary.getFormatManager(Optional.empty(), clName); } void importCDOMToFormat(Class cl) diff --git a/code/src/java/pcgen/rules/context/ConsolidatedObjectCommitStrategy.java b/code/src/java/pcgen/rules/context/ConsolidatedObjectCommitStrategy.java index d8b8b862e4e..ac993a454d5 100644 --- a/code/src/java/pcgen/rules/context/ConsolidatedObjectCommitStrategy.java +++ b/code/src/java/pcgen/rules/context/ConsolidatedObjectCommitStrategy.java @@ -22,7 +22,7 @@ import java.util.Set; import java.util.regex.Pattern; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.util.Indirect; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.ConcretePrereqObject; diff --git a/code/src/java/pcgen/rules/context/LoadContextInst.java b/code/src/java/pcgen/rules/context/LoadContextInst.java index 0394b798f64..762f37d2824 100644 --- a/code/src/java/pcgen/rules/context/LoadContextInst.java +++ b/code/src/java/pcgen/rules/context/LoadContextInst.java @@ -23,10 +23,10 @@ import java.util.Collections; import java.util.List; import java.util.Objects; -import java.util.Optional; import java.util.logging.Logger; import java.util.logging.Level; +import pcgen.base.formula.base.ImplementedScope; import pcgen.base.formula.inst.NEPFormula; import pcgen.base.proxy.DeferredMethodController; import pcgen.base.text.ParsingSeparator; @@ -116,7 +116,7 @@ public LoadContextInst(AbstractReferenceContext rc, AbstractListContext lc, Abst ref = rc; list = lc; obj = oc; - var = new VariableContext(new PCGenManagerFactory(this)); + var = new VariableContext(this); } @Override @@ -549,13 +549,16 @@ public void addDeferredMethodController(DeferredMethodController commitTask) private LoadContext dropIntoContext(PCGenScope lvs) { - Optional parent = lvs.getParentScope(); - if (!parent.isPresent()) + if (lvs.isGlobal()) { - //is Global return this; } - LoadContext parentLC = dropIntoContext(parent.get()); + List parents = lvs.drawsFrom(); + if (parents.isEmpty()) + { + return this; + } + LoadContext parentLC = dropIntoContext((PCGenScope) parents.get(0)); return new DerivedLoadContext(parentLC, lvs); } @@ -829,12 +832,13 @@ public LoadContext dropIntoContext(String scope) { return this; } - else if (!toScope.getParentScope().isPresent()) + else if (toScope.isGlobal()) { //No parent is global return parent; } - else if (toScope.getParentScope().get().equals(derivedScope)) + else if (!toScope.drawsFrom().isEmpty() + && toScope.drawsFrom().get(0).equals(derivedScope)) { //Direct drop from this return new DerivedLoadContext(this, toScope); diff --git a/code/src/java/pcgen/rules/context/ObjectCommitStrategy.java b/code/src/java/pcgen/rules/context/ObjectCommitStrategy.java index b017e8a2c7f..1919caed918 100644 --- a/code/src/java/pcgen/rules/context/ObjectCommitStrategy.java +++ b/code/src/java/pcgen/rules/context/ObjectCommitStrategy.java @@ -20,7 +20,7 @@ import java.net.URI; import java.util.Set; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.util.Indirect; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.ConcretePrereqObject; diff --git a/code/src/java/pcgen/rules/context/PCGenManagerFactory.java b/code/src/java/pcgen/rules/context/PCGenManagerFactory.java index cdf157f5c96..507f7ae8204 100644 --- a/code/src/java/pcgen/rules/context/PCGenManagerFactory.java +++ b/code/src/java/pcgen/rules/context/PCGenManagerFactory.java @@ -1,16 +1,16 @@ /* * Copyright 2017 (C) Tom Parker - * + * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. - * + * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA @@ -18,14 +18,20 @@ package pcgen.rules.context; import java.lang.ref.WeakReference; +import java.util.Objects; import pcgen.base.formula.base.DependencyManager; import pcgen.base.formula.base.EvaluationManager; -import pcgen.base.formula.base.FormulaManager; import pcgen.base.formula.base.FormulaSemantics; -import pcgen.base.formula.base.LegalScope; +import pcgen.base.formula.base.FunctionLibrary; +import pcgen.base.formula.base.ImplementedScope; +import pcgen.base.formula.base.OperatorLibrary; +import pcgen.base.formula.base.ScopeImplementer; +import pcgen.base.formula.base.ScopeInstanceFactory; import pcgen.base.formula.base.ManagerFactory; -import pcgen.base.formula.base.ScopeInstance; +import pcgen.base.formula.base.VariableLibrary; +import pcgen.base.formula.base.VariableStore; +import pcgen.base.formula.base.WriteableVariableStore; import pcgen.cdom.formula.ManagerKey; import pcgen.cdom.helper.ReferenceDependency; @@ -37,40 +43,87 @@ public class PCGenManagerFactory implements ManagerFactory { private final WeakReference context; + private final ScopeImplementer scopeLib; + private final OperatorLibrary opLib; + private final VariableLibrary varLib; + private final FunctionLibrary functionLib; + private final VariableStore varStore; + private final ScopeInstanceFactory siFactory; /** - * Constructs a new PCGenManagerFactory with the provided LoadContext to be included - * in each Manager that is returned. - * + * Constructs a new PCGenManagerFactory with the provided components. + * * @param context - * The LoadContext for this ManagerFactory to include in each Manager that - * is returned + * The LoadContext for this ManagerFactory + * @param scopeLib + * The ScopeImplementer + * @param opLib + * The OperatorLibrary + * @param varLib + * The VariableLibrary + * @param functionLib + * The FunctionLibrary + * @param varStore + * The VariableStore + * @param siFactory + * The ScopeInstanceFactory */ - public PCGenManagerFactory(LoadContext context) + public PCGenManagerFactory(LoadContext context, ScopeImplementer scopeLib, + OperatorLibrary opLib, VariableLibrary varLib, FunctionLibrary functionLib, + VariableStore varStore, ScopeInstanceFactory siFactory) { - this.context = new WeakReference<>(context); + this.context = new WeakReference<>(Objects.requireNonNull(context)); + this.scopeLib = Objects.requireNonNull(scopeLib); + this.opLib = Objects.requireNonNull(opLib); + this.varLib = Objects.requireNonNull(varLib); + this.functionLib = Objects.requireNonNull(functionLib); + this.varStore = Objects.requireNonNull(varStore); + this.siFactory = Objects.requireNonNull(siFactory); } @Override - public FormulaSemantics generateFormulaSemantics(FormulaManager manager, LegalScope legalScope) + public DependencyManager generateDependencyManager() { - FormulaSemantics semantics = ManagerFactory.super.generateFormulaSemantics(manager, legalScope); - return semantics.getWith(ManagerKey.CONTEXT, context.get()); + DependencyManager depManager = new DependencyManager(); + depManager = depManager.getWith(DependencyManager.FUNCTION, functionLib); + depManager = depManager.getWith(DependencyManager.SCOPELIB, scopeLib); + depManager = depManager.getWith(DependencyManager.VARLIB, varLib); + depManager = depManager.getWith(DependencyManager.SIFACTORY, siFactory); + depManager = depManager.getWith(DependencyManager.OPLIB, opLib); + depManager = depManager.getWith(ManagerKey.CONTEXT, context.get()); + return depManager.getWith(ManagerKey.REFERENCES, new ReferenceDependency()); } @Override - public EvaluationManager generateEvaluationManager(FormulaManager formulaManager) + public FormulaSemantics generateFormulaSemantics(ImplementedScope scope) { - EvaluationManager evalManager = ManagerFactory.super.generateEvaluationManager(formulaManager); - return evalManager.getWith(ManagerKey.CONTEXT, context.get()); + FormulaSemantics semantics = new FormulaSemantics(); + semantics = semantics.getWith(FormulaSemantics.FUNCTION, functionLib); + semantics = semantics.getWith(FormulaSemantics.OPLIB, opLib); + semantics = semantics.getWith(FormulaSemantics.SCOPELIB, scopeLib); + semantics = semantics.getWith(FormulaSemantics.VARLIB, varLib); + semantics = semantics.getWith(FormulaSemantics.SIFACTORY, siFactory); + semantics = semantics.getWith(FormulaSemantics.SCOPE, scope); + return semantics.getWith(ManagerKey.CONTEXT, context.get()); } @Override - public DependencyManager generateDependencyManager(FormulaManager formulaManager, ScopeInstance scopeInst) + public EvaluationManager generateEvaluationManager() { - DependencyManager depManager = ManagerFactory.super.generateDependencyManager(formulaManager, scopeInst); - return depManager.getWith(ManagerKey.CONTEXT, context.get()).getWith(ManagerKey.REFERENCES, - new ReferenceDependency()); + EvaluationManager manager = new EvaluationManager(); + manager = manager.getWith(EvaluationManager.FUNCTION, functionLib); + manager = manager.getWith(EvaluationManager.OPLIB, opLib); + manager = manager.getWith(EvaluationManager.SCOPELIB, scopeLib); + manager = manager.getWith(EvaluationManager.VARLIB, varLib); + manager = manager.getWith(EvaluationManager.SIFACTORY, siFactory); + manager = manager.getWith(EvaluationManager.RESULTS, varStore); + return manager.getWith(ManagerKey.CONTEXT, context.get()); } + @Override + public PCGenManagerFactory createReplacement(WriteableVariableStore newVarStore) + { + return new PCGenManagerFactory(context.get(), scopeLib, opLib, varLib, + functionLib, newVarStore, siFactory); + } } diff --git a/code/src/java/pcgen/rules/context/VariableContext.java b/code/src/java/pcgen/rules/context/VariableContext.java index 87964217848..5dcce2ce1ed 100644 --- a/code/src/java/pcgen/rules/context/VariableContext.java +++ b/code/src/java/pcgen/rules/context/VariableContext.java @@ -1,16 +1,16 @@ /* * Copyright 2014-9 (C) Tom Parker - * + * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. - * + * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA @@ -23,15 +23,17 @@ import java.util.Optional; import java.util.function.Supplier; -import pcgen.base.calculation.FormulaModifier; -import pcgen.base.calculation.IgnoreVariables; +import pcgen.cdom.calculation.FormulaModifier; +import pcgen.cdom.calculation.IgnoreVariables; import pcgen.base.formula.base.DependencyManager; +import pcgen.base.formula.base.DependencyStrategy; import pcgen.base.formula.base.FormulaFunction; -import pcgen.base.formula.base.FormulaManager; import pcgen.base.formula.base.FormulaSemantics; -import pcgen.base.formula.base.LegalScope; +import pcgen.base.formula.base.ImplementedScope; import pcgen.base.formula.base.ManagerFactory; import pcgen.base.formula.base.ScopeInstance; +import pcgen.base.formula.base.OperatorLibrary; +import pcgen.base.formula.base.ScopeInstanceFactory; import pcgen.base.formula.base.VarScoped; import pcgen.base.formula.base.VariableID; import pcgen.base.formula.base.VariableLibrary; @@ -39,17 +41,15 @@ import pcgen.base.formula.base.WriteableVariableStore; import pcgen.base.formula.exception.SemanticsException; import pcgen.base.formula.inst.FormulaUtilities; +import pcgen.base.formula.inst.ImplementedScopeLibrary; import pcgen.base.formula.inst.NEPFormula; -import pcgen.base.formula.inst.ScopeManagerInst; +import pcgen.base.formula.inst.SimpleOperatorLibrary; import pcgen.base.formula.inst.SimpleFunctionLibrary; +import pcgen.base.formula.inst.SimpleScopeInstanceFactory; import pcgen.base.formula.inst.VariableManager; -import pcgen.base.solver.DynamicSolverManager; -import pcgen.base.solver.FormulaSetupFactory; -import pcgen.base.solver.SimpleSolverFactory; -import pcgen.base.solver.SolverFactory; +import pcgen.base.solver.SimpleSolverManager; import pcgen.base.solver.SolverManager; import pcgen.base.solver.SupplierValueStore; -import pcgen.base.util.ComplexResult; import pcgen.base.util.FormatManager; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.enumeration.CharID; @@ -66,7 +66,6 @@ import pcgen.cdom.helper.ReferenceDependency; import pcgen.rules.persistence.TokenLibrary; import pcgen.rules.persistence.token.ModifierFactory; -import pcgen.util.Logging; /** * A VariableContext is responsible for managing variable items during the load of data @@ -76,67 +75,51 @@ public class VariableContext implements VariableChannelFactory, VariableWrapperFactory, VariableLibrary { + /** - * This is the FormulaSetupFactory for this VariableContext. This is used to generate - * a FormulaManager for each PC. + * The FunctionLibrary for this VariableContext. Local so that we can add functions + * based on plugins and data. */ - private final FormulaSetupFactory formulaSetupFactory = new FormulaSetupFactory(); + private final WriteableFunctionLibrary myFunctionLibrary = new SimpleFunctionLibrary(); /** - * This is the ManagerFactory for this VariableContext. This is used to generate an - * EvaluationManager, FormulaSemantics and other relevant items provided to the - * formula system during formula processing. + * The ValueStore for this VariableContext. Local so that we can set the defaults for + * variable formats from data. */ - private final ManagerFactory managerFactory; + private final SupplierValueStore myValueStore = new SupplierValueStore(); - /* - * There are a series of items we override in the FormulaSetupFactory, and keep - * locally for certain types of processing. - */ /** - * The FunctionLibrary for the FormulaSetupFactory and this VariableContext. Local so - * that we can add functions based on plugins and data. + * The ImplementedScopeLibrary for this VariableContext. Local so that we can load + * scopes based on data and provide it to the VariableManager. */ - private final WriteableFunctionLibrary myFunctionLibrary = new SimpleFunctionLibrary(); + private final ImplementedScopeLibrary scopeLibrary = new ImplementedScopeLibrary(); /** - * The ValueStore for the FormulaSetupFactory and this VariableContext. Local so - * that we can set the defaults for variable formats from data. + * The OperatorLibrary for this VariableContext. */ - private final SupplierValueStore myValueStore = new SupplierValueStore(); + private final OperatorLibrary operatorLibrary; /** - * The SolverFactory for the FormulaSetupFactory and this VariableContext. Local so - * that we can set the defaults for variable formats from data. + * The ScopeInstanceFactory for this VariableContext. */ - private final SolverFactory solverFactory = new SimpleSolverFactory(myValueStore); + private final ScopeInstanceFactory scopeInstanceFactory; /** - * The LegalScopeManager for the FormulaSetupFactory and this VariableContext. Local - * so that we can load scopes based on data (like DYNAMICSCOPE:) and provide it to the - * VariableManager. + * The VariableManager for this VariableContext. Local so the data can assert legal + * variables. */ - private final ScopeManagerInst legalScopeManager = new ScopeManagerInst(); + private final VariableManager variableManager; /** - * The VariableManager for the FormulaSetupFactory and this VariableContext. Local so - * the data can assert legal variables. + * The ManagerFactory for this VariableContext. Lazily initialized because it needs + * a VariableStore, which isn't available until a PC is created. */ - private final VariableManager variableManager = - new VariableManager(legalScopeManager, myValueStore); + private PCGenManagerFactory managerFactory; /** - * The naive FormulaManager for this VariableContext. This serves only as a base item - * for loading formulas, not for evaluation. - * - * Each PC will also have its own FormulaManager (which will contain a dedicated - * VariableStore for that PC). This specific FormulaManager is derived from this - * FormulaManager in generateSolverManager(). - * - * Lazy instantiation to avoid trying to pull the "Global" scope before it is loaded - * from plugins. - */ - private FormulaManager loadFormulaManager = null; + * The LoadContext that owns this VariableContext. + */ + private final LoadContext loadContext; /** * Contains a VariableChannelFactory used to develop VariableChannels for this @@ -152,56 +135,60 @@ public class VariableContext implements VariableChannelFactory, new VariableWrapperFactoryInst(); /** - * Constructs a new VariableContext with the given ManagerFactory. - * - * @param managerFactory - * The ManagerFactory used to generate managers for formula evaluation by - * all items loaded while this VariableContext is active + * Constructs a new VariableContext for the given LoadContext. + * + * @param loadContext + * The LoadContext that owns this VariableContext */ - public VariableContext(ManagerFactory managerFactory) + public VariableContext(LoadContext loadContext) { - this.managerFactory = Objects.requireNonNull(managerFactory); + this.loadContext = Objects.requireNonNull(loadContext); for (FormulaFunction f : PluginFunctionLibrary.getInstance().getFunctions()) { myFunctionLibrary.addFunction(f); } FormulaUtilities.loadBuiltInFunctions(myFunctionLibrary); - LegalScopeUtilities.loadLegalScopeLibrary(legalScopeManager); - formulaSetupFactory.setValueStoreSupplier(() -> myValueStore); - formulaSetupFactory.setLegalScopeManagerSupplier(() -> legalScopeManager); - formulaSetupFactory.setFunctionLibrarySupplier(() -> myFunctionLibrary); - formulaSetupFactory.setVariableLibraryFunction((lsm, vs) -> variableManager); + LegalScopeUtilities.loadLegalScopeLibrary(scopeLibrary); + operatorLibrary = FormulaUtilities.loadBuiltInOperators(new SimpleOperatorLibrary()); + scopeInstanceFactory = new SimpleScopeInstanceFactory(scopeLibrary); + variableManager = new VariableManager(scopeLibrary, scopeLibrary, + scopeInstanceFactory, myValueStore); } /** - * Returns the FormulaManager for this VariableContext. - * - * Lazy instantiation to avoid trying to pull the "Global" scope before it is loaded - * from plugins (so care should be taken to only call this method after the "Global" - * scope is loaded). - * - * @return The FormulaManager for this VariableContext - */ - public FormulaManager getFormulaManager() + * Returns the ManagerFactory for this VariableContext. Creates a base ManagerFactory + * using a default (empty) variable store for load-time formula checking. + * + * @return The ManagerFactory for this VariableContext + */ + public ManagerFactory getManagerFactory() { - if (loadFormulaManager == null) + if (managerFactory == null) { - loadFormulaManager = formulaSetupFactory.generate(); + managerFactory = new PCGenManagerFactory(loadContext, scopeLibrary, + operatorLibrary, variableManager, myFunctionLibrary, + new pcgen.base.formula.inst.SimpleVariableStore(), scopeInstanceFactory); } - return loadFormulaManager; + return managerFactory; } /** - * Returns a new FormulaManager; method is designed to be used once with each PC. + * Returns a new ManagerFactory for a specific PC, using the given WriteableVariableStore. + * + * @param varStore + * The WriteableVariableStore for the PC + * @return A new ManagerFactory for a PC */ - public FormulaManager getPCFormulaManager() + public ManagerFactory getPCManagerFactory(WriteableVariableStore varStore) { - return formulaSetupFactory.generate(); + return new PCGenManagerFactory(loadContext, scopeLibrary, + operatorLibrary, variableManager, myFunctionLibrary, + varStore, scopeInstanceFactory); } /** * Returns a FormulaModifier based on the given information. - * + * * @param modType * The type of the modifier to be generated (e.g. "ADD") * @param instructions @@ -214,8 +201,7 @@ public FormulaManager getPCFormulaManager() * @return a FormulaModifier based on the given information */ public FormulaModifier getModifier(String modType, - String instructions, FormulaManager formulaManager, PCGenScope varScope, - FormatManager formatManager) + String instructions, PCGenScope varScope, FormatManager formatManager) { Class varClass = formatManager.getManagedClass(); ModifierFactory factory = TokenLibrary.getModifier(varClass, modType); @@ -226,9 +212,19 @@ public FormulaModifier getModifier(String modType, } FormulaModifier modifier = factory.getModifier(instructions, formatManager); - - FormulaSemantics semantics = managerFactory.generateFormulaSemantics(formulaManager, varScope); + + ManagerFactory mf = getManagerFactory(); + FormulaSemantics semantics = mf.generateFormulaSemantics(varScope); semantics = semantics.getWith(FormulaSemantics.INPUT_FORMAT, Optional.of(formatManager)); + Optional> scopeFormat = varScope.getFormatManager(loadContext); + if (scopeFormat.isPresent()) + { + pcgen.base.formula.base.FunctionLibrary functionLib = + semantics.get(FormulaSemantics.FUNCTION); + functionLib = new pcgen.cdom.formula.local.DefinedWrappingLibrary( + functionLib, "this", new Object(), scopeFormat.get()); + semantics = semantics.getWith(FormulaSemantics.FUNCTION, functionLib); + } try { modifier.isValid(semantics); @@ -240,11 +236,12 @@ public FormulaModifier getModifier(String modType, } /* - * getDependencies needs to be called during LST load, so that object references are captured + * getDependencies needs to be called during LST load, so that object references + * are captured */ - DependencyManager fdm = managerFactory.generateDependencyManager(formulaManager, null); + DependencyManager fdm = mf.generateDependencyManager(); fdm = fdm.getWith(DependencyManager.SCOPE, Optional.of(varScope)); - fdm = fdm.getWith(DependencyManager.VARSTRATEGY, Optional.of(new IgnoreVariables())); + fdm = fdm.getWith(DependencyManager.VARSTRATEGY, Optional.of(new IgnoreVariables())); fdm = fdm.getWith(ManagerKey.REFERENCES, new ReferenceDependency()); modifier.getDependencies(fdm); modifier.addReferences(fdm.get(ManagerKey.REFERENCES).getReferences()); @@ -253,10 +250,7 @@ public FormulaModifier getModifier(String modType, /** * Adds a FormulaFunction to the VariableContext. - * - * Behavior is not defined if an an attempt is made to add null or a FormulaFunction - * with a null name. An exception may be thrown. - * + * * @param function * The FormulaFunction to be added to the VariableContext */ @@ -265,103 +259,95 @@ public void addFunction(FormulaFunction function) myFunctionLibrary.addFunction(function); } + public WriteableFunctionLibrary getFunctionLibrary() + { + return myFunctionLibrary; + } + + public OperatorLibrary getOperatorLibrary() + { + return operatorLibrary; + } + /** * Returns the PCGenScope for the given name. - * + * * @param name * The name of the PCGenScope to be returned * @return The PCGenScope for the given name */ public PCGenScope getScope(String name) { - return (PCGenScope) legalScopeManager.getScope(name); + return (PCGenScope) scopeLibrary.getImplementedScope(name); } /** * Registers the given PCGenScope. - * + * * @param scope * The PCGenScope to be registered */ public void registerScope(PCGenScope scope) { - legalScopeManager.registerScope(scope); + scopeLibrary.addScope(scope); } /** - * Returns a Collection of the LegalScope objects for this Context. - * - * @return A Collection of the LegalScope objects for this Context + * Returns the ImplementedScopeLibrary for this VariableContext. + * + * @return The ImplementedScopeLibrary for this VariableContext */ - public Collection getScopes() + public ImplementedScopeLibrary getScopeLibrary() { - return legalScopeManager.getLegalScopes(); + return scopeLibrary; } /** - * Validates the default values provided to the formula system. Effectively ensures - * that each default value is not dependent on variables or in other ways can't be - * directly calculated. Will report to the error system any results from the analysis. + * Returns a Collection of all ImplementedScope objects registered in this + * VariableContext. + * + * @return A Collection of all ImplementedScope objects */ - public void validateDefaults() + public Collection getScopes() { - ComplexResult result = solverFactory.validateDefaults(); - if (!result.get()) - { - result.getMessages().stream().forEach(Logging::errorPrint); - } + return scopeLibrary.getScopes(); } /** - * Generates a SolverManager with a FormulaManager using the given - * WriteableVariableStore. - * + * Generates a SolverManager with the given WriteableVariableStore. + * * @param varStore * The WriteableVariableStore to be used for the returned SolverManager - * @return A SolverManager with a FormulaManager using the given - * WriteableVariableStore + * @return A SolverManager using the given WriteableVariableStore */ public SolverManager generateSolverManager(WriteableVariableStore varStore) { - FormulaManager derived = getFormulaManager().getWith(FormulaManager.RESULTS, varStore); - return new DynamicSolverManager(derived, managerFactory, solverFactory, varStore); + ManagerFactory mf = getPCManagerFactory(varStore); + return new SimpleSolverManager(variableManager::isLegalVariableID, + mf, myValueStore, varStore); } /** * Returns a "valid" NEPFormula for the given expression. - * - * If the given expression does not represent a valid formula, then this - * will throw an IllegalArgumentException. - * - * If the given expression does not return an object of the type in the - * given FormatManager, then this will throw an IllegalArgumentException. - * + * * @param activeScope - * The PCGenScope in which the NEPFormula is established and - * checked + * The PCGenScope in which the NEPFormula is established and checked * @param formatManager - * The FormatManager in which the NEPFormula is established and - * checked + * The FormatManager in which the NEPFormula is established and checked * @param instructions - * The String representation of the formula to be converted to a - * NEPFormula + * The String representation of the formula to be converted to a NEPFormula * @return a "valid" NEPFormula for the given expression */ public NEPFormula getValidFormula(PCGenScope activeScope, FormatManager formatManager, String instructions) { - return FormulaFactory.getValidFormula(instructions, managerFactory, getFormulaManager(), activeScope, + return FormulaFactory.getValidFormula(instructions, getManagerFactory(), activeScope, formatManager); } /** - * Adds a relationship between a Solver format and a default Supplier for that format - * of Solver to this VariableContext. - * - * The default Supplier for a format of Solver may not be redefined for a - * SolverFactory. Once a given default Supplier has been established for a format of - * Solver, this method MUST NOT be called a second time for that format of Solver. - * + * Adds a relationship between a Solver format and a default Supplier for that format. + * * @param * The format (class) of object changed by the given Supplier * @param varFormat @@ -370,18 +356,15 @@ public NEPFormula getValidFormula(PCGenScope activeScope, FormatManager void addDefault(FormatManager varFormat, Supplier defaultValue) { - solverFactory.addSolverFormat(varFormat, defaultValue); + myValueStore.addSolverFormat(varFormat, defaultValue); } /** * Returns the default value for a given Format (provided as a FormatManager). - * + * * @param * The format (class) of object for which the default value should be * returned @@ -391,18 +374,20 @@ public void addDefault(FormatManager varFormat, Supplier defaultValue) */ public T getDefaultValue(FormatManager variableFormat) { - return solverFactory.getDefault(variableFormat); + return variableFormat.initializeFrom(myValueStore); + } + + /** + * Validates that all defaults in the ValueStore are consistent. + */ + public void validateDefaults() + { + myValueStore.validateDefaults(); } /** * Returns true if there is a default modifier set for the given FormatManager. - * - * Warning: This is NOT whether there is a Default Value for the given FormatManager. - * This is a much simpler test that checks if there is a specifically provided Default - * Modifier. The distinction here is that a format like ARRAY[NUMBER] will return - * false from this; while it is legal, it never have a specifically defined default, - * as it is a derived default value. - * + * * @param formatManager * The FormatManager indicating the format to check for a default modifier * @return true if there is a default modifier set for the given FormatManager; false @@ -413,17 +398,27 @@ public boolean hasDefaultModifier(FormatManager formatManager) return myValueStore.get(formatManager) != null; } + /** + * Returns the ScopeInstanceFactory for this VariableContext. + * + * @return The ScopeInstanceFactory + */ + public ScopeInstanceFactory getScopeInstanceFactory() + { + return scopeInstanceFactory; + } + /* * Begin: (Delegated) Items part of VariableLibrary interface */ @Override - public boolean isLegalVariableID(LegalScope varScope, String varName) + public boolean isLegalVariableID(ImplementedScope varScope, String varName) { return variableManager.isLegalVariableID(varScope, varName); } @Override - public FormatManager getVariableFormat(LegalScope varScope, String varName) + public Optional> getVariableFormat(ImplementedScope varScope, String varName) { return variableManager.getVariableFormat(varScope, varName); } @@ -435,7 +430,7 @@ public VariableID getVariableID(ScopeInstance instance, String varName) } @Override - public void assertLegalVariableID(String varName, LegalScope varScope, FormatManager formatManager) + public void assertLegalVariableID(String varName, ImplementedScope varScope, FormatManager formatManager) { variableManager.assertLegalVariableID(varName, varScope, formatManager); } @@ -445,6 +440,12 @@ public List> getInvalidFormats() { return variableManager.getInvalidFormats(); } + + @Override + public T getDefault(FormatManager formatManager) + { + return variableManager.getDefault(formatManager); + } /* * End: (Delegated) Items part of VariableLibrary interface */ diff --git a/code/src/java/pcgen/rules/persistence/token/AbstractFixedSetModifierFactory.java b/code/src/java/pcgen/rules/persistence/token/AbstractFixedSetModifierFactory.java index c71890ede26..f3fb1a8de2d 100644 --- a/code/src/java/pcgen/rules/persistence/token/AbstractFixedSetModifierFactory.java +++ b/code/src/java/pcgen/rules/persistence/token/AbstractFixedSetModifierFactory.java @@ -15,7 +15,7 @@ */ package pcgen.rules.persistence.token; -import pcgen.base.calculation.FormulaModifier; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.base.util.FormatManager; /** diff --git a/code/src/java/pcgen/rules/persistence/token/AbstractNumberModifierFactory.java b/code/src/java/pcgen/rules/persistence/token/AbstractNumberModifierFactory.java index 7dc06e45fba..7ad98e0aed0 100644 --- a/code/src/java/pcgen/rules/persistence/token/AbstractNumberModifierFactory.java +++ b/code/src/java/pcgen/rules/persistence/token/AbstractNumberModifierFactory.java @@ -17,11 +17,11 @@ */ package pcgen.rules.persistence.token; -import pcgen.base.calculation.BasicCalculation; -import pcgen.base.calculation.CalculationModifier; -import pcgen.base.calculation.FormulaCalculation; -import pcgen.base.calculation.FormulaModifier; -import pcgen.base.calculation.NEPCalculation; +import pcgen.cdom.calculation.BasicCalculation; +import pcgen.cdom.calculation.CalculationModifier; +import pcgen.cdom.calculation.FormulaCalculation; +import pcgen.cdom.calculation.FormulaModifier; +import pcgen.cdom.calculation.NEPCalculation; import pcgen.base.formula.inst.NEPFormula; import pcgen.base.util.FormatManager; import pcgen.cdom.base.FormulaFactory; diff --git a/code/src/java/pcgen/rules/persistence/token/AbstractRestrictedSpellPrimitive.java b/code/src/java/pcgen/rules/persistence/token/AbstractRestrictedSpellPrimitive.java index 01d9c3c327d..84234bdad85 100644 --- a/code/src/java/pcgen/rules/persistence/token/AbstractRestrictedSpellPrimitive.java +++ b/code/src/java/pcgen/rules/persistence/token/AbstractRestrictedSpellPrimitive.java @@ -21,7 +21,7 @@ import java.util.List; import java.util.StringTokenizer; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMList; import pcgen.cdom.base.CDOMReference; import pcgen.cdom.base.Converter; diff --git a/code/src/java/pcgen/rules/persistence/token/AbstractSetModifierFactory.java b/code/src/java/pcgen/rules/persistence/token/AbstractSetModifierFactory.java index 48c2074f766..db0c265bace 100644 --- a/code/src/java/pcgen/rules/persistence/token/AbstractSetModifierFactory.java +++ b/code/src/java/pcgen/rules/persistence/token/AbstractSetModifierFactory.java @@ -17,10 +17,10 @@ */ package pcgen.rules.persistence.token; -import pcgen.base.calculation.BasicCalculation; -import pcgen.base.calculation.CalculationModifier; -import pcgen.base.calculation.FormulaModifier; -import pcgen.base.calculation.NEPCalculation; +import pcgen.cdom.calculation.BasicCalculation; +import pcgen.cdom.calculation.CalculationModifier; +import pcgen.cdom.calculation.FormulaModifier; +import pcgen.cdom.calculation.NEPCalculation; import pcgen.base.util.FormatManager; import pcgen.cdom.content.ProcessCalculation; diff --git a/code/src/java/pcgen/rules/persistence/token/ModifierFactory.java b/code/src/java/pcgen/rules/persistence/token/ModifierFactory.java index fa690fdd674..77928346f00 100644 --- a/code/src/java/pcgen/rules/persistence/token/ModifierFactory.java +++ b/code/src/java/pcgen/rules/persistence/token/ModifierFactory.java @@ -17,7 +17,7 @@ */ package pcgen.rules.persistence.token; -import pcgen.base.calculation.FormulaModifier; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.base.util.FormatManager; /** diff --git a/code/src/java/pcgen/util/NamedFormula.java b/code/src/java/pcgen/util/NamedFormula.java index f7301da55dc..c5c0ae6966f 100644 --- a/code/src/java/pcgen/util/NamedFormula.java +++ b/code/src/java/pcgen/util/NamedFormula.java @@ -17,7 +17,7 @@ */ package pcgen.util; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; /** * A NamedFormula is a String-Formula pair (similar to a Map.Entry). This is diff --git a/code/src/java/plugin/function/GetOtherFunction.java b/code/src/java/plugin/function/GetOtherFunction.java index ed78c0d630a..4ea402acfb9 100644 --- a/code/src/java/plugin/function/GetOtherFunction.java +++ b/code/src/java/plugin/function/GetOtherFunction.java @@ -22,13 +22,14 @@ import pcgen.base.formula.base.DynamicDependency; import pcgen.base.formula.base.EvaluationManager; import pcgen.base.formula.base.FormulaFunction; -import pcgen.base.formula.base.FormulaManager; import pcgen.base.formula.base.FormulaSemantics; -import pcgen.base.formula.base.LegalScope; +import pcgen.base.formula.base.ScopeImplementer; import pcgen.base.formula.base.ScopeInstance; import pcgen.base.formula.base.ScopeInstanceFactory; import pcgen.base.formula.base.TrainingStrategy; +import pcgen.base.formula.base.VarIDResolver; import pcgen.base.formula.base.VarScoped; +import pcgen.base.formula.base.VariableLibrary; import pcgen.base.formula.exception.SemanticsFailureException; import pcgen.base.formula.parse.ASTQuotString; import pcgen.base.formula.parse.Node; @@ -83,8 +84,8 @@ public FormatManager allowArgs(SemanticsVisitor visitor, Node[] args, Formula + " Static String (first arg cannot be evaluated)"); } String legalScopeName = qs.getText(); - FormulaManager formulaManager = semantics.get(FormulaSemantics.FMANAGER); - PCGenScope legalScope = (PCGenScope) formulaManager.getScopeInstanceFactory().getScope(legalScopeName); + ScopeImplementer scopeImplementer = semantics.get(FormulaSemantics.SCOPELIB); + PCGenScope legalScope = (PCGenScope) scopeImplementer.getImplementedScope(legalScopeName); if (legalScope == null) { throw new SemanticsFailureException( @@ -125,16 +126,13 @@ public FormatManager allowArgs(SemanticsVisitor visitor, Node[] args, Formula public Object evaluate(EvaluateVisitor visitor, Node[] args, EvaluationManager manager) { String legalScopeName = ((ASTQuotString) args[0]).getText(); - FormulaManager formulaManager = manager.get(EvaluationManager.FMANAGER); - PCGenScope legalScope = (PCGenScope) formulaManager.getScopeInstanceFactory().getScope(legalScopeName); + ScopeImplementer scopeImplementer = manager.get(EvaluationManager.SCOPELIB); + PCGenScope legalScope = (PCGenScope) scopeImplementer.getImplementedScope(legalScopeName); LoadContext context = manager.get(ManagerKey.CONTEXT); VarScoped vs = (VarScoped) args[1].jjtAccept(visitor, manager.getWith(EvaluationManager.ASSERTED, legalScope.getFormatManager(context))); - FormulaManager fm = manager.get(EvaluationManager.FMANAGER); - ScopeInstanceFactory siFactory = fm.getScopeInstanceFactory(); - Optional localScopeName = vs.getLocalScopeName(); - //TODO This may be a bug? What if it doesn't have a localScopeName? - ScopeInstance scopeInst = siFactory.get(localScopeName.get(), Optional.of(vs)); + ScopeInstanceFactory siFactory = manager.get(EvaluationManager.SIFACTORY); + ScopeInstance scopeInst = siFactory.get(legalScopeName, vs); //Rest of Equation return args[2].jjtAccept(visitor, manager.getWith(EvaluationManager.INSTANCE, scopeInst)); } @@ -144,17 +142,21 @@ public Optional> getDependencies(DependencyVisitor visitor, Dep { String legalScopeName = ((ASTQuotString) args[0]).getText(); TrainingStrategy ts = new TrainingStrategy(); - FormulaManager formulaManager = fdm.get(DependencyManager.FMANAGER); - ScopeInstanceFactory scopeInstanceFactory = formulaManager.getScopeInstanceFactory(); - PCGenScope legalScope = (PCGenScope) scopeInstanceFactory.getScope(legalScopeName); + ScopeImplementer scopeImplementer = fdm.get(DependencyManager.SCOPELIB); + PCGenScope legalScope = (PCGenScope) scopeImplementer.getImplementedScope(legalScopeName); LoadContext context = fdm.get(ManagerKey.CONTEXT); args[1].jjtAccept(visitor, fdm.getWith(DependencyManager.VARSTRATEGY, Optional.of(ts)) .getWith(DependencyManager.ASSERTED, legalScope.getFormatManager(context))); - DynamicDependency dd = new DynamicDependency(ts.getControlVar(), LegalScope.getFullName(legalScope)); - fdm.get(DependencyManager.DYNAMIC).addDependency(dd); + ScopeInstanceFactory siFactory = fdm.get(DependencyManager.SIFACTORY); + VariableLibrary varLib = fdm.get(DependencyManager.VARLIB); + VarIDResolver varResolver = (scopeName, sourceObject, varName) -> + varLib.getVariableID(siFactory.get(scopeName, sourceObject), varName); + DynamicDependency dd = new DynamicDependency(varResolver, ts.getControlVar(), legalScope.getName()); DependencyManager dynamic = fdm.getWith(DependencyManager.VARSTRATEGY, Optional.of(dd)); dynamic = dynamic.getWith(DependencyManager.SCOPE, Optional.of(legalScope)); //Rest of Equation - return (Optional>) args[2].jjtAccept(visitor, dynamic); + FormatManager returnFormat = (FormatManager) args[2].jjtAccept(visitor, dynamic); + fdm.get(DependencyManager.DYNAMIC).addDependency(dd); + return Optional.of(returnFormat); } } diff --git a/code/src/java/plugin/function/InputFunction.java b/code/src/java/plugin/function/InputFunction.java index 5783821c7bc..34c0b9dee67 100644 --- a/code/src/java/plugin/function/InputFunction.java +++ b/code/src/java/plugin/function/InputFunction.java @@ -24,7 +24,7 @@ import pcgen.base.formula.base.EvaluationManager; import pcgen.base.formula.base.FormulaFunction; import pcgen.base.formula.base.FormulaSemantics; -import pcgen.base.formula.base.LegalScope; +import pcgen.base.formula.base.ImplementedScope; import pcgen.base.formula.base.VariableLibrary; import pcgen.base.formula.exception.SemanticsFailureException; import pcgen.base.formula.parse.ASTQuotString; @@ -38,6 +38,7 @@ import pcgen.base.util.FormatManager; import pcgen.output.channel.ChannelUtilities; + /** * InputFunction is a function designed to allow pulling information from a channel (as * defined by the argument to the input function). @@ -74,14 +75,14 @@ public final FormatManager allowArgs(SemanticsVisitor visitor, Node[] args, F } String inputName = ((SimpleNode) inputNode).getText(); String varName = ChannelUtilities.createVarName(inputName); - VariableLibrary varLib = semantics.get(FormulaSemantics.FMANAGER).getFactory(); - LegalScope scope = semantics.get(FormulaSemantics.SCOPE); - FormatManager formatManager = varLib.getVariableFormat(scope, varName); - if (formatManager == null) + VariableLibrary varLib = semantics.get(FormulaSemantics.VARLIB); + ImplementedScope scope = semantics.get(FormulaSemantics.SCOPE); + Optional> formatManager = varLib.getVariableFormat(scope, varName); + if (formatManager.isEmpty()) { throw new SemanticsFailureException("Input Channel: " + varName + " was not found"); } - return formatManager; + return formatManager.get(); } @Override @@ -103,6 +104,6 @@ public Optional> getDependencies(DependencyVisitor visitor, Dep { ASTQuotString inputName = (ASTQuotString) args[0]; String varName = inputName.getText(); - return visitor.visitVariable(ChannelUtilities.createVarName(varName), fdm); + return Optional.of(visitor.visitVariable(ChannelUtilities.createVarName(varName), fdm)); } } diff --git a/code/src/java/plugin/function/LookupFunction.java b/code/src/java/plugin/function/LookupFunction.java index dfe4a6f6e84..2d9ac57c203 100644 --- a/code/src/java/plugin/function/LookupFunction.java +++ b/code/src/java/plugin/function/LookupFunction.java @@ -24,8 +24,8 @@ import pcgen.base.formula.base.DependencyManager; import pcgen.base.formula.base.EvaluationManager; import pcgen.base.formula.base.FormulaFunction; -import pcgen.base.formula.base.FormulaManager; import pcgen.base.formula.base.FormulaSemantics; +import pcgen.base.formula.base.VariableLibrary; import pcgen.base.formula.exception.SemanticsFailureException; import pcgen.base.formula.parse.ASTQuotString; import pcgen.base.formula.parse.Node; @@ -163,8 +163,8 @@ public Object evaluate(EvaluateVisitor visitor, Node[] args, EvaluationManager m FormatManager fmt = column.getFormatManager(); System.out.println("Lookup called on invalid column: '" + columnName + "' is not present on table '" + dataTable.getName() + "' assuming default for " + fmt.getIdentifierType()); - FormulaManager fm = manager.get(EvaluationManager.FMANAGER); - return fm.getDefault(fmt); + VariableLibrary varLib = manager.get(EvaluationManager.VARLIB); + return varLib.getDefault(fmt); } String lookupRule = "EXACT"; if (args.length == 4) @@ -179,8 +179,8 @@ public Object evaluate(EvaluateVisitor visitor, Node[] args, EvaluationManager m System.out.println( "Lookup called on invalid item: '" + lookupValue + "' is not present in the first row of table '" + dataTable.getName() + "' assuming default for " + fmt.getIdentifierType()); - FormulaManager fm = manager.get(EvaluationManager.FMANAGER); - return fm.getDefault(fmt); + VariableLibrary varLib = manager.get(EvaluationManager.VARLIB); + return varLib.getDefault(fmt); } return dataTable.lookup(lookupType, lookupValue, columnName); } diff --git a/code/src/java/plugin/lsttokens/ChooseLst.java b/code/src/java/plugin/lsttokens/ChooseLst.java index 1875ba55f40..b98905fc35b 100644 --- a/code/src/java/plugin/lsttokens/ChooseLst.java +++ b/code/src/java/plugin/lsttokens/ChooseLst.java @@ -19,7 +19,7 @@ import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.ChooseInformation; import pcgen.cdom.base.ChooseSelectionActor; diff --git a/code/src/java/plugin/lsttokens/DefineLst.java b/code/src/java/plugin/lsttokens/DefineLst.java index 401db49207d..596874dd809 100644 --- a/code/src/java/plugin/lsttokens/DefineLst.java +++ b/code/src/java/plugin/lsttokens/DefineLst.java @@ -20,7 +20,7 @@ import java.util.Set; import java.util.TreeSet; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.Constants; diff --git a/code/src/java/plugin/lsttokens/DefineStatLst.java b/code/src/java/plugin/lsttokens/DefineStatLst.java index bcc1d2ddc7d..e90179d4da6 100644 --- a/code/src/java/plugin/lsttokens/DefineStatLst.java +++ b/code/src/java/plugin/lsttokens/DefineStatLst.java @@ -19,7 +19,7 @@ import java.util.TreeSet; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.Constants; diff --git a/code/src/java/plugin/lsttokens/DrLst.java b/code/src/java/plugin/lsttokens/DrLst.java index 57534bb49e7..de738ba93b4 100644 --- a/code/src/java/plugin/lsttokens/DrLst.java +++ b/code/src/java/plugin/lsttokens/DrLst.java @@ -24,7 +24,7 @@ import java.util.StringTokenizer; import java.util.TreeSet; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.Constants; import pcgen.cdom.base.FormulaFactory; diff --git a/code/src/java/plugin/lsttokens/FollowersLst.java b/code/src/java/plugin/lsttokens/FollowersLst.java index aae77907654..e7afa64459b 100644 --- a/code/src/java/plugin/lsttokens/FollowersLst.java +++ b/code/src/java/plugin/lsttokens/FollowersLst.java @@ -21,7 +21,7 @@ import java.util.TreeSet; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.Constants; diff --git a/code/src/java/plugin/lsttokens/KitLst.java b/code/src/java/plugin/lsttokens/KitLst.java index 671e53c2f81..dad959d6cb4 100644 --- a/code/src/java/plugin/lsttokens/KitLst.java +++ b/code/src/java/plugin/lsttokens/KitLst.java @@ -24,7 +24,7 @@ import java.util.StringTokenizer; import java.util.TreeSet; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.CDOMReference; import pcgen.cdom.base.ChoiceActor; diff --git a/code/src/java/plugin/lsttokens/ModifyLst.java b/code/src/java/plugin/lsttokens/ModifyLst.java index 0617ee5e0f8..2d5b6078bce 100644 --- a/code/src/java/plugin/lsttokens/ModifyLst.java +++ b/code/src/java/plugin/lsttokens/ModifyLst.java @@ -24,9 +24,7 @@ import java.util.Optional; import java.util.Set; -import pcgen.base.calculation.FormulaModifier; -import pcgen.base.formula.base.FormulaManager; -import pcgen.base.formula.base.FunctionLibrary; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.base.lang.StringUtil; import pcgen.base.text.ParsingSeparator; import pcgen.base.util.CaseInsensitiveMap; @@ -35,7 +33,6 @@ import pcgen.cdom.base.VarContainer; import pcgen.cdom.base.VarHolder; import pcgen.cdom.content.VarModifier; -import pcgen.cdom.formula.local.DefinedWrappingLibrary; import pcgen.cdom.formula.scope.PCGenScope; import pcgen.rules.context.LoadContext; import pcgen.rules.persistence.token.AbstractNonEmptyToken; @@ -63,7 +60,7 @@ public ParseResult parseNonEmptyToken(LoadContext context, VarHolder obj, String { PCGenScope scope = context.getActiveScope(); VarModifier varModifier = parseModifyInfo(context, value, scope, - generateFormulaManager(context, scope), getTokenName(), 0); + getTokenName(), 0); obj.addModifier(varModifier); } catch (ModifyException e) @@ -76,7 +73,7 @@ public ParseResult parseNonEmptyToken(LoadContext context, VarHolder obj, String /** * Parses the 3 arguments plus associations that are part of a token doing a * modification. - * + * * @param context * The LoadContext for processing * @param value @@ -92,14 +89,9 @@ public ParseResult parseNonEmptyToken(LoadContext context, VarHolder obj, String * if the parsing failed. The message contains information about the error */ public static VarModifier parseModifyInfo(LoadContext context, - String value, PCGenScope scope, FormulaManager formulaManager, + String value, PCGenScope scope, String tokenName, int argsConsumed) throws ModifyException { - /* - * TODO CODE-3299 Need to check the object type of the VarHolder to make sure it - * is legal. Note it's a proxy, so a @ReadOnly method needs to be used to support - * the analysis. - */ ParsingSeparator sep = new ParsingSeparator(value, '|'); sep.addGroupingPair('[', ']'); sep.addGroupingPair('(', ')'); @@ -130,10 +122,16 @@ public static VarModifier parseModifyInfo(LoadContext context, FormulaModifier modifier; try { - FormatManager format = context.getVariableContext().getVariableFormat(scope, varName); + Optional> format = context.getVariableContext().getVariableFormat(scope, varName); + if (format.isEmpty()) + { + throw new ModifyException( + tokenName + " found no format for var name: " + varName + + "(scope: " + scope.getName() + ")"); + } modifier = context.getVariableContext().getModifier(modIdentification, - modInstructions, formulaManager, scope, format); + modInstructions, scope, format.get()); } catch (IllegalArgumentException e) { @@ -166,23 +164,6 @@ public static VarModifier parseModifyInfo(LoadContext context, return new VarModifier<>(varName, scope, modifier); } - private final FormulaManager generateFormulaManager(LoadContext context, PCGenScope scope) - { - FormulaManager formulaManager = - context.getVariableContext().getFormulaManager(); - Optional> formatManager = scope.getFormatManager(context); - if (formatManager.isEmpty()) - { - //Okay, we won't add this() - return formulaManager; - } - //Note: Passing new Object() as DefinedValue is a dummy - FunctionLibrary functionLibrary = new DefinedWrappingLibrary( - formulaManager.get(FormulaManager.FUNCTION), "this", new Object(), - formatManager.get()); - return formulaManager.getWith(FormulaManager.FUNCTION, functionLibrary); - } - @Override public String[] unparse(LoadContext context, VarContainer obj) { diff --git a/code/src/java/plugin/lsttokens/ModifyOtherLst.java b/code/src/java/plugin/lsttokens/ModifyOtherLst.java index 517e5721d9e..c2025359cbf 100644 --- a/code/src/java/plugin/lsttokens/ModifyOtherLst.java +++ b/code/src/java/plugin/lsttokens/ModifyOtherLst.java @@ -19,23 +19,16 @@ import java.util.ArrayList; import java.util.List; -import java.util.Optional; import java.util.StringJoiner; -import pcgen.base.formula.base.FormulaManager; -import pcgen.base.formula.base.FunctionLibrary; -import pcgen.base.formula.base.LegalScope; import pcgen.base.text.ParsingSeparator; -import pcgen.base.util.FormatManager; import pcgen.cdom.base.Constants; import pcgen.cdom.base.VarContainer; import pcgen.cdom.base.VarHolder; import pcgen.cdom.content.RemoteModifier; import pcgen.cdom.content.VarModifier; -import pcgen.cdom.formula.local.DefinedWrappingLibrary; import pcgen.cdom.formula.scope.PCGenScope; import pcgen.cdom.grouping.GroupingCollection; -import pcgen.rules.context.AbstractObjectContext.DummyCDOMObject; import pcgen.rules.context.LoadContext; import pcgen.rules.persistence.token.AbstractNonEmptyToken; import pcgen.rules.persistence.token.CDOMInterfaceToken; @@ -72,7 +65,7 @@ public ParseResult parseNonEmptyToken(LoadContext context, VarHolder obj, String return new ParseResult.Fail( getTokenName() + " found illegal variable scope: " + scopeName + " as first argument: " + value); } - if (lvs.getParentScope() == null) + if (lvs.isGlobal()) { return new ParseResult.Fail( getTokenName() + " found illegal variable scope: " + scopeName + " is a global scope"); @@ -81,7 +74,7 @@ public ParseResult parseNonEmptyToken(LoadContext context, VarHolder obj, String { return new ParseResult.Fail(getTokenName() + " needed 2nd argument: " + value); } - String fullName = LegalScope.getFullName(lvs); + String fullName = lvs.getName(); LoadContext subContext = context.dropIntoContext(fullName); String groupingName = sep.next(); @@ -96,7 +89,7 @@ public ParseResult parseNonEmptyToken(LoadContext context, VarHolder obj, String try { VarModifier vm = ModifyLst.parseModifyInfo(subContext, sb.toString(), - scope, generateFormulaManager(context, scope), getTokenName(), 2); + scope, getTokenName(), 2); obj.addRemoteModifier(new RemoteModifier<>(group, vm)); } catch (ModifyException e) @@ -106,34 +99,6 @@ public ParseResult parseNonEmptyToken(LoadContext context, VarHolder obj, String return ParseResult.SUCCESS; } - private final FormulaManager generateFormulaManager(LoadContext context, PCGenScope scope) - { - FormulaManager formulaManager = - context.getVariableContext().getFormulaManager(); - FunctionLibrary functionManager = formulaManager.get(FormulaManager.FUNCTION); - boolean modified = false; - Optional> sourceFormatManager = scope.getFormatManager(context); - if (sourceFormatManager.isPresent()) - { - functionManager = new DefinedWrappingLibrary(functionManager, - "source", new DummyCDOMObject(), sourceFormatManager.get()); - modified = true; - } - Optional> targetFormatManager = scope.getFormatManager(context); - if (targetFormatManager.isPresent()) - { - functionManager = new DefinedWrappingLibrary(functionManager, - "target", new DummyCDOMObject(), targetFormatManager.get()); - modified = true; - } - if (!modified) - { - //Fine then :P - return formulaManager; - } - return formulaManager.getWith(FormulaManager.FUNCTION, functionManager); - } - @Override public String[] unparse(LoadContext context, VarContainer obj) { @@ -144,7 +109,7 @@ public String[] unparse(LoadContext context, VarContainer obj) VarModifier vm = rm.getVarModifier(); StringBuilder sb = new StringBuilder(); GroupingCollection og = rm.getGrouping(); - sb.append(LegalScope.getFullName(vm.getLegalScope())); + sb.append(vm.getLegalScope().getName()); sb.append(Constants.PIPE); sb.append(og.getInstructions()); sb.append(Constants.PIPE); diff --git a/code/src/java/plugin/lsttokens/NaturalattacksLst.java b/code/src/java/plugin/lsttokens/NaturalattacksLst.java index 1a8ae23b722..cb0ec15bf4d 100644 --- a/code/src/java/plugin/lsttokens/NaturalattacksLst.java +++ b/code/src/java/plugin/lsttokens/NaturalattacksLst.java @@ -24,7 +24,7 @@ import java.util.Set; import java.util.StringTokenizer; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.lang.StringUtil; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.Constants; diff --git a/code/src/java/plugin/lsttokens/SelectLst.java b/code/src/java/plugin/lsttokens/SelectLst.java index 179ff6bdbc3..d698f3b9568 100644 --- a/code/src/java/plugin/lsttokens/SelectLst.java +++ b/code/src/java/plugin/lsttokens/SelectLst.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.base.Ungranted; diff --git a/code/src/java/plugin/lsttokens/SpellsLst.java b/code/src/java/plugin/lsttokens/SpellsLst.java index b5044c42c92..230c7322a33 100644 --- a/code/src/java/plugin/lsttokens/SpellsLst.java +++ b/code/src/java/plugin/lsttokens/SpellsLst.java @@ -27,7 +27,7 @@ import java.util.Set; import java.util.TreeSet; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.lang.StringUtil; import pcgen.base.text.ParsingSeparator; import pcgen.base.util.DoubleKeyMap; diff --git a/code/src/java/plugin/lsttokens/SrLst.java b/code/src/java/plugin/lsttokens/SrLst.java index 4389c868574..5f8b6f1bfd5 100644 --- a/code/src/java/plugin/lsttokens/SrLst.java +++ b/code/src/java/plugin/lsttokens/SrLst.java @@ -20,7 +20,7 @@ import java.util.LinkedList; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.Constants; import pcgen.cdom.base.FormulaFactory; diff --git a/code/src/java/plugin/lsttokens/add/AbilityToken.java b/code/src/java/plugin/lsttokens/add/AbilityToken.java index 5f9a2807d20..8c165b0ea7b 100644 --- a/code/src/java/plugin/lsttokens/add/AbilityToken.java +++ b/code/src/java/plugin/lsttokens/add/AbilityToken.java @@ -22,7 +22,7 @@ import java.util.Collection; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.CDOMReference; diff --git a/code/src/java/plugin/lsttokens/add/ClassSkillsLevelToken.java b/code/src/java/plugin/lsttokens/add/ClassSkillsLevelToken.java index 86c04cb7aef..061339ffae2 100644 --- a/code/src/java/plugin/lsttokens/add/ClassSkillsLevelToken.java +++ b/code/src/java/plugin/lsttokens/add/ClassSkillsLevelToken.java @@ -22,7 +22,7 @@ import java.util.List; import java.util.StringTokenizer; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.CDOMReference; import pcgen.cdom.base.ChoiceSet; diff --git a/code/src/java/plugin/lsttokens/add/ClassSkillsToken.java b/code/src/java/plugin/lsttokens/add/ClassSkillsToken.java index c1e4ec1cb95..5835b47ff8e 100644 --- a/code/src/java/plugin/lsttokens/add/ClassSkillsToken.java +++ b/code/src/java/plugin/lsttokens/add/ClassSkillsToken.java @@ -22,7 +22,7 @@ import java.util.List; import java.util.StringTokenizer; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.CDOMReference; import pcgen.cdom.base.ChoiceSet; diff --git a/code/src/java/plugin/lsttokens/add/EquipToken.java b/code/src/java/plugin/lsttokens/add/EquipToken.java index a635b705fa3..4aa05684eef 100644 --- a/code/src/java/plugin/lsttokens/add/EquipToken.java +++ b/code/src/java/plugin/lsttokens/add/EquipToken.java @@ -22,7 +22,7 @@ import java.util.List; import java.util.StringTokenizer; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.CDOMReference; diff --git a/code/src/java/plugin/lsttokens/add/LanguageToken.java b/code/src/java/plugin/lsttokens/add/LanguageToken.java index 565af9492a5..c80e7d19cc9 100644 --- a/code/src/java/plugin/lsttokens/add/LanguageToken.java +++ b/code/src/java/plugin/lsttokens/add/LanguageToken.java @@ -22,7 +22,7 @@ import java.util.List; import java.util.StringTokenizer; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.CDOMReference; diff --git a/code/src/java/plugin/lsttokens/add/SkillToken.java b/code/src/java/plugin/lsttokens/add/SkillToken.java index 171ab5c6a06..52f6add0524 100644 --- a/code/src/java/plugin/lsttokens/add/SkillToken.java +++ b/code/src/java/plugin/lsttokens/add/SkillToken.java @@ -22,7 +22,7 @@ import java.util.List; import java.util.StringTokenizer; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.CDOMReference; diff --git a/code/src/java/plugin/lsttokens/add/SpellCasterToken.java b/code/src/java/plugin/lsttokens/add/SpellCasterToken.java index b42833c3822..a3844275219 100644 --- a/code/src/java/plugin/lsttokens/add/SpellCasterToken.java +++ b/code/src/java/plugin/lsttokens/add/SpellCasterToken.java @@ -22,7 +22,7 @@ import java.util.List; import java.util.StringTokenizer; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.CDOMReference; diff --git a/code/src/java/plugin/lsttokens/add/TemplateToken.java b/code/src/java/plugin/lsttokens/add/TemplateToken.java index 28efc687a55..a427d976b72 100644 --- a/code/src/java/plugin/lsttokens/add/TemplateToken.java +++ b/code/src/java/plugin/lsttokens/add/TemplateToken.java @@ -22,7 +22,7 @@ import java.util.List; import java.util.StringTokenizer; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.CDOMReference; diff --git a/code/src/java/plugin/lsttokens/choose/SpellLevelToken.java b/code/src/java/plugin/lsttokens/choose/SpellLevelToken.java index 52050d311cb..e65f71316a6 100644 --- a/code/src/java/plugin/lsttokens/choose/SpellLevelToken.java +++ b/code/src/java/plugin/lsttokens/choose/SpellLevelToken.java @@ -20,7 +20,7 @@ import java.util.ArrayList; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.ChooseDriver; diff --git a/code/src/java/plugin/lsttokens/choose/UserInputToken.java b/code/src/java/plugin/lsttokens/choose/UserInputToken.java index 426c166235e..e5315be3a7b 100644 --- a/code/src/java/plugin/lsttokens/choose/UserInputToken.java +++ b/code/src/java/plugin/lsttokens/choose/UserInputToken.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.choose; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.ChooseInformation; import pcgen.cdom.base.FormulaFactory; diff --git a/code/src/java/plugin/lsttokens/deprecated/AddFeatToken.java b/code/src/java/plugin/lsttokens/deprecated/AddFeatToken.java index 304ba280ae4..7c50eafbeeb 100644 --- a/code/src/java/plugin/lsttokens/deprecated/AddFeatToken.java +++ b/code/src/java/plugin/lsttokens/deprecated/AddFeatToken.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.deprecated; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.FormulaFactory; diff --git a/code/src/java/plugin/lsttokens/deprecated/AddVFeatToken.java b/code/src/java/plugin/lsttokens/deprecated/AddVFeatToken.java index 24fc2529233..cbe3a826d71 100644 --- a/code/src/java/plugin/lsttokens/deprecated/AddVFeatToken.java +++ b/code/src/java/plugin/lsttokens/deprecated/AddVFeatToken.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.deprecated; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.FormulaFactory; diff --git a/code/src/java/plugin/lsttokens/deprecated/RemoveFeatToken.java b/code/src/java/plugin/lsttokens/deprecated/RemoveFeatToken.java index 221dc817a86..053d08e93f2 100644 --- a/code/src/java/plugin/lsttokens/deprecated/RemoveFeatToken.java +++ b/code/src/java/plugin/lsttokens/deprecated/RemoveFeatToken.java @@ -22,7 +22,7 @@ import java.util.Collection; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.CDOMObjectUtilities; diff --git a/code/src/java/plugin/lsttokens/equipment/PageUsageToken.java b/code/src/java/plugin/lsttokens/equipment/PageUsageToken.java index 993e5f8a023..0c88900f7f5 100644 --- a/code/src/java/plugin/lsttokens/equipment/PageUsageToken.java +++ b/code/src/java/plugin/lsttokens/equipment/PageUsageToken.java @@ -18,7 +18,7 @@ */ package plugin.lsttokens.equipment; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.enumeration.FormulaKey; import pcgen.core.Equipment; diff --git a/code/src/java/plugin/lsttokens/equipmentmodifier/CostToken.java b/code/src/java/plugin/lsttokens/equipmentmodifier/CostToken.java index bd438118b8b..bae40275c32 100644 --- a/code/src/java/plugin/lsttokens/equipmentmodifier/CostToken.java +++ b/code/src/java/plugin/lsttokens/equipmentmodifier/CostToken.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.equipmentmodifier; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.enumeration.FormulaKey; import pcgen.core.EquipmentModifier; diff --git a/code/src/java/plugin/lsttokens/equipmentmodifier/CostpreToken.java b/code/src/java/plugin/lsttokens/equipmentmodifier/CostpreToken.java index c832b1fa507..8ec00e6c1b8 100644 --- a/code/src/java/plugin/lsttokens/equipmentmodifier/CostpreToken.java +++ b/code/src/java/plugin/lsttokens/equipmentmodifier/CostpreToken.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.equipmentmodifier; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.enumeration.FormulaKey; import pcgen.core.EquipmentModifier; diff --git a/code/src/java/plugin/lsttokens/gamemode/abilitycategory/PoolToken.java b/code/src/java/plugin/lsttokens/gamemode/abilitycategory/PoolToken.java index 447694d5fbb..23aeaeac3bb 100644 --- a/code/src/java/plugin/lsttokens/gamemode/abilitycategory/PoolToken.java +++ b/code/src/java/plugin/lsttokens/gamemode/abilitycategory/PoolToken.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.gamemode.abilitycategory; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.core.AbilityCategory; import pcgen.rules.context.LoadContext; diff --git a/code/src/java/plugin/lsttokens/gamemode/ageset/KitToken.java b/code/src/java/plugin/lsttokens/gamemode/ageset/KitToken.java index 1a488a6359b..2340b6dbd6c 100644 --- a/code/src/java/plugin/lsttokens/gamemode/ageset/KitToken.java +++ b/code/src/java/plugin/lsttokens/gamemode/ageset/KitToken.java @@ -23,7 +23,7 @@ import java.util.StringTokenizer; import java.util.TreeSet; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.CDOMReference; import pcgen.cdom.base.ChoiceActor; diff --git a/code/src/java/plugin/lsttokens/kit/SelectToken.java b/code/src/java/plugin/lsttokens/kit/SelectToken.java index 292d20b92af..81c9aee9ebd 100644 --- a/code/src/java/plugin/lsttokens/kit/SelectToken.java +++ b/code/src/java/plugin/lsttokens/kit/SelectToken.java @@ -18,7 +18,7 @@ package plugin.lsttokens.kit; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.core.kit.KitSelect; import pcgen.rules.context.LoadContext; diff --git a/code/src/java/plugin/lsttokens/kit/StatToken.java b/code/src/java/plugin/lsttokens/kit/StatToken.java index cb20fcfc2a4..d859740f61c 100644 --- a/code/src/java/plugin/lsttokens/kit/StatToken.java +++ b/code/src/java/plugin/lsttokens/kit/StatToken.java @@ -20,7 +20,7 @@ import java.util.StringTokenizer; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.Constants; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.enumeration.ListKey; diff --git a/code/src/java/plugin/lsttokens/kit/basekit/LookupToken.java b/code/src/java/plugin/lsttokens/kit/basekit/LookupToken.java index 94aa36ef6c2..33bebbccfb9 100644 --- a/code/src/java/plugin/lsttokens/kit/basekit/LookupToken.java +++ b/code/src/java/plugin/lsttokens/kit/basekit/LookupToken.java @@ -22,7 +22,7 @@ import java.util.Collection; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.util.NamedFormula; import pcgen.cdom.base.FormulaFactory; diff --git a/code/src/java/plugin/lsttokens/kit/basekit/OptionToken.java b/code/src/java/plugin/lsttokens/kit/basekit/OptionToken.java index 83b0bf36cd1..ce2f19e24af 100644 --- a/code/src/java/plugin/lsttokens/kit/basekit/OptionToken.java +++ b/code/src/java/plugin/lsttokens/kit/basekit/OptionToken.java @@ -22,7 +22,7 @@ import java.util.Collection; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.lang.StringUtil; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.Constants; diff --git a/code/src/java/plugin/lsttokens/kit/clazz/LevelToken.java b/code/src/java/plugin/lsttokens/kit/clazz/LevelToken.java index 83b0188b6c5..faab25f5a79 100644 --- a/code/src/java/plugin/lsttokens/kit/clazz/LevelToken.java +++ b/code/src/java/plugin/lsttokens/kit/clazz/LevelToken.java @@ -18,7 +18,7 @@ package plugin.lsttokens.kit.clazz; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.core.kit.KitClass; import pcgen.rules.context.LoadContext; diff --git a/code/src/java/plugin/lsttokens/kit/deity/CountToken.java b/code/src/java/plugin/lsttokens/kit/deity/CountToken.java index 655ee9a65f8..2d0f7658597 100644 --- a/code/src/java/plugin/lsttokens/kit/deity/CountToken.java +++ b/code/src/java/plugin/lsttokens/kit/deity/CountToken.java @@ -18,7 +18,7 @@ package plugin.lsttokens.kit.deity; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.core.kit.KitDeity; import pcgen.rules.context.LoadContext; diff --git a/code/src/java/plugin/lsttokens/kit/funds/QtyToken.java b/code/src/java/plugin/lsttokens/kit/funds/QtyToken.java index 4e8b68c6e36..9de10fb61bb 100644 --- a/code/src/java/plugin/lsttokens/kit/funds/QtyToken.java +++ b/code/src/java/plugin/lsttokens/kit/funds/QtyToken.java @@ -18,7 +18,7 @@ package plugin.lsttokens.kit.funds; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.core.kit.KitFunds; import pcgen.rules.context.LoadContext; diff --git a/code/src/java/plugin/lsttokens/kit/gear/QtyToken.java b/code/src/java/plugin/lsttokens/kit/gear/QtyToken.java index 2fce80f4544..f9773d2f54e 100644 --- a/code/src/java/plugin/lsttokens/kit/gear/QtyToken.java +++ b/code/src/java/plugin/lsttokens/kit/gear/QtyToken.java @@ -18,7 +18,7 @@ package plugin.lsttokens.kit.gear; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.core.kit.KitGear; import pcgen.rules.context.LoadContext; diff --git a/code/src/java/plugin/lsttokens/kit/spells/CountToken.java b/code/src/java/plugin/lsttokens/kit/spells/CountToken.java index f93ac61e8f0..21557b0cdf2 100644 --- a/code/src/java/plugin/lsttokens/kit/spells/CountToken.java +++ b/code/src/java/plugin/lsttokens/kit/spells/CountToken.java @@ -18,7 +18,7 @@ package plugin.lsttokens.kit.spells; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.core.kit.KitSpells; import pcgen.rules.context.LoadContext; diff --git a/code/src/java/plugin/lsttokens/kit/startpack/EquipBuyToken.java b/code/src/java/plugin/lsttokens/kit/startpack/EquipBuyToken.java index 2ee601b9bf9..5dcbc0e7ab1 100644 --- a/code/src/java/plugin/lsttokens/kit/startpack/EquipBuyToken.java +++ b/code/src/java/plugin/lsttokens/kit/startpack/EquipBuyToken.java @@ -21,7 +21,7 @@ import java.util.ArrayList; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.Constants; import pcgen.cdom.base.FormulaFactory; diff --git a/code/src/java/plugin/lsttokens/kit/startpack/TotalCostToken.java b/code/src/java/plugin/lsttokens/kit/startpack/TotalCostToken.java index ae5c2ff3f0d..eda15f950f1 100644 --- a/code/src/java/plugin/lsttokens/kit/startpack/TotalCostToken.java +++ b/code/src/java/plugin/lsttokens/kit/startpack/TotalCostToken.java @@ -21,7 +21,7 @@ import java.util.ArrayList; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.Constants; import pcgen.cdom.base.FormulaFactory; diff --git a/code/src/java/plugin/lsttokens/kit/table/ValuesToken.java b/code/src/java/plugin/lsttokens/kit/table/ValuesToken.java index 165124aa294..5695a010c7a 100644 --- a/code/src/java/plugin/lsttokens/kit/table/ValuesToken.java +++ b/code/src/java/plugin/lsttokens/kit/table/ValuesToken.java @@ -21,7 +21,7 @@ import java.util.Collection; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.Constants; import pcgen.cdom.base.FormulaFactory; diff --git a/code/src/java/plugin/lsttokens/pcclass/CrformulaToken.java b/code/src/java/plugin/lsttokens/pcclass/CrformulaToken.java index 9f3c3203892..ec650c3e1b0 100644 --- a/code/src/java/plugin/lsttokens/pcclass/CrformulaToken.java +++ b/code/src/java/plugin/lsttokens/pcclass/CrformulaToken.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.pcclass; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.enumeration.FormulaKey; import pcgen.core.PCClass; diff --git a/code/src/java/plugin/lsttokens/pcclass/SkilllistToken.java b/code/src/java/plugin/lsttokens/pcclass/SkilllistToken.java index b0d275957aa..6936a35ddca 100644 --- a/code/src/java/plugin/lsttokens/pcclass/SkilllistToken.java +++ b/code/src/java/plugin/lsttokens/pcclass/SkilllistToken.java @@ -21,7 +21,7 @@ import java.util.List; import java.util.StringTokenizer; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMReference; import pcgen.cdom.base.ChoiceSet; import pcgen.cdom.base.ConcreteTransitionChoice; diff --git a/code/src/java/plugin/lsttokens/pcclass/SpelllistToken.java b/code/src/java/plugin/lsttokens/pcclass/SpelllistToken.java index ef883956828..dda3542ea96 100644 --- a/code/src/java/plugin/lsttokens/pcclass/SpelllistToken.java +++ b/code/src/java/plugin/lsttokens/pcclass/SpelllistToken.java @@ -21,7 +21,7 @@ import java.util.List; import java.util.StringTokenizer; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMListObject; import pcgen.cdom.base.CDOMReference; import pcgen.cdom.base.ChoiceSet; diff --git a/code/src/java/plugin/lsttokens/pcclass/StartskillptsToken.java b/code/src/java/plugin/lsttokens/pcclass/StartskillptsToken.java index 0849f36d403..d91164b5170 100644 --- a/code/src/java/plugin/lsttokens/pcclass/StartskillptsToken.java +++ b/code/src/java/plugin/lsttokens/pcclass/StartskillptsToken.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.pcclass; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.enumeration.FormulaKey; import pcgen.core.PCClass; diff --git a/code/src/java/plugin/lsttokens/pcclass/level/CastToken.java b/code/src/java/plugin/lsttokens/pcclass/level/CastToken.java index ba279d42a62..a472d953432 100644 --- a/code/src/java/plugin/lsttokens/pcclass/level/CastToken.java +++ b/code/src/java/plugin/lsttokens/pcclass/level/CastToken.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.pcclass.level; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.lang.StringUtil; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.Constants; diff --git a/code/src/java/plugin/lsttokens/pcclass/level/KnownToken.java b/code/src/java/plugin/lsttokens/pcclass/level/KnownToken.java index 946be0e4664..54013452898 100644 --- a/code/src/java/plugin/lsttokens/pcclass/level/KnownToken.java +++ b/code/src/java/plugin/lsttokens/pcclass/level/KnownToken.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.pcclass.level; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.lang.StringUtil; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.Constants; diff --git a/code/src/java/plugin/lsttokens/pcclass/level/SpecialtyknownToken.java b/code/src/java/plugin/lsttokens/pcclass/level/SpecialtyknownToken.java index 978d4d8ef0c..93fc9a595d1 100644 --- a/code/src/java/plugin/lsttokens/pcclass/level/SpecialtyknownToken.java +++ b/code/src/java/plugin/lsttokens/pcclass/level/SpecialtyknownToken.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.pcclass.level; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.lang.StringUtil; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.Constants; diff --git a/code/src/java/plugin/lsttokens/race/CrToken.java b/code/src/java/plugin/lsttokens/race/CrToken.java index 4a9746c0bff..d9519627cf3 100644 --- a/code/src/java/plugin/lsttokens/race/CrToken.java +++ b/code/src/java/plugin/lsttokens/race/CrToken.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.race; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.content.ChallengeRating; import pcgen.cdom.enumeration.FormulaKey; diff --git a/code/src/java/plugin/lsttokens/race/FaceToken.java b/code/src/java/plugin/lsttokens/race/FaceToken.java index 89048bc6576..ad23f51286d 100644 --- a/code/src/java/plugin/lsttokens/race/FaceToken.java +++ b/code/src/java/plugin/lsttokens/race/FaceToken.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.race; -import pcgen.base.calculation.FormulaModifier; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.base.math.OrderedPair; import pcgen.base.util.FormatManager; import pcgen.cdom.base.LimitedVarContainer; @@ -72,8 +72,7 @@ protected ParseResult parseNonEmptyToken(LoadContext context, LimitedVarHolder r { modifier = context.getVariableContext().getModifier(MOD_IDENTIFICATION, - value, context.getVariableContext().getFormulaManager(), - scope, formatManager); + value, scope, formatManager); } catch (IllegalArgumentException iae) { @@ -112,7 +111,7 @@ public String[] unparse(LoadContext context, LimitedVarContainer race) { FormulaModifier modifier = vm.getModifier(); if (CControl.FACE.getDefaultValue().equals(vm.getVarName()) - && (!vm.getLegalScope().getParentScope().isPresent()) + && (vm.getLegalScope().isGlobal()) && (modifier.getIdentification().equals(MOD_IDENTIFICATION))) { face = modifier.getInstructions(); diff --git a/code/src/java/plugin/lsttokens/race/LeveladjustmentToken.java b/code/src/java/plugin/lsttokens/race/LeveladjustmentToken.java index e5ae5221101..c3881ce16a8 100644 --- a/code/src/java/plugin/lsttokens/race/LeveladjustmentToken.java +++ b/code/src/java/plugin/lsttokens/race/LeveladjustmentToken.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.race; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.enumeration.FormulaKey; import pcgen.core.Race; diff --git a/code/src/java/plugin/lsttokens/race/SizeToken.java b/code/src/java/plugin/lsttokens/race/SizeToken.java index 2884abdb114..bee37fe2763 100644 --- a/code/src/java/plugin/lsttokens/race/SizeToken.java +++ b/code/src/java/plugin/lsttokens/race/SizeToken.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.race; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.enumeration.FormulaKey; import pcgen.cdom.formula.FixedSizeFormula; import pcgen.cdom.reference.CDOMSingleRef; diff --git a/code/src/java/plugin/lsttokens/race/XtraskillptsperlvlToken.java b/code/src/java/plugin/lsttokens/race/XtraskillptsperlvlToken.java index 442890668b2..309fb6b2d36 100644 --- a/code/src/java/plugin/lsttokens/race/XtraskillptsperlvlToken.java +++ b/code/src/java/plugin/lsttokens/race/XtraskillptsperlvlToken.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.race; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.enumeration.FormulaKey; import pcgen.core.Race; diff --git a/code/src/java/plugin/lsttokens/statsandchecks/stat/StatmodToken.java b/code/src/java/plugin/lsttokens/statsandchecks/stat/StatmodToken.java index add230a1111..da70d410d59 100644 --- a/code/src/java/plugin/lsttokens/statsandchecks/stat/StatmodToken.java +++ b/code/src/java/plugin/lsttokens/statsandchecks/stat/StatmodToken.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.statsandchecks.stat; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.enumeration.FormulaKey; import pcgen.core.PCStat; diff --git a/code/src/java/plugin/lsttokens/template/AddLevelToken.java b/code/src/java/plugin/lsttokens/template/AddLevelToken.java index 19c08ed0f3d..2336632cd30 100644 --- a/code/src/java/plugin/lsttokens/template/AddLevelToken.java +++ b/code/src/java/plugin/lsttokens/template/AddLevelToken.java @@ -21,7 +21,7 @@ import java.util.Collection; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.base.text.ParsingSeparator; import pcgen.cdom.base.Constants; import pcgen.cdom.base.FormulaFactory; diff --git a/code/src/java/plugin/lsttokens/template/LeveladjustmentToken.java b/code/src/java/plugin/lsttokens/template/LeveladjustmentToken.java index f2f60510e54..82499d69738 100644 --- a/code/src/java/plugin/lsttokens/template/LeveladjustmentToken.java +++ b/code/src/java/plugin/lsttokens/template/LeveladjustmentToken.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.template; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.enumeration.FormulaKey; import pcgen.core.PCTemplate; diff --git a/code/src/java/plugin/lsttokens/template/SizeToken.java b/code/src/java/plugin/lsttokens/template/SizeToken.java index eb1feda9971..e92a2c5e27b 100644 --- a/code/src/java/plugin/lsttokens/template/SizeToken.java +++ b/code/src/java/plugin/lsttokens/template/SizeToken.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.template; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.enumeration.FormulaKey; import pcgen.cdom.enumeration.StringKey; diff --git a/code/src/java/plugin/lsttokens/variable/LocalToken.java b/code/src/java/plugin/lsttokens/variable/LocalToken.java index f4467bbf827..4231f827d09 100644 --- a/code/src/java/plugin/lsttokens/variable/LocalToken.java +++ b/code/src/java/plugin/lsttokens/variable/LocalToken.java @@ -17,7 +17,6 @@ */ package plugin.lsttokens.variable; -import pcgen.base.formula.base.LegalScope; import pcgen.base.formula.exception.LegalVariableException; import pcgen.base.util.FormatManager; import pcgen.cdom.base.Constants; @@ -137,7 +136,7 @@ public String[] unparse(LoadContext context, DatasetVariable dv) return null; } StringBuilder sb = new StringBuilder(); - sb.append(LegalScope.getFullName(scope)); + sb.append(scope.getName()); sb.append(Constants.PIPE); String identifier = format.getIdentifierType(); if (!"NUMBER".equals(identifier)) diff --git a/code/src/java/plugin/modifier/cdom/SetModifierFactory.java b/code/src/java/plugin/modifier/cdom/SetModifierFactory.java index eeb8aef1c79..d260ef1522f 100644 --- a/code/src/java/plugin/modifier/cdom/SetModifierFactory.java +++ b/code/src/java/plugin/modifier/cdom/SetModifierFactory.java @@ -17,10 +17,10 @@ */ package plugin.modifier.cdom; -import pcgen.base.calculation.CalculationModifier; -import pcgen.base.calculation.FormulaCalculation; -import pcgen.base.calculation.FormulaModifier; -import pcgen.base.calculation.NEPCalculation; +import pcgen.cdom.calculation.CalculationModifier; +import pcgen.cdom.calculation.FormulaCalculation; +import pcgen.cdom.calculation.FormulaModifier; +import pcgen.cdom.calculation.NEPCalculation; import pcgen.base.formula.inst.NEPFormula; import pcgen.base.util.FormatManager; import pcgen.cdom.base.CDOMObject; diff --git a/code/src/java/plugin/modifier/dynamic/SetModifierFactory.java b/code/src/java/plugin/modifier/dynamic/SetModifierFactory.java index c65c7ca4772..189e5ed0a82 100644 --- a/code/src/java/plugin/modifier/dynamic/SetModifierFactory.java +++ b/code/src/java/plugin/modifier/dynamic/SetModifierFactory.java @@ -17,9 +17,9 @@ */ package plugin.modifier.dynamic; -import pcgen.base.calculation.CalculationModifier; -import pcgen.base.calculation.FormulaModifier; -import pcgen.base.calculation.NEPCalculation; +import pcgen.cdom.calculation.CalculationModifier; +import pcgen.cdom.calculation.FormulaModifier; +import pcgen.cdom.calculation.NEPCalculation; import pcgen.base.util.FormatManager; import pcgen.base.util.Indirect; import pcgen.cdom.content.IndirectCalculation; diff --git a/code/src/java/plugin/modifier/number/SetModifierFactory.java b/code/src/java/plugin/modifier/number/SetModifierFactory.java index 040b81cab7c..5c48a9e7272 100644 --- a/code/src/java/plugin/modifier/number/SetModifierFactory.java +++ b/code/src/java/plugin/modifier/number/SetModifierFactory.java @@ -17,10 +17,10 @@ */ package plugin.modifier.number; -import pcgen.base.calculation.CalculationModifier; -import pcgen.base.calculation.FormulaCalculation; -import pcgen.base.calculation.FormulaModifier; -import pcgen.base.calculation.NEPCalculation; +import pcgen.cdom.calculation.CalculationModifier; +import pcgen.cdom.calculation.FormulaCalculation; +import pcgen.cdom.calculation.FormulaModifier; +import pcgen.cdom.calculation.NEPCalculation; import pcgen.base.formula.inst.NEPFormula; import pcgen.base.util.FormatManager; import pcgen.cdom.base.FormulaFactory; diff --git a/code/src/java/plugin/modifier/set/AddModifierFactory.java b/code/src/java/plugin/modifier/set/AddModifierFactory.java index 983cf4b57d0..527ac9d0fe9 100644 --- a/code/src/java/plugin/modifier/set/AddModifierFactory.java +++ b/code/src/java/plugin/modifier/set/AddModifierFactory.java @@ -22,8 +22,8 @@ import java.util.HashSet; import java.util.Set; -import pcgen.base.calculation.AbstractPCGenModifier; -import pcgen.base.calculation.FormulaModifier; +import pcgen.cdom.calculation.AbstractPCGenModifier; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.base.formula.base.DependencyManager; import pcgen.base.formula.base.EvaluationManager; import pcgen.base.formula.base.FormulaSemantics; diff --git a/code/src/java/plugin/modifier/set/SetModifierFactory.java b/code/src/java/plugin/modifier/set/SetModifierFactory.java index 3d0f1eac3c0..3978225de56 100644 --- a/code/src/java/plugin/modifier/set/SetModifierFactory.java +++ b/code/src/java/plugin/modifier/set/SetModifierFactory.java @@ -17,8 +17,8 @@ */ package plugin.modifier.set; -import pcgen.base.calculation.AbstractPCGenModifier; -import pcgen.base.calculation.FormulaModifier; +import pcgen.cdom.calculation.AbstractPCGenModifier; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.base.formula.base.DependencyManager; import pcgen.base.formula.base.EvaluationManager; import pcgen.base.formula.base.FormulaSemantics; diff --git a/code/src/java/plugin/primitive/race/BaseSizeToken.java b/code/src/java/plugin/primitive/race/BaseSizeToken.java index ebde0dcb46d..3852d7e512b 100644 --- a/code/src/java/plugin/primitive/race/BaseSizeToken.java +++ b/code/src/java/plugin/primitive/race/BaseSizeToken.java @@ -19,7 +19,7 @@ import java.util.Collection; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMReference; import pcgen.cdom.base.Converter; import pcgen.cdom.base.PrimitiveFilter; diff --git a/code/src/test/pcgen/core/SpellProgressionCacheTest.java b/code/src/test/pcgen/core/SpellProgressionCacheTest.java index d79813cbdaf..98202cbe6d4 100644 --- a/code/src/test/pcgen/core/SpellProgressionCacheTest.java +++ b/code/src/test/pcgen/core/SpellProgressionCacheTest.java @@ -9,7 +9,7 @@ import java.util.ArrayList; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import org.junit.jupiter.api.AfterEach; diff --git a/code/src/testcommon/compare/InequalityTesterInst.java b/code/src/testcommon/compare/InequalityTesterInst.java index 8e8fa30ec11..b20525fbcb3 100644 --- a/code/src/testcommon/compare/InequalityTesterInst.java +++ b/code/src/testcommon/compare/InequalityTesterInst.java @@ -30,8 +30,7 @@ import pcgen.base.formula.base.ScopeInstanceFactory; import pcgen.base.formula.inst.SimpleVariableStore; import pcgen.base.lang.StringUtil; -import pcgen.base.solver.AggressiveSolverManager; -import pcgen.base.solver.DynamicSolverManager; +import pcgen.base.solver.SimpleSolverManager; import pcgen.base.test.InequalityTester; import pcgen.cdom.facet.model.ClassFacet; import pcgen.cdom.formula.MonitorableVariableStore; @@ -56,8 +55,7 @@ public final class InequalityTesterInst implements InequalityTester INEQ_MAP.put(PlayerCharacter.class, new IgnoreInequality()); INEQ_MAP.put(SpellSupportForPCClass.class, new IgnoreInequality()); INEQ_MAP.put(ScopeInstanceFactory.class, new IgnoreInequality()); - INEQ_MAP.put(AggressiveSolverManager.class, new IgnoreInequality()); - INEQ_MAP.put(DynamicSolverManager.class, new IgnoreInequality()); + INEQ_MAP.put(SimpleSolverManager.class, new IgnoreInequality()); //TODO SimpleVariableStore should not be ignored - but needs (hard?) custom comparator due to scopes... INEQ_MAP.put(SimpleVariableStore.class, new IgnoreInequality()); //TODO MonitorableVariableStore should not be ignored - but needs (hard?) custom comparator due to scopes... diff --git a/code/src/testcommon/util/SimpleSetModifier.java b/code/src/testcommon/util/SimpleSetModifier.java index fa30d447362..eca285107f8 100644 --- a/code/src/testcommon/util/SimpleSetModifier.java +++ b/code/src/testcommon/util/SimpleSetModifier.java @@ -17,6 +17,8 @@ import pcgen.base.formula.base.DependencyManager; import pcgen.base.formula.base.EvaluationManager; +import pcgen.base.formula.base.FormulaSemantics; +import pcgen.base.formula.exception.SemanticsException; import pcgen.base.solver.Modifier; import pcgen.base.util.FormatManager; @@ -39,7 +41,12 @@ public T process(EvaluationManager manager) } @Override - public void getDependencies(DependencyManager fdm) + public void captureDependencies(DependencyManager fdm) + { + } + + @Override + public void isValid(FormulaSemantics semantics) throws SemanticsException { } diff --git a/code/src/utest/pcgen/base/solver/SetSolverManagerTest.java b/code/src/utest/pcgen/base/solver/SetSolverManagerTest.java index 57030f2722c..332f9b2e004 100644 --- a/code/src/utest/pcgen/base/solver/SetSolverManagerTest.java +++ b/code/src/utest/pcgen/base/solver/SetSolverManagerTest.java @@ -1,14 +1,14 @@ /* * Copyright 2014 (C) Tom Parker - * + * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License along with * this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA @@ -21,39 +21,24 @@ import java.util.Arrays; import java.util.List; -import java.util.Objects; -import java.util.Optional; -import pcgen.base.calculation.BasicCalculation; -import pcgen.base.calculation.CalculationModifier; -import pcgen.base.calculation.FormulaModifier; -import pcgen.base.calculation.NEPCalculation; +import pcgen.cdom.calculation.BasicCalculation; +import pcgen.cdom.calculation.CalculationModifier; +import pcgen.cdom.calculation.FormulaModifier; +import pcgen.cdom.calculation.NEPCalculation; import pcgen.base.format.ArrayFormatManager; import pcgen.base.formatmanager.FormatUtilities; -import pcgen.base.formula.base.DependencyManager; -import pcgen.base.formula.base.EvaluationManager; -import pcgen.base.formula.base.FormulaManager; -import pcgen.base.formula.base.FormulaSemantics; -import pcgen.base.formula.base.LegalScope; -import pcgen.base.formula.base.ManagerFactory; -import pcgen.base.formula.base.OperatorLibrary; import pcgen.base.formula.base.ScopeInstance; import pcgen.base.formula.base.ScopeInstanceFactory; import pcgen.base.formula.base.VariableID; -import pcgen.base.formula.base.WriteableFunctionLibrary; -import pcgen.base.formula.inst.ScopeManagerInst; -import pcgen.base.formula.inst.SimpleFormulaManager; -import pcgen.base.formula.inst.SimpleFunctionLibrary; -import pcgen.base.formula.inst.SimpleOperatorLibrary; -import pcgen.base.formula.inst.SimpleScopeInstanceFactory; -import pcgen.base.formula.inst.VariableManager; +import pcgen.base.formula.base.VariableLibrary; import pcgen.base.solver.testsupport.TrackingVariableCache; import pcgen.base.util.FormatManager; import pcgen.cdom.content.ProcessCalculation; -import pcgen.cdom.formula.ManagerKey; import pcgen.cdom.formula.local.ModifierDecoration; import pcgen.cdom.formula.scope.EquipmentScope; import pcgen.cdom.formula.scope.GlobalPCScope; +import pcgen.cdom.formula.scope.GlobalPCVarScoped; import pcgen.cdom.formula.scope.PCGenScope; import pcgen.cdom.formula.scope.SkillScope; import pcgen.core.Skill; @@ -61,9 +46,11 @@ import pcgen.rules.context.LoadContext; import pcgen.rules.context.RuntimeLoadContext; import pcgen.rules.context.RuntimeReferenceContext; +import pcgen.rules.context.VariableContext; import pcgen.rules.persistence.token.ModifierFactory; import plugin.function.GetOtherFunction; +import util.FormatSupport; import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.BeforeEach; @@ -72,65 +59,55 @@ class SetSolverManagerTest { - private final PCGenScope globalScope = new GlobalPCScope(); private TrackingVariableCache vc; - private ScopeManagerInst vsLib; - private VariableManager sl; - private FormulaManager fm; - private DynamicSolverManager manager; + private SolverManager manager; private FormatManager skillManager; private ArrayFormatManager arrayManager; private ScopeInstanceFactory siFactory; private RuntimeLoadContext context; - private MyManagerFactory managerFactory; + private VariableLibrary sl; @BeforeEach void setUp() throws Exception { - SupplierValueStore mvs = new SupplierValueStore(); - WriteableFunctionLibrary fl = new SimpleFunctionLibrary(); - fl.addFunction(new GetOtherFunction()); - OperatorLibrary ol = new SimpleOperatorLibrary(); - vc = new TrackingVariableCache(); - vsLib = new ScopeManagerInst(); - vsLib.registerScope(globalScope); + context = new RuntimeLoadContext( + RuntimeReferenceContext.createRuntimeReferenceContext(), + new ConsolidatedListCommitStrategy()); + FormatSupport.addBasicDefaults(context); + VariableContext variableContext = context.getVariableContext(); + variableContext.addFunction(new GetOtherFunction()); + + PCGenScope globalScope = new GlobalPCScope(); + variableContext.registerScope(globalScope); EquipmentScope equipScope = new EquipmentScope(); equipScope.setParent(globalScope); - vsLib.registerScope(equipScope); + variableContext.registerScope(equipScope); SkillScope skillScope = new SkillScope(); skillScope.setParent(globalScope); - vsLib.registerScope(skillScope); - sl = new VariableManager(vsLib, mvs); + variableContext.registerScope(skillScope); + arrayManager = new ArrayFormatManager<>(FormatUtilities.STRING_MANAGER, '\n', ','); - context = new RuntimeLoadContext( - RuntimeReferenceContext.createRuntimeReferenceContext(), - new ConsolidatedListCommitStrategy()); + variableContext.addDefault(arrayManager, () -> new String[0]); skillManager = context.getReferenceContext().getManufacturer(Skill.class); - managerFactory = new MyManagerFactory(context); - siFactory = new SimpleScopeInstanceFactory(vsLib); - fm = new SimpleFormulaManager(ol, sl, siFactory, vc, mvs); - fm = fm.getWith(FormulaManager.FUNCTION, fl); - SolverFactory solverFactory = new SimpleSolverFactory(mvs); - solverFactory.addSolverFormat(arrayManager, () -> new String[0]); - Skill defaultSkill = new Skill(); - solverFactory.addSolverFormat(skillManager, () -> defaultSkill); + variableContext.addDefault(skillManager, () -> defaultSkill); - manager = new DynamicSolverManager(fm, managerFactory, solverFactory, vc); - solverFactory.addSolverFormat(FormatUtilities.NUMBER_MANAGER, () -> 0); - solverFactory.addSolverFormat(FormatUtilities.STRING_MANAGER, () -> ""); + sl = variableContext; + vc = new TrackingVariableCache(); + siFactory = variableContext.getScopeInstanceFactory(); + manager = variableContext.generateSolverManager(vc); } - //TODO Tear Down - @Test public void testProcessDependentSet() { + PCGenScope globalScope = context.getVariableContext().getScope(GlobalPCScope.GLOBAL_SCOPE_NAME); sl.assertLegalVariableID("Regions", globalScope, arrayManager); - ScopeInstance scopeInst = siFactory.getGlobalInstance(globalScope.getName()); + ScopeInstance scopeInst = siFactory.get(GlobalPCScope.GLOBAL_SCOPE_NAME, + new GlobalPCVarScoped(GlobalPCScope.GLOBAL_SCOPE_NAME)); VariableID regions = (VariableID) sl.getVariableID(scopeInst, "Regions"); - manager.createChannel(regions); + manager.processSolver(regions); Object[] array = vc.get(regions); List list; assertEquals(0, array.length); @@ -142,6 +119,7 @@ public void testProcessDependentSet() FormulaModifier mod = am1.getModifier("France,England", arrayManager); mod.addAssociation("PRIORITY=2000"); manager.addModifier(regions, new ModifierDecoration<>(mod), scopeInst); + manager.processSolver(regions); array = vc.get(regions); MatcherAssert.assertThat(2, is(array.length)); list = Arrays.asList(array); @@ -155,6 +133,7 @@ public void testProcessDependentSet() mod = am2.getModifier("Greece,England", arrayManager); mod.addAssociation("PRIORITY=3000"); manager.addModifier(regions, new ModifierDecoration<>(mod), scopeInst); + manager.processSolver(regions); array = vc.get(regions); MatcherAssert.assertThat(3, is(array.length)); list = Arrays.asList(array); @@ -169,7 +148,9 @@ public void testProcessDependentSet() @Test public void testProcessDynamicSet() { - LegalScope skillScope = vsLib.getScope("PC.SKILL"); + VariableContext variableContext = context.getVariableContext(); + PCGenScope globalScope = variableContext.getScope(GlobalPCScope.GLOBAL_SCOPE_NAME); + PCGenScope skillScope = variableContext.getScope("PC.SKILL"); sl.assertLegalVariableID("LocalVar", skillScope, FormatUtilities.NUMBER_MANAGER); sl.assertLegalVariableID("ResultVar", globalScope, FormatUtilities.NUMBER_MANAGER); sl.assertLegalVariableID("SkillVar", globalScope, skillManager); @@ -179,21 +160,21 @@ public void testProcessDynamicSet() Skill skillalt = new Skill(); skillalt.setName("SkillAlt"); - ScopeInstance scopeInste = siFactory.get("PC.SKILL", Optional.of(skill)); + ScopeInstance scopeInste = siFactory.get("PC.SKILL", skill); VariableID varIDe = sl.getVariableID(scopeInste, "LocalVar"); - manager.createChannel(varIDe); + manager.processSolver(varIDe); vc.put(varIDe, 2); - ScopeInstance scopeInsta = siFactory.get("PC.SKILL", Optional.of(skillalt)); + ScopeInstance scopeInsta = siFactory.get("PC.SKILL", skillalt); VariableID varIDa = sl.getVariableID(scopeInsta, "LocalVar"); - manager.createChannel(varIDa); + manager.processSolver(varIDa); vc.put(varIDa, 3); - ScopeInstance globalInst = - siFactory.getGlobalInstance(GlobalPCScope.GLOBAL_SCOPE_NAME); + ScopeInstance globalInst = siFactory.get(GlobalPCScope.GLOBAL_SCOPE_NAME, + new GlobalPCVarScoped(GlobalPCScope.GLOBAL_SCOPE_NAME)); VariableID varIDq = sl.getVariableID(globalInst, "SkillVar"); - manager.createChannel(varIDq); + manager.processSolver(varIDq); VariableID varIDr = sl.getVariableID(globalInst, "ResultVar"); - manager.createChannel(varIDr); - + manager.processSolver(varIDr); + ModifierFactory am1 = new plugin.modifier.number.SetModifierFactory(); ModifierFactory amString = new plugin.modifier.string.SetModifierFactory(); FormulaModifier mod2 = @@ -210,7 +191,7 @@ public void testProcessDynamicSet() context.getReferenceContext().importObject(skillalt); FormulaModifier modf = am1.getModifier(formula, FormatUtilities.NUMBER_MANAGER); modf.addAssociation("PRIORITY=2000"); - + NEPCalculation calc1 = new ProcessCalculation<>(skill, new BasicSet(), skillManager); CalculationModifier mods1 = new CalculationModifier<>(calc1, skillManager); @@ -221,18 +202,26 @@ public void testProcessDynamicSet() manager.addModifier(varIDe, new ModifierDecoration<>(mod2), scopeInste); manager.addModifier(varIDa, new ModifierDecoration<>(mod3), scopeInsta); + manager.processSolver(varIDe); + manager.processSolver(varIDa); assertEquals(2, vc.get(varIDe)); assertEquals(3, vc.get(varIDa)); assertEquals(0, vc.get(varIDr)); manager.addModifier(varIDq, new ModifierDecoration<>(mods1), globalInst); manager.addModifier(varIDr, new ModifierDecoration<>(modf), globalInst); + manager.processSolver(varIDq); + manager.processSolver(varIDr); assertEquals(2, vc.get(varIDr)); manager.addModifier(varIDq, new ModifierDecoration<>(mods2), globalInst); + manager.processSolver(varIDq); + manager.processSolver(varIDr); assertEquals(3, vc.get(varIDr)); manager.addModifier(varIDa, new ModifierDecoration<>(mod4), scopeInsta); + manager.processSolver(varIDa); + manager.processSolver(varIDr); assertEquals(4, vc.get(varIDr)); } @@ -256,43 +245,4 @@ public Object process(Object previousValue, Object argument) return argument; } } - - /** - * A custom ManagerFactory to inject the LoadContext. - */ - private static class MyManagerFactory implements ManagerFactory - { - private final LoadContext context; - - private MyManagerFactory(LoadContext context) - { - this.context = Objects.requireNonNull(context); - } - - @Override - public DependencyManager generateDependencyManager(FormulaManager formulaManager, - ScopeInstance scopeInst) - { - DependencyManager dm = ManagerFactory.super.generateDependencyManager( - formulaManager, scopeInst); - return dm.getWith(ManagerKey.CONTEXT, context); - } - - @Override - public FormulaSemantics generateFormulaSemantics(FormulaManager manager, - LegalScope legalScope) - { - FormulaSemantics fs = - ManagerFactory.super.generateFormulaSemantics(manager, legalScope); - return fs.getWith(ManagerKey.CONTEXT, context); - } - - @Override - public EvaluationManager generateEvaluationManager(FormulaManager formulaManager) - { - EvaluationManager em = - ManagerFactory.super.generateEvaluationManager(formulaManager); - return em.getWith(ManagerKey.CONTEXT, context); - } - } } diff --git a/code/src/utest/pcgen/cdom/base/FormulaFactoryTest.java b/code/src/utest/pcgen/cdom/base/FormulaFactoryTest.java index 669cdc5aba4..df2b353176b 100644 --- a/code/src/utest/pcgen/cdom/base/FormulaFactoryTest.java +++ b/code/src/utest/pcgen/cdom/base/FormulaFactoryTest.java @@ -4,13 +4,16 @@ import pcgen.base.format.ArrayFormatManager; import pcgen.base.formatmanager.FormatUtilities; -import pcgen.base.formula.base.FormulaManager; import pcgen.base.formula.base.ManagerFactory; import pcgen.base.formula.inst.NEPFormula; -import pcgen.base.formula.inst.ScopeManagerInst; -import pcgen.base.solver.FormulaSetupFactory; import pcgen.cdom.formula.scope.GlobalPCScope; import pcgen.cdom.formula.scope.PCGenScope; +import pcgen.rules.context.ConsolidatedListCommitStrategy; +import pcgen.rules.context.LoadContext; +import pcgen.rules.context.RuntimeLoadContext; +import pcgen.rules.context.RuntimeReferenceContext; + +import util.FormatSupport; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -21,71 +24,60 @@ class FormulaFactoryTest private ArrayFormatManager arrayManager; private PCGenScope varScope; - private FormulaManager formulaManager; + private LoadContext context; + private ManagerFactory managerFactory; @BeforeEach void setUp() throws Exception { arrayManager = new ArrayFormatManager<>(FormatUtilities.NUMBER_MANAGER, '\n', ','); - varScope = new GlobalPCScope(); - FormulaSetupFactory formulaSetupFactory = new FormulaSetupFactory(); - ScopeManagerInst legalScopeManager = new ScopeManagerInst(); - formulaSetupFactory - .setLegalScopeManagerSupplier(() -> legalScopeManager); - formulaManager = formulaSetupFactory.generate(); - legalScopeManager.registerScope(varScope); + context = new RuntimeLoadContext( + RuntimeReferenceContext.createRuntimeReferenceContext(), + new ConsolidatedListCommitStrategy()); + FormatSupport.addBasicDefaults(context); + varScope = context.getVariableContext().getScope(GlobalPCScope.GLOBAL_SCOPE_NAME); + managerFactory = context.getVariableContext().getManagerFactory(); } @AfterEach void tearDown() throws Exception { arrayManager = null; - formulaManager = null; + context = null; varScope = null; + managerFactory = null; } @Test void testNumberFormula() { - NEPFormula formula1 = - FormulaFactory.getValidFormula("3", new ManagerFactory() - { - }, formulaManager, varScope, FormatUtilities.NUMBER_MANAGER); - NEPFormula formula2 = - FormulaFactory.getValidFormula("3", new ManagerFactory() - { - }, formulaManager, varScope, FormatUtilities.NUMBER_MANAGER); + NEPFormula formula1 = FormulaFactory.getValidFormula("3", + managerFactory, varScope, FormatUtilities.NUMBER_MANAGER); + NEPFormula formula2 = FormulaFactory.getValidFormula("3", + managerFactory, varScope, FormatUtilities.NUMBER_MANAGER); assertEquals(formula1, formula2); } @Test void testComplexNumberFormula() { - formulaManager.getFactory().assertLegalVariableID("Arm", varScope, + context.getVariableContext().assertLegalVariableID("Arm", varScope, FormatUtilities.NUMBER_MANAGER); - NEPFormula formula1 = - FormulaFactory.getValidFormula("3+Arm", new ManagerFactory() - { - }, formulaManager, varScope, FormatUtilities.NUMBER_MANAGER); - NEPFormula formula2 = - FormulaFactory.getValidFormula("3+Arm", new ManagerFactory() - { - }, formulaManager, varScope, FormatUtilities.NUMBER_MANAGER); + NEPFormula formula1 = FormulaFactory.getValidFormula("3+Arm", + managerFactory, varScope, FormatUtilities.NUMBER_MANAGER); + NEPFormula formula2 = FormulaFactory.getValidFormula("3+Arm", + managerFactory, varScope, FormatUtilities.NUMBER_MANAGER); assertEquals(formula1, formula2); } @Test void testArrayFormula() { - NEPFormula formula1 = - FormulaFactory.getValidFormula("3,4,5", new ManagerFactory() - { - }, formulaManager, varScope, arrayManager); - NEPFormula formula2 = - FormulaFactory.getValidFormula("3,4,5", new ManagerFactory() - { - }, formulaManager, varScope, arrayManager); + NEPFormula formula1 = FormulaFactory.getValidFormula("3,4,5", + managerFactory, varScope, arrayManager); + NEPFormula formula2 = FormulaFactory.getValidFormula("3,4,5", + managerFactory, varScope, arrayManager); assertEquals(formula1, formula2); } diff --git a/code/src/utest/pcgen/cdom/facet/analysis/CharacterSpellResistanceFacetTest.java b/code/src/utest/pcgen/cdom/facet/analysis/CharacterSpellResistanceFacetTest.java index 6774f220de7..9bcc271dbc3 100644 --- a/code/src/utest/pcgen/cdom/facet/analysis/CharacterSpellResistanceFacetTest.java +++ b/code/src/utest/pcgen/cdom/facet/analysis/CharacterSpellResistanceFacetTest.java @@ -17,7 +17,7 @@ */ package pcgen.cdom.facet.analysis; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.content.SpellResistance; diff --git a/code/src/utest/pcgen/cdom/formula/VariableChannelTest.java b/code/src/utest/pcgen/cdom/formula/VariableChannelTest.java index 5c4f2ec426e..6c106abf479 100644 --- a/code/src/utest/pcgen/cdom/formula/VariableChannelTest.java +++ b/code/src/utest/pcgen/cdom/formula/VariableChannelTest.java @@ -23,7 +23,6 @@ import pcgen.base.formatmanager.FormatUtilities; import pcgen.base.formula.base.ScopeInstance; -import pcgen.base.formula.base.ScopeInstanceFactory; import pcgen.base.formula.base.VariableID; import pcgen.base.formula.inst.ComplexNEPFormula; import pcgen.base.formula.inst.FormulaUtilities; @@ -59,8 +58,7 @@ public void setUp() throws Exception manager = context.getVariableContext().generateSolverManager(getVariableStore()); globalScope = context.getVariableContext().getScope(GlobalPCScope.GLOBAL_SCOPE_NAME); - ScopeInstanceFactory sif = getFormulaManager().getScopeInstanceFactory(); - globalInstance = sif.getGlobalInstance(globalScope.getName()); + globalInstance = getGlobalScopeInst(); } @AfterEach @@ -103,8 +101,11 @@ void testBadConstructionThirdArg() @Test void testGetSet() { - VariableID varID = new VariableID<>(globalInstance, - FormatUtilities.NUMBER_MANAGER, "MyNumber"); + getVariableLibrary().assertLegalVariableID("MyNumber", globalScope, + FormatUtilities.NUMBER_MANAGER); + @SuppressWarnings("unchecked") + VariableID varID = + (VariableID) getVariableLibrary().getVariableID(globalInstance, "MyNumber"); VariableChannel channel = VariableChannel.construct(manager, getVariableStore(), varID); assertEquals(0, channel.get()); @@ -117,8 +118,11 @@ void testGetSet() @Test void testGetSetEvents() { - VariableID varID = new VariableID<>(globalInstance, - FormatUtilities.NUMBER_MANAGER, "MyNumber"); + getVariableLibrary().assertLegalVariableID("MyNumber", globalScope, + FormatUtilities.NUMBER_MANAGER); + @SuppressWarnings("unchecked") + VariableID varID = + (VariableID) getVariableLibrary().getVariableID(globalInstance, "MyNumber"); VariableChannel channel = VariableChannel.construct(manager, getVariableStore(), varID); TestingReferenceListener listener = @@ -186,15 +190,18 @@ void testGetSetEffects() @SuppressWarnings("unchecked") VariableID limbs = (VariableID) getVariableLibrary().getVariableID(globalInstance, "Limbs"); - manager.addModifier(limbs, formulaMod, globalInstance); - @SuppressWarnings("unchecked") VariableID arms = (VariableID) getVariableLibrary().getVariableID(globalInstance, "Arms"); - @SuppressWarnings("unchecked") VariableID legs = (VariableID) getVariableLibrary().getVariableID(globalInstance, "Legs"); + + manager.processSolver(legs); + manager.processSolver(arms); + manager.addModifier(limbs, formulaMod, globalInstance); + manager.processSolver(limbs); + VariableChannel armsChannel = VariableChannel.construct(manager, getVariableStore(), arms); VariableChannel legsChannel = @@ -205,6 +212,7 @@ void testGetSetEffects() legsChannel.set(4); assertEquals(4, getVariableStore().get(legs)); assertEquals(4, legsChannel.get()); + manager.processSolver(limbs); assertEquals(4, getVariableStore().get(limbs)); assertEquals(0, armsChannel.get()); @@ -212,10 +220,12 @@ void testGetSetEffects() armsChannel.set(3); assertEquals(3, getVariableStore().get(arms)); assertEquals(3, armsChannel.get()); + manager.processSolver(limbs); assertEquals(7, getVariableStore().get(limbs)); armsChannel.set(6); assertEquals(6, getVariableStore().get(arms)); assertEquals(6, armsChannel.get()); + manager.processSolver(limbs); assertEquals(10, getVariableStore().get(limbs)); } diff --git a/code/src/utest/pcgen/cdom/formula/testsupport/AbstractModifier.java b/code/src/utest/pcgen/cdom/formula/testsupport/AbstractModifier.java index 87098a45929..f394b8a891c 100644 --- a/code/src/utest/pcgen/cdom/formula/testsupport/AbstractModifier.java +++ b/code/src/utest/pcgen/cdom/formula/testsupport/AbstractModifier.java @@ -20,13 +20,15 @@ import java.lang.reflect.Array; import pcgen.TestConstants; -import pcgen.base.calculation.CalculationModifier; -import pcgen.base.calculation.FormulaCalculation; -import pcgen.base.calculation.FormulaModifier; -import pcgen.base.calculation.NEPCalculation; +import pcgen.cdom.calculation.CalculationModifier; +import pcgen.cdom.calculation.FormulaCalculation; +import pcgen.cdom.calculation.FormulaModifier; +import pcgen.cdom.calculation.NEPCalculation; import pcgen.base.formatmanager.FormatUtilities; import pcgen.base.formula.base.DependencyManager; import pcgen.base.formula.base.EvaluationManager; +import pcgen.base.formula.base.FormulaSemantics; +import pcgen.base.formula.exception.SemanticsException; import pcgen.base.formula.inst.ComplexNEPFormula; import pcgen.base.formula.inst.NEPFormula; import pcgen.base.lang.NumberUtilities; @@ -53,7 +55,12 @@ public AbstractModifier(int inherent, FormatManager cl, int priority) } @Override - public void getDependencies(DependencyManager fdm) + public void captureDependencies(DependencyManager fdm) + { + } + + @Override + public void isValid(FormulaSemantics semantics) throws SemanticsException { } @@ -217,9 +224,9 @@ public Number process(EvaluationManager manager) } @Override - public void getDependencies(DependencyManager fdm) + public void captureDependencies(DependencyManager fdm) { - value.getDependencies(fdm); + value.captureDependencies(fdm); } @Override diff --git a/code/src/utest/pcgen/cdom/helper/BridgeListenerTest.java b/code/src/utest/pcgen/cdom/helper/BridgeListenerTest.java index 476f6c53952..04f27ec810c 100644 --- a/code/src/utest/pcgen/cdom/helper/BridgeListenerTest.java +++ b/code/src/utest/pcgen/cdom/helper/BridgeListenerTest.java @@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.Optional; import pcgen.base.formula.base.ScopeInstance; import pcgen.base.formula.base.VariableID; @@ -93,7 +92,7 @@ void testVariableBasic() BridgeListener bridge = new BridgeListener(id, target, this); GlobalPCScope scope = new GlobalPCScope(); ScopeInstance instance = - new SimpleScopeInstance(Optional.empty(), scope, owner); + new SimpleScopeInstance(scope, owner); TransparentFormatManager formatManager = new TransparentFormatManager(PCTemplate.class, "PCTEMPLATE"); @@ -126,7 +125,7 @@ void testVariableArray() BridgeListener bridge = new BridgeListener(id, target, this); GlobalPCScope scope = new GlobalPCScope(); ScopeInstance instance = - new SimpleScopeInstance(Optional.empty(), scope, owner); + new SimpleScopeInstance(scope, owner); TransparentFormatManager formatManager = new TransparentFormatManager(PCTemplate[].class, "PCTEMPLATE"); diff --git a/code/src/utest/plugin/function/GetFactFunctionTest.java b/code/src/utest/plugin/function/GetFactFunctionTest.java index 0ee082a3ca1..1b165371a69 100644 --- a/code/src/utest/plugin/function/GetFactFunctionTest.java +++ b/code/src/utest/plugin/function/GetFactFunctionTest.java @@ -25,7 +25,6 @@ import pcgen.base.formatmanager.FormatUtilities; import pcgen.base.formatmanager.SimpleFormatManagerLibrary; import pcgen.base.formula.base.FormulaSemantics; -import pcgen.base.formula.base.LegalScope; import pcgen.base.formula.base.ScopeInstance; import pcgen.base.formula.base.VariableID; import pcgen.base.formula.base.VariableLibrary; @@ -39,6 +38,8 @@ import pcgen.cdom.enumeration.FactKey; import pcgen.cdom.formula.ManagerKey; import pcgen.cdom.formula.scope.GlobalPCScope; +import pcgen.cdom.formula.scope.GlobalPCVarScoped; +import pcgen.cdom.formula.scope.PCGenScope; import pcgen.core.Skill; import pcgen.rules.context.AbstractReferenceContext; import pcgen.util.enumeration.Visibility; @@ -81,7 +82,7 @@ public void testInvalidWrongArgCount() @Test public void testInvalidWrongArgType() { - LegalScope skillScope = context.getVariableContext().getScope("PC.SKILL"); + PCGenScope skillScope = context.getVariableContext().getScope("PC.SKILL"); getVariableLibrary().assertLegalVariableID("LocalVar", skillScope, numberManager); String s = "getFact(\"SKILL\",\"SkillKey\",LocalVar)"; SimpleNode simpleNode = doParse(s); @@ -159,7 +160,7 @@ public void testBasic() public void testDynamic() { VariableLibrary vl = getVariableLibrary(); - LegalScope globalScope = + PCGenScope globalScope = context.getVariableContext().getScope(GlobalPCScope.GLOBAL_SCOPE_NAME); vl.assertLegalVariableID("SkillVar", globalScope, context.getManufacturer("SKILL")); @@ -183,8 +184,8 @@ public void testDynamic() skill.setName("SkillKey"); Skill skillalt = new Skill(); skillalt.setName("SkillAlt"); - ScopeInstance globalInst = getFormulaManager().getScopeInstanceFactory() - .getGlobalInstance(GlobalPCScope.GLOBAL_SCOPE_NAME); + ScopeInstance globalInst = getScopeInstanceFactory().get( + GlobalPCScope.GLOBAL_SCOPE_NAME, new GlobalPCVarScoped(GlobalPCScope.GLOBAL_SCOPE_NAME)); VariableID varIDq = vl.getVariableID(globalInst, "SkillVar"); getVariableStore().put(varIDq, skill); context.getReferenceContext().importObject(skill); diff --git a/code/src/utest/plugin/function/GetOtherFunctionTest.java b/code/src/utest/plugin/function/GetOtherFunctionTest.java index 871f129f25b..d0564201adc 100644 --- a/code/src/utest/plugin/function/GetOtherFunctionTest.java +++ b/code/src/utest/plugin/function/GetOtherFunctionTest.java @@ -22,12 +22,9 @@ import static org.junit.jupiter.api.Assertions.fail; import static plugin.function.testsupport.TestUtilities.doParse; -import java.util.Optional; - import pcgen.base.formatmanager.FormatUtilities; import pcgen.base.formatmanager.SimpleFormatManagerLibrary; import pcgen.base.formula.base.FormulaSemantics; -import pcgen.base.formula.base.LegalScope; import pcgen.base.formula.base.ScopeInstance; import pcgen.base.formula.base.ScopeInstanceFactory; import pcgen.base.formula.base.VariableID; @@ -39,6 +36,8 @@ import pcgen.base.formula.visitor.SemanticsVisitor; import pcgen.cdom.formula.ManagerKey; import pcgen.cdom.formula.scope.GlobalPCScope; +import pcgen.cdom.formula.scope.GlobalPCVarScoped; +import pcgen.cdom.formula.scope.PCGenScope; import pcgen.core.Skill; import pcgen.rules.context.AbstractReferenceContext; import pcgen.rules.context.VariableContext; @@ -118,7 +117,7 @@ public void testInvalidWrongFormat3() public void testBasic() { VariableLibrary vl = getVariableLibrary(); - LegalScope skillScope = context.getVariableContext().getScope("PC.SKILL"); + PCGenScope skillScope = context.getVariableContext().getScope("PC.SKILL"); vl.assertLegalVariableID("LocalVar", skillScope, numberManager); String formula = @@ -130,8 +129,8 @@ public void testBasic() isStatic(formula, node, false); Skill skill = new Skill(); skill.setName("SkillKey"); - ScopeInstance scopeInst = - getFormulaManager().getScopeInstanceFactory().get("PC.SKILL", Optional.of(skill)); + ScopeInstanceFactory scopeInstanceFactory = getScopeInstanceFactory(); + ScopeInstance scopeInst = scopeInstanceFactory.get("PC.SKILL", skill); VariableID varID = vl.getVariableID(scopeInst, "LocalVar"); getVariableStore().put(varID, 2); context.getReferenceContext().importObject(skill); @@ -146,8 +145,8 @@ public void testDynamic() { VariableLibrary vl = getVariableLibrary(); VariableContext variableContext = context.getVariableContext(); - LegalScope skillScope = variableContext.getScope("PC.SKILL"); - LegalScope globalScope = variableContext.getScope(GlobalPCScope.GLOBAL_SCOPE_NAME); + PCGenScope skillScope = variableContext.getScope("PC.SKILL"); + PCGenScope globalScope = variableContext.getScope(GlobalPCScope.GLOBAL_SCOPE_NAME); vl.assertLegalVariableID("LocalVar", skillScope, numberManager); vl.assertLegalVariableID("SkillVar", globalScope, context.getManufacturer("SKILL")); @@ -162,16 +161,15 @@ public void testDynamic() skill.setName("SkillKey"); Skill skillalt = new Skill(); skillalt.setName("SkillAlt"); - ScopeInstanceFactory scopeInstanceFactory = - getFormulaManager().getScopeInstanceFactory(); - ScopeInstance scopeInste = scopeInstanceFactory.get("PC.SKILL", Optional.of(skill)); + ScopeInstanceFactory scopeInstanceFactory = getScopeInstanceFactory(); + ScopeInstance scopeInste = scopeInstanceFactory.get("PC.SKILL", skill); VariableID varIDe = vl.getVariableID(scopeInste, "LocalVar"); getVariableStore().put(varIDe, 2); - ScopeInstance scopeInsta = scopeInstanceFactory.get("PC.SKILL", Optional.of(skillalt)); + ScopeInstance scopeInsta = scopeInstanceFactory.get("PC.SKILL", skillalt); VariableID varIDa = vl.getVariableID(scopeInsta, "LocalVar"); getVariableStore().put(varIDa, 3); - ScopeInstance globalInst = - scopeInstanceFactory.getGlobalInstance(GlobalPCScope.GLOBAL_SCOPE_NAME); + ScopeInstance globalInst = scopeInstanceFactory.get(GlobalPCScope.GLOBAL_SCOPE_NAME, + new GlobalPCVarScoped(GlobalPCScope.GLOBAL_SCOPE_NAME)); VariableID varIDq = vl.getVariableID(globalInst, "SkillVar"); getVariableStore().put(varIDq, skill); context.getReferenceContext().importObject(skill); diff --git a/code/src/utest/plugin/function/InputFunctionTest.java b/code/src/utest/plugin/function/InputFunctionTest.java index 541f2a28dd2..94058eb4ab0 100644 --- a/code/src/utest/plugin/function/InputFunctionTest.java +++ b/code/src/utest/plugin/function/InputFunctionTest.java @@ -20,7 +20,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import pcgen.base.formula.base.ScopeInstance; -import pcgen.base.formula.base.ScopeInstanceFactory; import pcgen.base.formula.parse.SimpleNode; import pcgen.base.formula.visitor.ReconstructionVisitor; import pcgen.cdom.enumeration.CharID; @@ -54,7 +53,7 @@ public void setUp() throws Exception super.setUp(); getFunctionLibrary().addFunction(new InputFunction()); id = CharID.getID(context.getDataSetID()); - scopeFacet.set(id, getFormulaManager().getScopeInstanceFactory()); + scopeFacet.set(id, getScopeInstanceFactory()); variableStoreFacet.set(id, getVariableStore()); solverManagerFacet.set(id, context.getVariableContext().generateSolverManager(getVariableStore())); @@ -98,11 +97,9 @@ public void testNotValidNoChannel() @Test public void testGlobalChannelStrength() { - ScopeInstanceFactory instFactory = scopeFacet.get(id); - ScopeInstance globalInstance = - instFactory.getGlobalInstance(GlobalPCScope.GLOBAL_SCOPE_NAME); + ScopeInstance globalInstance = scopeFacet.getGlobalScope(id); context.getVariableContext().assertLegalVariableID(ChannelUtilities.createVarName("STR"), - globalInstance.getLegalScope(), numberManager); + getGlobalScope(), numberManager); VariableChannel strChannel = (VariableChannel) context .getVariableContext().getGlobalChannel(id, "STR"); String formula = "input(\"STR\")"; diff --git a/code/src/utest/plugin/function/LookupFunctionTest.java b/code/src/utest/plugin/function/LookupFunctionTest.java index 879119239cc..05d190a45bd 100644 --- a/code/src/utest/plugin/function/LookupFunctionTest.java +++ b/code/src/utest/plugin/function/LookupFunctionTest.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Optional; import pcgen.base.formatmanager.FormatUtilities; import pcgen.base.formatmanager.SimpleFormatManagerLibrary; @@ -154,7 +155,7 @@ public void testInvalidWrongFormat1() VariableLibrary vl = getVariableLibrary(); WriteableVariableStore vs = getVariableStore(); ColumnFormatFactory cfac = new ColumnFormatFactory(finder); - FormatManager columnMgr = cfac.build("STRING", formatLibrary); + FormatManager columnMgr = cfac.build(Optional.empty(), Optional.of("STRING"), formatLibrary); vl.assertLegalVariableID("ResultColumn", getGlobalScope(), columnMgr); VariableID columnID = @@ -182,14 +183,14 @@ public void testInvalidWrongFormat2() WriteableVariableStore vs = getVariableStore(); TableFormatFactory fac = new TableFormatFactory(tablefinder); - FormatManager tableMgr = fac.build("STRING", formatLibrary); + FormatManager tableMgr = fac.build(Optional.empty(), Optional.of("STRING"), formatLibrary); vl.assertLegalVariableID("TableA", getGlobalScope(), tableMgr); VariableID tableID = vl.getVariableID(getGlobalScopeInst(), "TableA"); vs.put(tableID, tableMgr.convert("A")); ColumnFormatFactory cfac = new ColumnFormatFactory(finder); - FormatManager columnMgr = cfac.build("STRING", formatLibrary); + FormatManager columnMgr = cfac.build(Optional.empty(), Optional.of("STRING"), formatLibrary); vl.assertLegalVariableID("ResultColumn", getGlobalScope(), columnMgr); VariableID columnID = @@ -213,7 +214,7 @@ public void testInvalidWrongFormat3() WriteableVariableStore vs = getVariableStore(); TableFormatFactory fac = new TableFormatFactory(tablefinder); - FormatManager tableMgr = fac.build("STRING", formatLibrary); + FormatManager tableMgr = fac.build(Optional.empty(), Optional.of("STRING"), formatLibrary); vl.assertLegalVariableID("TableA", getGlobalScope(), tableMgr); VariableID tableID = vl.getVariableID(getGlobalScopeInst(), "TableA"); @@ -236,7 +237,7 @@ public void testInvalidBadSemantics1() WriteableVariableStore vs = getVariableStore(); ColumnFormatFactory cfac = new ColumnFormatFactory(finder); - FormatManager columnMgr = cfac.build("STRING", formatLibrary); + FormatManager columnMgr = cfac.build(Optional.empty(), Optional.of("STRING"), formatLibrary); vl.assertLegalVariableID("ResultColumn", getGlobalScope(), columnMgr); VariableID columnID = @@ -264,14 +265,14 @@ public void testInvalidBadSemantics2() WriteableVariableStore vs = getVariableStore(); TableFormatFactory fac = new TableFormatFactory(tablefinder); - FormatManager tableMgr = fac.build("STRING", formatLibrary); + FormatManager tableMgr = fac.build(Optional.empty(), Optional.of("STRING"), formatLibrary); vl.assertLegalVariableID("TableA", getGlobalScope(), tableMgr); VariableID tableID = vl.getVariableID(getGlobalScopeInst(), "TableA"); vs.put(tableID, tableMgr.convert("A")); ColumnFormatFactory cfac = new ColumnFormatFactory(finder); - FormatManager columnMgr = cfac.build("STRING", formatLibrary); + FormatManager columnMgr = cfac.build(Optional.empty(), Optional.of("STRING"), formatLibrary); vl.assertLegalVariableID("ResultColumn", getGlobalScope(), columnMgr); VariableID columnID = @@ -299,7 +300,7 @@ public void testInvalidBadSemantics3() WriteableVariableStore vs = getVariableStore(); TableFormatFactory fac = new TableFormatFactory(tablefinder); - FormatManager tableMgr = fac.build("STRING", formatLibrary); + FormatManager tableMgr = fac.build(Optional.empty(), Optional.of("STRING"), formatLibrary); vl.assertLegalVariableID("TableA", getGlobalScope(), tableMgr); VariableID tableID = vl.getVariableID(getGlobalScopeInst(), "TableA"); @@ -326,11 +327,11 @@ public void testBasic() WriteableVariableStore vs = getVariableStore(); TableFormatFactory fac = new TableFormatFactory(tablefinder); - FormatManager tableMgr = fac.build("STRING", formatLibrary); + FormatManager tableMgr = fac.build(Optional.empty(), Optional.of("STRING"), formatLibrary); vl.assertLegalVariableID("TableA", getGlobalScope(), tableMgr); ColumnFormatFactory cfac = new ColumnFormatFactory(finder); - FormatManager columnMgr = cfac.build("NUMBER", formatLibrary); + FormatManager columnMgr = cfac.build(Optional.empty(), Optional.of("NUMBER"), formatLibrary); vl.assertLegalVariableID("ResultColumn", getGlobalScope(), columnMgr); VariableID tableID = vl.getVariableID(getGlobalScopeInst(), "TableA"); @@ -365,7 +366,7 @@ public void testInvalidFormatDirect() WriteableVariableStore vs = getVariableStore(); ColumnFormatFactory cfac = new ColumnFormatFactory(finder); - FormatManager columnMgr = cfac.build("NUMBER", formatLibrary); + FormatManager columnMgr = cfac.build(Optional.empty(), Optional.of("NUMBER"), formatLibrary); vl.assertLegalVariableID("ResultColumn", getGlobalScope(), columnMgr); VariableID columnID = @@ -402,7 +403,7 @@ public void testInvalidTableFormatDirect() WriteableVariableStore vs = getVariableStore(); ColumnFormatFactory cfac = new ColumnFormatFactory(finder); - FormatManager columnMgr = cfac.build("NUMBER", formatLibrary); + FormatManager columnMgr = cfac.build(Optional.empty(), Optional.of("NUMBER"), formatLibrary); vl.assertLegalVariableID("ResultColumn", getGlobalScope(), columnMgr); VariableID columnID = @@ -439,7 +440,7 @@ public void testInvalidNameDirect() WriteableVariableStore vs = getVariableStore(); ColumnFormatFactory cfac = new ColumnFormatFactory(finder); - FormatManager columnMgr = cfac.build("NUMBER", formatLibrary); + FormatManager columnMgr = cfac.build(Optional.empty(), Optional.of("NUMBER"), formatLibrary); vl.assertLegalVariableID("ResultColumn", getGlobalScope(), columnMgr); VariableID columnID = @@ -476,7 +477,7 @@ public void testDirect() WriteableVariableStore vs = getVariableStore(); ColumnFormatFactory cfac = new ColumnFormatFactory(finder); - FormatManager columnMgr = cfac.build("NUMBER", formatLibrary); + FormatManager columnMgr = cfac.build(Optional.empty(), Optional.of("NUMBER"), formatLibrary); vl.assertLegalVariableID("ResultColumn", getGlobalScope(), columnMgr); VariableID columnID = @@ -512,7 +513,7 @@ public void testInDirectColumn() finder.map.put("Value", buildColumn("Value", numberManager)); ColumnFormatFactory cfac = new ColumnFormatFactory(finder); - FormatManager columnMgr = cfac.build("NUMBER", formatLibrary); + FormatManager columnMgr = cfac.build(Optional.empty(), Optional.of("NUMBER"), formatLibrary); VariableLibrary vl = getVariableLibrary(); vl.assertLegalVariableID("ResultColumn", getGlobalScope(), columnMgr); @@ -543,7 +544,7 @@ public void testInvalidExtra() WriteableVariableStore vs = getVariableStore(); ColumnFormatFactory cfac = new ColumnFormatFactory(finder); - FormatManager columnMgr = cfac.build("NUMBER", formatLibrary); + FormatManager columnMgr = cfac.build(Optional.empty(), Optional.of("NUMBER"), formatLibrary); vl.assertLegalVariableID("ResultColumn", getGlobalScope(), columnMgr); VariableID columnID = @@ -583,11 +584,11 @@ public void testNoColumn() WriteableVariableStore vs = getVariableStore(); TableFormatFactory fac = new TableFormatFactory(tablefinder); - FormatManager tableMgr = fac.build("STRING", formatLibrary); + FormatManager tableMgr = fac.build(Optional.empty(), Optional.of("STRING"), formatLibrary); vl.assertLegalVariableID("TableA", getGlobalScope(), tableMgr); ColumnFormatFactory cfac = new ColumnFormatFactory(finder); - FormatManager columnMgr = cfac.build("NUMBER", formatLibrary); + FormatManager columnMgr = cfac.build(Optional.empty(), Optional.of("NUMBER"), formatLibrary); vl.assertLegalVariableID("ResultColumn", getGlobalScope(), columnMgr); VariableID tableID = vl.getVariableID(getGlobalScopeInst(), "TableA"); @@ -628,11 +629,11 @@ public void testNoLookup() WriteableVariableStore vs = getVariableStore(); TableFormatFactory fac = new TableFormatFactory(tablefinder); - FormatManager tableMgr = fac.build("STRING", formatLibrary); + FormatManager tableMgr = fac.build(Optional.empty(), Optional.of("STRING"), formatLibrary); vl.assertLegalVariableID("TableA", getGlobalScope(), tableMgr); ColumnFormatFactory cfac = new ColumnFormatFactory(finder); - FormatManager columnMgr = cfac.build("NUMBER", formatLibrary); + FormatManager columnMgr = cfac.build(Optional.empty(), Optional.of("NUMBER"), formatLibrary); vl.assertLegalVariableID("ResultColumn", getGlobalScope(), columnMgr); VariableID tableID = vl.getVariableID(getGlobalScopeInst(), "TableA"); @@ -684,7 +685,7 @@ public void testLessThan() WriteableVariableStore vs = getVariableStore(); ColumnFormatFactory cfac = new ColumnFormatFactory(finder); - FormatManager columnMgr = cfac.build("NUMBER", formatLibrary); + FormatManager columnMgr = cfac.build(Optional.empty(), Optional.of("NUMBER"), formatLibrary); vl.assertLegalVariableID("ResultColumn", getGlobalScope(), columnMgr); VariableID columnID = diff --git a/code/src/utest/plugin/function/testsupport/AbstractFormulaTestCase.java b/code/src/utest/plugin/function/testsupport/AbstractFormulaTestCase.java index 6ffcae1403d..7ecea0c74b2 100644 --- a/code/src/utest/plugin/function/testsupport/AbstractFormulaTestCase.java +++ b/code/src/utest/plugin/function/testsupport/AbstractFormulaTestCase.java @@ -1,14 +1,14 @@ /* * Copyright 2014 (C) Tom Parker - * + * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License along with * this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA @@ -24,11 +24,12 @@ import pcgen.base.format.StringManager; import pcgen.base.formatmanager.FormatUtilities; import pcgen.base.formula.base.EvaluationManager; -import pcgen.base.formula.base.FormulaManager; import pcgen.base.formula.base.FormulaSemantics; -import pcgen.base.formula.base.LegalScope; +import pcgen.base.formula.base.FunctionLibrary; +import pcgen.base.formula.base.ManagerFactory; import pcgen.base.formula.base.OperatorLibrary; import pcgen.base.formula.base.ScopeInstance; +import pcgen.base.formula.base.ScopeInstanceFactory; import pcgen.base.formula.base.VariableLibrary; import pcgen.base.formula.base.WriteableFunctionLibrary; import pcgen.base.formula.exception.SemanticsFailureException; @@ -39,9 +40,10 @@ import pcgen.base.util.FormatManager; import pcgen.cdom.facet.FacetLibrary; import pcgen.cdom.facet.LoadContextFacet; -import pcgen.cdom.formula.ManagerKey; import pcgen.cdom.formula.MonitorableVariableStore; import pcgen.cdom.formula.scope.GlobalPCScope; +import pcgen.cdom.formula.scope.GlobalPCVarScoped; +import pcgen.cdom.formula.scope.PCGenScope; import pcgen.rules.context.ConsolidatedListCommitStrategy; import pcgen.rules.context.LoadContext; import pcgen.rules.context.RuntimeLoadContext; @@ -56,7 +58,9 @@ public abstract class AbstractFormulaTestCase protected FormatManager stringManager = new StringManager(); protected LoadContext context; - private FormulaManager formulaManager; + private ManagerFactory managerFactory; + private MonitorableVariableStore varStore; + private ScopeInstance globalInstance; public void setUp() throws Exception { @@ -66,18 +70,13 @@ public void setUp() throws Exception FacetLibrary.getFacet(LoadContextFacet.class).set(context.getDataSetID(), new WeakReference<>(context)); FormatSupport.addBasicDefaults(context); + varStore = new MonitorableVariableStore(); + managerFactory = context.getVariableContext().getPCManagerFactory(varStore); + ScopeInstanceFactory siFactory = context.getVariableContext().getScopeInstanceFactory(); + globalInstance = siFactory.get(GlobalPCScope.GLOBAL_SCOPE_NAME, + new GlobalPCVarScoped(GlobalPCScope.GLOBAL_SCOPE_NAME)); } - /** - * Force a given formula to be valid. - * - * @param node - * The root node for processing the formula - * @param formatManager - * The FormatManager indicating the format of the result of the formula - * @param assertedFormat - * The asserted format - */ protected void isValid(SimpleNode node, FormatManager formatManager, FormatManager assertedFormat) { @@ -95,7 +94,7 @@ protected void isValid(SimpleNode node, FormatManager formatManager, protected void isStatic(String formula, SimpleNode node, boolean b) { StaticVisitor staticVisitor = - new StaticVisitor(getFormulaManager().get(FormulaManager.FUNCTION)); + new StaticVisitor(context.getVariableContext().getFunctionLibrary()); boolean isStat = (Boolean) staticVisitor.visit(node, null); if (isStat != b) { @@ -150,63 +149,57 @@ protected void isNotValid(String formula, SimpleNode node) protected WriteableFunctionLibrary getFunctionLibrary() { - return (WriteableFunctionLibrary) getFormulaManager() - .get(FormulaManager.FUNCTION); + return context.getVariableContext().getFunctionLibrary(); } protected OperatorLibrary getOperatorLibrary() { - return getFormulaManager().getOperatorLibrary(); + return context.getVariableContext().getOperatorLibrary(); } protected VariableLibrary getVariableLibrary() { - return getFormulaManager().getFactory(); + return context.getVariableContext(); } protected MonitorableVariableStore getVariableStore() { - return (MonitorableVariableStore) getFormulaManager().get(FormulaManager.RESULTS); + return varStore; } - protected LegalScope getGlobalScope() + protected PCGenScope getGlobalScope() { - return getGlobalScopeInst().getLegalScope(); + return context.getVariableContext().getScope(GlobalPCScope.GLOBAL_SCOPE_NAME); } protected ScopeInstance getGlobalScopeInst() { - return getFormulaManager().getScopeInstanceFactory() - .getGlobalInstance(GlobalPCScope.GLOBAL_SCOPE_NAME); + return globalInstance; } - protected FormulaManager getFormulaManager() + protected ManagerFactory getManagerFactory() { - if (formulaManager == null) - { - formulaManager = context.getVariableContext().getFormulaManager() - .getWith(FormulaManager.RESULTS, new MonitorableVariableStore()); - } - return formulaManager; + return managerFactory; + } + + protected ScopeInstanceFactory getScopeInstanceFactory() + { + return context.getVariableContext().getScopeInstanceFactory(); } protected FormulaSemantics generateFormulaSemantics(FormatManager assertedFormat) { Optional> format = (assertedFormat == null) ? Optional.empty() : Optional.of(assertedFormat); - return new FormulaSemantics() - .getWith(FormulaSemantics.FMANAGER, formulaManager) - .getWith(FormulaSemantics.SCOPE, getGlobalScope()) - .getWith(FormulaSemantics.ASSERTED, format) - .getWith(ManagerKey.CONTEXT, context); + FormulaSemantics semantics = managerFactory.generateFormulaSemantics( + context.getVariableContext().getScope(GlobalPCScope.GLOBAL_SCOPE_NAME)); + return semantics.getWith(FormulaSemantics.ASSERTED, format); } public EvaluationManager generateManager() { - return new EvaluationManager() - .getWith(EvaluationManager.FMANAGER, getFormulaManager()) - .getWith(EvaluationManager.INSTANCE, getGlobalScopeInst()) - .getWith(EvaluationManager.ASSERTED, Optional.of(FormatUtilities.NUMBER_MANAGER)) - .getWith(ManagerKey.CONTEXT, context); + EvaluationManager em = managerFactory.generateEvaluationManager(); + return em.getWith(EvaluationManager.INSTANCE, getGlobalScopeInst()) + .getWith(EvaluationManager.ASSERTED, Optional.of(FormatUtilities.NUMBER_MANAGER)); } } diff --git a/code/src/utest/plugin/lsttokens/ModifyLstTest.java b/code/src/utest/plugin/lsttokens/ModifyLstTest.java index 24b5af8a9e8..efaf79dc0ec 100644 --- a/code/src/utest/plugin/lsttokens/ModifyLstTest.java +++ b/code/src/utest/plugin/lsttokens/ModifyLstTest.java @@ -21,10 +21,10 @@ import java.net.URISyntaxException; -import pcgen.base.formula.base.LegalScope; import pcgen.base.util.FormatManager; import pcgen.cdom.base.VarContainer; import pcgen.cdom.base.VarHolder; +import pcgen.cdom.formula.scope.PCGenScope; import pcgen.core.PCTemplate; import pcgen.persistence.PersistenceLayerException; import pcgen.rules.context.LoadContext; @@ -245,7 +245,7 @@ protected void additionalSetup(LoadContext context) { super.additionalSetup(context); FormatManager formatManager = context.getReferenceContext().getFormatManager("NUMBER"); - LegalScope scope = context.getActiveScope(); + PCGenScope scope = context.getActiveScope(); context.getVariableContext().assertLegalVariableID("MyVar", scope, formatManager); context.getVariableContext().assertLegalVariableID("OtherVar", scope, formatManager); } diff --git a/code/src/utest/plugin/lsttokens/ModifyOtherLstTest.java b/code/src/utest/plugin/lsttokens/ModifyOtherLstTest.java index bad7a66f0b1..fb7247448ff 100644 --- a/code/src/utest/plugin/lsttokens/ModifyOtherLstTest.java +++ b/code/src/utest/plugin/lsttokens/ModifyOtherLstTest.java @@ -21,10 +21,10 @@ import java.net.URISyntaxException; -import pcgen.base.formula.base.LegalScope; import pcgen.base.util.FormatManager; import pcgen.cdom.base.VarContainer; import pcgen.cdom.base.VarHolder; +import pcgen.cdom.formula.scope.PCGenScope; import pcgen.core.PCTemplate; import pcgen.core.Skill; import pcgen.persistence.PersistenceLayerException; @@ -282,7 +282,7 @@ protected void additionalSetup(LoadContext context) { super.additionalSetup(context); FormatManager formatManager = context.getReferenceContext().getFormatManager("NUMBER"); - LegalScope scope = context.getActiveScope(); + PCGenScope scope = context.getActiveScope(); context.getVariableContext().assertLegalVariableID("MyVar", scope, formatManager); context.getVariableContext().assertLegalVariableID("OtherVar", scope, formatManager); context.getReferenceContext().constructCDOMObject(Skill.class, "Dummy"); diff --git a/code/src/utest/plugin/lsttokens/SrLstTest.java b/code/src/utest/plugin/lsttokens/SrLstTest.java index 77252dd37ac..5208095a74f 100644 --- a/code/src/utest/plugin/lsttokens/SrLstTest.java +++ b/code/src/utest/plugin/lsttokens/SrLstTest.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.content.SpellResistance; import pcgen.cdom.enumeration.FormulaKey; diff --git a/code/src/utest/plugin/lsttokens/add/AbilityTokenTest.java b/code/src/utest/plugin/lsttokens/add/AbilityTokenTest.java index 51ef043ed34..af4219c54ff 100644 --- a/code/src/utest/plugin/lsttokens/add/AbilityTokenTest.java +++ b/code/src/utest/plugin/lsttokens/add/AbilityTokenTest.java @@ -25,7 +25,7 @@ import java.util.ArrayList; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.CDOMReference; import pcgen.cdom.base.ChoiceSet.AbilityChoiceSet; diff --git a/code/src/utest/plugin/lsttokens/kit/startpack/EquipBuyTokenTest.java b/code/src/utest/plugin/lsttokens/kit/startpack/EquipBuyTokenTest.java index bfed74db7ba..a686bbede87 100644 --- a/code/src/utest/plugin/lsttokens/kit/startpack/EquipBuyTokenTest.java +++ b/code/src/utest/plugin/lsttokens/kit/startpack/EquipBuyTokenTest.java @@ -21,7 +21,7 @@ import java.net.URISyntaxException; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.enumeration.FormulaKey; import pcgen.cdom.enumeration.ObjectKey; import pcgen.core.Kit; diff --git a/code/src/utest/plugin/lsttokens/kit/startpack/TotalCostTokenTest.java b/code/src/utest/plugin/lsttokens/kit/startpack/TotalCostTokenTest.java index 5cd4b6429c4..5c2e4ab7c66 100644 --- a/code/src/utest/plugin/lsttokens/kit/startpack/TotalCostTokenTest.java +++ b/code/src/utest/plugin/lsttokens/kit/startpack/TotalCostTokenTest.java @@ -21,7 +21,7 @@ import java.net.URISyntaxException; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.enumeration.FormulaKey; import pcgen.cdom.enumeration.ObjectKey; import pcgen.core.Kit; diff --git a/code/src/utest/plugin/lsttokens/pcclass/level/AbstractSpellCastingTokenTestCase.java b/code/src/utest/plugin/lsttokens/pcclass/level/AbstractSpellCastingTokenTestCase.java index 7ad8deae8b0..1337bf3da34 100644 --- a/code/src/utest/plugin/lsttokens/pcclass/level/AbstractSpellCastingTokenTestCase.java +++ b/code/src/utest/plugin/lsttokens/pcclass/level/AbstractSpellCastingTokenTestCase.java @@ -24,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.enumeration.ListKey; import pcgen.persistence.PersistenceLayerException; diff --git a/code/src/utest/plugin/lsttokens/pcclass/level/CastTokenTest.java b/code/src/utest/plugin/lsttokens/pcclass/level/CastTokenTest.java index 2d648a23ffb..d3715c8aead 100644 --- a/code/src/utest/plugin/lsttokens/pcclass/level/CastTokenTest.java +++ b/code/src/utest/plugin/lsttokens/pcclass/level/CastTokenTest.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.pcclass.level; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.enumeration.ListKey; import pcgen.cdom.inst.PCClassLevel; import pcgen.rules.persistence.token.CDOMPrimaryToken; diff --git a/code/src/utest/plugin/lsttokens/pcclass/level/KnownTokenTest.java b/code/src/utest/plugin/lsttokens/pcclass/level/KnownTokenTest.java index 6d5ce2d0da8..f6f206aaa9a 100644 --- a/code/src/utest/plugin/lsttokens/pcclass/level/KnownTokenTest.java +++ b/code/src/utest/plugin/lsttokens/pcclass/level/KnownTokenTest.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.pcclass.level; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.enumeration.ListKey; import pcgen.cdom.inst.PCClassLevel; import pcgen.rules.persistence.token.CDOMPrimaryToken; diff --git a/code/src/utest/plugin/lsttokens/pcclass/level/SpecialtyKnownTokenTest.java b/code/src/utest/plugin/lsttokens/pcclass/level/SpecialtyKnownTokenTest.java index 0121eee950d..3a7c13f8618 100644 --- a/code/src/utest/plugin/lsttokens/pcclass/level/SpecialtyKnownTokenTest.java +++ b/code/src/utest/plugin/lsttokens/pcclass/level/SpecialtyKnownTokenTest.java @@ -17,7 +17,7 @@ */ package plugin.lsttokens.pcclass.level; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.enumeration.ListKey; import pcgen.cdom.inst.PCClassLevel; import pcgen.rules.persistence.token.CDOMPrimaryToken; diff --git a/code/src/utest/plugin/lsttokens/testsupport/AbstractAddTokenTestCase.java b/code/src/utest/plugin/lsttokens/testsupport/AbstractAddTokenTestCase.java index 2bf77fad213..5e2288f465d 100644 --- a/code/src/utest/plugin/lsttokens/testsupport/AbstractAddTokenTestCase.java +++ b/code/src/utest/plugin/lsttokens/testsupport/AbstractAddTokenTestCase.java @@ -20,7 +20,7 @@ import java.util.ArrayList; import java.util.List; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.CDOMReference; import pcgen.cdom.base.ChoiceActor; diff --git a/code/src/utest/plugin/lsttokens/testsupport/AbstractFormulaTokenTestCase.java b/code/src/utest/plugin/lsttokens/testsupport/AbstractFormulaTokenTestCase.java index 0eb92486cc6..b111385e629 100644 --- a/code/src/utest/plugin/lsttokens/testsupport/AbstractFormulaTokenTestCase.java +++ b/code/src/utest/plugin/lsttokens/testsupport/AbstractFormulaTokenTestCase.java @@ -21,7 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.CDOMObject; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.enumeration.FormulaKey; diff --git a/code/src/utest/plugin/lsttokens/testsupport/AbstractGlobalFormulaTokenTestCase.java b/code/src/utest/plugin/lsttokens/testsupport/AbstractGlobalFormulaTokenTestCase.java index fe08b948f2b..88eedb36c64 100644 --- a/code/src/utest/plugin/lsttokens/testsupport/AbstractGlobalFormulaTokenTestCase.java +++ b/code/src/utest/plugin/lsttokens/testsupport/AbstractGlobalFormulaTokenTestCase.java @@ -22,7 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import pcgen.base.formula.Formula; +import pcgen.cdom.formula.Formula; import pcgen.cdom.base.FormulaFactory; import pcgen.cdom.enumeration.FormulaKey; import pcgen.persistence.PersistenceLayerException; diff --git a/code/src/utest/plugin/modifier/bool/SetBooleanModifierTest.java b/code/src/utest/plugin/modifier/bool/SetBooleanModifierTest.java index 2b995b4a31d..be8e6a2b6ec 100644 --- a/code/src/utest/plugin/modifier/bool/SetBooleanModifierTest.java +++ b/code/src/utest/plugin/modifier/bool/SetBooleanModifierTest.java @@ -20,7 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; -import pcgen.base.calculation.FormulaModifier; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.base.format.BooleanManager; import pcgen.base.util.FormatManager; import pcgen.rules.persistence.token.ModifierFactory; diff --git a/code/src/utest/plugin/modifier/number/AddNumberModifierTest.java b/code/src/utest/plugin/modifier/number/AddNumberModifierTest.java index 49045fb1ba1..62fa364e6f1 100644 --- a/code/src/utest/plugin/modifier/number/AddNumberModifierTest.java +++ b/code/src/utest/plugin/modifier/number/AddNumberModifierTest.java @@ -20,8 +20,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; -import pcgen.base.calculation.BasicCalculation; -import pcgen.base.calculation.FormulaModifier; +import pcgen.cdom.calculation.BasicCalculation; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.base.format.NumberManager; import pcgen.base.util.FormatManager; import pcgen.rules.persistence.token.ModifierFactory; diff --git a/code/src/utest/plugin/modifier/number/DivideNumberModifierTest.java b/code/src/utest/plugin/modifier/number/DivideNumberModifierTest.java index 8b5c8b32c96..ea1da4999a6 100644 --- a/code/src/utest/plugin/modifier/number/DivideNumberModifierTest.java +++ b/code/src/utest/plugin/modifier/number/DivideNumberModifierTest.java @@ -20,8 +20,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; -import pcgen.base.calculation.BasicCalculation; -import pcgen.base.calculation.FormulaModifier; +import pcgen.cdom.calculation.BasicCalculation; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.base.format.NumberManager; import pcgen.base.util.FormatManager; diff --git a/code/src/utest/plugin/modifier/number/MaxNumberModifierTest.java b/code/src/utest/plugin/modifier/number/MaxNumberModifierTest.java index 0ba4899e83f..2d55b49e52d 100644 --- a/code/src/utest/plugin/modifier/number/MaxNumberModifierTest.java +++ b/code/src/utest/plugin/modifier/number/MaxNumberModifierTest.java @@ -20,8 +20,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; -import pcgen.base.calculation.BasicCalculation; -import pcgen.base.calculation.FormulaModifier; +import pcgen.cdom.calculation.BasicCalculation; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.base.format.NumberManager; import pcgen.base.util.FormatManager; import pcgen.rules.persistence.token.ModifierFactory; diff --git a/code/src/utest/plugin/modifier/number/MinNumberModifierTest.java b/code/src/utest/plugin/modifier/number/MinNumberModifierTest.java index 5bba91edecb..335ec466f63 100644 --- a/code/src/utest/plugin/modifier/number/MinNumberModifierTest.java +++ b/code/src/utest/plugin/modifier/number/MinNumberModifierTest.java @@ -20,8 +20,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; -import pcgen.base.calculation.BasicCalculation; -import pcgen.base.calculation.FormulaModifier; +import pcgen.cdom.calculation.BasicCalculation; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.base.format.NumberManager; import pcgen.base.util.FormatManager; import pcgen.rules.persistence.token.ModifierFactory; diff --git a/code/src/utest/plugin/modifier/number/MultiplyNumberModifierTest.java b/code/src/utest/plugin/modifier/number/MultiplyNumberModifierTest.java index 4230947f245..10a42756de4 100644 --- a/code/src/utest/plugin/modifier/number/MultiplyNumberModifierTest.java +++ b/code/src/utest/plugin/modifier/number/MultiplyNumberModifierTest.java @@ -20,8 +20,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; -import pcgen.base.calculation.BasicCalculation; -import pcgen.base.calculation.FormulaModifier; +import pcgen.cdom.calculation.BasicCalculation; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.base.format.NumberManager; import pcgen.base.util.FormatManager; import pcgen.rules.persistence.token.ModifierFactory; diff --git a/code/src/utest/plugin/modifier/number/OverallModifierTest.java b/code/src/utest/plugin/modifier/number/OverallModifierTest.java index 25a3f1e4bb9..ca0420a9726 100644 --- a/code/src/utest/plugin/modifier/number/OverallModifierTest.java +++ b/code/src/utest/plugin/modifier/number/OverallModifierTest.java @@ -20,7 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; -import pcgen.base.calculation.CalculationInfo; +import pcgen.cdom.calculation.CalculationInfo; import org.junit.jupiter.api.Test; diff --git a/code/src/utest/plugin/modifier/number/SetNumberModifierTest.java b/code/src/utest/plugin/modifier/number/SetNumberModifierTest.java index bd6969bae31..6e4402119d8 100644 --- a/code/src/utest/plugin/modifier/number/SetNumberModifierTest.java +++ b/code/src/utest/plugin/modifier/number/SetNumberModifierTest.java @@ -20,17 +20,20 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; -import pcgen.base.calculation.FormulaModifier; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.base.format.NumberManager; import pcgen.base.formula.base.EvaluationManager; -import pcgen.base.formula.base.FormulaManager; -import pcgen.base.formula.inst.ScopeManagerInst; -import pcgen.base.solver.FormulaSetupFactory; +import pcgen.base.formula.base.ManagerFactory; import pcgen.base.util.FormatManager; import pcgen.cdom.formula.scope.GlobalPCScope; import pcgen.cdom.formula.scope.PCGenScope; +import pcgen.rules.context.ConsolidatedListCommitStrategy; +import pcgen.rules.context.LoadContext; +import pcgen.rules.context.RuntimeLoadContext; +import pcgen.rules.context.RuntimeReferenceContext; import plugin.modifier.testsupport.EvalManagerUtilities; +import util.FormatSupport; import org.junit.jupiter.api.Test; @@ -211,18 +214,18 @@ public void testGetModifier() @Test public void testGetFormulaModifier() { - FormulaSetupFactory formulaSetupFactory = new FormulaSetupFactory(); - ScopeManagerInst legalScopeManager = new ScopeManagerInst(); - formulaSetupFactory.setLegalScopeManagerSupplier(() -> legalScopeManager); - FormulaManager formulaManager = formulaSetupFactory.generate(); - legalScopeManager.registerScope(varScope); + LoadContext context = new RuntimeLoadContext( + RuntimeReferenceContext.createRuntimeReferenceContext(), + new ConsolidatedListCommitStrategy()); + FormatSupport.addBasicDefaults(context); + ManagerFactory managerFactory = context.getVariableContext().getManagerFactory(); SetModifierFactory factory = new SetModifierFactory(); FormulaModifier modifier = factory.getModifier("6+5", numManager); modifier.addAssociation("PRIORITY=35"); assertEquals((35L<<32)+factory.getInherentPriority(), modifier.getPriority()); assertEquals(numManager, modifier.getVariableFormat()); - EvaluationManager evalManager = EvalManagerUtilities.getInputEM(4.3); - assertEquals(11, modifier.process( - evalManager.getWith(EvaluationManager.FMANAGER, formulaManager))); + EvaluationManager evalManager = managerFactory.generateEvaluationManager() + .getWith(EvaluationManager.INPUT, 4.3); + assertEquals(11, modifier.process(evalManager)); } } diff --git a/code/src/utest/plugin/modifier/orderedpair/SetOrderedPairModifierTest.java b/code/src/utest/plugin/modifier/orderedpair/SetOrderedPairModifierTest.java index 1529c1d4d4c..a13b0d7ef65 100644 --- a/code/src/utest/plugin/modifier/orderedpair/SetOrderedPairModifierTest.java +++ b/code/src/utest/plugin/modifier/orderedpair/SetOrderedPairModifierTest.java @@ -20,7 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; -import pcgen.base.calculation.FormulaModifier; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.base.format.OrderedPairManager; import pcgen.base.math.OrderedPair; import pcgen.base.util.FormatManager; diff --git a/code/src/utest/plugin/modifier/string/SetStringModifierTest.java b/code/src/utest/plugin/modifier/string/SetStringModifierTest.java index c1c3f66a26a..c1f4d09a92e 100644 --- a/code/src/utest/plugin/modifier/string/SetStringModifierTest.java +++ b/code/src/utest/plugin/modifier/string/SetStringModifierTest.java @@ -20,7 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; -import pcgen.base.calculation.FormulaModifier; +import pcgen.cdom.calculation.FormulaModifier; import pcgen.base.format.StringManager; import pcgen.base.util.FormatManager; import pcgen.rules.persistence.token.ModifierFactory; diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f193d72905e..e74c8700b2a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.0-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-all.zip networkTimeout=10000 retries=0 retryBackOffMs=500 diff --git a/settings.gradle b/settings.gradle index e64944b26e7..4374ea0181a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,2 @@ rootProject.name = 'pcgen' +include 'PCGen-base', 'PCGen-Formula'