From efb744be6034f6a1ca8ce0f83d8a3fb6665efacd Mon Sep 17 00:00:00 2001 From: douira Date: Wed, 28 Dec 2022 04:29:40 +0100 Subject: [PATCH] rename generic type parameters with consistent rules --- docs/development.md | 17 ++++ .../ast/data/ProxyArrayList.java | 58 +++++++------- .../glsl_transformer/ast/data/TypeUtil.java | 6 +- .../ast/node/abstract_node/ASTNode.java | 46 +++++------ .../glsl_transformer/ast/query/Root.java | 78 +++++++++---------- .../ast/query/index/IdentifierIndex.java | 2 +- .../ast/query/index/Index.java | 6 +- .../ast/query/index/NodeIndex.java | 42 +++++----- .../ast/query/match/AutoHintedMatcher.java | 22 +++--- .../ast/query/match/HintedMatcher.java | 18 ++--- .../ast/query/match/Matcher.java | 66 ++++++++-------- .../ast/transform/ASTBuilder.java | 42 +++++----- .../ast/transform/ASTParser.java | 20 ++--- .../ast/transform/ASTTransformer.java | 12 +-- .../ast/transform/EnumASTTransformer.java | 4 +- .../ast/transform/GroupedASTTransformer.java | 8 +- .../ast/transform/ParameterHolder.java | 8 +- .../transform/ParameterizedTransformer.java | 4 +- .../ast/transform/SingleASTTransformer.java | 6 +- .../ast/transform/Template.java | 44 +++++------ .../ast/transform/TriASTTransformer.java | 10 +-- .../ast/transform/TriFullTransformation.java | 4 +- .../transform/TriRootOnlyTransformation.java | 4 +- .../ast/traversal/ASTListenerVisitor.java | 4 +- .../ast/traversal/ASTWalker.java | 4 +- .../parser/CachingParser.java | 14 ++-- .../parser/EnhancedParser.java | 32 ++++---- .../token_filter/ChannelFilter.java | 2 +- .../token_filter/MultiFilter.java | 20 ++--- .../token_filter/NewlineFilter.java | 2 +- .../token_filter/StringFilter.java | 2 +- .../token_filter/TokenFilter.java | 20 ++--- .../glsl_transformer/util/CompatUtil.java | 36 ++++----- .../glsl_transformer/util/ConfigUtil.java | 14 ++-- .../token_filter/MultiFilterTest.java | 10 +-- 35 files changed, 352 insertions(+), 335 deletions(-) diff --git a/docs/development.md b/docs/development.md index 4288ab10..98a21ed9 100644 --- a/docs/development.md +++ b/docs/development.md @@ -33,6 +33,23 @@ gradle test --tests GrammarDebugTest # Development Notes +## Conventions + +### Generic Type Parameters + +Generic type parameters are named with the follwing rules: + +- `N` for `extends ASTNode` +- `C` for `extends ParserRuleContext` +- `T` for `extends ParseTree` +- `Child` for `extends ASTNode` if it's the child parameter of an `ASTNode` sub class +- `J` for `extends JobParameters` +- `E` for extending some kind of Enum +- `R` for some other return type +- `V` for generic (unconstrained) values that aren't any of the above + +`P` can't be used because it makes javadoc think it's a `

