Skip to content

Commit fa74c65

Browse files
committed
fix: don't compute label unless necessary.
1 parent b19c007 commit fa74c65

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

gen.treesitter-ng/src/main/java/com/github/gumtreediff/gen/treesitterng/AbstractTreeSitterNgGenerator.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ private static String getLabel(List<String> contentLines, TSNode node) {
7272
// endColumn == startRowBytes.length + 1 when the label in tree-sitter contains line separator
7373
if (endColumn == startRowBytes.length + 1) {
7474
substringLines = Collections.singletonList(startRowStr);
75-
} else {
75+
}
76+
else {
7677
substringLines = Collections.singletonList(new String(
7778
startRowBytes, startColumn, endColumn - startColumn));
7879
}
79-
} else {
80+
}
81+
else {
8082
substringLines = new ArrayList<>();
8183
String endRowStr = contentLines.get(endRow);
8284
byte[] endRowBytes = endRowStr.getBytes();
@@ -92,14 +94,14 @@ private static String getLabel(List<String> contentLines, TSNode node) {
9294
String endLineSubstring;
9395
if (endColumn > endRowStr.length()) {
9496
endLineSubstring = endRowStr;
95-
} else {
97+
}
98+
else {
9699
endLineSubstring = new String(endRowBytes, 0, endColumn);
97100
}
98101
substringLines.add(startLineSubstring);
99102
substringLines.addAll(middleLines);
100103
substringLines.add(endLineSubstring);
101104
}
102-
103105
return String.join(System.lineSeparator(), substringLines);
104106
}
105107

@@ -118,7 +120,7 @@ private static int calculateOffset(List<String> contentLines, TSPoint point) {
118120
* try match node's type or node and its ancestors' types in given ruleSet.
119121
*
120122
* @param ruleSet a rule's list or rule's ketSet if the rule is a map.
121-
* @param node the node being to match.
123+
* @param node the node to match.
122124
* @return matched types. null if not matched.
123125
*/
124126
protected static String matchNodeOrAncestorTypes(Collection<String> ruleSet, TSNode node) {
@@ -154,7 +156,6 @@ protected static String matchNodeOrAncestorTypes(Collection<String> ruleSet, TSN
154156
protected static Pair<Tree, Boolean> tsNode2GumTree(
155157
List<String> contentLines, Map<String, Object> currentRule, TreeContext context, TSNode node) {
156158
String type = node.getType();
157-
String label = getLabel(contentLines, node);
158159
if (currentRule.containsKey(YAML_IGNORED)) {
159160
List<String> ignores = (List<String>) currentRule.get(YAML_IGNORED);
160161
if (matchNodeOrAncestorTypes(ignores, node) != null) {
@@ -185,6 +186,7 @@ protected static Pair<Tree, Boolean> tsNode2GumTree(
185186
Tree tree;
186187
// attach label for non ignore-label leafs or flattened nodes
187188
if ((node.getChildCount() == 0 && !ignoreLabel) || flatten) {
189+
String label = getLabel(contentLines, node);
188190
tree = context.createTree(TypeSet.type(type), label);
189191
}
190192
else {

0 commit comments

Comments
 (0)