Skip to content

Commit

Permalink
Shorter, more concise toString() output for console
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Jun 2, 2021
1 parent 922cefe commit 0d4f8ba
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
*/
package de.fraunhofer.aisec.cpg.console

import de.fraunhofer.aisec.cpg.graph.Node
import kotlin.script.experimental.api.ScriptCompilationConfiguration
import kotlin.script.experimental.api.ScriptEvaluationConfiguration
import kotlin.script.experimental.jvm.baseClassLoader
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
import kotlin.script.experimental.jvm.dependenciesFromClassloader
import kotlin.script.experimental.jvm.jvm
import org.apache.commons.lang3.builder.ToStringStyle
import org.jetbrains.kotlinx.ki.shell.KotlinShell
import org.jetbrains.kotlinx.ki.shell.Plugin
import org.jetbrains.kotlinx.ki.shell.Shell
Expand All @@ -41,6 +43,8 @@ import org.jetbrains.kotlinx.ki.shell.configuration.ReplConfigurationBase
object CpgConsole {
@JvmStatic
fun main(args: Array<String>) {
Node.TO_STRING_STYLE = ToStringStyle.JSON_STYLE

val repl =
Shell(
configuration(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,8 @@ open class Node : IVisitable<Node>, Persistable {

override fun toString(): String {
return ToStringBuilder(this, TO_STRING_STYLE)
.append("id", id)
.append("name", name)
.append("location", location)
.append("argumentIndex", argumentIndex)
.toString()
}

Expand Down Expand Up @@ -253,7 +251,7 @@ open class Node : IVisitable<Node>, Persistable {
}

companion object {
@JvmField val TO_STRING_STYLE: ToStringStyle = ToStringStyle.SHORT_PREFIX_STYLE
@JvmField var TO_STRING_STYLE: ToStringStyle = ToStringStyle.SHORT_PREFIX_STYLE

protected val log: Logger = LoggerFactory.getLogger(Node::class.java)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
package de.fraunhofer.aisec.cpg.graph.declarations;

import de.fraunhofer.aisec.cpg.graph.Node;
import org.apache.commons.lang3.builder.ToStringBuilder;

/**
* Represents a single declaration or definition, i.e. of a variable ({@link VariableDeclaration})
Expand All @@ -40,10 +39,4 @@
*/
// TODO: expressionRefersToDeclaration definition and declaration nodes and introduce a field if its
// declaration only
public class Declaration extends Node {

@Override
public String toString() {
return new ToStringBuilder(this, Node.TO_STRING_STYLE).toString();
}
}
public class Declaration extends Node {}
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,19 @@ public Optional<VariableDeclaration> getVariableDeclarationByName(String name) {
return Optional.empty();
}

@NotNull
@Override
public String toString() {
return new ToStringBuilder(this, Node.TO_STRING_STYLE)
.appendSuper(super.toString())
.append("type", type)
// .append("type", type)
.append(
"parameters",
parameters.stream()
.map(PropertyEdge::getEnd)
.map(ParamVariableDeclaration::getName)
.collect(Collectors.joining(", ")))
/*.map(ParamVariableDeclaration::toString)
.collect(Collectors.joining(", ")))*/
.collect(Collectors.toList()))
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.jetbrains.annotations.NotNull;
import org.neo4j.ogm.annotation.Transient;

/** A declaration who has a type. */
Expand Down Expand Up @@ -182,12 +183,13 @@ public void refreshType() {
});
}

@NotNull
@Override
public String toString() {
return new ToStringBuilder(this, Node.TO_STRING_STYLE)
.appendSuper(super.toString())
.append("type", type)
.append("possibleSubTypes", possibleSubTypes)
// .append("possibleSubTypes", possibleSubTypes)
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,4 @@ public int hashCode() {

return Objects.hash(super.hashCode());
}

@Override
public String toString() {
return "IncompleteType{"
+ "typeName='"
+ getName()
+ '\''
+ ", storage="
+ this.getStorage()
+ ", qualifier="
+ this.getQualifier()
+ ", origin="
+ this.getTypeOrigin()
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,4 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(super.hashCode(), generics, modifier, primitive);
}

@Override
public String toString() {
return "ObjectType{"
+ "generics="
+ generics
+ ", typeName='"
+ getName()
+ '\''
+ ", storage="
+ this.getStorage()
+ ", qualifier="
+ this.getQualifier()
+ ", modifier="
+ modifier
+ ", primitive="
+ primitive
+ ", origin="
+ this.getTypeOrigin()
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,4 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(super.hashCode(), elementType);
}

@Override
public String toString() {
return "PointerType{"
+ "elementType="
+ elementType
+ ", typeName='"
+ getName()
+ '\''
+ ", storage="
+ this.getStorage()
+ ", qualifier="
+ this.getQualifier()
+ ", origin="
+ this.getTypeOrigin()
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@

import de.fraunhofer.aisec.cpg.graph.Node;
import java.util.*;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;
import org.neo4j.ogm.annotation.Relationship;
import org.neo4j.ogm.annotation.typeconversion.Convert;

Expand Down Expand Up @@ -347,18 +349,9 @@ public int hashCode() {
return Objects.hash(getName(), storage, qualifier);
}

@NotNull
@Override
public String toString() {
return "Type{"
+ "typeName='"
+ getName()
+ '\''
+ ", storage="
+ storage
+ ", qualifier="
+ qualifier
+ ", origin="
+ origin
+ '}';
return new ToStringBuilder(this, TO_STRING_STYLE).append("name", getName()).toString();
}
}

0 comments on commit 0d4f8ba

Please sign in to comment.