Skip to content

Commit

Permalink
Apply Spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
robinmaisch committed Mar 18, 2024
1 parent 4ed18ea commit 5536a3f
Show file tree
Hide file tree
Showing 25 changed files with 225 additions and 255 deletions.
6 changes: 6 additions & 0 deletions language-api/src/main/java/de/jplag/AbstractParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@
/**
* Abstract parser class. Counts errors and manages an error consumer.
* @author Emeric Kwemou
* @version $Id: $Id
*/
public abstract class AbstractParser {
public final Logger logger;

/**
* <p>
* Constructor for AbstractParser.
* </p>
*/
protected AbstractParser() {
this.logger = LoggerFactory.getLogger(this.getClass());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CpgAdapter {
private List<Token> tokenList;
private boolean reorderingEnabled = true;

public CpgAdapter(GraphTransformation<?>... transformations) {
public CpgAdapter(GraphTransformation... transformations) {
addTransformations(transformations);
}

Expand Down Expand Up @@ -85,11 +85,11 @@ private void setTokenList(List<Token> tokenList) {
* Registers the given transformations to be applied in the transformation step.
* @param transformations the transformations
*/
public void addTransformations(GraphTransformation<?>[] transformations) {
public void addTransformations(GraphTransformation[] transformations) {
Arrays.stream(transformations).forEach(this::addTransformation);
}

public void addTransformation(GraphTransformation<?> transformation) {
public void addTransformation(GraphTransformation transformation) {
switch (transformation.getPhase()) {
case OBLIGATORY -> PrepareTransformationPass.registerTransformation(transformation);
case AST_TRANSFORM -> AstTransformationPass.registerTransformation(transformation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public JavaCpgLanguage() {
* Adds the given {@link GraphTransformation} to the list to apply to the submissions.
* @param transformation the transformation
*/
public void addTransformation(GraphTransformation<?> transformation) {
public void addTransformation(GraphTransformation transformation) {
this.cpgAdapter.addTransformation(transformation);
}

/**
* Adds the given {@link GraphTransformation}s to the list to apply to the submissions.
* @param transformations the transformations
*/
public void addTransformations(GraphTransformation<?>[] transformations) {
public void addTransformations(GraphTransformation[] transformations) {
this.cpgAdapter.addTransformations(transformations);
}

Expand Down Expand Up @@ -78,15 +78,15 @@ public void resetTransformations() {
* Returns the set of transformations required to ensure that the tokenization works properly.
* @return the array of obligatory transformations
*/
private GraphTransformation<?>[] obligatoryTransformations() {
private GraphTransformation[] obligatoryTransformations() {
return new GraphTransformation[] {wrapThenStatement, wrapElseStatement, wrapForStatement, wrapWhileStatement, wrapDoStatement};
}

/**
* Returns a set of transformations suggested for use.
* @return the array of recommended transformations
*/
public GraphTransformation<?>[] standardTransformations() {
public GraphTransformation[] standardTransformations() {
return new GraphTransformation[] {removeOptionalOfCall, // 3
removeOptionalGetCall, // 4
moveConstantToOnlyUsingClass, // 6
Expand All @@ -100,7 +100,7 @@ public GraphTransformation<?>[] standardTransformations() {
* Returns a set of all transformations.
* @return the array of all transformations
*/
public GraphTransformation<?>[] allTransformations() {
public GraphTransformation[] allTransformations() {
return new GraphTransformation[] {ifWithNegatedConditionResolution, // 1
forStatementToWhileStatement, // 2
removeOptionalOfCall, // 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ abstract class ATransformationPass(ctx: TranslationContext) : TranslationResultP

override fun accept(t: TranslationResult) {
val detector = CpgIsomorphismDetector()
for (transformation: GraphTransformation<*> in getPhaseSpecificTransformations()) {
for (transformation: GraphTransformation in getPhaseSpecificTransformations()) {
detector.loadGraph(t)
instantiate(transformation, detector)
}

}

abstract fun getPhaseSpecificTransformations(): List<GraphTransformation<*>>
abstract fun getPhaseSpecificTransformations(): List<GraphTransformation>

/**
* Applies the given transformation to all the matches that the detector can find.
* @param <T> The concrete node type of the target node/GraphTransformation/Match
*/
private fun <T : Node?> instantiate(transformation: GraphTransformation<T>, detector: CpgIsomorphismDetector) {
private fun instantiate(transformation: GraphTransformation, detector: CpgIsomorphismDetector) {
val sourcePattern: GraphPattern = transformation.sourcePattern

var count = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package de.jplag.java_cpg.passes
import de.fraunhofer.aisec.cpg.TranslationContext
import de.fraunhofer.aisec.cpg.passes.EvaluationOrderGraphPass
import de.fraunhofer.aisec.cpg.passes.ImportResolver
import de.fraunhofer.aisec.cpg.passes.TranslationResultPass
import de.fraunhofer.aisec.cpg.passes.order.DependsOn
import de.fraunhofer.aisec.cpg.passes.order.ExecuteBefore
import de.jplag.java_cpg.transformation.GraphTransformation
Expand All @@ -16,21 +15,21 @@ import de.jplag.java_cpg.transformation.GraphTransformation
class AstTransformationPass(ctx: TranslationContext) : ATransformationPass(ctx) {


override fun getPhaseSpecificTransformations(): List<GraphTransformation<*>> {
override fun getPhaseSpecificTransformations(): List<GraphTransformation> {
return transformations.toList()
}

companion object {
@JvmStatic
val transformations: MutableList<GraphTransformation<*>> = ArrayList()
val transformations: MutableList<GraphTransformation> = ArrayList()

@JvmStatic
fun registerTransformation(transformation: GraphTransformation<*>) {
fun registerTransformation(transformation: GraphTransformation) {
transformations.add(transformation)
}

@JvmStatic
fun registerTransformations(newTransformations: Array<GraphTransformation<*>>) {
fun registerTransformations(newTransformations: Array<GraphTransformation>) {
transformations.addAll(newTransformations)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import de.jplag.java_cpg.transformation.GraphTransformation
@ExecuteBefore(TokenizationPass::class)
class CpgTransformationPass(ctx: TranslationContext) : ATransformationPass(ctx) {

override fun getPhaseSpecificTransformations(): List<GraphTransformation<*>> {
override fun getPhaseSpecificTransformations(): List<GraphTransformation> {
return transformations.toList()
}

companion object {
@JvmStatic
val transformations: MutableList<GraphTransformation<*>> = ArrayList()
val transformations: MutableList<GraphTransformation> = ArrayList()

@JvmStatic
fun registerTransformation(transformation: GraphTransformation<*>) {
fun registerTransformation(transformation: GraphTransformation) {
transformations.add(transformation)
}

@JvmStatic
fun registerTransformations(newTransformations: Array<GraphTransformation<*>>) {
fun registerTransformations(newTransformations: Array<GraphTransformation>) {
transformations.addAll(newTransformations)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ import de.jplag.java_cpg.transformation.GraphTransformation
@ExecuteBefore(AstTransformationPass::class)
class PrepareTransformationPass(ctx: TranslationContext) : ATransformationPass(ctx) {

override fun getPhaseSpecificTransformations(): List<GraphTransformation<*>> {
override fun getPhaseSpecificTransformations(): List<GraphTransformation> {
return transformations.toList();
}

companion object {
@JvmStatic
val transformations: MutableList<GraphTransformation<*>> = ArrayList()
val transformations: MutableList<GraphTransformation> = ArrayList()

@JvmStatic
fun registerTransformation(transformation: GraphTransformation<*>) {
fun registerTransformation(transformation: GraphTransformation) {
transformations.add(transformation)
}

@JvmStatic
fun registerTransformations(newTransformations: Array<GraphTransformation<*>>) {
fun registerTransformations(newTransformations: Array<GraphTransformation>) {
transformations.addAll(newTransformations)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
/**
* This saves all information related to a transformation on a graph. Note that the source and target patterns have to
* have compatible root types, otherwise the transformed graph may not be semantically correct.
* @param <T> the common root {@link Node} type of the source and target {@link NodePattern}s.
*/
public interface GraphTransformation<T extends Node> {
public interface GraphTransformation {

/**
* Applies the transformation to the Graph represented by the given {@link Match} which indicates which {@link Node}s
Expand Down Expand Up @@ -79,7 +78,7 @@ enum ExecutionOrder {
DESCENDING_LOCATION
}

class GraphTransformationImpl<T extends Node> implements GraphTransformation<T> {
class GraphTransformationImpl<T extends Node> implements GraphTransformation {
private final static Logger logger = LoggerFactory.getLogger(GraphTransformationImpl.class);
protected final GraphPattern sourcePattern;
protected final GraphPattern targetPattern;
Expand Down Expand Up @@ -211,7 +210,7 @@ public static Builder<Node> from(MultiGraphPattern sourcePattern, MultiGraphPatt
return new Builder<>(sourcePattern, targetPattern, name, phase);
}

private GraphTransformation<T> calculateTransformation() {
private GraphTransformation calculateTransformation() {
List<CreateNodeOperation<?>> newNodes = this.createNewNodes(sourcePattern, targetPattern);
List<GraphOperation> ops = new ArrayList<>();
sourcePattern.compareTo(targetPattern, (srcPattern, tgtPattern) -> compare(srcPattern, tgtPattern, null, ops, null));
Expand Down Expand Up @@ -287,16 +286,14 @@ private <T extends Node, P extends Node, AS extends T, AT extends T> void compar

}


private <S extends Node> void handleSimpleRelationships(NodePattern<S> source, NodePattern<S> target, List<GraphOperation> ops) {
List<NodePattern.RelatedNode<? super S, ?>> unprocessedTargetRelated = new ArrayList<>(target.getRelatedNodes());
for (NodePattern.RelatedNode<? super S, ?> sourceRelated : source.getRelatedNodes()) {
if (sourceRelated.edge().isAnalytic())
continue;

Optional<? extends NodePattern.RelatedNode> maybeNextTarget = unprocessedTargetRelated.stream()
.filter(rel -> sourceRelated.edge().isEquivalentTo(rel.edge()))
.map(rel -> sourceRelated.getClass().cast(rel)).findFirst();
.filter(rel -> sourceRelated.edge().isEquivalentTo(rel.edge())).map(rel -> sourceRelated.getClass().cast(rel)).findFirst();

maybeNextTarget.ifPresent(unprocessedTargetRelated::remove);
recurseSimple(source, sourceRelated, maybeNextTarget.orElse(null), ops);
Expand Down Expand Up @@ -398,7 +395,7 @@ private <S extends Node, P extends S, R extends Node> void recurseSequence(NodeP
}
}

public GraphTransformation<T> build() {
public GraphTransformation build() {
return this.calculateTransformation();
}

Expand Down
Loading

0 comments on commit 5536a3f

Please sign in to comment.