Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Language Specifics in Symbol Extraction #6119

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package com.datadog.debugger.symbol;

import com.datadog.debugger.agent.Generated;
import com.squareup.moshi.Json;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

public class LanguageSpecifics {
@Json(name = "access_modifiers")
private final List<String> accessModifiers;

private final List<String> annotations;

@Json(name = "super_class")
private final String superClass;

private final List<String> interfaces;

@Json(name = "return_type")
private final String returnType;

public LanguageSpecifics(
List<String> accessModifiers,
List<String> annotations,
String superClass,
List<String> interfaces,
String returnType) {
this.accessModifiers = accessModifiers;
this.annotations = annotations;
this.superClass = superClass;
this.interfaces = interfaces;
this.returnType = returnType;
}

public List<String> getAccessModifiers() {
return accessModifiers;
}

public List<String> getAnnotations() {
return annotations;
}

public String getSuperClass() {
return superClass;
}

public List<String> getInterfaces() {
return interfaces;
}

public String getReturnType() {
return returnType;
}

@Generated
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LanguageSpecifics that = (LanguageSpecifics) o;
return Objects.equals(accessModifiers, that.accessModifiers)
&& Objects.equals(annotations, that.annotations)
&& Objects.equals(superClass, that.superClass)
&& Objects.equals(interfaces, that.interfaces)
&& Objects.equals(returnType, that.returnType);
}

@Generated
@Override
public int hashCode() {
return Objects.hash(accessModifiers, annotations, superClass, interfaces, returnType);
}

@Generated
@Override
public String toString() {
return "LanguageSpecifics{"
+ "accessModifiers="
+ accessModifiers
+ ", annotations="
+ annotations
+ ", superClass='"
+ superClass
+ '\''
+ ", interfaces="
+ interfaces
+ ", returnType='"
+ returnType
+ '\''
+ '}';
}

public static class Builder {
private List<String> accessModifiers;
private List<String> annotations;
private String superClass;
private List<String> interfaces;
private String returnType;

public Builder addModifiers(Collection<String> modifiers) {
if (modifiers == null || modifiers.isEmpty()) {
this.accessModifiers = null;
return this;
}
accessModifiers = new ArrayList<>(modifiers);
return this;
}

public Builder addAnnotations(Collection<String> annotations) {
if (annotations == null || annotations.isEmpty()) {
this.annotations = null;
return this;
}
this.annotations = new ArrayList<>(annotations);
return this;
}

public Builder superClass(String superClass) {
this.superClass = superClass;
return this;
}

public Builder addInterfaces(Collection<String> interfaces) {
if (interfaces == null || interfaces.isEmpty()) {
this.interfaces = null;
return this;
}
this.interfaces = new ArrayList<>(interfaces);
return this;
}

public Builder returnType(String returnType) {
this.returnType = returnType;
return this;
}

public LanguageSpecifics build() {
return new LanguageSpecifics(
accessModifiers, annotations, superClass, interfaces, returnType);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Scope {
private final String name;

@Json(name = "language_specifics")
private final List<Object> languageSpecifics;
private final LanguageSpecifics languageSpecifics;

private final List<Symbol> symbols;
private final List<Scope> scopes;
Expand All @@ -30,7 +30,7 @@ public Scope(
int startLine,
int endLine,
String name,
List<Object> languageSpecifics,
LanguageSpecifics languageSpecifics,
List<Symbol> symbols,
List<Scope> scopes) {
this.scopeType = scopeType;
Expand Down Expand Up @@ -63,7 +63,7 @@ public String getName() {
return name;
}

public List<Object> getLanguageSpecifics() {
public LanguageSpecifics getLanguageSpecifics() {
return languageSpecifics;
}

Expand Down Expand Up @@ -110,7 +110,7 @@ public static class Builder {
private final int startLine;
private final int endLine;
private String name;
private List<Object> languageSpecifics;
private LanguageSpecifics languageSpecifics;
private List<Symbol> symbols;
private List<Scope> scopes;

Expand All @@ -126,7 +126,7 @@ public Builder name(String name) {
return this;
}

public Builder languageSpecifics(List<Object> languageSpecifics) {
public Builder languageSpecifics(LanguageSpecifics languageSpecifics) {
this.languageSpecifics = languageSpecifics;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@ public class Symbol {
private final int line;
private final String type;

public Symbol(SymbolType symbolType, String name, int line, String type) {
@Json(name = "language_specifics")
private final LanguageSpecifics languageSpecifics;

public Symbol(
SymbolType symbolType,
String name,
int line,
String type,
LanguageSpecifics languageSpecifics) {
this.symbolType = symbolType;
this.name = name;
this.line = line;
this.type = type;
this.languageSpecifics = languageSpecifics;
}

public SymbolType getSymbolType() {
Expand All @@ -33,6 +42,10 @@ public String getType() {
return type;
}

public LanguageSpecifics getLanguageSpecifics() {
return languageSpecifics;
}

@Override
public String toString() {
return "Symbol{"
Expand All @@ -46,6 +59,8 @@ public String toString() {
+ ", type='"
+ type
+ '\''
+ ", languageSpecifics="
+ languageSpecifics
+ '}';
}
}
Loading
Loading