Skip to content

Add Java-cpg language module with cpg version 8.3.0#2767

Open
LundiNord wants to merge 32 commits intojplag:developfrom
LundiNord:cpg-8.3.0
Open

Add Java-cpg language module with cpg version 8.3.0#2767
LundiNord wants to merge 32 commits intojplag:developfrom
LundiNord:cpg-8.3.0

Conversation

@LundiNord
Copy link

@LundiNord LundiNord commented Dec 24, 2025

JPlag currently is vulnerable to attacks like changing for loops to while loops.
The Java CPG language module in this PR solves this by using a Code Property Graph (CPG) and normalizing/standardizing the resulting code graph. The graph is then converted into tokens.

robinmaisch and others added 30 commits December 29, 2023 11:55
Content:
 - A new CPG language frontend for JPlag
 - An interface to transform submissions into CPGs
 - An interface to transform CPGs into token lists
 - A Graph Transformation Engine (to be extended)
   . interfaces representing node and graph patterns, matches of these patterns, transformations
   . an isomorphism detector
   . a transformation algorithm
 - Some graph transformations (to be extended)
- implemented multi-root graph patterns
- implemented searching for "all matches at once"
- GraphOperations should leave EOG intact
- implemented new kinds of edges and properties for graph patterns
- tokenization works well
- implemented DFG sort pass
-- this requires specialized treatment for all kinds of language features. Surely the considered feature set is incomplete.
It was designed for local use.
Add many comments and put a file in the 'passes' package. When JavaDoc cannot find a Java file in there, it quits.
Copilot AI review requested due to automatic review settings December 24, 2025 10:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new Java-cpg language module that uses CPG (Code Property Graph) version 8.3.0 for enhanced Java code analysis. The implementation includes comprehensive graph transformation capabilities, pattern matching, and visitor-based token extraction.

Key Changes:

  • Added new java-cpg language module with CPG integration
  • Implemented graph transformation framework for code normalization
  • Added comprehensive test resources covering various Java patterns
  • Updated UI components to recognize the new language variant

Reviewed changes

Copilot reviewed 103 out of 104 changed files in this pull request and generated 59 comments.

Show a summary per file
File Description
report-viewer/model/src/Language.ts Added JAVA_CPG enum value for new language support
report-viewer/ui-components/widget/fileDisplaying/CodeHighlighter.ts Added case for JAVA_CPG to use Java syntax highlighting
pom.xml Formatted maven-surefire-plugin argLine for readability
languages/pom.xml Added java-cpg module to language modules list
languages/java-cpg/src/test/resources/** Added comprehensive Java test files for various transformations
languages/java-cpg/src/test/java/** Added test infrastructure and transformation tests
languages/java-cpg/src/main/java/** Core implementation: visitors, transformations, pattern matching, operations
.gitignore Added .factorypath and website to ignored files

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

newSource = (NodePattern<T2>) source;
} else {

boolean disconnectEog = this.phase.disconnectEog && incomingEdge.isAst();
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable incomingEdge may be null at this access because of this null argument.

Copilot uses AI. Check for mistakes.
// // empty dummy implementation
// }

void exit(ValueDeclaration valueDeclaration) {
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.

Copilot uses AI. Check for mistakes.
// empty dummy implementation
}

void exit(TypeParameterDeclaration typeParameterDeclaration) {
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.

Copilot uses AI. Check for mistakes.
// empty dummy implementation
}

void exit(TupleDeclaration tupleDeclaration) {
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.

Copilot uses AI. Check for mistakes.
void exit(ShortCircuitOperator shortCircuitOperator) {
// empty dummy implementation
}

Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.
Method ACpgNodeListener.exit(..) could be confused with overloaded method exit, since dispatch depends on static types.

Suggested change
@SuppressWarnings("java/confusing-overload")

Copilot uses AI. Check for mistakes.
return this.multiEdge;
}

public List<R> getTarget(T from) {
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method overrides Relation<T,R,List>.getTarget; it is advisable to add an Override annotation.

Copilot uses AI. Check for mistakes.
return cpgEdge.getRelated(from);
}

public <C extends T> void recursiveMatch(NodePattern<C> pattern, T parent, List<Match> openMatches) {
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method overrides Relation<T,R,R>.recursiveMatch; it is advisable to add an Override annotation.

Copilot uses AI. Check for mistakes.
return cpgEdge;
}

public R getTarget(T from) {
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method overrides Relation<T,R,R>.getTarget; it is advisable to add an Override annotation.

Copilot uses AI. Check for mistakes.

}

public <T2 extends Node> RemoveOperation<T2, R> fromWildcardMatch(NodePattern<? extends T2> pattern, CpgEdge<T2, R> edge) {
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method overrides GraphOperationImpl<T,R>.fromWildcardMatch; it is advisable to add an Override annotation.

Copilot uses AI. Check for mistakes.
return match.instantiateGraphOperation(wcParent, this);
}

public <T2 extends Node> ReplaceOperation<T2, R> fromWildcardMatch(NodePattern<? extends T2> pattern, CpgEdge<T2, R> edge) {
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method overrides GraphOperationImpl<T,R>.fromWildcardMatch; it is advisable to add an Override annotation.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments