logic: add lots of Java indexing fixes
* update JavaSymbolSolver to version 0.6.0 * moved to Javaparser 3.3.0 * fixed solving type parameter names in symbols solved in jar files * implemented ignoring name contexts in javassist and jre based method signatures to break infinite recursion
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -50,7 +50,7 @@
|
||||
<dependency>
|
||||
<groupId>com.github.javaparser</groupId>
|
||||
<artifactId>javaparser-core</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<version>3.3.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -66,9 +66,9 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.javaslang</groupId>
|
||||
<groupId>io.javaslang</groupId>
|
||||
<artifactId>javaslang</artifactId>
|
||||
<version>2.0.0-beta</version>
|
||||
<version>2.0.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -38,7 +38,6 @@ import com.github.javaparser.ast.Modifier;
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.PackageDeclaration;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserConstructorDeclaration;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserFieldDeclaration;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserMethodDeclaration;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserParameterDeclaration;
|
||||
@@ -132,16 +131,12 @@ public class AstVisitor extends AstVisitorAdapter
|
||||
// todo: test recording of typeargument of type parameter bound type??
|
||||
|
||||
|
||||
|
||||
if (m_context.size() != 1)
|
||||
{
|
||||
// throw something!
|
||||
}
|
||||
|
||||
String qualifiedName = m_context.get(0).getName();
|
||||
qualifiedName += "\tn";
|
||||
qualifiedName += n.getName() + "\ts\tp";
|
||||
|
||||
|
||||
String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(n, m_typeSolver).toNameHierarchy().serialize();
|
||||
|
||||
Optional<Range> range = Optional.empty();
|
||||
if (n.getBegin().isPresent())
|
||||
@@ -570,7 +565,7 @@ public class AstVisitor extends AstVisitorAdapter
|
||||
|
||||
@Override public void visit(final FieldAccessExpr n, final Void v)
|
||||
{
|
||||
SimpleName fieldName = n.getField();
|
||||
SimpleName fieldName = n.getName();
|
||||
|
||||
try
|
||||
{
|
||||
@@ -616,7 +611,88 @@ public class AstVisitor extends AstVisitorAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
recordRef(n);
|
||||
SymbolReference<? extends ValueDeclaration> ref = JavaParserFacade.get(m_typeSolver).solve(n);
|
||||
if (ref.isSolved())
|
||||
{
|
||||
ValueDeclaration valueDecl = ref.getCorrespondingDeclaration();
|
||||
|
||||
Node wrappedNode = null;
|
||||
if (valueDecl instanceof JavaParserSymbolDeclaration)
|
||||
{
|
||||
wrappedNode = ((JavaParserSymbolDeclaration)valueDecl).getWrappedNode();
|
||||
}
|
||||
else if (valueDecl instanceof JavaParserParameterDeclaration)
|
||||
{
|
||||
wrappedNode = ((JavaParserParameterDeclaration)valueDecl).getWrappedNode();
|
||||
}
|
||||
else if (valueDecl instanceof JavaParserFieldDeclaration)
|
||||
{
|
||||
wrappedNode = ((JavaParserFieldDeclaration)valueDecl).getWrappedNode();
|
||||
}
|
||||
|
||||
if (wrappedNode != null)
|
||||
{
|
||||
if (wrappedNode instanceof FieldDeclaration)
|
||||
{
|
||||
|
||||
for (VariableDeclarator var: ((FieldDeclaration)wrappedNode).getVariables())
|
||||
{
|
||||
if (var.getName().getIdentifier().equals(n.getName().getIdentifier()))
|
||||
{
|
||||
String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(var, m_typeSolver).toNameHierarchy().serialize();
|
||||
for (DeclContext context: m_context)
|
||||
{
|
||||
m_client.recordReference(
|
||||
ReferenceKind.USAGE, qualifiedName, context.getName(),
|
||||
n.getName().getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (wrappedNode instanceof Parameter)
|
||||
{
|
||||
SimpleName name = ((Parameter)wrappedNode).getName();
|
||||
if (name.getBegin().isPresent())
|
||||
{
|
||||
String qualifiedName = m_filePath + "<" + name.getBegin().get().line + ":" + name.getBegin().get().column + ">";
|
||||
|
||||
m_client.recordLocalSymbol(
|
||||
qualifiedName,
|
||||
n.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
else if (wrappedNode instanceof VariableDeclarator)
|
||||
{
|
||||
if (wrappedNode.getAncestorOfType(FieldDeclaration.class).isPresent())
|
||||
{
|
||||
String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName((VariableDeclarator)wrappedNode, m_typeSolver).toNameHierarchy().serialize();
|
||||
|
||||
for (DeclContext context: m_context)
|
||||
{
|
||||
m_client.recordReference(
|
||||
ReferenceKind.USAGE, qualifiedName, context.getName(),
|
||||
n.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SimpleName name = ((VariableDeclarator)wrappedNode).getName();
|
||||
if (name.getBegin().isPresent())
|
||||
{
|
||||
String qualifiedName = m_filePath + "<" + name.getBegin().get().line + ":" + name.getBegin().get().column + ">";
|
||||
|
||||
m_client.recordLocalSymbol(
|
||||
qualifiedName,
|
||||
n.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -626,92 +702,6 @@ public class AstVisitor extends AstVisitorAdapter
|
||||
super.visit(n, v);
|
||||
}
|
||||
|
||||
private void recordRef(NameExpr e)
|
||||
{
|
||||
SymbolReference<? extends ValueDeclaration> ref = JavaParserFacade.get(m_typeSolver).solve(e);
|
||||
if (ref.isSolved())
|
||||
{
|
||||
ValueDeclaration valueDecl = ref.getCorrespondingDeclaration();
|
||||
|
||||
Node wrappedNode = null;
|
||||
if (valueDecl instanceof JavaParserSymbolDeclaration)
|
||||
{
|
||||
wrappedNode = ((JavaParserSymbolDeclaration)valueDecl).getWrappedNode();
|
||||
}
|
||||
else if (valueDecl instanceof JavaParserParameterDeclaration)
|
||||
{
|
||||
wrappedNode = ((JavaParserParameterDeclaration)valueDecl).getWrappedNode();
|
||||
}
|
||||
else if (valueDecl instanceof JavaParserFieldDeclaration)
|
||||
{
|
||||
wrappedNode = ((JavaParserFieldDeclaration)valueDecl).getWrappedNode();
|
||||
}
|
||||
|
||||
if (wrappedNode != null)
|
||||
{
|
||||
if (wrappedNode instanceof FieldDeclaration)
|
||||
{
|
||||
|
||||
for (VariableDeclarator var: ((FieldDeclaration)wrappedNode).getVariables())
|
||||
{
|
||||
if (var.getName().getIdentifier().equals(e.getName().getIdentifier()))
|
||||
{
|
||||
String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(var, m_typeSolver).toNameHierarchy().serialize();
|
||||
for (DeclContext context: m_context)
|
||||
{
|
||||
m_client.recordReference(
|
||||
ReferenceKind.USAGE, qualifiedName, context.getName(),
|
||||
e.getName().getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (wrappedNode instanceof Parameter)
|
||||
{
|
||||
SimpleName name = ((Parameter)wrappedNode).getName();
|
||||
if (name.getBegin().isPresent())
|
||||
{
|
||||
String qualifiedName = m_filePath + "<" + name.getBegin().get().line + ":" + name.getBegin().get().column + ">";
|
||||
|
||||
m_client.recordLocalSymbol(
|
||||
qualifiedName,
|
||||
e.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
else if (wrappedNode instanceof VariableDeclarator)
|
||||
{
|
||||
if (wrappedNode.getAncestorOfType(FieldDeclaration.class).isPresent())
|
||||
{
|
||||
String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName((VariableDeclarator)wrappedNode, m_typeSolver).toNameHierarchy().serialize();
|
||||
|
||||
for (DeclContext context: m_context)
|
||||
{
|
||||
m_client.recordReference(
|
||||
ReferenceKind.USAGE, qualifiedName, context.getName(),
|
||||
e.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SimpleName name = ((VariableDeclarator)wrappedNode).getName();
|
||||
if (name.getBegin().isPresent())
|
||||
{
|
||||
String qualifiedName = m_filePath + "<" + name.getBegin().get().line + ":" + name.getBegin().get().column + ">";
|
||||
|
||||
m_client.recordLocalSymbol(
|
||||
qualifiedName,
|
||||
e.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void visit(final MethodCallExpr n, final Void v)
|
||||
{
|
||||
String qualifiedName = "";
|
||||
@@ -722,7 +712,7 @@ public class AstVisitor extends AstVisitorAdapter
|
||||
SymbolReference<com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration> solvedSymbol = JavaParserFacade.get(m_typeSolver).solve(n);
|
||||
if (solvedSymbol.isSolved())
|
||||
{
|
||||
qualifiedName = getQualifiedName(solvedSymbol.getCorrespondingDeclaration());
|
||||
qualifiedName = JavaSymbolSolverDeclNameResolver.getQualifiedDeclName(solvedSymbol.getCorrespondingDeclaration(), m_typeSolver).toNameHierarchy().serialize();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -786,7 +776,7 @@ public class AstVisitor extends AstVisitorAdapter
|
||||
|
||||
m_client.logError(e + " at " + m_filePath + "<"+ beginLine + ", " + beginColumn + ">");
|
||||
m_client.recordSymbolWithLocation(
|
||||
".\tmunsolved-symbol\ts\tp", SymbolKind.TYPE_MAX,
|
||||
JavaDeclName.unsolved().toNameHierarchy().serialize(), SymbolKind.TYPE_MAX,
|
||||
n.getRange(),
|
||||
AccessKind.DEFAULT,
|
||||
DefinitionKind.EXPLICIT
|
||||
@@ -803,7 +793,7 @@ public class AstVisitor extends AstVisitorAdapter
|
||||
SymbolReference<com.github.javaparser.symbolsolver.model.declarations.ConstructorDeclaration> solvedSymbol = JavaParserFacade.get(m_typeSolver).solve(n);
|
||||
if (solvedSymbol.isSolved())
|
||||
{
|
||||
qualifiedName = getQualifiedName(solvedSymbol.getCorrespondingDeclaration());
|
||||
qualifiedName = JavaSymbolSolverDeclNameResolver.getQualifiedDeclName(solvedSymbol.getCorrespondingDeclaration(), m_typeSolver).toNameHierarchy().serialize();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -843,70 +833,6 @@ public class AstVisitor extends AstVisitorAdapter
|
||||
super.visit(n, v);
|
||||
}
|
||||
|
||||
private String getQualifiedName(com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration method)
|
||||
{
|
||||
String qualifiedName = "";
|
||||
if (method instanceof JavaParserMethodDeclaration)
|
||||
{
|
||||
MethodDeclaration wrappedNode = ((JavaParserMethodDeclaration)method).getWrappedNode();
|
||||
qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(wrappedNode, m_typeSolver).toNameHierarchy().serialize();
|
||||
}
|
||||
else // todo: move this implementation somewhere else
|
||||
{
|
||||
qualifiedName = ".\tm" + method.declaringType().getQualifiedName();
|
||||
qualifiedName = qualifiedName.replace(".", "\ts\tp\tn");
|
||||
|
||||
qualifiedName += "\ts\tp\tn" + method.getName() + "\ts";
|
||||
|
||||
String returnType = method.getReturnType().describe();
|
||||
qualifiedName += returnType;
|
||||
// qualifiedName += returnType.substring(returnType.lastIndexOf(".") + 1);
|
||||
|
||||
qualifiedName += "\tp(";
|
||||
for (int i = 0; i < method.getNumberOfParams(); i++)
|
||||
{
|
||||
if(i != 0)
|
||||
{
|
||||
qualifiedName += (", ");
|
||||
}
|
||||
String paramType = method.getParam(i).describeType();
|
||||
qualifiedName += paramType;
|
||||
// qualifiedName += paramType.substring(paramType.lastIndexOf(".") + 1);
|
||||
}
|
||||
qualifiedName = qualifiedName.concat(")");
|
||||
}
|
||||
return qualifiedName;
|
||||
}
|
||||
|
||||
private String getQualifiedName(com.github.javaparser.symbolsolver.model.declarations.ConstructorDeclaration constructor)
|
||||
{
|
||||
String qualifiedName = "";
|
||||
if (constructor instanceof JavaParserConstructorDeclaration)
|
||||
{
|
||||
ConstructorDeclaration wrappedNode = ((JavaParserConstructorDeclaration)constructor).getWrappedNode();
|
||||
qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(wrappedNode, m_typeSolver).toNameHierarchy().serialize();
|
||||
}
|
||||
else // todo: move this implementation somewhere else
|
||||
{
|
||||
qualifiedName = ".\tm" + constructor.declaringType().getQualifiedName();
|
||||
qualifiedName = qualifiedName.replace(".", "\ts\tp\tn");
|
||||
|
||||
qualifiedName += "\ts\tp\tn" + constructor.getName() + "\ts\tp(";
|
||||
for (int i = 0; i < constructor.getNumberOfParams(); i++)
|
||||
{
|
||||
if(i != 0)
|
||||
{
|
||||
qualifiedName += (", ");
|
||||
}
|
||||
String paramType = constructor.getParam(i).describeType();
|
||||
qualifiedName += paramType;
|
||||
// qualifiedName += paramType.substring(paramType.lastIndexOf(".") + 1);
|
||||
}
|
||||
qualifiedName = qualifiedName.concat(")");
|
||||
}
|
||||
return qualifiedName;
|
||||
}
|
||||
|
||||
@Override public void visit(final BlockStmt n, final Void v)
|
||||
{
|
||||
recordScope(n.getRange());
|
||||
|
||||
@@ -22,6 +22,11 @@ public class CallableConstructorDecl implements CallableDecl
|
||||
return m_decl;
|
||||
}
|
||||
|
||||
public boolean isMethod()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return m_decl.getNameAsString();
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.github.javaparser.ast.type.Type;
|
||||
public interface CallableDecl
|
||||
{
|
||||
public BodyDeclaration getWrappedNode();
|
||||
public boolean isMethod();
|
||||
public String getName();
|
||||
public NodeList<TypeParameter> getTypeParameters();
|
||||
public NodeList<Parameter> getParameters();
|
||||
|
||||
@@ -21,6 +21,11 @@ public class CallableMethodDecl implements CallableDecl
|
||||
return m_decl;
|
||||
}
|
||||
|
||||
public boolean isMethod()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return m_decl.getNameAsString();
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.sourcetrail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.javaparser.ast.body.BodyDeclaration;
|
||||
import com.github.javaparser.symbolsolver.model.declarations.TypeParametrizable;
|
||||
|
||||
public class ContextList
|
||||
{
|
||||
private List<BodyDeclaration> m_bodyDeclarations = new ArrayList<>();
|
||||
private List<TypeParametrizable> m_typeParameterizables = new ArrayList<>();
|
||||
|
||||
public ContextList copy()
|
||||
{
|
||||
ContextList contextList = new ContextList();
|
||||
|
||||
contextList.m_bodyDeclarations = new ArrayList<>(m_bodyDeclarations);
|
||||
contextList.m_typeParameterizables = new ArrayList<>(m_typeParameterizables);
|
||||
|
||||
return contextList;
|
||||
}
|
||||
|
||||
public void add(BodyDeclaration v)
|
||||
{
|
||||
m_bodyDeclarations.add(v);
|
||||
}
|
||||
|
||||
public boolean contains(BodyDeclaration v)
|
||||
{
|
||||
for (BodyDeclaration bodyDeclaration: m_bodyDeclarations)
|
||||
{
|
||||
if (bodyDeclaration.equals(v))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void add(TypeParametrizable v)
|
||||
{
|
||||
m_typeParameterizables.add(v);
|
||||
}
|
||||
|
||||
public boolean contains(TypeParametrizable v)
|
||||
{
|
||||
for (TypeParametrizable typeParameterizable: m_typeParameterizables)
|
||||
{
|
||||
if (typeParameterizable.toString().equals(v.toString()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,10 @@ import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.PackageDeclaration;
|
||||
import com.github.javaparser.JavaParser;
|
||||
import com.github.javaparser.ParseProblemException;
|
||||
import com.github.javaparser.Position;
|
||||
import com.github.javaparser.Problem;
|
||||
import com.github.javaparser.Range;
|
||||
import com.github.javaparser.TokenRange;
|
||||
import com.github.javaparser.symbolsolver.javaparser.Navigator;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade;
|
||||
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
|
||||
@@ -85,35 +87,20 @@ public class JavaIndexer
|
||||
{
|
||||
for (Problem problem: e.getProblems())
|
||||
{
|
||||
// "Parse error. Found \"package\", expected one of \";\" \"@\" \"\\u001a\" \"abstract\" \"class\" \"default\" \"enum\" \"final\" \"import\" \"interface\" \"module\" \"native\" \"open\" \"private\" \"protected\" \"public\" \"static\" \"stric...
|
||||
String message = problem.toString();
|
||||
if (message.startsWith("(line "))
|
||||
if (message.startsWith("Parse error. Found "))
|
||||
{
|
||||
int startLine = Integer.parseInt(message.substring(
|
||||
message.indexOf("line ") + ("line ").length(),
|
||||
message.indexOf(",")
|
||||
));
|
||||
|
||||
int startColumn = Integer.parseInt(message.substring(
|
||||
message.indexOf("col ") + ("col ").length(),
|
||||
message.indexOf(")")
|
||||
));
|
||||
|
||||
astVisitorClient.recordError(
|
||||
"Encountered unexpected token.", true, true,
|
||||
Range.range(startLine, startColumn, startLine, startColumn)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
Optional<Range> range = problem.getRange();
|
||||
if (range.isPresent())
|
||||
{
|
||||
astVisitorClient.recordError(
|
||||
problem.toString(), true, true,
|
||||
range.get()
|
||||
);
|
||||
}
|
||||
message = "Encountered unexpected token.";
|
||||
}
|
||||
|
||||
Range range = new Range(new Position(0, 0), new Position(0, 0));
|
||||
if (problem.getLocation().isPresent())
|
||||
{
|
||||
range = problem.getLocation().get().toRange();
|
||||
}
|
||||
|
||||
astVisitorClient.recordError(message, true, true, range);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.sourcetrail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.javaparser.ast.body.BodyDeclaration;
|
||||
|
||||
@@ -9,9 +10,9 @@ import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
|
||||
public abstract class JavaNameResolver
|
||||
{
|
||||
TypeSolver m_typeSolver = null;
|
||||
ArrayList<BodyDeclaration> m_ignoredContexts = null;
|
||||
ContextList m_ignoredContexts = null;
|
||||
|
||||
public JavaNameResolver(TypeSolver typeSolver, ArrayList<BodyDeclaration> ignoredContexts)
|
||||
public JavaNameResolver(TypeSolver typeSolver, ContextList ignoredContexts)
|
||||
{
|
||||
m_typeSolver = typeSolver;
|
||||
if (ignoredContexts != null)
|
||||
@@ -20,23 +21,7 @@ public abstract class JavaNameResolver
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ignoredContexts = new ArrayList<BodyDeclaration>();
|
||||
m_ignoredContexts = new ContextList();
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean ignoresContext(BodyDeclaration context)
|
||||
{
|
||||
if (m_ignoredContexts != null)
|
||||
{
|
||||
for (BodyDeclaration ignoredContext: m_ignoredContexts)
|
||||
{
|
||||
if (ignoredContext.equals(context))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,26 +2,45 @@ package com.sourcetrail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.github.javaparser.ast.body.BodyDeclaration;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
|
||||
import com.github.javaparser.ast.body.FieldDeclaration;
|
||||
import com.github.javaparser.ast.body.Parameter;
|
||||
import com.github.javaparser.ast.type.TypeParameter;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnnotationDeclaration;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnonymousClassDeclaration;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserConstructorDeclaration;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumConstantDeclaration;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserEnumDeclaration;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserFieldDeclaration;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserInterfaceDeclaration;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserMethodDeclaration;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserParameterDeclaration;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeVariableDeclaration;
|
||||
import com.github.javaparser.symbolsolver.javassistmodel.JavassistClassDeclaration;
|
||||
import com.github.javaparser.symbolsolver.javassistmodel.JavassistTypeParameter;
|
||||
import com.github.javaparser.symbolsolver.model.declarations.Declaration;
|
||||
import com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration;
|
||||
import com.github.javaparser.symbolsolver.model.declarations.MethodLikeDeclaration;
|
||||
import com.github.javaparser.symbolsolver.model.declarations.ReferenceTypeDeclaration;
|
||||
import com.github.javaparser.symbolsolver.model.declarations.TypeDeclaration;
|
||||
import com.github.javaparser.symbolsolver.model.declarations.TypeParameterDeclaration;
|
||||
import com.github.javaparser.symbolsolver.model.declarations.TypeParametrizable;
|
||||
import com.github.javaparser.symbolsolver.model.declarations.ValueDeclaration;
|
||||
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
|
||||
|
||||
import com.sourcetrail.name.JavaDeclName;
|
||||
import com.sourcetrail.name.JavaFunctionDeclName;
|
||||
import com.sourcetrail.name.JavaTypeName;
|
||||
import com.sourcetrail.name.JavaVariableDeclName;
|
||||
|
||||
public class JavaSymbolSolverDeclNameResolver extends JavaNameResolver
|
||||
{
|
||||
public JavaSymbolSolverDeclNameResolver(TypeSolver typeSolver, ArrayList<BodyDeclaration> ignoredContexts)
|
||||
public JavaSymbolSolverDeclNameResolver(TypeSolver typeSolver, ContextList ignoredContexts)
|
||||
{
|
||||
super(typeSolver, ignoredContexts);
|
||||
}
|
||||
@@ -31,7 +50,7 @@ public class JavaSymbolSolverDeclNameResolver extends JavaNameResolver
|
||||
return getQualifiedDeclName(decl, typeSolver, null);
|
||||
}
|
||||
|
||||
public static JavaDeclName getQualifiedDeclName(Declaration decl, TypeSolver typeSolver, ArrayList<BodyDeclaration> ignoredContexts)
|
||||
public static JavaDeclName getQualifiedDeclName(Declaration decl, TypeSolver typeSolver, ContextList ignoredContexts)
|
||||
{
|
||||
JavaSymbolSolverDeclNameResolver resolver = new JavaSymbolSolverDeclNameResolver(typeSolver, ignoredContexts);
|
||||
return resolver.getQualifiedDeclName(decl);
|
||||
@@ -41,76 +60,166 @@ public class JavaSymbolSolverDeclNameResolver extends JavaNameResolver
|
||||
{
|
||||
JavaDeclName declName = null;
|
||||
|
||||
if (decl != null)
|
||||
if (decl instanceof JavaParserAnnotationDeclaration)
|
||||
{
|
||||
// TODO: implement
|
||||
System.out.println("solving name of JavaParserAnnotationDeclaration not implemented");
|
||||
declName = JavaDeclName.unsolved();
|
||||
|
||||
}
|
||||
if (decl instanceof JavaParserAnonymousClassDeclaration)
|
||||
{
|
||||
// TODO: implement
|
||||
System.out.println("solving name of JavaParserAnonymousClassDeclaration not implemented");
|
||||
declName = JavaDeclName.unsolved();
|
||||
}
|
||||
else if (decl instanceof JavaParserClassDeclaration)
|
||||
{
|
||||
declName = JavaparserDeclNameResolver.getQualifiedDeclName(
|
||||
((JavaParserClassDeclaration)decl).getWrappedNode(), m_typeSolver, m_ignoredContexts);
|
||||
}
|
||||
else if (decl instanceof JavaParserConstructorDeclaration)
|
||||
{
|
||||
declName = JavaparserDeclNameResolver.getQualifiedDeclName(
|
||||
((JavaParserConstructorDeclaration)decl).getWrappedNode(), m_typeSolver, m_ignoredContexts);
|
||||
}
|
||||
else if (decl instanceof JavaParserEnumDeclaration)
|
||||
{
|
||||
declName = JavaparserDeclNameResolver.getQualifiedDeclName(
|
||||
((JavaParserEnumDeclaration)decl).getWrappedNode(), m_typeSolver, m_ignoredContexts);
|
||||
}
|
||||
else if (decl instanceof JavaParserEnumConstantDeclaration)
|
||||
{
|
||||
declName = JavaparserDeclNameResolver.getQualifiedDeclName(
|
||||
((JavaParserEnumConstantDeclaration)decl).getWrappedNode(), m_typeSolver, m_ignoredContexts);
|
||||
}
|
||||
else if (decl instanceof JavaParserFieldDeclaration)
|
||||
{
|
||||
declName = JavaparserDeclNameResolver.getQualifiedDeclName(
|
||||
((JavaParserFieldDeclaration)decl).getWrappedNode(), m_typeSolver, m_ignoredContexts);
|
||||
}
|
||||
else if (decl instanceof JavaParserInterfaceDeclaration)
|
||||
{
|
||||
declName = JavaparserDeclNameResolver.getQualifiedDeclName(
|
||||
((JavaParserInterfaceDeclaration)decl).getWrappedNode(), m_typeSolver, m_ignoredContexts);
|
||||
}
|
||||
else if (decl instanceof JavaParserMethodDeclaration)
|
||||
{
|
||||
declName = JavaparserDeclNameResolver.getQualifiedDeclName(
|
||||
((JavaParserMethodDeclaration)decl).getWrappedNode(), m_typeSolver, m_ignoredContexts);
|
||||
}
|
||||
else if (decl instanceof JavaParserParameterDeclaration)
|
||||
{
|
||||
System.out.println("solving name of JavaParserParameterDeclaration not implemented");
|
||||
declName = JavaDeclName.unsolved();
|
||||
}
|
||||
else if (decl instanceof JavaParserSymbolDeclaration)
|
||||
{
|
||||
System.out.println("solving name of JavaParserSymbolDeclaration not implemented");
|
||||
declName = JavaDeclName.unsolved();
|
||||
}
|
||||
else if (decl instanceof JavaParserTypeParameter)
|
||||
{
|
||||
declName = JavaparserDeclNameResolver.getQualifiedDeclName(
|
||||
((JavaParserTypeParameter)decl).getWrappedNode(), m_typeSolver, m_ignoredContexts);
|
||||
}
|
||||
else if (decl instanceof JavaParserTypeVariableDeclaration)
|
||||
{
|
||||
declName = JavaparserDeclNameResolver.getQualifiedDeclName(
|
||||
((JavaParserTypeVariableDeclaration)decl).getWrappedNode(), m_typeSolver, m_ignoredContexts);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (decl instanceof TypeDeclaration)
|
||||
String name = decl.getName();
|
||||
List<String> typeParameters = new ArrayList<>();
|
||||
if (decl instanceof TypeParametrizable)
|
||||
{
|
||||
typeParameters = getTypeParameterNames((TypeParametrizable) decl);
|
||||
}
|
||||
|
||||
if (decl instanceof ReferenceTypeDeclaration)
|
||||
{
|
||||
TypeDeclaration typeDecl = (TypeDeclaration)decl;
|
||||
declName = new JavaDeclName(name, typeParameters);
|
||||
|
||||
ClassOrInterfaceDeclaration javaparserDecl = null;
|
||||
if (typeDecl instanceof JavaParserClassDeclaration)
|
||||
Optional<ReferenceTypeDeclaration> containerType = ((ReferenceTypeDeclaration) decl).containerType();
|
||||
if (containerType.isPresent())
|
||||
{
|
||||
javaparserDecl = ((JavaParserClassDeclaration)typeDecl).getWrappedNode();
|
||||
}
|
||||
else if (typeDecl instanceof JavaParserInterfaceDeclaration)
|
||||
{
|
||||
javaparserDecl = ((JavaParserInterfaceDeclaration)typeDecl).getWrappedNode();
|
||||
}
|
||||
|
||||
if (javaparserDecl != null)
|
||||
{
|
||||
declName = JavaparserDeclNameResolver.getQualifiedDeclName(javaparserDecl, m_typeSolver, m_ignoredContexts);
|
||||
declName.setParent(getQualifiedDeclName(containerType.get(), m_typeSolver, m_ignoredContexts));
|
||||
}
|
||||
else
|
||||
{
|
||||
declName = JavaDeclName.fromDotSeparatedString(typeDecl.getQualifiedName());
|
||||
declName.setParent(JavaDeclName.fromDotSeparatedString(((ReferenceTypeDeclaration) decl).getPackageName()));
|
||||
}
|
||||
|
||||
}
|
||||
else if (decl instanceof TypeParameterDeclaration)
|
||||
{
|
||||
declName = new JavaDeclName(name);
|
||||
TypeParametrizable container = ((TypeParameterDeclaration) decl).getContainer();
|
||||
if (!m_ignoredContexts.contains(container))
|
||||
{
|
||||
if (container instanceof ReferenceTypeDeclaration)
|
||||
{
|
||||
declName.setParent(getQualifiedDeclName((ReferenceTypeDeclaration) container, m_typeSolver, m_ignoredContexts));
|
||||
}
|
||||
if (container instanceof MethodLikeDeclaration)
|
||||
{
|
||||
declName.setParent(getQualifiedDeclName((MethodLikeDeclaration) container, m_typeSolver, m_ignoredContexts));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (decl instanceof MethodDeclaration)
|
||||
else if (decl instanceof MethodLikeDeclaration)
|
||||
{
|
||||
MethodDeclaration methodDecl = (MethodDeclaration)decl;
|
||||
|
||||
if (methodDecl instanceof JavaParserMethodDeclaration)
|
||||
ContextList ignoredContextsForTypes = m_ignoredContexts.copy();
|
||||
ignoredContextsForTypes.add((MethodLikeDeclaration) decl); // adding own decl
|
||||
|
||||
JavaTypeName returnTypeName = new JavaTypeName("", null);
|
||||
boolean isStatic = false;
|
||||
if (decl instanceof MethodDeclaration)
|
||||
{
|
||||
declName = JavaparserDeclNameResolver.getQualifiedDeclName(
|
||||
((JavaParserMethodDeclaration)methodDecl).getWrappedNode(),
|
||||
m_typeSolver,
|
||||
m_ignoredContexts
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: what about endless recursion regarding type parameters and return type??
|
||||
|
||||
List<JavaTypeName> parameterNames = new ArrayList<>();
|
||||
for (int i = 0; i < methodDecl.getNumberOfParams(); i++)
|
||||
{
|
||||
parameterNames.add(JavaSymbolSolverTypeNameResolver.getQualifiedTypeName(
|
||||
methodDecl.getParam(i).getType(), m_typeSolver, m_ignoredContexts
|
||||
));
|
||||
}
|
||||
|
||||
declName = new JavaFunctionDeclName(
|
||||
methodDecl.getName(),
|
||||
getTypeParameterNames(methodDecl.getTypeParameters()),
|
||||
JavaSymbolSolverTypeNameResolver.getQualifiedTypeName(methodDecl.getReturnType(), m_typeSolver, m_ignoredContexts),
|
||||
parameterNames,
|
||||
methodDecl.isStatic()
|
||||
);
|
||||
|
||||
declName.setParent(
|
||||
getQualifiedDeclName(methodDecl.declaringType(), m_typeSolver, m_ignoredContexts)
|
||||
);
|
||||
returnTypeName = JavaSymbolSolverTypeNameResolver.getQualifiedTypeName(((MethodDeclaration)decl).getReturnType(), m_typeSolver, ignoredContextsForTypes);
|
||||
isStatic = ((MethodDeclaration)decl).isStatic();
|
||||
}
|
||||
|
||||
declName = new JavaFunctionDeclName(
|
||||
name, typeParameters,
|
||||
returnTypeName,
|
||||
getParameterTypeNames((MethodLikeDeclaration) decl, m_typeSolver, ignoredContextsForTypes),
|
||||
isStatic);
|
||||
|
||||
declName.setParent(
|
||||
getQualifiedDeclName(((MethodLikeDeclaration) decl).declaringType(), m_typeSolver, m_ignoredContexts));
|
||||
|
||||
}
|
||||
else if (decl instanceof com.github.javaparser.symbolsolver.model.declarations.FieldDeclaration)
|
||||
{
|
||||
com.github.javaparser.symbolsolver.model.declarations.FieldDeclaration fieldDecl = ((com.github.javaparser.symbolsolver.model.declarations.FieldDeclaration) decl);
|
||||
declName = new JavaVariableDeclName(
|
||||
name,
|
||||
JavaSymbolSolverTypeNameResolver.getQualifiedTypeName(fieldDecl.getType(), m_typeSolver, m_ignoredContexts),
|
||||
fieldDecl.isStatic());
|
||||
|
||||
declName.setParent(
|
||||
getQualifiedDeclName(
|
||||
fieldDecl.declaringType(),
|
||||
m_typeSolver,
|
||||
m_ignoredContexts));
|
||||
}
|
||||
}
|
||||
|
||||
if (declName == null)
|
||||
{
|
||||
System.out.println("Unable to resolve qualified declaration name of " + decl.getClass().toString() + ": " + decl.toString());
|
||||
declName = new JavaDeclName("unsolved-jss-decl"); // JavaDeclName.unsolved();
|
||||
}
|
||||
|
||||
return declName;
|
||||
}
|
||||
|
||||
private static List<String> getTypeParameterNames(List<TypeParameterDeclaration> typeParameters)
|
||||
private static List<String> getTypeParameterNames(TypeParametrizable decl)
|
||||
{
|
||||
List<String> typeParameterNames = new ArrayList<>();
|
||||
List<TypeParameterDeclaration> typeParameters = decl.getTypeParameters();
|
||||
if (typeParameters != null && typeParameters.size() > 0)
|
||||
{
|
||||
for (int i = 0; i < typeParameters.size(); i++)
|
||||
@@ -121,4 +230,16 @@ public class JavaSymbolSolverDeclNameResolver extends JavaNameResolver
|
||||
return typeParameterNames;
|
||||
}
|
||||
|
||||
private static List<JavaTypeName> getParameterTypeNames(MethodLikeDeclaration decl, TypeSolver typeSolver, ContextList ignoredContexts)
|
||||
{
|
||||
List<JavaTypeName> typeTypeParameterNames = new ArrayList<>();
|
||||
for (int i = 0; i < decl.getNumberOfParams(); i++)
|
||||
{
|
||||
typeTypeParameterNames.add(JavaSymbolSolverTypeNameResolver.getQualifiedTypeName(
|
||||
decl.getParam(i).getType(), typeSolver, ignoredContexts
|
||||
));
|
||||
}
|
||||
return typeTypeParameterNames;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.sourcetrail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.body.BodyDeclaration;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter;
|
||||
@@ -24,7 +24,7 @@ import com.sourcetrail.name.JavaTypeName;
|
||||
|
||||
public class JavaSymbolSolverTypeNameResolver extends JavaNameResolver
|
||||
{
|
||||
public JavaSymbolSolverTypeNameResolver(TypeSolver typeSolver, ArrayList<BodyDeclaration> ignoredContexts)
|
||||
public JavaSymbolSolverTypeNameResolver(TypeSolver typeSolver, ContextList ignoredContexts)
|
||||
{
|
||||
super(typeSolver, ignoredContexts);
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public class JavaSymbolSolverTypeNameResolver extends JavaNameResolver
|
||||
return getQualifiedTypeName(type, typeSolver, null);
|
||||
}
|
||||
|
||||
public static JavaTypeName getQualifiedTypeName(Type type, TypeSolver typeSolver, ArrayList<BodyDeclaration> ignoredContexts)
|
||||
public static JavaTypeName getQualifiedTypeName(Type type, TypeSolver typeSolver, ContextList ignoredContexts)
|
||||
{
|
||||
JavaSymbolSolverTypeNameResolver resolver = new JavaSymbolSolverTypeNameResolver(typeSolver, ignoredContexts);
|
||||
return resolver.getQualifiedTypeName(type);
|
||||
@@ -67,46 +67,18 @@ public class JavaSymbolSolverTypeNameResolver extends JavaNameResolver
|
||||
ReferenceType refTypeUsage = (ReferenceType)type;
|
||||
|
||||
JavaDeclName declName = JavaSymbolSolverDeclNameResolver.getQualifiedDeclName(
|
||||
refTypeUsage.getTypeDeclaration(),
|
||||
m_typeSolver,
|
||||
m_ignoredContexts
|
||||
);
|
||||
|
||||
refTypeUsage.getTypeDeclaration(),
|
||||
m_typeSolver,
|
||||
m_ignoredContexts);
|
||||
return new JavaTypeName(declName.getName() + declName.getTypeParameterString(), new ArrayList<JavaTypeName>(), declName.getParent());
|
||||
/*
|
||||
if (declName != null)
|
||||
{
|
||||
List<JavaTypeName> typeArgumentNames = new ArrayList<>();
|
||||
|
||||
for (TypeUsage typeArgument: refTypeUsage.parameters()) // don't know why this method is called "parameters()"
|
||||
{
|
||||
typeArgumentNames.add(getQualifiedTypeName(typeArgument, m_typeSolver, m_ignoredContexts));
|
||||
}
|
||||
return new JavaTypeName(declName.getName(), typeArgumentNames, declName.getParent());
|
||||
}
|
||||
*/
|
||||
}
|
||||
else if (type instanceof TypeVariable)
|
||||
{
|
||||
TypeParameterDeclaration typeParam = ((TypeVariable)type).asTypeParameter();
|
||||
if (typeParam instanceof JavaParserTypeParameter)
|
||||
{
|
||||
com.github.javaparser.ast.type.TypeParameter jpTypeParameter = ((JavaParserTypeParameter)typeParam).getWrappedNode();
|
||||
Optional<BodyDeclaration> genericDecl = jpTypeParameter.getAncestorOfType(BodyDeclaration.class);
|
||||
if (genericDecl.isPresent())
|
||||
{
|
||||
JavaDeclName genericName = null;
|
||||
if (!ignoresContext(genericDecl.get()))
|
||||
{
|
||||
genericName = JavaparserDeclNameResolver.getQualifiedDeclName(genericDecl.get(), m_typeSolver, m_ignoredContexts);
|
||||
}
|
||||
return new JavaTypeName(jpTypeParameter.getName().getId(), genericName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// do we need to handle using type parameters of external code? YES! so: TODO: do this!
|
||||
}
|
||||
JavaDeclName declName = JavaSymbolSolverDeclNameResolver.getQualifiedDeclName(
|
||||
((TypeVariable)type).asTypeParameter(),
|
||||
m_typeSolver,
|
||||
m_ignoredContexts);
|
||||
return new JavaTypeName(declName.getName(), new ArrayList<JavaTypeName>(), declName.getParent());
|
||||
}
|
||||
else if (type instanceof VoidType)
|
||||
{
|
||||
@@ -118,6 +90,7 @@ public class JavaSymbolSolverTypeNameResolver extends JavaNameResolver
|
||||
}
|
||||
|
||||
System.out.println("Unable to resolve qualified name of " + type.getClass().toString() + ": " + type.toString());
|
||||
return new JavaTypeName("unresolved-type", null);
|
||||
|
||||
return new JavaTypeName("unsolved-jss-type", null); // JavaTypeName.unsolved();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.github.javaparser.ast.body.AnnotationMemberDeclaration;
|
||||
import com.github.javaparser.ast.body.BodyDeclaration;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.ast.body.ConstructorDeclaration;
|
||||
import com.github.javaparser.ast.body.EmptyMemberDeclaration;
|
||||
import com.github.javaparser.ast.body.EnumConstantDeclaration;
|
||||
import com.github.javaparser.ast.body.FieldDeclaration;
|
||||
import com.github.javaparser.ast.body.InitializerDeclaration;
|
||||
@@ -21,6 +20,7 @@ import com.github.javaparser.ast.body.Parameter;
|
||||
import com.github.javaparser.ast.body.TypeDeclaration;
|
||||
import com.github.javaparser.ast.body.VariableDeclarator;
|
||||
import com.github.javaparser.ast.expr.Name;
|
||||
import com.github.javaparser.ast.expr.SimpleName;
|
||||
import com.github.javaparser.ast.type.TypeParameter;
|
||||
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
|
||||
|
||||
@@ -31,7 +31,7 @@ import com.sourcetrail.name.JavaVariableDeclName;
|
||||
|
||||
public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
{
|
||||
public JavaparserDeclNameResolver(TypeSolver typeSolver, ArrayList<BodyDeclaration> ignoredContexts)
|
||||
public JavaparserDeclNameResolver(TypeSolver typeSolver, ContextList ignoredContexts)
|
||||
{
|
||||
super(typeSolver, ignoredContexts);
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
return getQualifiedDeclName(decl, typeSolver, null);
|
||||
}
|
||||
|
||||
public static JavaDeclName getQualifiedDeclName(VariableDeclarator decl, TypeSolver typeSolver, ArrayList<BodyDeclaration> ignoredContexts)
|
||||
public static JavaDeclName getQualifiedDeclName(VariableDeclarator decl, TypeSolver typeSolver, ContextList ignoredContexts)
|
||||
{
|
||||
JavaparserDeclNameResolver resolver = new JavaparserDeclNameResolver(typeSolver, ignoredContexts);
|
||||
return resolver.getQualifiedDeclName(decl);
|
||||
@@ -49,8 +49,8 @@ public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
|
||||
public JavaDeclName getQualifiedDeclName(VariableDeclarator decl)
|
||||
{
|
||||
JavaDeclName declName = null;
|
||||
|
||||
JavaDeclName declName = new JavaDeclName("unsolved-jp-decl"); // JavaDeclName.unsolved();
|
||||
|
||||
if (decl != null)
|
||||
{
|
||||
declName = getDeclName(decl);
|
||||
@@ -58,7 +58,7 @@ public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
BodyDeclaration declContext = getBodyDeclContext(decl);
|
||||
if (declContext != null)
|
||||
{
|
||||
if (!ignoresContext(declContext))
|
||||
if (!m_ignoredContexts.contains(declContext))
|
||||
{
|
||||
declName.setParent(getQualifiedDeclName(declContext));
|
||||
}
|
||||
@@ -84,58 +84,9 @@ public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
return declName;
|
||||
}
|
||||
|
||||
public static JavaDeclName getQualifiedDeclName(BodyDeclaration decl, TypeSolver typeSolver)
|
||||
{
|
||||
return getQualifiedDeclName(decl, typeSolver, null);
|
||||
}
|
||||
|
||||
public static JavaDeclName getQualifiedDeclName(BodyDeclaration decl, TypeSolver typeSolver, ArrayList<BodyDeclaration> ignoredContexts)
|
||||
{
|
||||
JavaparserDeclNameResolver resolver = new JavaparserDeclNameResolver(typeSolver, ignoredContexts);
|
||||
return resolver.getQualifiedDeclName(decl);
|
||||
}
|
||||
|
||||
public JavaDeclName getQualifiedDeclName(BodyDeclaration<?> decl)
|
||||
{
|
||||
JavaDeclName declName = null;
|
||||
|
||||
if (decl != null)
|
||||
{
|
||||
declName = getDeclName(decl);
|
||||
|
||||
BodyDeclaration declContext = getBodyDeclContext(decl);
|
||||
if (declContext != null)
|
||||
{
|
||||
if (!ignoresContext(declContext))
|
||||
{
|
||||
declName.setParent(getQualifiedDeclName(declContext));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Optional<CompilationUnit> compilationUnit = decl.getAncestorOfType(CompilationUnit.class);
|
||||
|
||||
if (compilationUnit.isPresent())
|
||||
{
|
||||
Optional<PackageDeclaration> packageDecl = compilationUnit.get().getPackageDeclaration();
|
||||
if (packageDecl.isPresent())
|
||||
{
|
||||
declName.setParent(getQualifiedName(packageDecl.get().getName()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
return declName;
|
||||
}
|
||||
|
||||
public JavaDeclName getDeclName(VariableDeclarator decl)
|
||||
{
|
||||
ArrayList<BodyDeclaration> ignoredContextsForTypes = new ArrayList<BodyDeclaration>(m_ignoredContexts);
|
||||
JavaTypeName typeName = JavaparserTypeNameResolver.getQualifiedTypeName(decl.getType(), m_typeSolver, ignoredContextsForTypes);
|
||||
JavaTypeName typeName = JavaparserTypeNameResolver.getQualifiedTypeName(decl.getType(), m_typeSolver, m_ignoredContexts.copy());
|
||||
|
||||
boolean isStatic = false;
|
||||
Optional<FieldDeclaration> fieldDeclaration = decl.getAncestorOfType(FieldDeclaration.class);
|
||||
@@ -147,9 +98,58 @@ public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
return new JavaVariableDeclName(decl.getNameAsString(), typeName, isStatic);
|
||||
}
|
||||
|
||||
public static JavaDeclName getQualifiedDeclName(BodyDeclaration decl, TypeSolver typeSolver)
|
||||
{
|
||||
return getQualifiedDeclName(decl, typeSolver, null);
|
||||
}
|
||||
|
||||
public static JavaDeclName getQualifiedDeclName(BodyDeclaration decl, TypeSolver typeSolver, ContextList ignoredContexts)
|
||||
{
|
||||
JavaparserDeclNameResolver resolver = new JavaparserDeclNameResolver(typeSolver, ignoredContexts);
|
||||
return resolver.getQualifiedDeclName(decl);
|
||||
}
|
||||
|
||||
public JavaDeclName getQualifiedDeclName(BodyDeclaration<?> decl)
|
||||
{
|
||||
JavaDeclName declName = new JavaDeclName("unsolved-jp-decl"); // JavaDeclName.unsolved();
|
||||
|
||||
if (decl != null)
|
||||
{
|
||||
declName = getDeclName(decl);
|
||||
|
||||
BodyDeclaration declContext = getBodyDeclContext(decl);
|
||||
if (declContext != null)
|
||||
{
|
||||
if (!m_ignoredContexts.contains(declContext))
|
||||
{
|
||||
declName.setParent(getQualifiedDeclName(declContext));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Optional<CompilationUnit> compilationUnit = decl.getAncestorOfType(CompilationUnit.class);
|
||||
|
||||
if (compilationUnit.isPresent())
|
||||
{
|
||||
Optional<PackageDeclaration> packageDecl = compilationUnit.get().getPackageDeclaration();
|
||||
if (packageDecl.isPresent())
|
||||
{
|
||||
declName.setParent(getQualifiedName(packageDecl.get().getName()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return declName;
|
||||
}
|
||||
|
||||
public JavaDeclName getDeclName(BodyDeclaration decl)
|
||||
{
|
||||
JavaDeclName declName = null;
|
||||
JavaDeclName declName = new JavaDeclName("unsolved-jp-decl"); // JavaDeclName.unsolved();
|
||||
|
||||
if (decl != null)
|
||||
{
|
||||
@@ -162,10 +162,6 @@ public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
CallableConstructorDecl callableDecl = new CallableConstructorDecl((ConstructorDeclaration)decl);
|
||||
declName = getDeclNameOfCallable(callableDecl);
|
||||
}
|
||||
else if (decl instanceof EmptyMemberDeclaration)
|
||||
{
|
||||
declName = new JavaDeclName("EmptyMemberDeclaration");
|
||||
}
|
||||
else if (decl instanceof EnumConstantDeclaration)
|
||||
{
|
||||
declName = new JavaDeclName(((EnumConstantDeclaration)decl).getNameAsString());
|
||||
@@ -192,6 +188,46 @@ public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
return declName;
|
||||
}
|
||||
|
||||
public static JavaDeclName getQualifiedDeclName(TypeParameter decl, TypeSolver typeSolver)
|
||||
{
|
||||
return getQualifiedDeclName(decl, typeSolver, null);
|
||||
}
|
||||
|
||||
public static JavaDeclName getQualifiedDeclName(TypeParameter decl, TypeSolver typeSolver, ContextList ignoredContexts)
|
||||
{
|
||||
JavaparserDeclNameResolver resolver = new JavaparserDeclNameResolver(typeSolver, ignoredContexts);
|
||||
return resolver.getQualifiedDeclName(decl);
|
||||
}
|
||||
|
||||
public JavaDeclName getQualifiedDeclName(TypeParameter decl)
|
||||
{
|
||||
JavaDeclName declName = new JavaDeclName("unsolved-jp-decl"); // JavaDeclName.unsolved();
|
||||
|
||||
if (decl != null)
|
||||
{
|
||||
declName = getDeclName(decl);
|
||||
|
||||
BodyDeclaration declContext = getBodyDeclContext(decl);
|
||||
if (declContext != null)
|
||||
{
|
||||
if (!m_ignoredContexts.contains(declContext))
|
||||
{
|
||||
declName.setParent(getQualifiedDeclName(declContext));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnsupportedOperationException("no appropriate parent found for TypeParameter");
|
||||
}
|
||||
}
|
||||
return declName;
|
||||
}
|
||||
|
||||
public JavaDeclName getDeclName(TypeParameter decl)
|
||||
{
|
||||
return new JavaDeclName(decl.getName().asString());
|
||||
}
|
||||
|
||||
private static List<String> getTypeParameterNames(TypeDeclaration decl)
|
||||
{
|
||||
NodeList<TypeParameter> typeParameters = null;
|
||||
@@ -228,7 +264,7 @@ public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
|
||||
private <T extends CallableDecl> JavaDeclName getDeclNameOfCallable(T decl)
|
||||
{
|
||||
ArrayList<BodyDeclaration> ignoredContextsForTypes = new ArrayList<BodyDeclaration>(m_ignoredContexts);
|
||||
ContextList ignoredContextsForTypes = m_ignoredContexts.copy();
|
||||
ignoredContextsForTypes.add(decl.getWrappedNode()); // adding own decl
|
||||
|
||||
List<JavaTypeName> parameterNames = new ArrayList<>();
|
||||
@@ -237,10 +273,16 @@ public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
parameterNames.add(JavaparserTypeNameResolver.getQualifiedTypeName(parameter.getType(), m_typeSolver, ignoredContextsForTypes));
|
||||
}
|
||||
|
||||
JavaTypeName returnType = new JavaTypeName("", null);
|
||||
if (decl.isMethod())
|
||||
{
|
||||
returnType = JavaparserTypeNameResolver.getQualifiedTypeName(decl.getType(), m_typeSolver, ignoredContextsForTypes);
|
||||
}
|
||||
|
||||
return new JavaFunctionDeclName(
|
||||
decl.getName(),
|
||||
getTypeParameterNames(decl.getTypeParameters()),
|
||||
JavaparserTypeNameResolver.getQualifiedTypeName(decl.getType(), m_typeSolver, ignoredContextsForTypes),
|
||||
returnType,
|
||||
parameterNames,
|
||||
decl.isStatic()
|
||||
);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.sourcetrail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.javaparser.ast.body.BodyDeclaration;
|
||||
import com.github.javaparser.ast.type.*;
|
||||
@@ -11,7 +11,7 @@ import com.sourcetrail.name.JavaTypeName;
|
||||
|
||||
public class JavaparserTypeNameResolver extends JavaNameResolver
|
||||
{
|
||||
public JavaparserTypeNameResolver(TypeSolver typeSolver, ArrayList<BodyDeclaration> ignoredContexts)
|
||||
public JavaparserTypeNameResolver(TypeSolver typeSolver, ContextList ignoredContexts)
|
||||
{
|
||||
super(typeSolver, ignoredContexts);
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class JavaparserTypeNameResolver extends JavaNameResolver
|
||||
return getQualifiedTypeName(type, typeSolver, null);
|
||||
}
|
||||
|
||||
public static JavaTypeName getQualifiedTypeName(Type type, TypeSolver typeSolver, ArrayList<BodyDeclaration> ignoredContexts)
|
||||
public static JavaTypeName getQualifiedTypeName(Type type, TypeSolver typeSolver, ContextList ignoredContexts)
|
||||
{
|
||||
JavaparserTypeNameResolver resolver = new JavaparserTypeNameResolver(typeSolver, ignoredContexts);
|
||||
return resolver.getQualifiedTypeName(type);
|
||||
@@ -92,7 +92,8 @@ public class JavaparserTypeNameResolver extends JavaNameResolver
|
||||
}
|
||||
|
||||
System.out.println("Unable to resolve qualified name of " + type.getClass().toString() + ": " + fallbackTypeName);
|
||||
return new JavaTypeName("unresolved-type", null);
|
||||
|
||||
return new JavaTypeName("unsolved-jp-type", null); // JavaTypeName.unsolved();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -90,8 +90,6 @@ public class VerboseAstVisitor extends AstVisitor{
|
||||
|
||||
public void visit(Parameter n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(EmptyMemberDeclaration n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(InitializerDeclaration n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(JavadocComment n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
@@ -223,4 +221,6 @@ public class VerboseAstVisitor extends AstVisitor{
|
||||
public void visit(MethodReferenceExpr n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(TypeExpr n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(UnparsableStmt n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
}
|
||||
|
||||
@@ -8,9 +8,13 @@ public class JavaDeclName
|
||||
private String m_name = "";
|
||||
private List<String> m_typeParameterNames = null;
|
||||
|
||||
public static JavaDeclName unsolved()
|
||||
{
|
||||
return new JavaDeclName("unsolved-symbol");
|
||||
}
|
||||
|
||||
public static JavaDeclName fromDotSeparatedString(String s)
|
||||
{
|
||||
|
||||
JavaDeclName declName = null;
|
||||
|
||||
int separatorIndex = s.lastIndexOf('.');
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.sourcetrail.name;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class JavaFunctionDeclName extends JavaDeclName
|
||||
{
|
||||
private JavaTypeName m_returnTypeName = null;
|
||||
private List<JavaTypeName> m_parameterNames = null;
|
||||
private List<JavaTypeName> m_parameterNames = new ArrayList<>();
|
||||
private boolean m_isStatic = false;
|
||||
|
||||
public JavaFunctionDeclName(String name, JavaTypeName returnTypeName, List<JavaTypeName> parameterNames, boolean isStatic)
|
||||
@@ -14,7 +15,7 @@ public class JavaFunctionDeclName extends JavaDeclName
|
||||
super(name);
|
||||
|
||||
m_returnTypeName = returnTypeName;
|
||||
m_parameterNames = parameterNames;
|
||||
if (m_parameterNames != null) m_parameterNames = parameterNames;
|
||||
m_isStatic = isStatic;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,11 @@ public class JavaTypeName
|
||||
private String m_name = "";
|
||||
private List<JavaTypeName> m_typeArgumentNames = null;
|
||||
|
||||
public static JavaTypeName unsolved()
|
||||
{
|
||||
return new JavaTypeName("unsolved-type", null);
|
||||
}
|
||||
|
||||
public static JavaTypeName fromDotSeparatedString(String s)
|
||||
{
|
||||
JavaTypeName typeName = null;
|
||||
|
||||
Reference in New Issue
Block a user