data: recording braces in java
* implemented recording of scope braces as local symbols for java
This commit is contained in:
@@ -11,8 +11,8 @@ import me.tomassetti.symbolsolver.model.resolution.TypeSolver;
|
||||
|
||||
public class ASTDumper extends JavaAstVisitor{
|
||||
|
||||
public ASTDumper(int callbackId, String filePath, TypeSolver typeSolver) {
|
||||
super(callbackId, filePath, typeSolver);
|
||||
public ASTDumper(int callbackId, String filePath, FileContent fileContent, TypeSolver typeSolver) {
|
||||
super(callbackId, filePath, fileContent, typeSolver);
|
||||
}
|
||||
|
||||
int indent = 0;
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package io.coati;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class FileContent
|
||||
{
|
||||
public class Location
|
||||
{
|
||||
public int line;
|
||||
public int column;
|
||||
|
||||
Location(int line, int column)
|
||||
{
|
||||
this.line = line;
|
||||
this.column = column;
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> m_lines;
|
||||
|
||||
public FileContent(String text)
|
||||
{
|
||||
m_lines = Arrays.asList(text.split("\\r?\\n"));
|
||||
}
|
||||
|
||||
public Location find(String s)
|
||||
{
|
||||
return find(s, 1, 1);
|
||||
}
|
||||
|
||||
public Location find(String s, int fromLine, int fromColumn)
|
||||
{
|
||||
int lineIndex = fromLine - 1;
|
||||
int startColumn = fromColumn - 1;
|
||||
int column = -1;
|
||||
while (lineIndex < m_lines.size())
|
||||
{
|
||||
column = m_lines.get(lineIndex).indexOf(s, startColumn);
|
||||
if (column != -1)
|
||||
{
|
||||
return new Location(lineIndex + 1, column + 1);
|
||||
}
|
||||
startColumn = 0;
|
||||
lineIndex++;
|
||||
}
|
||||
return new Location(0, 0);
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,12 @@ import com.github.javaparser.ast.body.VariableDeclarator;
|
||||
import com.github.javaparser.ast.body.VariableDeclaratorId;
|
||||
import com.github.javaparser.ast.comments.BlockComment;
|
||||
import com.github.javaparser.ast.comments.LineComment;
|
||||
import com.github.javaparser.ast.expr.ArrayInitializerExpr;
|
||||
import com.github.javaparser.ast.expr.MethodCallExpr;
|
||||
import com.github.javaparser.ast.expr.NameExpr;
|
||||
import com.github.javaparser.ast.expr.VariableDeclarationExpr;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.ast.stmt.SwitchStmt;
|
||||
import com.github.javaparser.ast.type.ClassOrInterfaceType;
|
||||
import com.github.javaparser.ast.type.PrimitiveType;
|
||||
import com.github.javaparser.ast.type.Type;
|
||||
@@ -44,14 +47,16 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
{
|
||||
private int m_callbackId = -1;
|
||||
private String m_filePath;
|
||||
private FileContent m_fileContent;
|
||||
private TypeSolver m_typeSolver;
|
||||
private List<DeclContext> m_context = new ArrayList<DeclContext>();
|
||||
private boolean m_verbose = false;
|
||||
|
||||
public JavaAstVisitor(int callbackId, String filePath, TypeSolver typeSolver)
|
||||
public JavaAstVisitor(int callbackId, String filePath, FileContent fileContent, TypeSolver typeSolver)
|
||||
{
|
||||
m_callbackId = callbackId;
|
||||
m_filePath = filePath;
|
||||
m_fileContent = fileContent;
|
||||
m_typeSolver = typeSolver;
|
||||
|
||||
String[] filePathParts = filePath.split("/");
|
||||
@@ -90,6 +95,9 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
n.getBeginLine(), n.getBeginColumn(), n.getEndLine(), n.getEndColumn(),
|
||||
AccessKind.fromAccessSpecifier(ModifierSet.getAccessSpecifier(n.getModifiers())), false
|
||||
);
|
||||
|
||||
FileContent.Location scopeStartLocation = m_fileContent.find("{", n.getBeginLine(), n.getBeginColumn());
|
||||
recordScope(scopeStartLocation.line, scopeStartLocation.column, n.getEndLine(), n.getEndColumn());
|
||||
|
||||
List<DeclContext> parentContext = m_context;
|
||||
m_context = new ArrayList<DeclContext>();
|
||||
@@ -139,6 +147,9 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
AccessKind.fromAccessSpecifier(ModifierSet.getAccessSpecifier(n.getModifiers())), false
|
||||
);
|
||||
|
||||
FileContent.Location scopeStartLocation = m_fileContent.find("{", n.getBeginLine(), n.getBeginColumn());
|
||||
recordScope(scopeStartLocation.line, scopeStartLocation.column, n.getEndLine(), n.getEndColumn());
|
||||
|
||||
List<DeclContext> parentContext = m_context;
|
||||
m_context = new ArrayList<DeclContext>();
|
||||
m_context.add(new DeclContext(qualifiedName));
|
||||
@@ -754,12 +765,39 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
return qualifiedName;
|
||||
}
|
||||
|
||||
@Override public void visit(final BlockStmt n, final Void v)
|
||||
{
|
||||
recordScope(n.getBeginLine(), n.getBeginColumn(), n.getEndLine(), n.getEndColumn());
|
||||
super.visit(n, v);
|
||||
}
|
||||
|
||||
@Override public void visit(final ArrayInitializerExpr n, final Void v)
|
||||
{
|
||||
recordScope(n.getBeginLine(), n.getBeginColumn(), n.getEndLine(), n.getEndColumn());
|
||||
super.visit(n, v);
|
||||
}
|
||||
|
||||
@Override public void visit(final SwitchStmt n, final Void v)
|
||||
{
|
||||
FileContent.Location scopeStartLocation = m_fileContent.find("{", n.getBeginLine(), n.getBeginColumn());
|
||||
recordScope(scopeStartLocation.line, scopeStartLocation.column, n.getEndLine(), n.getEndColumn());
|
||||
super.visit(n, v);
|
||||
}
|
||||
|
||||
private void recordScope(int beginLine, int beginColumn, int endLine, int endColumn)
|
||||
{
|
||||
String qualifiedName = m_filePath + "<" + beginLine + ":" + beginColumn + ">";
|
||||
JavaIndexer.recordLocalSymbol(m_callbackId, qualifiedName, beginLine, beginColumn, beginLine, beginColumn);
|
||||
JavaIndexer.recordLocalSymbol(m_callbackId, qualifiedName, endLine, endColumn, endLine, endColumn);
|
||||
}
|
||||
|
||||
@Override public void visit(final LineComment n, final Void v)
|
||||
{
|
||||
JavaIndexer.recordComment(
|
||||
m_callbackId,
|
||||
n.getBeginLine(), n.getBeginColumn(), n.getEndLine(), n.getEndColumn()
|
||||
);
|
||||
super.visit(n, v);
|
||||
}
|
||||
|
||||
@Override public void visit(final BlockComment n, final Void v)
|
||||
@@ -768,5 +806,6 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
m_callbackId,
|
||||
n.getBeginLine(), n.getBeginColumn(), n.getEndLine(), n.getEndColumn()
|
||||
);
|
||||
super.visit(n, v);
|
||||
}
|
||||
}
|
||||
@@ -48,9 +48,9 @@ public class JavaIndexer
|
||||
}
|
||||
}
|
||||
CompilationUnit cu = JavaParser.parse(new StringReader(fileContent), true);
|
||||
|
||||
JavaAstVisitor astVisitor = new JavaAstVisitor(address, filePath, typeSolver);
|
||||
// JavaAstVisitor astVisitor = new ASTDumper(address, filePath, typeSolver);
|
||||
|
||||
// JavaAstVisitor astVisitor = new JavaAstVisitor(address, filePath, new FileContent(fileContent), typeSolver);
|
||||
JavaAstVisitor astVisitor = new ASTDumper(address, filePath, new FileContent(fileContent), typeSolver);
|
||||
cu.accept(astVisitor, null);
|
||||
}
|
||||
catch (ParseException e)
|
||||
|
||||
Reference in New Issue
Block a user