` paragraph tag. + ## AST Development ### AST Node Registration diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/data/ProxyArrayList.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/data/ProxyArrayList.java index 9e3b4289..3d8f0cf2 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/data/ProxyArrayList.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/data/ProxyArrayList.java @@ -8,8 +8,8 @@ * is added or removed from the list. The notification methods should be * idempotent and reversible with the inverse other method. */ -public abstract class ProxyArrayList extends ArrayList { - private Set elements = null; +public abstract class ProxyArrayList extends ArrayList { + private Set elements = null; public ProxyArrayList() { } @@ -18,22 +18,22 @@ public ProxyArrayList(int initialCapacity) { super(initialCapacity); } - public ProxyArrayList(Collection c) { + public ProxyArrayList(Collection c) { this(c, true); } - public ProxyArrayList(Collection c, boolean notifyInitial) { + public ProxyArrayList(Collection c, boolean notifyInitial) { super(c); if (notifyInitial) { notifyAdditionSafe(c); } } - protected abstract void notifyAddition(T added); + protected abstract void notifyAddition(V added); - protected abstract void notifyRemoval(T removed); + protected abstract void notifyRemoval(V removed); - void notifyAdditionSafe(T added) { + void notifyAdditionSafe(V added) { if (added != null) { notifyAddition(added); if (elements != null) { @@ -42,13 +42,13 @@ void notifyAdditionSafe(T added) { } } - void notifyAdditionSafe(Collection collection) { - for (var element : collection) { + void notifyAdditionSafe(Collection collection) { + for (V element : collection) { notifyAdditionSafe(element); } } - private void notifyRemovalSafe(T removed) { + private void notifyRemovalSafe(V removed) { if (removed != null) { notifyRemoval(removed); if (elements != null) { @@ -57,13 +57,13 @@ private void notifyRemovalSafe(T removed) { } } - private void notifyRemovalSafe(Collection collection) { - for (var element : collection) { + private void notifyRemovalSafe(Collection collection) { + for (V element : collection) { notifyRemovalSafe(element); } } - private Set getElements() { + private Set getElements() { if (elements == null) { elements = new HashSet<>(this); } @@ -71,8 +71,8 @@ private Set getElements() { } @Override - public T set(int index, T element) { - var prev = super.set(index, element); + public V set(int index, V element) { + V prev = super.set(index, element); if (prev != element) { notifyRemovalSafe(prev); notifyAdditionSafe(element); @@ -81,20 +81,20 @@ public T set(int index, T element) { } @Override - public boolean add(T e) { + public boolean add(V e) { var result = super.add(e); notifyAdditionSafe(e); return result; } @Override - public void add(int index, T element) { + public void add(int index, V element) { super.add(index, element); notifyAdditionSafe(element); } @Override - public boolean addAll(Collection c) { + public boolean addAll(Collection c) { var result = super.addAll(c); if (result) { notifyAdditionSafe(c); @@ -103,7 +103,7 @@ public boolean addAll(Collection c) { } @Override - public boolean addAll(int index, Collection c) { + public boolean addAll(int index, Collection c) { var result = super.addAll(index, c); if (result) { notifyAdditionSafe(c); @@ -112,8 +112,8 @@ public boolean addAll(int index, Collection c) { } @Override - public T remove(int index) { - var removed = super.remove(index); + public V remove(int index) { + V removed = super.remove(index); notifyRemovalSafe(removed); return removed; } @@ -124,7 +124,7 @@ public boolean remove(Object o) { var result = super.remove(o); if (result) { // the cast is ok because only T-type elements could have been added - notifyRemovalSafe((T) o); + notifyRemovalSafe((V) o); } return result; } @@ -136,7 +136,7 @@ public boolean removeAll(Collection c) { if (result) { for (Object element : this) { if (getElements().contains(element)) { - notifyRemovalSafe((T) element); + notifyRemovalSafe((V) element); } } } @@ -144,7 +144,7 @@ public boolean removeAll(Collection c) { } @Override - public void replaceAll(UnaryOperator operator) { + public void replaceAll(UnaryOperator operator) { for (int i = 0; i < size(); i++) { set(i, operator.apply(get(i))); } @@ -157,7 +157,7 @@ public boolean retainAll(Collection c) { if (result) { for (Object element : this) { if (!getElements().contains(element)) { - notifyRemovalSafe((T) element); + notifyRemovalSafe((V) element); } } } @@ -165,10 +165,10 @@ public boolean retainAll(Collection c) { } @Override - public boolean removeIf(Predicate filter) { + public boolean removeIf(Predicate filter) { var result = super.removeIf(filter); if (result) { - for (var element : this) { + for (V element : this) { if (filter.test(element)) { notifyRemovalSafe(element); } @@ -196,8 +196,8 @@ public void clear() { @Override @SuppressWarnings("unchecked") - public ProxyArrayList clone() { - var result = (ProxyArrayList) super.clone(); + public ProxyArrayList clone() { + var result = (ProxyArrayList) super.clone(); result.elements = null; return result; } diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/data/TypeUtil.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/data/TypeUtil.java index efbde446..de85c7c7 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/data/TypeUtil.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/data/TypeUtil.java @@ -3,8 +3,8 @@ import org.antlr.v4.runtime.Token; public class TypeUtil { - public static T enumFromToken(T[] enumValues, Token token) { - for (T value : enumValues) { + public static E enumFromToken(E[] enumValues, Token token) { + for (E value : enumValues) { if (value.getTokenType() == token.getType()) { return value; } @@ -12,7 +12,7 @@ public static T enumFromToken(T[] enumValues, Token token throw new IllegalArgumentException("Unknown token: " + token.getText()); } - public static T enumFromToken(T[] values, int[] tokenTypes, Token token) { + public static E enumFromToken(E[] values, int[] tokenTypes, Token token) { if (values.length != tokenTypes.length) { throw new IllegalArgumentException("values.length != tokenTypes.length"); } diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/node/abstract_node/ASTNode.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/node/abstract_node/ASTNode.java index da6bceb8..3eae2312 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/node/abstract_node/ASTNode.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/node/abstract_node/ASTNode.java @@ -196,7 +196,7 @@ public ASTNode getAncestor(Predicate predicate) { * @return the first ancestor that is an instance of the given class, or null * otherwise */ - public T getAncestor(Class ancestorType) { + public N getAncestor(Class ancestorType) { return ancestorType.cast(getAncestor(ancestorType::isInstance)); } @@ -217,9 +217,9 @@ public ASTNode getBranchAncestor(int limit, int skip, BiPredicate T getBranchAncestor(int limit, int skip, Class branchClass, - Function branchGetter) { - return (T) getBranchAncestor(limit, skip, (node, last) -> { + public N getBranchAncestor(int limit, int skip, Class branchClass, + Function branchGetter) { + return (N) getBranchAncestor(limit, skip, (node, last) -> { if (!branchClass.isInstance(node)) { return false; } @@ -227,14 +227,14 @@ public T getBranchAncestor(int limit, int skip, Class bra }); } - public T getBranchAncestor(Class branchClass, - Function branchGetter) { + public N getBranchAncestor(Class branchClass, + Function branchGetter) { return getBranchAncestor(Integer.MAX_VALUE, 0, branchClass, branchGetter); } - public R getBranchAncestorContinue(Class branchClass, - Function branchGetter, Class continueClass) { - var result = getBranchAncestor(branchClass, branchGetter); + public R getBranchAncestorContinue(Class branchClass, + Function branchGetter, Class continueClass) { + N result = getBranchAncestor(branchClass, branchGetter); return result == null ? null : result.getAncestor(continueClass); } @@ -438,14 +438,14 @@ public static boolean swap(ASTNode a, ASTNode b) { * already have a reference to the current root but will not be registered to it * yet. * - * @param Type of the node for passthrough + * @param Type of the node for passthrough * @param node The node to add * @param setter The setter to replace the node in this parent * @return The node itself */ - public NodeType setup( - NodeType node, - Consumer setter) { + public N setup( + N node, + Consumer setter) { if (node != null) { node.setParent(this, setter); } @@ -457,17 +457,17 @@ public NodeType setup( * node. Both of them may be null if either the existing value is being removed * or a new value is being set. * - * @param The type of the nodes for pass-through + * @param The type of the nodes for pass-through * @param currentNode The current node * @param newNode The new node * @param setter The setter to replace the node in this parent (this is * usually a method reference to a setter method of the * parent, this node) */ - public void updateParents( - NodeType currentNode, - NodeType newNode, - Consumer setter) { + public void updateParents( + N currentNode, + N newNode, + Consumer setter) { if (currentNode == newNode && newNode.getParent() == this) { return; } @@ -501,18 +501,18 @@ public ASTNode cloneSeparate() { } @SuppressWarnings("unchecked") // the nodes clone themselves correctly - public static T clone(T node) { + public static N clone(N node) { if (node == null) { return null; } if (node.template == null) { - return (T) node.clone(); + return (N) node.clone(); } - var replacement = node.template.getReplacement(node); - return replacement == null ? (T) node.clone() : replacement; + N replacement = node.template.getReplacement(node); + return replacement == null ? (N) node.clone() : replacement; } - public static Stream clone(ChildNodeList nodes) { + public static Stream clone(ChildNodeList nodes) { return nodes == null ? null : nodes.getClonedStream(); } } diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/Root.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/Root.java index 0ac2ce87..dfabb736 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/Root.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/Root.java @@ -130,13 +130,13 @@ protected static final synchronized R withActiveBuildRoot( * either manually registered as it is being done here or added as a child to * another node with the root. * - * @param The type of the node to build - * @param instance The root to run the builder with - * @param builder The builder to run + * @param The type of the node to build + * @param instance The root to run the builder with + * @param builder The builder to run * @return The built and registered node */ - public static synchronized NodeType indexNodes( - Root instance, Supplier builder) { + public static synchronized N indexNodes( + Root instance, Supplier builder) { return withActiveBuildRoot(instance, root -> { var result = builder.get(); root.registerNode(result); @@ -147,12 +147,12 @@ public static synchronized NodeType indexNodes( /** * Runs the given builder supplier with a new root as the active build root. * - * @param The type of the node to build - * @param builder The builder to run + * @param The type of the node to build + * @param builder The builder to run * @return The built and registered node */ - public static NodeType indexNodes( - Supplier builder) { + public static N indexNodes( + Supplier builder) { return indexNodes(new Root(), builder); } @@ -160,13 +160,13 @@ public static NodeType indexNodes( * Runs the given builder supplier with the same root as a given tree node as * the active build root. * - * @param The type of the node to build + * @param The type of the node to build * @param parentTreeMember The tree member to get the root from * @param builder The builder to run * @return The built and registered node */ - public static NodeType indexNodes( - ASTNode parentTreeMember, Supplier builder) { + public static N indexNodes( + ASTNode parentTreeMember, Supplier builder) { return indexNodes(parentTreeMember.getRoot(), builder); } @@ -211,12 +211,12 @@ public static void indexBuildSession(ASTNode treeMember, Runnable session) { * function that takes a constructed node and registers it with the root. This * is helpful for constructing trees manually and registering them inline. * - * @param The type of the nodes to register + * @param The type of the nodes to register * @param instance the root to register the nodes with * @param registererConsumer The consumer to run */ - public static synchronized void indexSeparateTrees( - Root instance, Consumer> registererConsumer) { + public static synchronized void indexSeparateTrees( + Root instance, Consumer> registererConsumer) { withActiveBuildRoot(instance, root -> { registererConsumer.accept(Passthrough.of(root::registerNode)); return null; @@ -227,11 +227,11 @@ public static synchronized void indexSeparateTrees( * Runs the given consumer of a registration pass-through function with a new * root as the active build root. * - * @param The type of the nodes to register + * @param The type of the nodes to register * @param registerer The consumer to run */ - public static void indexSeparateTrees( - Consumer> registerer) { + public static void indexSeparateTrees( + Consumer> registerer) { indexSeparateTrees(new Root(), registerer); } @@ -239,12 +239,12 @@ public static void indexSeparateTrees( * Runs the given consumer of a registration pass-through function with the same * root as a given tree node as the active build root. * - * @param The type of the nodes to register + * @param The type of the nodes to register * @param treeMember The tree member to get the root from * @param registerer The consumer to run */ - public static void indexSeparateTrees( - ASTNode treeMember, Consumer> registerer) { + public static void indexSeparateTrees( + ASTNode treeMember, Consumer> registerer) { indexSeparateTrees(treeMember.getRoot(), registerer); } @@ -318,21 +318,21 @@ public boolean rename(String oldName, String newName) { * This method ensures there is no concurrent modification of the node index by * collecting the stream into a shared list. * - * @param The type of the target nodes + * @param The type of the target nodes * @param targets The stream of target nodes to process * @param replacer The consumer to process the target nodes with * @return Whether anything was processed */ @SuppressWarnings("unchecked") - public boolean process(Stream targets, Consumer replacer) { + public boolean process(Stream targets, Consumer replacer) { ensureEmptyNodeList(); if (targets == null) { return false; } - var typedList = (List) nodeList; + var typedList = (List) nodeList; targets.forEach(typedList::add); var activity = false; - for (var node : typedList) { + for (N node : typedList) { if (node != null) { replacer.accept(node); activity = true; @@ -485,18 +485,18 @@ public static boolean replaceExpressionsConcurrent( * Processes all matches of nodes from the given stream matched with the given * matcher. * - * @param The type of the matched nodes + * @param The type of the matched nodes * @param t The AST transformer * @param matchTargetChildren The stream of nodes to match * @param matcher The matcher to match the nodes with * @param replacer The consumer to process the matched nodes with * @return Whether anything was processed */ - public boolean processMatches( + public boolean processMatches( ASTParser t, Stream matchTargetChildren, - Matcher matcher, - Consumer replacer) { + Matcher matcher, + Consumer replacer) { var matchClass = matcher.getPatternClass(); return process(matchTargetChildren .map(node -> node.getAncestor(matchClass)) @@ -509,16 +509,16 @@ public boolean processMatches( * Processes all matches of nodes in the tree that match the given hinted * matcher. The hint is used to identify the nodes to match. * - * @param The type of the matched nodes + * @param The type of the matched nodes * @param t The AST transformer * @param hintedMatcher The matcher to match the nodes with * @param replacer The consumer to process the matched nodes with * @return Whether anything was processed */ - public boolean processMatches( + public boolean processMatches( ASTParser t, - HintedMatcher hintedMatcher, - Consumer replacer) { + HintedMatcher hintedMatcher, + Consumer replacer) { return processMatches(t, identifierIndex.getStream(hintedMatcher.getHint()), hintedMatcher, replacer); } @@ -527,17 +527,17 @@ public boolean processMatches( * Replaces expressions from the given stream that match the given matcher with * new expressions created from the given string. * - * @param The type of the matched expression nodes + * @param The type of the matched expression nodes * @param t The AST transformer * @param matchTargetChildren The stream of nodes to match * @param matcher The matcher to match the nodes with * @param expression The content of the replacement expression * @return Whether anything was processed */ - public boolean replaceExpressionMatches( + public boolean replaceExpressionMatches( ASTParser t, Stream matchTargetChildren, - Matcher matcher, + Matcher matcher, String expression) { var matchClass = matcher.getPatternClass(); return replaceExpressions(t, @@ -552,15 +552,15 @@ public boolean replaceExpressionMatches( * Replaces expressions all matches of expression nodes in the tree that match * the given hinted matcher with new expressions created from the given string. * - * @param The type of the matched expression nodes + * @param The type of the matched expression nodes * @param t The AST transformer * @param hintedMatcher The matcher to match the nodes with * @param expression The content of the replacement expression * @return Whether anything was processed */ - public boolean replaceExpressionMatches( + public boolean replaceExpressionMatches( ASTParser t, - HintedMatcher hintedMatcher, + HintedMatcher hintedMatcher, String expression) { return replaceExpressionMatches(t, identifierIndex.getStream(hintedMatcher.getHint()), hintedMatcher, expression); diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/index/IdentifierIndex.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/index/IdentifierIndex.java index 6c11b067..b511f2f8 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/index/IdentifierIndex.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/index/IdentifierIndex.java @@ -54,7 +54,7 @@ public Stream getStream(String key) { return result == null ? Stream.empty() : result.stream(); } - public Stream getAncestors(String key, Class ancestorType) { + public Stream getAncestors(String key, Class ancestorType) { return getStream(key) .map(id -> id.getAncestor(ancestorType)) .filter(Objects::nonNull); diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/index/Index.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/index/Index.java index 2d388f4b..e602248f 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/index/Index.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/index/Index.java @@ -6,10 +6,10 @@ import io.github.douira.glsl_transformer.ast.node.abstract_node.ASTNode; -public interface Index { - void add(T node); +public interface Index { + void add(N node); - void remove(T node); + void remove(N node); public static Consumer> iterate(Consumer consumer) { return set -> set.stream().forEach(consumer); diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/index/NodeIndex.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/index/NodeIndex.java index 6da9151b..4f6eea78 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/index/NodeIndex.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/index/NodeIndex.java @@ -66,39 +66,39 @@ public void remove(ASTNode node) { /** * Returns a set of all nodes with the given type. * - * @param the type of the class + * @param the type of the class * @param type the class of nodes to return * @return a set of nodes with the given type */ @SuppressWarnings("unchecked") - public Set get(Class type) { - var result = (Set) index.get(type); + public Set get(Class type) { + var result = (Set) index.get(type); return result == null ? Collections.emptySet() : result; } /** * Returns a stream of all nodes with the given type. * - * @param the type of the class + * @param the type of the class * @param type the class of nodes to return * @return a stream of nodes with the given type */ @SuppressWarnings("unchecked") - public Stream getStream(Class type) { - var result = (Set) index.get(type); + public Stream getStream(Class type) { + var result = (Set) index.get(type); return result == null ? Stream.empty() : result.stream(); } /** * Returns an arbitrary node with the given type. * - * @param the type of the class + * @param the type of the class * @param type the class of the node to return * @return an arbitrary node with the given type */ @SuppressWarnings("unchecked") - public T getOne(Class type) { - var result = (Set) index.get(type); + public N getOne(Class type) { + var result = (Set) index.get(type); if (result == null) { return null; } @@ -110,13 +110,13 @@ public T getOne(Class type) { * Returns the only node with the given type. Throws an exception if there is * not exactly one node with the given type. * - * @param the type of the class + * @param the type of the class * @param type the class of the node to return * @return the only node with the given type */ @SuppressWarnings("unchecked") - public T getUnique(Class type) { - var result = (Set) index.get(type); + public N getUnique(Class type) { + var result = (Set) index.get(type); var resultCount = result == null ? 0 : result.size(); if (resultCount != 1) { throw new IllegalStateException("Expected exactly one node of type " + type + " but found " + resultCount); @@ -138,25 +138,25 @@ public boolean has(Class type) { /** * Returns the set of nodes that have the same class as the given node. * - * @param The type of the nodes + * @param The type of the nodes * @param node The node to get the set of * @return The set of nodes that have the same class as the given node */ @SuppressWarnings("unchecked") - public Set get(T node) { - return (Set) get(node.getClass()); + public Set get(N node) { + return (Set) get(node.getClass()); } /** * Returns an arbitrary node that has the same class as the given node. * - * @param The type of the node + * @param The type of the node * @param node The node to get a node from the index for * @return An arbitrary node that has the same class as the given node */ @SuppressWarnings("unchecked") - public T getOne(T node) { - return (T) getOne(node.getClass()); + public N getOne(N node) { + return (N) getOne(node.getClass()); } /** @@ -164,13 +164,13 @@ public T getOne(T node) { * exception if there is not exactly one node with the same class as the given * node. * - * @param The type of the node + * @param The type of the node * @param node The node to get a node from the index for * @return The only node that has the same class as the given node */ @SuppressWarnings("unchecked") - public T getUnique(T node) { - return (T) getUnique(node.getClass()); + public N getUnique(N node) { + return (N) getUnique(node.getClass()); } /** diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/match/AutoHintedMatcher.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/match/AutoHintedMatcher.java index 7843c30f..745109ef 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/match/AutoHintedMatcher.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/match/AutoHintedMatcher.java @@ -15,32 +15,32 @@ * best (most distinguishing) hint, then the manually hinted * {@link HintedMatcher} should be used instead. */ -public class AutoHintedMatcher extends HintedMatcher { - public AutoHintedMatcher(String input, - Function parseMethod, - BiFunction visitMethod, String wildcardPrefix) { +public class AutoHintedMatcher extends HintedMatcher { + public AutoHintedMatcher(String input, + Function parseMethod, + BiFunction visitMethod, String wildcardPrefix) { super(input, parseMethod, visitMethod, wildcardPrefix, null); } - public AutoHintedMatcher(T pattern, String wildcardPrefix) { + public AutoHintedMatcher(N pattern, String wildcardPrefix) { super(pattern, wildcardPrefix, null); } - public AutoHintedMatcher(T pattern) { + public AutoHintedMatcher(N pattern) { super(pattern, null); } - public AutoHintedMatcher(String input, - Function parseMethod, - BiFunction visitMethod) { + public AutoHintedMatcher(String input, + Function parseMethod, + BiFunction visitMethod) { super(input, parseMethod, visitMethod, null); } - public AutoHintedMatcher(String input, Function patternParser, String wildcardPrefix) { + public AutoHintedMatcher(String input, Function patternParser, String wildcardPrefix) { super(input, patternParser, wildcardPrefix, null); } - public AutoHintedMatcher(String input, Function patternParser) { + public AutoHintedMatcher(String input, Function patternParser) { super(input, patternParser, null); } diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/match/HintedMatcher.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/match/HintedMatcher.java index a34c482a..4e6baeba 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/match/HintedMatcher.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/match/HintedMatcher.java @@ -13,37 +13,37 @@ * identifiers whose matching ancestor might match the pattern. This makes * working with matchers much less verbose. */ -public class HintedMatcher extends Matcher { +public class HintedMatcher extends Matcher { protected String hint; - public HintedMatcher(String input, Function parseMethod, - BiFunction visitMethod, String wildcardPrefix, String hint) { + public HintedMatcher(String input, Function parseMethod, + BiFunction visitMethod, String wildcardPrefix, String hint) { super(input, parseMethod, visitMethod, wildcardPrefix); this.hint = hint; } - public HintedMatcher(T pattern, String wildcardPrefix, String hint) { + public HintedMatcher(N pattern, String wildcardPrefix, String hint) { super(pattern, wildcardPrefix); this.hint = hint; } - public HintedMatcher(T pattern, String hint) { + public HintedMatcher(N pattern, String hint) { super(pattern); this.hint = hint; } - public HintedMatcher(String input, Function parseMethod, - BiFunction visitMethod, String hint) { + public HintedMatcher(String input, Function parseMethod, + BiFunction visitMethod, String hint) { super(input, parseMethod, visitMethod); this.hint = hint; } - public HintedMatcher(String input, Function patternParser, String wildcardPrefix, String hint) { + public HintedMatcher(String input, Function patternParser, String wildcardPrefix, String hint) { super(input, patternParser, wildcardPrefix); this.hint = hint; } - public HintedMatcher(String input, Function patternParser, String hint) { + public HintedMatcher(String input, Function patternParser, String hint) { super(input, patternParser); this.hint = hint; } diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/match/Matcher.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/match/Matcher.java index 1a3d37a8..3f3debb7 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/match/Matcher.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/query/match/Matcher.java @@ -20,11 +20,11 @@ * Instances of the matcher can match a node against a stored pattern. This * avoids a separate equality implementation for each node type. */ -public class Matcher { +public class Matcher { /** * The node of the pattern being matched. */ - protected final T pattern; + protected final N pattern; protected final String wildcardPrefix; private Map dataMatches; @@ -43,7 +43,7 @@ public class Matcher { * @param pattern The pattern to match * @param wildcardPrefix The prefix for wildcard identifiers */ - public Matcher(T pattern, String wildcardPrefix) { + public Matcher(N pattern, String wildcardPrefix) { this.pattern = pattern; this.wildcardPrefix = wildcardPrefix; } @@ -53,7 +53,7 @@ public Matcher(T pattern, String wildcardPrefix) { * * @param pattern The pattern to match */ - public Matcher(T pattern) { + public Matcher(N pattern) { this(pattern, null); } @@ -61,15 +61,15 @@ public Matcher(T pattern) { * Creates a new matcher that matches the pattern parsed from the given string, * parser method and visitor method. There is also a given wildcard prefix. * - * @param The type of the parser rule context + * @param The type of the parser rule context * @param input The string to parse * @param parseMethod The parser method to use * @param visitMethod The build visitor method to use * @param wildcardPrefix The wildcard prefix */ - public Matcher(String input, - Function parseMethod, - BiFunction visitMethod, + public Matcher(String input, + Function parseMethod, + BiFunction visitMethod, String wildcardPrefix) { this(ASTBuilder.build( EnhancedParser.getInternalInstance().parse(input, parseMethod), @@ -81,29 +81,29 @@ public Matcher(String input, * Creates a new matcher that matches the pattern parsed from the given string, * parser method and visitor method. There is no wildcard prefix. * - * @param The type of the parser rule context + * @param The type of the parser rule context * @param input The string to parse * @param parseMethod The parser method to use * @param visitMethod The build visitor method to use */ - public Matcher(String input, - Function parseMethod, - BiFunction visitMethod) { + public Matcher(String input, + Function parseMethod, + BiFunction visitMethod) { this(input, parseMethod, visitMethod, null); } - public Matcher(String input, Function patternParser, String wildcardPrefix) { + public Matcher(String input, Function patternParser, String wildcardPrefix) { this(patternParser.apply(input), wildcardPrefix); } - public Matcher(String input, Function patternParser) { + public Matcher(String input, Function patternParser) { this(input, patternParser, null); } - private static Function makePatternParser( - Class ruleType, - Function parseMethod, - BiFunction visitMethod) { + private static Function makePatternParser( + Class ruleType, + Function parseMethod, + BiFunction visitMethod) { return input -> ASTParser.getInternalInstance().parseNodeSeparate(input, ruleType, parseMethod, visitMethod); } @@ -249,7 +249,7 @@ public void visitVoidData(Object data) { * @param tree The tree to match * @return True if the tree matches the pattern, false otherwise */ - public boolean matches(T tree) { + public boolean matches(N tree) { if (tree == null) { return false; } @@ -277,7 +277,7 @@ private void ensureMatchMaps() { * @param tree The tree to match * @return True if the tree matches the pattern, false otherwise */ - public boolean matchesExtract(T tree) { + public boolean matchesExtract(N tree) { ensureMatchMaps(); dataMatches.clear(); nodeMatches.clear(); @@ -301,7 +301,7 @@ public boolean matchesExtract(T tree) { * @return */ public boolean matchesExtract( - T tree, + N tree, Map dataMatches, Map nodeMatches) { this.dataMatches = dataMatches; @@ -364,19 +364,19 @@ public ASTNode getNodeMatch(String name) { /** * Gets a node match with the given name if it is available as the given class. * - * @param The type of the node match + * @param The type of the node match * @param name The name of the node match * @param type The class of the node match * @return The node match or null if not found or not of the given class */ - public R getNodeMatch(String name, Class type) { + public NN getNodeMatch(String name, Class type) { var result = nodeMatches.get(name); return type.isInstance(result) ? type.cast(result) : null; } @SuppressWarnings("unchecked") - public Class getPatternClass() { - return (Class) pattern.getClass(); + public Class getPatternClass() { + return (Class) pattern.getClass(); } private void ensureWildcardMap() { @@ -496,11 +496,11 @@ public void markClassWildcard( nodeWildcards.put(patternNode, new ClassWildcard(name, patternNode.getClass())); } - private static class ClassedPredicateWildcard extends NodeWildcard { - final Class type; - final Predicate predicate; + private static class ClassedPredicateWildcard extends NodeWildcard { + final Class type; + final Predicate predicate; - ClassedPredicateWildcard(String name, Class type, Predicate predicate) { + ClassedPredicateWildcard(String name, Class type, Predicate predicate) { super(name); this.type = type; this.predicate = predicate; @@ -517,17 +517,17 @@ public boolean test(ASTNode node) { * wildcard will match any node in the same position in the tree that is an * instance of the given class and matches the predicate. * - * @param The type of the node match + * @param The type of the node match * @param name The name of the wildcard * @param patternNode The node to mark as a classed predicate wildcard * @param type The class to match the node with * @param predicate The predicate to match the node with */ - public void markClassedPredicateWildcard( + public void markClassedPredicateWildcard( String name, ASTNode patternNode, - Class type, - Predicate predicate) { + Class type, + Predicate predicate) { markWildcard(patternNode, new ClassedPredicateWildcard<>(name, type, predicate)); } } diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/ASTBuilder.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/ASTBuilder.java index edec12ee..f08eed60 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/ASTBuilder.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/ASTBuilder.java @@ -73,22 +73,22 @@ public static ASTNode build(Root rootInstance, ParseTree ctx) { /** * Builds an AST of a specific type from the given parse tree with a new root. * - * @param The type of the parse tree - * @param The type of the AST node - * @param ctx The parse tree - * @param visitMethod The build method reference to this class + * @param The type of the parse tree + * @param The type of the AST node + * @param ctx The parse tree + * @param visitMethod The build method reference to this class * @return The built AST */ - public static ReturnType build( - TreeType ctx, - BiFunction visitMethod) { + public static N build( + T ctx, + BiFunction visitMethod) { return Root.indexNodes(() -> buildInternal(ctx, visitMethod)); } - public static ReturnType build( + public static N build( Root rootInstance, - TreeType ctx, - BiFunction visitMethod) { + T ctx, + BiFunction visitMethod) { return Root.indexNodes(rootInstance, () -> buildInternal(ctx, visitMethod)); } @@ -107,17 +107,17 @@ public static ASTNode buildSubtree(ASTNode parentTreeMember, ParseTree ctx) { * Builds a subtree of a specific type that has the same root as the given AST * node. * - * @param The type of the parse tree - * @param The type of the AST node + * @param The type of the parse tree + * @param The type of the AST node * @param parentTreeMember The parent tree member * @param ctx The parse tree * @param visitMethod The build method reference to this class * @return The built AST */ - public static ReturnType buildSubtree( + public static N buildSubtree( ASTNode parentTreeMember, - TreeType ctx, - BiFunction visitMethod) { + T ctx, + BiFunction visitMethod) { return Root.indexNodes(parentTreeMember, () -> buildInternal(ctx, visitMethod)); } @@ -125,9 +125,9 @@ private static ASTNode buildInternal(ParseTree ctx) { return new ASTBuilder().visit(ctx); } - private static ReturnType buildInternal( - TreeType ctx, - BiFunction visitMethod) { + private static N buildInternal( + T ctx, + BiFunction visitMethod) { return visitMethod.apply(new ASTBuilder(), ctx); } @@ -154,10 +154,10 @@ private static void endConstruction() { sourceLineStack.pop(); } - private static R constructSimple( - ParseTree ctx, Supplier constructor) { + private static N constructSimple( + ParseTree ctx, Supplier constructor) { startConstruction(ctx); - var result = constructor.get(); + N result = constructor.get(); endConstruction(); return result; } diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/ASTParser.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/ASTParser.java index eb577154..9af1c8ae 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/ASTParser.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/ASTParser.java @@ -112,12 +112,12 @@ public void setTokenFilter(TokenFilter setTokenFilter) { } @SuppressWarnings("unchecked") // consistent use of the cache results in the same type - public ReturnType parseNode( + public N parseNode( String input, ASTNode parentTreeMember, - Class ruleType, - Function parseMethod, - BiFunction visitMethod) throws RecognitionException { + Class ruleType, + Function parseMethod, + BiFunction visitMethod) throws RecognitionException { if (ruleType == TranslationUnitContext.class) { throw new IllegalArgumentException("Translation units may not be parsed into another node, that makes no sense."); } @@ -126,24 +126,24 @@ public ReturnTy return ASTBuilder.buildSubtree(parentTreeMember, parser.parse(input, ruleType, parseMethod), visitMethod); } else { // cache and possibly build, always clone to return new trees - return (ReturnType) buildCache.cachedGet(input, ruleType, + return (N) buildCache.cachedGet(input, ruleType, () -> ASTBuilder.build(new EmptyRoot(), parser.parse(input, ruleType, parseMethod), visitMethod)) .cloneInto(parentTreeMember); } } @SuppressWarnings("unchecked") // consistent use of the cache results in the same type - public ReturnType parseNodeSeparate( + public N parseNodeSeparate( String input, - Class ruleType, - Function parseMethod, - BiFunction visitMethod) throws RecognitionException { + Class ruleType, + Function parseMethod, + BiFunction visitMethod) throws RecognitionException { if (astCacheStrategy == ASTCacheStrategy.NONE || astCacheStrategy == ASTCacheStrategy.ALL_EXCLUDING_TRANSLATION_UNIT && ruleType == TranslationUnitContext.class) { return ASTBuilder.build(parser.parse(input, ruleType, parseMethod), visitMethod); } else { - return (ReturnType) buildCache.cachedGet(input, ruleType, + return (N) buildCache.cachedGet(input, ruleType, () -> ASTBuilder.build(new EmptyRoot(), parser.parse(input, ruleType, parseMethod), visitMethod)) .cloneSeparate(); } diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/ASTTransformer.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/ASTTransformer.java index 1de7b793..36cce1bf 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/ASTTransformer.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/ASTTransformer.java @@ -8,19 +8,19 @@ * the same kind of output. The implementations of this class determine how it * works in detail. */ -public abstract class ASTTransformer extends ASTParser - implements ParameterizedTransformer { - private T jobParameters; +public abstract class ASTTransformer extends ASTParser + implements ParameterizedTransformer { + private J jobParameters; private static final PrintType defaultPrintType = PrintType.COMPACT; private PrintType printType = defaultPrintType; @Override - public T getJobParameters() { + public J getJobParameters() { return jobParameters; } @Override - public void setJobParameters(T parameters) { + public void setJobParameters(J parameters) { jobParameters = parameters; } @@ -28,7 +28,7 @@ public void setJobParameters(T parameters) { @SuppressWarnings("unchecked") public void setTokenFilter(TokenFilter tokenFilter) { super.setTokenFilter(tokenFilter); - ((TokenFilter) tokenFilter).setJobParametersSupplier(this::getJobParameters); + ((TokenFilter) tokenFilter).setJobParametersSupplier(this::getJobParameters); } public void setPrintType(PrintType printType) { diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/EnumASTTransformer.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/EnumASTTransformer.java index a1d9a91d..2e44ab6b 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/EnumASTTransformer.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/EnumASTTransformer.java @@ -5,8 +5,8 @@ import io.github.douira.glsl_transformer.ast.node.TranslationUnit; -public class EnumASTTransformer> - extends GroupedASTTransformer, EnumMap> { +public class EnumASTTransformer> + extends GroupedASTTransformer, EnumMap> { public EnumASTTransformer(Consumer> transformation, Class enumClass) { super(transformation, () -> new EnumMap<>(enumClass), () -> new EnumMap<>(enumClass)); } diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/GroupedASTTransformer.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/GroupedASTTransformer.java index 24716c69..d0ef7d71 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/GroupedASTTransformer.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/GroupedASTTransformer.java @@ -11,8 +11,8 @@ /** * The grouped AST transformer parses multiple strings stored in an arbitrarily */ -public class GroupedASTTransformer, N extends Map> - extends ASTTransformer> { +public class GroupedASTTransformer, N extends Map> + extends ASTTransformer> { private Consumer transformation; private Supplier tuMapSupplier; private Supplier resultMapSupplier; @@ -34,7 +34,7 @@ public GroupedASTTransformer( } public GroupedASTTransformer( - BiConsumer transformation, + BiConsumer transformation, Supplier tuMapSupplier, Supplier resultMapSupplier) { setTransformation(transformation); @@ -53,7 +53,7 @@ public void setTransformation(Consumer transformation) { this.transformation = transformation; } - public void setTransformation(BiConsumer transformation) { + public void setTransformation(BiConsumer transformation) { this.transformation = trees -> transformation.accept(trees, getJobParameters()); } diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/ParameterHolder.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/ParameterHolder.java index 144fd1cf..5307ae56 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/ParameterHolder.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/ParameterHolder.java @@ -2,10 +2,10 @@ import java.util.function.Supplier; -public interface ParameterHolder { - T getJobParameters(); +public interface ParameterHolder { + J getJobParameters(); - void setJobParameters(T parameters); + void setJobParameters(J parameters); /** * Runs a function with job parameters available set in the context. @@ -16,7 +16,7 @@ public interface ParameterHolder { * job parameters * @return The value returned by the supplier function */ - default R withJobParameters(T parameters, Supplier run) { + default R withJobParameters(J parameters, Supplier run) { setJobParameters(parameters); var value = run.get(); setJobParameters(null); diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/ParameterizedTransformer.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/ParameterizedTransformer.java index e61ce05b..ef849a1f 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/ParameterizedTransformer.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/ParameterizedTransformer.java @@ -2,8 +2,8 @@ import org.antlr.v4.runtime.RecognitionException; -public interface ParameterizedTransformer extends ParameterHolder, Transformer { - default V transform(V str, T parameters) throws RecognitionException { +public interface ParameterizedTransformer extends ParameterHolder, Transformer { + default V transform(V str, J parameters) throws RecognitionException { return withJobParameters(parameters, () -> transform(str)); } } diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/SingleASTTransformer.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/SingleASTTransformer.java index 1e45293c..1bd71ed0 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/SingleASTTransformer.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/SingleASTTransformer.java @@ -13,7 +13,7 @@ * The AST transformer takes parses a string, turns it into an AST, transforms * it with the given transformation and then prints it back. */ -public class SingleASTTransformer extends ASTTransformer { +public class SingleASTTransformer extends ASTTransformer { public static final Consumer IDENTITY_TRANSFORMATION = (tu) -> { }; @@ -32,7 +32,7 @@ public SingleASTTransformer(BiConsumer transformation) { setTransformation(transformation); } - public SingleASTTransformer(TriConsumer transformation) { + public SingleASTTransformer(TriConsumer transformation) { super(); setTransformation(transformation); } @@ -45,7 +45,7 @@ public void setTransformation(BiConsumer transformation) this.transformation = wrapTransformation(this, transformation); } - public void setTransformation(TriConsumer transformation) { + public void setTransformation(TriConsumer transformation) { this.transformation = wrapTransformation(this, transformation); } diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/Template.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/Template.java index 3e4ac190..5f1c6027 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/Template.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/Template.java @@ -9,17 +9,17 @@ import io.github.douira.glsl_transformer.ast.node.statement.Statement; import io.github.douira.glsl_transformer.ast.query.Root; -public class Template { +public class Template { private final Map> replacements = new HashMap<>(); private int localReplacementsMarked = 0; private List localReplacements = Collections.emptyList(); - protected final T source; + protected final N source; - public Template(T source) { + public Template(N source) { this.source = source; } - public T getSource() { + public N getSource() { return source; } @@ -35,18 +35,18 @@ public R getReplacement(R original) { } @SuppressWarnings("unchecked") // all ASTNodes clone themselves with the right type - public T getSeparateInstance() { - return (T) source.cloneSeparate(); + public N getSeparateInstance() { + return (N) source.cloneSeparate(); } @SuppressWarnings("unchecked") // all ASTNodes clone themselves with the right type - public T getInstanceFor(Root root) { - return (T) source.cloneInto(root); + public N getInstanceFor(Root root) { + return (N) source.cloneInto(root); } @SuppressWarnings("unchecked") // all ASTNodes clone themselves with the right type - public T getInstanceFor(ASTNode treeMember) { - return (T) source.cloneInto(treeMember); + public N getInstanceFor(ASTNode treeMember) { + return (N) source.cloneInto(treeMember); } public void supplyLocalReplacements(List replacements) { @@ -68,47 +68,47 @@ public void supplyLocalReplacements(ASTNode... replacements) { supplyLocalReplacements(Arrays.asList(replacements)); } - public T getSeparateInstance(List localReplacements) { + public N getSeparateInstance(List localReplacements) { supplyLocalReplacements(localReplacements); return getSeparateInstance(); } - public T getInstanceFor(Root root, List localReplacements) { + public N getInstanceFor(Root root, List localReplacements) { supplyLocalReplacements(localReplacements); return getInstanceFor(root); } - public T getInstanceFor(ASTNode treeMember, List localReplacements) { + public N getInstanceFor(ASTNode treeMember, List localReplacements) { supplyLocalReplacements(localReplacements); return getInstanceFor(treeMember); } - public T getSeparateInstance(ASTNode localReplacement) { + public N getSeparateInstance(ASTNode localReplacement) { supplyLocalReplacements(localReplacement); return getSeparateInstance(); } - public T getInstanceFor(Root root, ASTNode localReplacement) { + public N getInstanceFor(Root root, ASTNode localReplacement) { supplyLocalReplacements(localReplacement); return getInstanceFor(root); } - public T getInstanceFor(ASTNode treeMember, ASTNode localReplacement) { + public N getInstanceFor(ASTNode treeMember, ASTNode localReplacement) { supplyLocalReplacements(localReplacement); return getInstanceFor(treeMember); } - public T getSeparateInstance(ASTNode... localReplacements) { + public N getSeparateInstance(ASTNode... localReplacements) { supplyLocalReplacements(localReplacements); return getSeparateInstance(); } - public T getInstanceFor(Root root, ASTNode... localReplacements) { + public N getInstanceFor(Root root, ASTNode... localReplacements) { supplyLocalReplacements(localReplacements); return getInstanceFor(root); } - public T getInstanceFor(ASTNode treeMember, ASTNode... localReplacements) { + public N getInstanceFor(ASTNode treeMember, ASTNode... localReplacements) { supplyLocalReplacements(localReplacements); return getInstanceFor(treeMember); } @@ -138,13 +138,13 @@ public void markReplacement(ASTNode original, Supplier replacement) { } @SuppressWarnings("unchecked") - public void markReplacement(String tag, Class type, Supplier replacement) { + public void markReplacement(String tag, Class type, Supplier replacement) { markReplacement(source.getRoot().identifierIndex.getOne(tag).getAncestor(type), (Supplier) replacement); } @SuppressWarnings("unchecked") // all ASTNodes clone themselves with the right type - public static Template ofCloned(T source) { - return new Template((T) source.cloneSeparate()); + public static Template ofCloned(N source) { + return new Template((N) source.cloneSeparate()); } public static Template withExternalDeclaration(String input) { diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/TriASTTransformer.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/TriASTTransformer.java index ec8ec474..5aa6436e 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/TriASTTransformer.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/TriASTTransformer.java @@ -8,7 +8,7 @@ import io.github.douira.glsl_transformer.ast.node.TranslationUnit; import io.github.douira.glsl_transformer.util.*; -public class TriASTTransformer> extends EnumASTTransformer { +public class TriASTTransformer> extends EnumASTTransformer { private final E aType, bType, cType; private final Class enumClass; @@ -54,7 +54,7 @@ public TriASTTransformer( } public TriASTTransformer( - TriFullTransformation transformation, + TriFullTransformation transformation, Class enumClass, E aType, E bType, @@ -79,7 +79,7 @@ public void setTransformation(TriRootOnlyTransformation transfo }); } - public void setTransformation(TriFullTransformation transformation) { + public void setTransformation(TriFullTransformation transformation) { super.setTransformation(map -> { final var a = map.get(aType); final var b = map.get(bType); @@ -106,7 +106,7 @@ public EnumMap transform(String a, String b, String c) return transform(items); } - public EnumMap transform(String a, String b, String c, T parameters) + public EnumMap transform(String a, String b, String c, J parameters) throws RecognitionException { return withJobParameters(parameters, () -> transform(a, b, c)); } @@ -116,7 +116,7 @@ public Triple transform(Triple str) throws RecognitionException return new Triple<>(result.get(aType), result.get(bType), result.get(cType)); } - public Triple transform(Triple str, T parameters) throws RecognitionException { + public Triple transform(Triple str, J parameters) throws RecognitionException { return withJobParameters(parameters, () -> transform(str)); } } diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/TriFullTransformation.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/TriFullTransformation.java index 45aecc8d..1237dccf 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/TriFullTransformation.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/TriFullTransformation.java @@ -4,6 +4,6 @@ import io.github.douira.glsl_transformer.ast.query.Root; @FunctionalInterface -public interface TriFullTransformation { - void accept(A a, A b, A c, Root rootA, Root rootB, Root rootC, T jobParameters); +public interface TriFullTransformation { + void accept(N a, N b, N c, Root rootA, Root rootB, Root rootC, J jobParameters); } diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/TriRootOnlyTransformation.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/TriRootOnlyTransformation.java index 1a5cc864..e8f3b7f5 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/TriRootOnlyTransformation.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/transform/TriRootOnlyTransformation.java @@ -4,6 +4,6 @@ import io.github.douira.glsl_transformer.ast.query.Root; @FunctionalInterface -public interface TriRootOnlyTransformation { - void accept(A a, A b, A c, Root rootA, Root rootB, Root rootC); +public interface TriRootOnlyTransformation { + void accept(N a, N b, N c, Root rootA, Root rootB, Root rootC); } diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/traversal/ASTListenerVisitor.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/traversal/ASTListenerVisitor.java index 86b016c3..69583bcc 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/traversal/ASTListenerVisitor.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/traversal/ASTListenerVisitor.java @@ -7,8 +7,8 @@ public ASTListenerVisitor() { this.listener = this; } - public static T walkAndListen(ASTNode node) { - return new ASTListenerVisitor().visit(node); + public static R walkAndListen(ASTNode node) { + return new ASTListenerVisitor().visit(node); } @Override diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/traversal/ASTWalker.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/traversal/ASTWalker.java index af16f8b5..ddb94a25 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/traversal/ASTWalker.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/ast/traversal/ASTWalker.java @@ -12,8 +12,8 @@ private ASTWalker(ASTListener listener) { this.listener = listener; } - public static T walk(ASTListener listener, ASTNode node) { - return new ASTWalker(listener).startVisit(node); + public static R walk(ASTListener listener, ASTNode node) { + return new ASTWalker(listener).startVisit(node); } @Override diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/parser/CachingParser.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/parser/CachingParser.java index 59b4f72f..bab3564f 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/parser/CachingParser.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/parser/CachingParser.java @@ -48,21 +48,21 @@ public TranslationUnitContext parse(String str) { } @Override - public RuleType parse( + public C parse( String str, - Class ruleType, - Function parseMethod) { + Class ruleType, + Function parseMethod) { return parse(str, null, ruleType, parseMethod); } @Override @SuppressWarnings("unchecked") - public RuleType parse( + public C parse( String str, ParserRuleContext parent, - Class ruleType, - Function parseMethod) { - return (RuleType) parseCache.cachedGet(str, ruleType, + Class ruleType, + Function parseMethod) { + return (C) parseCache.cachedGet(str, ruleType, () -> parse(str, parent, parseMethod)); } diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/parser/EnhancedParser.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/parser/EnhancedParser.java index a5124ebc..9655d947 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/parser/EnhancedParser.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/parser/EnhancedParser.java @@ -201,45 +201,45 @@ public TranslationUnitContext parse(String str) { /** * Parses a string using a parser method reference into a parse tree. * - * @param The type of the resulting parsed node + * @param The type of the resulting parsed node * @param str The string to parse * @param parseMethod The parser method reference to use for parsing * @return The parsed string as a parse tree that has the given type */ - public RuleType parse( + public C parse( String str, - Function parseMethod) { + Function parseMethod) { return parse(str, (ParserRuleContext) null, parseMethod); } - public RuleType parse( + public C parse( String str, - Class ruleType, - Function parseMethod) { + Class ruleType, + Function parseMethod) { return parse(str, (ParserRuleContext) null, parseMethod); } /** * Parses a string using a parser method reference into a parse tree. * - * @param The type of the resulting parsed node + * @param The type of the resulting parsed node * @param str The string to parse * @param parent The parent to attach to the parsed node * @param parseMethod The parser method reference to use for parsing * @return The parsed string as a parse tree that has the given type */ - public RuleType parse( + public C parse( String str, ParserRuleContext parent, - Function parseMethod) { + Function parseMethod) { return parse(CharStreams.fromString(str), parent, parseMethod); } - public RuleType parse( + public C parse( String str, ParserRuleContext parent, - Class ruleType, - Function parseMethod) { + Class ruleType, + Function parseMethod) { return parse(CharStreams.fromString(str), parent, parseMethod); } @@ -248,16 +248,16 @@ public RuleType parse( * reference into a parse tree. This method exists so non-string streams can * also be parsed. * - * @param The type of the resulting parsed node + * @param The type of the resulting parsed node * @param stream The int stream to parse * @param parent The parent to attach to the parsed node * @param parseMethod The parser method reference to use for parsing * @return The parsed string as a parse tree that has the given type */ - private RuleType parse( + private C parse( IntStream stream, ParserRuleContext parent, - Function parseMethod) { + Function parseMethod) { // setup lexer input = stream; lexer.setInputStream(input); @@ -274,7 +274,7 @@ private RuleType parse( parser.setTokenStream(tokenStream); parser.reset(); - RuleType node; + C node; if (parsingStrategy == ParsingStrategy.SLL_AND_LL_ON_ERROR) { // never throw SLL errors parser.removeErrorListener(ThrowingErrorListener.INSTANCE); diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/token_filter/ChannelFilter.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/token_filter/ChannelFilter.java index d86c5894..c10158a8 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/token_filter/ChannelFilter.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/token_filter/ChannelFilter.java @@ -10,7 +10,7 @@ * The channel filter accepts all tokens that are not from a lexer channel that * is on the given list of disallowed channels. */ -public class ChannelFilter extends TokenFilter { +public class ChannelFilter extends TokenFilter { private final EnumSet disallowedChannels; /** diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/token_filter/MultiFilter.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/token_filter/MultiFilter.java index 08452c8d..17e0e6a6 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/token_filter/MultiFilter.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/token_filter/MultiFilter.java @@ -18,8 +18,8 @@ * filter has disallowed it. Since filters can have state, it can be desirerable * to notify all of them of all tokens. */ -public class MultiFilter extends TokenFilter { - private Collection> subfilters; +public class MultiFilter extends TokenFilter { + private Collection> subfilters; /** * If this is true, then it will require all filters to allow a token for it to @@ -44,7 +44,7 @@ public class MultiFilter extends TokenFilter { * @param conjunction The conjunction flag state * @param shortCircuit The short circuit flag state */ - public MultiFilter(Collection> subfilters, boolean conjunction, boolean shortCircuit) { + public MultiFilter(Collection> subfilters, boolean conjunction, boolean shortCircuit) { this(subfilters); this.conjunction = conjunction; this.shortCircuit = shortCircuit; @@ -104,7 +104,7 @@ public MultiFilter() { * * @param subfilters The subfilters to add initially */ - public MultiFilter(Collection> subfilters) { + public MultiFilter(Collection> subfilters) { this.subfilters = new ArrayList<>(subfilters); } @@ -132,7 +132,7 @@ public void setShortCircuit(boolean shortCircuit) { * @param filter The filter to add * @return {@code true} if the underlying collection changed */ - public boolean add(TokenFilter filter) { + public boolean add(TokenFilter filter) { return subfilters.add(filter); } @@ -142,7 +142,7 @@ public boolean add(TokenFilter filter) { * @param newSubfilters The filters to add * @return {@code true} if the underlying collection changed */ - public boolean addAll(Collection> newSubfilters) { + public boolean addAll(Collection> newSubfilters) { return subfilters.addAll(newSubfilters); } @@ -153,7 +153,7 @@ public boolean addAll(Collection> newSubfilters) { * @param other The other multi filter to take subfilters from * @return {@code true} if the underlying collection changed */ - public boolean addAll(MultiFilter other) { + public boolean addAll(MultiFilter other) { return addAll(other.subfilters); } @@ -161,8 +161,8 @@ public boolean addAll(MultiFilter other) { * Creates a shallow clone of this multi filter. It copies over the collection * of subfilters shallowly and copies the settings. */ - public MultiFilter clone() { - return new MultiFilter(subfilters, conjunction, shortCircuit); + public MultiFilter clone() { + return new MultiFilter(subfilters, conjunction, shortCircuit); } @Override @@ -174,7 +174,7 @@ public void resetState() { } @Override - public void setJobParametersSupplier(Supplier jobParametersSupplier) { + public void setJobParametersSupplier(Supplier jobParametersSupplier) { super.setJobParametersSupplier(jobParametersSupplier); for (var filter : subfilters) { filter.setJobParametersSupplier(jobParametersSupplier); diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/token_filter/NewlineFilter.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/token_filter/NewlineFilter.java index fc6b5934..8330a2a1 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/token_filter/NewlineFilter.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/token_filter/NewlineFilter.java @@ -9,7 +9,7 @@ * The newline filter filters out regular unnecessary newlines if there is more * than one. */ -public class NewlineFilter extends TokenFilter { +public class NewlineFilter extends TokenFilter { private boolean lastWasNewline; @Override diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/token_filter/StringFilter.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/token_filter/StringFilter.java index e1857550..ed94f6a9 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/token_filter/StringFilter.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/token_filter/StringFilter.java @@ -11,7 +11,7 @@ * The string token filter disallows tokens that are matched against a set of * disallowed strings. */ -public class StringFilter extends TokenFilter { +public class StringFilter extends TokenFilter { private Set disallowed; /** diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/token_filter/TokenFilter.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/token_filter/TokenFilter.java index d7b89f6c..bce13e05 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/token_filter/TokenFilter.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/token_filter/TokenFilter.java @@ -10,8 +10,8 @@ * A token filter is an object that can check if given tokens should be printed * or not. */ -public abstract class TokenFilter { - private Supplier jobParametersSupplier; +public abstract class TokenFilter { + private Supplier jobParametersSupplier; /** * Checks if the token should be printed. @@ -32,7 +32,7 @@ public void resetState() { * * @param jobParametersSupplier The job parameters supplier */ - public void setJobParametersSupplier(Supplier jobParametersSupplier) { + public void setJobParametersSupplier(Supplier jobParametersSupplier) { this.jobParametersSupplier = jobParametersSupplier; } @@ -41,7 +41,7 @@ public void setJobParametersSupplier(Supplier jobParametersSupplier) { * * @return The job parameters */ - protected T getJobParameters() { + protected J getJobParameters() { return jobParametersSupplier.get(); } @@ -54,20 +54,20 @@ protected T getJobParameters() { * If a multi filter is generated, the settings from the first multi filter in * the parameters are copied. * - * @param The job parameter type + * @param The job parameter type * @param a A token filter. May be {@code null}. * @param b A token filter. May be {@code null}. * @return The joined token filter */ - public static TokenFilter join(TokenFilter a, TokenFilter b) { + public static TokenFilter join(TokenFilter a, TokenFilter b) { if (a == null) { return b; } else if (b == null) { return a; } else if (MultiFilter.class.isInstance(b)) { if (MultiFilter.class.isInstance(a)) { - MultiFilter bMulti = (MultiFilter) b; - MultiFilter aMulti = (MultiFilter) a; + MultiFilter bMulti = (MultiFilter) b; + MultiFilter aMulti = (MultiFilter) a; var multi = aMulti.clone(); multi.addAll(bMulti); return multi; @@ -75,12 +75,12 @@ public static TokenFilter join(TokenFilter a, To return join(b, a); } } else if (MultiFilter.class.isInstance(a)) { - MultiFilter aMulti = (MultiFilter) a; + MultiFilter aMulti = (MultiFilter) a; var multi = aMulti.clone(); multi.add(b); return multi; } else { - var multi = new MultiFilter(); + var multi = new MultiFilter(); multi.add(a); multi.add(b); return multi; diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/util/CompatUtil.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/util/CompatUtil.java index 0125ed02..a0d694f8 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/util/CompatUtil.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/util/CompatUtil.java @@ -40,24 +40,24 @@ public static String repeat(String str, int n) { * Creates a {@link java.util.HashSet} that contains the given items. The heap * pollution warning is suppressed as it is in {@link java.util.Arrays}. * - * @param The type of the items + * @param The type of the items * @param items The items to add to the set * @return The set with the given items */ @SafeVarargs - public static Set setOf(T... items) { + public static Set setOf(V... items) { return new HashSet<>(Arrays.asList(items)); } /** * Creates a {@link java.util.HashSet} that contains the given item. * - * @param The type of the item + * @param The type of the item * @param item The item to add to the set * @return The set with the given item */ - public static Set setOf(T item) { - var set = new HashSet(); + public static Set setOf(V item) { + var set = new HashSet(); set.add(item); return set; } @@ -65,13 +65,13 @@ public static Set setOf(T item) { /** * Creates a {@link java.util.HashSet} that contains the given items. * - * @param The type of the items + * @param The type of the items * @param itemA The first item to add to the set * @param itemB The second item to add to the set * @return The set with the given items */ - public static Set setOf(T itemA, T itemB) { - var set = new HashSet(); + public static Set setOf(V itemA, V itemB) { + var set = new HashSet(); set.add(itemA); set.add(itemB); return set; @@ -82,12 +82,12 @@ public static Set setOf(T itemA, T itemB) { * same order. This is likely cheaper for making a collection than using * {@link #setOf(Object...)}. * - * @param The type of the items + * @param The type of the items * @param items The items to create the list out of * @return The list with the given items */ @SafeVarargs - public static List listOf(T... items) { + public static List listOf(V... items) { return Arrays.asList(items); } @@ -125,7 +125,7 @@ public static List listOf(T... items) { * predicate for subsequent elements. For any given element an action may * be performed in whatever thread the library chooses. * - * @param the type of stream elements + * @param the type of stream elements * @param seed the initial element * @param hasNext a predicate to apply to elements to determine when the * stream must terminate. @@ -134,20 +134,20 @@ public static List listOf(T... items) { * @return a new sequential {@code Stream} * @implNote The implementation was taken from the JDK 9 source code. */ - public static Stream iterateStream(T seed, Predicate hasNext, UnaryOperator next) { + public static Stream iterateStream(V seed, Predicate hasNext, UnaryOperator next) { Objects.requireNonNull(next); Objects.requireNonNull(hasNext); - Spliterator spliterator = new Spliterators.AbstractSpliterator<>(Long.MAX_VALUE, + Spliterator spliterator = new Spliterators.AbstractSpliterator<>(Long.MAX_VALUE, Spliterator.ORDERED | Spliterator.IMMUTABLE) { - T prev; + V prev; boolean started, finished; @Override - public boolean tryAdvance(Consumer action) { + public boolean tryAdvance(Consumer action) { Objects.requireNonNull(action); if (finished) return false; - T t; + V t; if (started) t = next.apply(prev); else { @@ -164,12 +164,12 @@ public boolean tryAdvance(Consumer action) { } @Override - public void forEachRemaining(Consumer action) { + public void forEachRemaining(Consumer action) { Objects.requireNonNull(action); if (finished) return; finished = true; - T t = started ? next.apply(prev) : seed; + V t = started ? next.apply(prev) : seed; prev = null; while (hasNext.test(t)) { action.accept(t); diff --git a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/util/ConfigUtil.java b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/util/ConfigUtil.java index 92baa18a..72a116ff 100644 --- a/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/util/ConfigUtil.java +++ b/glsl-transformer/src/main/java/io/github/douira/glsl_transformer/util/ConfigUtil.java @@ -14,12 +14,12 @@ public class ConfigUtil { * writing getter methods in core classes that use the chaining configuration * pattern. * - * @param The value type + * @param The value type * @param setValue The value set for this configuration by the user * @param defaultGenerator The default value generator * @return The set value or the generated value */ - public static V withDefault(V setValue, Supplier defaultGenerator) { + public static R withDefault(R setValue, Supplier defaultGenerator) { return setValue == null ? withDefault(setValue, defaultGenerator.get()) : setValue; } @@ -29,26 +29,26 @@ public static V withDefault(V setValue, Supplier defaultGenerator) { * methods in core classes that use the chaining configuration pattern. Note * that nothing special happens if the set value generator returns null. * - * @param The value type + * @param The value type * @param setValueSupplier The value generator set for this configuration by the * user * @param defaultValue The default value * @return The generated value or the default value */ - public static V withDefault(Supplier setValueSupplier, V defaultValue) { - return setValueSupplier == null ? withDefault((V) null, defaultValue) : setValueSupplier.get(); + public static R withDefault(Supplier setValueSupplier, R defaultValue) { + return setValueSupplier == null ? withDefault((R) null, defaultValue) : setValueSupplier.get(); } /** * Returns the set value if it is not null and returns the default value * otherwise. If the default is also null it throws an error. * - * @param The value type + * @param The value type * @param setValue The value set for this configuration by the user * @param defaultValue The default value * @return The set value or the default value */ - public static V withDefault(V setValue, V defaultValue) { + public static R withDefault(R setValue, R defaultValue) { if (setValue == null) { Objects.requireNonNull(defaultValue, "Generated default value is null!"); return defaultValue; diff --git a/glsl-transformer/src/test/java/io/github/douira/glsl_transformer/token_filter/MultiFilterTest.java b/glsl-transformer/src/test/java/io/github/douira/glsl_transformer/token_filter/MultiFilterTest.java index 15af0413..d2077037 100644 --- a/glsl-transformer/src/test/java/io/github/douira/glsl_transformer/token_filter/MultiFilterTest.java +++ b/glsl-transformer/src/test/java/io/github/douira/glsl_transformer/token_filter/MultiFilterTest.java @@ -11,15 +11,15 @@ public class MultiFilterTest { int nextIndex; - static void assertPrintFilterResult( - String expected, String input, T parameters, TokenFilter filter, String message) { - var t = new SingleASTTransformer(SingleASTTransformer.IDENTITY_TRANSFORMATION); + static void assertPrintFilterResult( + String expected, String input, J parameters, TokenFilter filter, String message) { + var t = new SingleASTTransformer(SingleASTTransformer.IDENTITY_TRANSFORMATION); t.setTokenFilter(filter); assertEquals(expected, t.transform(input, parameters), message); } - static void assertPrintFilterResult( - String expected, String input, TokenFilter filter, String message) { + static void assertPrintFilterResult( + String expected, String input, TokenFilter filter, String message) { assertPrintFilterResult(expected, input, null, filter, message); }