forked from jplag/JPlag
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add many comments and put a file in the 'passes' package. When JavaDoc cannot find a Java file in there, it quits.
- Loading branch information
1 parent
eb592f0
commit 88dd331
Showing
45 changed files
with
1,170 additions
and
448 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
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
76 changes: 76 additions & 0 deletions
76
languages/java-cpg/src/main/java/de/jplag/java_cpg/passes/JTokenizationPass.java
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,76 @@ | ||
package de.jplag.java_cpg.passes; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import de.fraunhofer.aisec.cpg.TranslationContext; | ||
import de.fraunhofer.aisec.cpg.TranslationResult; | ||
import de.fraunhofer.aisec.cpg.graph.Name; | ||
import de.fraunhofer.aisec.cpg.helpers.SubgraphWalker; | ||
import de.fraunhofer.aisec.cpg.passes.TranslationResultPass; | ||
import de.jplag.Token; | ||
import de.jplag.TokenType; | ||
import de.jplag.java_cpg.token.CpgNodeListener; | ||
import de.jplag.java_cpg.token.CpgToken; | ||
import de.jplag.java_cpg.token.CpgTokenConsumer; | ||
import de.jplag.java_cpg.visitorStrategy.NodeOrderStrategy; | ||
|
||
/** | ||
* This pass tokenizes the {@link de.fraunhofer.aisec.cpg.TranslationResult}. It is a duplicate of | ||
* de.jplag.java_cpg.passes.TokenizationPass implemented in Java as a workaround to make JavaDoc work. If the package | ||
* 'passes' contains only Kotlin files, JavaDoc fails. | ||
*/ | ||
public class JTokenizationPass extends TranslationResultPass { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(TokenizationPass.class); | ||
private final ArrayList<Token> tokenList = new ArrayList<>(); | ||
private final CpgTokenConsumer consumer = new ConcreteCpgTokenConsumer(); | ||
private final NodeOrderStrategy strategy = new NodeOrderStrategy(); | ||
Consumer<List<Token>> callback = null; | ||
|
||
/** | ||
* <p> | ||
* Constructor for JTokenizationPass. | ||
* </p> | ||
* @param ctx a {@link de.fraunhofer.aisec.cpg.TranslationContext} object | ||
*/ | ||
public JTokenizationPass(@NotNull TranslationContext ctx) { | ||
super(ctx); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
public void accept(TranslationResult translationResult) { | ||
tokenList.clear(); | ||
CpgNodeListener listener = new CpgNodeListener(consumer); | ||
SubgraphWalker.IterativeGraphWalker walker = new SubgraphWalker.IterativeGraphWalker(); | ||
walker.setStrategy(strategy::getIterator); | ||
walker.registerOnNodeVisit(listener::visit); | ||
walker.registerOnNodeExit(listener::exit); | ||
walker.iterate(translationResult); | ||
callback.accept(tokenList); | ||
} | ||
|
||
/** | ||
* <p> | ||
* cleanup. | ||
* </p> | ||
*/ | ||
public void cleanup() { | ||
logger.info("Found %d tokens".formatted(tokenList.size())); | ||
} | ||
|
||
private class ConcreteCpgTokenConsumer extends CpgTokenConsumer { | ||
public void addToken(TokenType type, File file, int rowBegin, int colBegin, int length, Name name) { | ||
CpgToken token = new CpgToken(type, file, rowBegin, colBegin, length, name); | ||
tokenList.add(token); | ||
} | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.