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 extends T> c) {
+ public ProxyArrayList(Collection extends V> c) {
this(c, true);
}
- public ProxyArrayList(Collection extends T> c, boolean notifyInitial) {
+ public ProxyArrayList(Collection extends V> 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 extends T> collection) {
- for (var element : collection) {
+ void notifyAdditionSafe(Collection extends V> 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 extends T> collection) {
- for (var element : collection) {
+ private void notifyRemovalSafe(Collection extends V> 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 extends T> c) {
+ public boolean addAll(Collection extends V> c) {
var result = super.addAll(c);
if (result) {
notifyAdditionSafe(c);
@@ -103,7 +103,7 @@ public boolean addAll(Collection extends T> c) {
}
@Override
- public boolean addAll(int index, Collection extends T> c) {
+ public boolean addAll(int index, Collection extends V> c) {
var result = super.addAll(index, c);
if (result) {
notifyAdditionSafe(c);
@@ -112,8 +112,8 @@ public boolean addAll(int index, Collection extends T> 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 super T> filter) {
+ public boolean removeIf(Predicate super V> 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 extends NodeType> setter) {
+ public N setup(
+ N node,
+ Consumer extends N> 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 extends NodeType> setter) {
+ public void updateParents(
+ N currentNode,
+ N newNode,
+ Consumer extends N> 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 extends T> targets, Consumer super T> replacer) {
+ public boolean process(Stream extends N> targets, Consumer super N> 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 extends ASTNode> matchTargetChildren,
- Matcher matcher,
- Consumer super T> replacer) {
+ Matcher matcher,
+ Consumer super N> 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 super T> replacer) {
+ HintedMatcher hintedMatcher,
+ Consumer super N> 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 extends ASTNode> 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 extends ASTNode> 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