-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
160 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/test/resources/codegen/java/matcher_generator_only_holes_with_type.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2022 Ivan Kniazkov | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package org.uast; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.cqfn.astranaut.core.Matcher; | ||
import org.cqfn.astranaut.core.Node; | ||
|
||
/** | ||
* Checks if the node matches some structure, and extracts the data and children. | ||
* | ||
* @since 1.0 | ||
*/ | ||
public final class Matcher0 implements Matcher { | ||
/** | ||
* The instance. | ||
*/ | ||
public static final Matcher INSTANCE = new Matcher0(); | ||
|
||
/** | ||
* Expected node type. | ||
*/ | ||
private static final String EXPECTED_TYPE = "AAA"; | ||
|
||
/** | ||
* The number of the first hole. | ||
*/ | ||
private static final int FIRST_HOLE_ID = 1; | ||
|
||
/** | ||
* The type of the first hole. | ||
*/ | ||
private static final String FIRST_HOLE_TYPE = "BBB"; | ||
|
||
/** | ||
* The number of the second hole. | ||
*/ | ||
private static final int SECOND_HOLE_ID = 2; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
private Matcher0() { | ||
} | ||
|
||
@Override | ||
public boolean match(final Node node, | ||
final Map<Integer, List<Node>> children, | ||
final Map<Integer, String> data) { | ||
final boolean result = node.belongsToGroup(Matcher0.EXPECTED_TYPE); | ||
final LinkedList<Node> batch = new LinkedList<>(node.getChildrenList()); | ||
if (result) { | ||
final List<Node> list = new LinkedList<>(); | ||
while (!batch.isEmpty()) { | ||
final Node child = batch.pollFirst(); | ||
if (Matcher0.FIRST_HOLE_TYPE.equals(child.getTypeName())) { | ||
list.add(child); | ||
} else { | ||
batch.addFirst(child); | ||
break; | ||
} | ||
} | ||
children.put(Matcher0.FIRST_HOLE_ID, list); | ||
} | ||
if (result) { | ||
final List<Node> list = new LinkedList<>(); | ||
while (!batch.isEmpty()) { | ||
list.add(batch.pollFirst()); | ||
} | ||
children.put(Matcher0.SECOND_HOLE_ID, list); | ||
} | ||
return result; | ||
} | ||
} |