logic: update java indexer
* update to use JavaSymbolSolver 0.5.2.x (fce40b67) * update to use JavaParse 3.1.2 (4537e57a) * implemented solving constructor calls instead of just recording a type usage here
This commit is contained in:
@@ -72,3 +72,4 @@ TokenLocationCollection.cpp ERROR: TokenLocation has wrong boundaries: file.c 4:
|
||||
INFO: Indexer - indexing source file: input.cc
|
||||
INFO: Indexer - indexing source file: input.cc
|
||||
INFO: Indexer - indexing source file: input.cc
|
||||
INFO: Indexer - indexing source file: input.cc
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.github.javaparser.ast.expr.FieldAccessExpr;
|
||||
import com.github.javaparser.ast.expr.MethodCallExpr;
|
||||
import com.github.javaparser.ast.expr.Name;
|
||||
import com.github.javaparser.ast.expr.NameExpr;
|
||||
import com.github.javaparser.ast.expr.ObjectCreationExpr;
|
||||
import com.github.javaparser.ast.expr.SimpleName;
|
||||
import com.github.javaparser.ast.expr.VariableDeclarationExpr;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
@@ -29,13 +30,14 @@ import com.github.javaparser.ast.type.PrimitiveType;
|
||||
import com.github.javaparser.ast.type.Type;
|
||||
import com.github.javaparser.ast.type.TypeParameter;
|
||||
import com.github.javaparser.ast.type.VoidType;
|
||||
import com.github.javaparser.ast.imports.*;
|
||||
import com.github.javaparser.Position;
|
||||
import com.github.javaparser.Range;
|
||||
import com.github.javaparser.ast.ImportDeclaration;
|
||||
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;
|
||||
@@ -270,7 +272,7 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
|
||||
private com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration getOverridden(MethodDeclaration overrider)
|
||||
{
|
||||
com.github.javaparser.ast.body.TypeDeclaration<?> scopeNode = overrider.getAncestorOfType(com.github.javaparser.ast.body.TypeDeclaration.class);
|
||||
com.github.javaparser.ast.body.TypeDeclaration<?> scopeNode = overrider.getAncestorOfType(com.github.javaparser.ast.body.TypeDeclaration.class).get();
|
||||
if (scopeNode instanceof ClassOrInterfaceDeclaration)
|
||||
{
|
||||
List<com.github.javaparser.symbolsolver.model.typesystem.Type> parameterTypes = new ArrayList<>();
|
||||
@@ -392,120 +394,12 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
|
||||
// --- record references ---
|
||||
|
||||
|
||||
@Override
|
||||
public void visit(SingleStaticImportDeclaration n, Void arg)
|
||||
@Override
|
||||
public void visit(final ImportDeclaration n, final Void v)
|
||||
{
|
||||
try
|
||||
Name name = n.getName();
|
||||
if (n.isAsterisk() || !n.isStatic())
|
||||
{
|
||||
ClassOrInterfaceType type = n.getType();
|
||||
List<JavaDeclName> importedDeclNames = new ArrayList<>();
|
||||
|
||||
com.github.javaparser.symbolsolver.model.typesystem.Type solvedType = JavaParserFacade.get(m_typeSolver).convert(type, type);
|
||||
|
||||
if (solvedType instanceof ReferenceType)
|
||||
{
|
||||
ReferenceTypeDeclaration solvedDecl = ((ReferenceType)solvedType).getTypeDeclaration();
|
||||
for (com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration methodDecl: solvedDecl.getDeclaredMethods()) // look for method
|
||||
{
|
||||
if (methodDecl.getName().equals(n.getStaticMember()))
|
||||
{
|
||||
importedDeclNames.add(
|
||||
JavaSymbolSolverDeclNameResolver.getQualifiedDeclName(methodDecl, m_typeSolver
|
||||
));
|
||||
}
|
||||
}
|
||||
if (importedDeclNames.isEmpty() && solvedDecl.hasField(n.getStaticMember())) // look for field
|
||||
{
|
||||
JavaDeclName importedTypeDeclName = JavaSymbolSolverDeclNameResolver.getQualifiedDeclName(solvedDecl, m_typeSolver);
|
||||
if (importedTypeDeclName != null)
|
||||
{
|
||||
JavaDeclName importedDeclName = new JavaDeclName(n.getStaticMember());
|
||||
importedDeclName.setParent(importedTypeDeclName);
|
||||
importedDeclNames.add(importedDeclName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!importedDeclNames.isEmpty())
|
||||
{
|
||||
for (JavaDeclName importedDeclName: importedDeclNames)
|
||||
{
|
||||
String nameHierarchy = importedDeclName.toSerializedNameHierarchy();
|
||||
for (DeclContext context: m_context)
|
||||
{
|
||||
JavaIndexer.recordReference(
|
||||
m_callbackId, ReferenceKind.IMPORT,
|
||||
nameHierarchy, context.getName(),
|
||||
n.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JavaIndexer.recordError(
|
||||
m_callbackId, "Import not found.", true, true,
|
||||
n.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
recordException(e, n);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SingleTypeImportDeclaration n, Void arg)
|
||||
{
|
||||
try
|
||||
{
|
||||
ClassOrInterfaceType type = n.getType();
|
||||
String importedName = JavaparserTypeNameResolver.getQualifiedTypeName(type, m_typeSolver).toSerializedNameHierarchy();
|
||||
for (DeclContext context: m_context)
|
||||
{
|
||||
JavaIndexer.recordReference(
|
||||
m_callbackId, ReferenceKind.IMPORT,
|
||||
importedName, context.getName(),
|
||||
type.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
recordException(e, n);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(StaticImportOnDemandDeclaration n, Void arg)
|
||||
{
|
||||
try
|
||||
{
|
||||
ClassOrInterfaceType type = n.getType();
|
||||
String importedName = JavaparserTypeNameResolver.getQualifiedTypeName(type, m_typeSolver).toSerializedNameHierarchy();
|
||||
for (DeclContext context: m_context)
|
||||
{
|
||||
JavaIndexer.recordReference(
|
||||
m_callbackId, ReferenceKind.IMPORT,
|
||||
importedName, context.getName(),
|
||||
type.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
recordException(e, n);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TypeImportOnDemandDeclaration n, Void arg)
|
||||
{
|
||||
try
|
||||
{
|
||||
Name name = n.getName();
|
||||
String importedName = JavaparserDeclNameResolver.getQualifiedName(name).toSerializedNameHierarchy();
|
||||
for (DeclContext context: m_context)
|
||||
{
|
||||
@@ -516,12 +410,69 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
else
|
||||
{
|
||||
recordException(e, n);
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
String typeName = name.getQualifier().get().asString();
|
||||
String memberName = name.getIdentifier();
|
||||
|
||||
List<JavaDeclName> importedDeclNames = new ArrayList<>();
|
||||
|
||||
ReferenceTypeDeclaration solvedDecl = m_typeSolver.solveType(typeName);
|
||||
|
||||
for (com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration methodDecl: solvedDecl.getDeclaredMethods()) // look for method
|
||||
{
|
||||
if (methodDecl.getName().equals(memberName))
|
||||
{
|
||||
importedDeclNames.add(
|
||||
JavaSymbolSolverDeclNameResolver.getQualifiedDeclName(methodDecl, m_typeSolver
|
||||
));
|
||||
}
|
||||
}
|
||||
if (importedDeclNames.isEmpty() && solvedDecl.hasField(memberName)) // look for field
|
||||
{
|
||||
JavaDeclName importedTypeDeclName = JavaSymbolSolverDeclNameResolver.getQualifiedDeclName(solvedDecl, m_typeSolver);
|
||||
if (importedTypeDeclName != null)
|
||||
{
|
||||
JavaDeclName importedDeclName = new JavaDeclName(memberName);
|
||||
importedDeclName.setParent(importedTypeDeclName);
|
||||
importedDeclNames.add(importedDeclName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!importedDeclNames.isEmpty())
|
||||
{
|
||||
for (JavaDeclName importedDeclName: importedDeclNames)
|
||||
{
|
||||
String nameHierarchy = importedDeclName.toSerializedNameHierarchy();
|
||||
for (DeclContext context: m_context)
|
||||
{
|
||||
JavaIndexer.recordReference(
|
||||
m_callbackId, ReferenceKind.IMPORT,
|
||||
nameHierarchy, context.getName(),
|
||||
n.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JavaIndexer.recordError(
|
||||
m_callbackId, "Import not found.", true, true,
|
||||
n.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
recordException(e, n);
|
||||
}
|
||||
}
|
||||
super.visit(n, v);
|
||||
}
|
||||
|
||||
@Override public void visit(final ClassOrInterfaceType n, final Void v)
|
||||
{
|
||||
try
|
||||
@@ -543,12 +494,17 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
}
|
||||
|
||||
Optional<ClassOrInterfaceType> scope = n.getScope();
|
||||
if (scope.isPresent() && scope.get().getEnd().isPresent())
|
||||
if (scope.isPresent())
|
||||
{
|
||||
range = range.withEnd(
|
||||
Position.pos(scope.get().getEnd().get().line,
|
||||
scope.get().getEnd().get().column + n.getNameAsString().length() + 1 // +1 for separator
|
||||
));
|
||||
Optional<Position> position = scope.get().getEnd();
|
||||
|
||||
if (position.isPresent())
|
||||
{
|
||||
range = range.withEnd(
|
||||
Position.pos(position.get().line,
|
||||
position.get().column + n.getNameAsString().length() + 1 // +1 for separator
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
JavaIndexer.recordReference(
|
||||
@@ -694,10 +650,32 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
{
|
||||
wrappedNode = ((JavaParserParameterDeclaration)valueDecl).getWrappedNode();
|
||||
}
|
||||
else if (valueDecl instanceof JavaParserFieldDeclaration)
|
||||
{
|
||||
wrappedNode = ((JavaParserFieldDeclaration)valueDecl).getWrappedNode();
|
||||
}
|
||||
|
||||
if (wrappedNode != null)
|
||||
{
|
||||
if (wrappedNode instanceof Parameter)
|
||||
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).toSerializedNameHierarchy();
|
||||
for (DeclContext context: m_context)
|
||||
{
|
||||
JavaIndexer.recordReference(
|
||||
m_callbackId, ReferenceKind.USAGE, qualifiedName, context.getName(),
|
||||
e.getName().getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (wrappedNode instanceof Parameter)
|
||||
{
|
||||
SimpleName name = ((Parameter)wrappedNode).getName();
|
||||
if (name.getBegin().isPresent())
|
||||
@@ -712,7 +690,7 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
}
|
||||
else if (wrappedNode instanceof VariableDeclarator)
|
||||
{
|
||||
if (wrappedNode.getAncestorOfType(FieldDeclaration.class) != null)
|
||||
if (wrappedNode.getAncestorOfType(FieldDeclaration.class).isPresent())
|
||||
{
|
||||
String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName((VariableDeclarator)wrappedNode, m_typeSolver).toSerializedNameHierarchy();
|
||||
|
||||
@@ -749,10 +727,10 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
SymbolReference<com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration> solvedMethod = JavaParserFacade.get(m_typeSolver).solve(n);
|
||||
if (solvedMethod.isSolved())
|
||||
SymbolReference<com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration> solvedSymbol = JavaParserFacade.get(m_typeSolver).solve(n);
|
||||
if (solvedSymbol.isSolved())
|
||||
{
|
||||
qualifiedName = getQualifiedName(solvedMethod.getCorrespondingDeclaration());
|
||||
qualifiedName = getQualifiedName(solvedSymbol.getCorrespondingDeclaration());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -823,8 +801,6 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@Override public void visit(final ObjectCreationExpr n, final Void v)
|
||||
{
|
||||
String qualifiedName = "";
|
||||
@@ -832,57 +808,31 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
ClassOrInterfaceDeclaration decl = Utility.getJavaparserDeclForType(n.getType(), m_typeSolver);
|
||||
if (decl != null)
|
||||
SymbolReference<com.github.javaparser.symbolsolver.model.declarations.ConstructorDeclaration> solvedSymbol = JavaParserFacade.get(m_typeSolver).solve(n);
|
||||
if (solvedSymbol.isSolved())
|
||||
{
|
||||
TODO: implement when there is a method to get the constructor decl for a constructor expression.
|
||||
|
||||
for (BodyDeclaration member: decl.getMembers())
|
||||
{
|
||||
if (member instanceof ConstructorDeclaration)
|
||||
{
|
||||
ConstructorDeclaration constructorDecl = (ConstructorDeclaration)member;
|
||||
|
||||
for (Expression arg: n.getArgs())
|
||||
{
|
||||
JavaParserFacade.get(m_typeSolver).getType(arg).asReferenceTypeUsage().getQualifiedName();
|
||||
}
|
||||
|
||||
constructorDecl.getParameters().get(0).getType().;
|
||||
}
|
||||
}
|
||||
qualifiedName = getQualifiedName(solvedSymbol.getCorrespondingDeclaration());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnsolvedSymbolException("constructor for " + n.getType().getNameAsString());
|
||||
}
|
||||
|
||||
|
||||
qualifiedName = getQualifiedName(methodUsage.get());
|
||||
}
|
||||
catch (UnsupportedOperationException e)
|
||||
{
|
||||
if (m_verbose)
|
||||
{
|
||||
System.out.println(e + " at location " + n.getBegin().line + ", " + n.getBegin().column);
|
||||
}
|
||||
recordException(e, n);
|
||||
}
|
||||
catch (MethodAmbiguityException e)
|
||||
{
|
||||
if (m_verbose)
|
||||
{
|
||||
System.out.println(e + " at location " + n.getBegin().line + ", " + n.getBegin().column);
|
||||
}
|
||||
recordException(e, n);
|
||||
}
|
||||
catch(StackOverflowError e)
|
||||
{
|
||||
if (m_verbose)
|
||||
{
|
||||
System.out.println(e + " at location " + n.getBegin().line + ", " + n.getBegin().column);
|
||||
}
|
||||
recordError(e, n);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (m_verbose)
|
||||
{
|
||||
System.out.println(e + " at location " + n.getBegin().line + ", " + n.getBegin().column);
|
||||
}
|
||||
recordException(e, n);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -891,43 +841,72 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
ClassOrInterfaceType type = n.getType();
|
||||
for (DeclContext context: m_context)
|
||||
{
|
||||
JavaIndexer.recordRef(
|
||||
m_callbackId, ReferenceType.CALL.getValue(), qualifiedName, context.getName(),
|
||||
type.getBegin().line, type.getBegin().column, type.getEnd().line, type.getEnd().column
|
||||
JavaIndexer.recordReference(
|
||||
m_callbackId, ReferenceKind.CALL, qualifiedName, context.getName(),
|
||||
type.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
super.visit(n, v);
|
||||
}
|
||||
*/
|
||||
private String getQualifiedName(com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration solvedMethod)
|
||||
|
||||
private String getQualifiedName(com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration method)
|
||||
{
|
||||
String qualifiedName = "";
|
||||
if (solvedMethod instanceof JavaParserMethodDeclaration)
|
||||
if (method instanceof JavaParserMethodDeclaration)
|
||||
{
|
||||
MethodDeclaration wrappedNode = ((JavaParserMethodDeclaration)solvedMethod).getWrappedNode();
|
||||
MethodDeclaration wrappedNode = ((JavaParserMethodDeclaration)method).getWrappedNode();
|
||||
qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(wrappedNode, m_typeSolver).toSerializedNameHierarchy();
|
||||
}
|
||||
else // todo: move this implementation somewhere else
|
||||
{
|
||||
qualifiedName = solvedMethod.declaringType().getQualifiedName();
|
||||
qualifiedName = method.declaringType().getQualifiedName();
|
||||
qualifiedName = qualifiedName.replace(".", "\ts\tp\tn");
|
||||
|
||||
qualifiedName += "\ts\tp\tn" + solvedMethod.getName() + "\ts";
|
||||
qualifiedName += "\ts\tp\tn" + method.getName() + "\ts";
|
||||
|
||||
String returnType = solvedMethod.getReturnType().describe();
|
||||
String returnType = method.getReturnType().describe();
|
||||
qualifiedName += returnType;
|
||||
// qualifiedName += returnType.substring(returnType.lastIndexOf(".") + 1);
|
||||
|
||||
qualifiedName += "\tp(";
|
||||
for (int i = 0; i < solvedMethod.getNumberOfParams(); i++)
|
||||
for (int i = 0; i < method.getNumberOfParams(); i++)
|
||||
{
|
||||
if(i != 0)
|
||||
{
|
||||
qualifiedName += (", ");
|
||||
}
|
||||
String paramType = solvedMethod.getParam(i).describeType();
|
||||
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).toSerializedNameHierarchy();
|
||||
}
|
||||
else // todo: move this implementation somewhere else
|
||||
{
|
||||
qualifiedName = 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);
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@ import com.github.javaparser.ast.*;
|
||||
import com.github.javaparser.ast.body.*;
|
||||
import com.github.javaparser.ast.comments.Comment;
|
||||
import com.github.javaparser.ast.expr.*;
|
||||
import com.github.javaparser.ast.imports.*;
|
||||
import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
|
||||
import com.github.javaparser.ast.stmt.*;
|
||||
import com.github.javaparser.ast.type.*;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Stack;
|
||||
|
||||
public abstract class JavaAstVisitorAdapter extends VoidVisitorAdapter<Void>
|
||||
@@ -53,27 +53,6 @@ public abstract class JavaAstVisitorAdapter extends VoidVisitorAdapter<Void>
|
||||
m_typeRefKind.pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SingleStaticImportDeclaration n, Void arg)
|
||||
{
|
||||
visitComment(n.getComment(), arg);
|
||||
// n.getType().accept(this, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SingleTypeImportDeclaration n, Void arg)
|
||||
{
|
||||
visitComment(n.getComment(), arg);
|
||||
// n.getType().accept(this, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(StaticImportOnDemandDeclaration n, Void arg)
|
||||
{
|
||||
visitComment(n.getComment(), arg);
|
||||
// n.getType().accept(this, arg);
|
||||
}
|
||||
|
||||
//- Body ----------------------------------------------
|
||||
|
||||
@Override public void visit(ClassOrInterfaceDeclaration n, Void arg)
|
||||
@@ -162,9 +141,9 @@ public abstract class JavaAstVisitorAdapter extends VoidVisitorAdapter<Void>
|
||||
@Override public void visit(MethodCallExpr n, Void arg)
|
||||
{
|
||||
visitComment(n.getComment(), arg);
|
||||
if (n.getScope() != null)
|
||||
if (n.getScope().isPresent())
|
||||
{
|
||||
n.getScope().accept(this, arg);
|
||||
n.getScope().get().accept(this, arg);
|
||||
}
|
||||
|
||||
m_typeRefKind.push(ReferenceKind.TYPE_ARGUMENT);
|
||||
@@ -205,7 +184,7 @@ public abstract class JavaAstVisitorAdapter extends VoidVisitorAdapter<Void>
|
||||
}
|
||||
m_typeRefKind.pop();
|
||||
|
||||
n.getType().accept(this, arg);
|
||||
// n.getType().accept(this, arg);
|
||||
if (n.getArguments() != null)
|
||||
{
|
||||
for (final Expression e : n.getArguments())
|
||||
@@ -251,11 +230,11 @@ public abstract class JavaAstVisitorAdapter extends VoidVisitorAdapter<Void>
|
||||
}
|
||||
}
|
||||
|
||||
private void visitComment(final Comment n, final Void arg)
|
||||
private void visitComment(final Optional<Comment> n, final Void arg)
|
||||
{
|
||||
if (n != null)
|
||||
if (n.isPresent())
|
||||
{
|
||||
n.accept(this, arg);
|
||||
n.get().accept(this, arg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public class JavaIndexer
|
||||
System.out.println("unable to add jar file: " + path);
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (!path.isEmpty())
|
||||
{
|
||||
JavaParserTypeSolver solver = new JavaParserTypeSolver(new File(path));
|
||||
typeSolver.add(solver);
|
||||
@@ -64,8 +64,8 @@ public class JavaIndexer
|
||||
{
|
||||
for (Problem problem: e.getProblems())
|
||||
{
|
||||
String message = problem.getMessage();
|
||||
if (message.startsWith("Encountered unexpected token"))
|
||||
String message = problem.toString();
|
||||
if (message.startsWith("(line "))
|
||||
{
|
||||
int startLine = Integer.parseInt(message.substring(
|
||||
message.indexOf("line ") + ("line ").length(),
|
||||
@@ -73,8 +73,8 @@ public class JavaIndexer
|
||||
));
|
||||
|
||||
int startColumn = Integer.parseInt(message.substring(
|
||||
message.indexOf("column ") + ("column ").length(),
|
||||
message.indexOf(".")
|
||||
message.indexOf("col ") + ("col ").length(),
|
||||
message.indexOf(")")
|
||||
));
|
||||
|
||||
recordError(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.coati;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.body.BodyDeclaration;
|
||||
@@ -38,7 +39,7 @@ public class JavaSymbolSolverTypeNameResolver extends JavaNameResolver
|
||||
}
|
||||
|
||||
public JavaTypeName getQualifiedTypeName(Type type)
|
||||
{ // , inferencevariabletype, , , , , typevar,
|
||||
{
|
||||
if (type instanceof ArrayType)
|
||||
{
|
||||
return getQualifiedTypeName(((ArrayType)type).getComponentType());
|
||||
@@ -89,13 +90,13 @@ public class JavaSymbolSolverTypeNameResolver extends JavaNameResolver
|
||||
if (typeParam instanceof JavaParserTypeParameter)
|
||||
{
|
||||
com.github.javaparser.ast.type.TypeParameter jpTypeParameter = ((JavaParserTypeParameter)typeParam).getWrappedNode();
|
||||
BodyDeclaration<?> genericDecl = jpTypeParameter.getAncestorOfType(BodyDeclaration.class);
|
||||
if (genericDecl instanceof BodyDeclaration)
|
||||
Optional<BodyDeclaration> genericDecl = jpTypeParameter.getAncestorOfType(BodyDeclaration.class);
|
||||
if (genericDecl.isPresent())
|
||||
{
|
||||
JavaDeclName genericName = null;
|
||||
if (!ignoresContext((BodyDeclaration)genericDecl))
|
||||
if (!ignoresContext(genericDecl.get()))
|
||||
{
|
||||
genericName = JavaparserDeclNameResolver.getQualifiedDeclName((BodyDeclaration)genericDecl, m_typeSolver, m_ignoredContexts);
|
||||
genericName = JavaparserDeclNameResolver.getQualifiedDeclName(genericDecl.get(), m_typeSolver, m_ignoredContexts);
|
||||
}
|
||||
return new JavaTypeName(jpTypeParameter.getName().getId(), genericName);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.github.javaparser.ast.*;
|
||||
import com.github.javaparser.ast.body.*;
|
||||
import com.github.javaparser.ast.comments.*;
|
||||
import com.github.javaparser.ast.expr.*;
|
||||
import com.github.javaparser.ast.imports.*;
|
||||
import com.github.javaparser.ast.nodeTypes.NodeWithName;
|
||||
import com.github.javaparser.ast.stmt.*;
|
||||
import com.github.javaparser.ast.type.*;
|
||||
@@ -61,15 +60,7 @@ public class JavaVerboseAstVisitor extends JavaAstVisitor{
|
||||
|
||||
public void visit(PackageDeclaration n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(BadImportDeclaration n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(SingleStaticImportDeclaration n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(SingleTypeImportDeclaration n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(StaticImportOnDemandDeclaration n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(TypeImportOnDemandDeclaration n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
public void visit(ImportDeclaration n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(TypeParameter n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
@@ -189,8 +180,6 @@ public class JavaVerboseAstVisitor extends JavaAstVisitor{
|
||||
|
||||
public void visit(ExplicitConstructorInvocationStmt n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(TypeDeclarationStmt n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(AssertStmt n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(BlockStmt n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
@@ -60,11 +60,11 @@ public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
}
|
||||
else
|
||||
{
|
||||
CompilationUnit compilationUnit = decl.getAncestorOfType(CompilationUnit.class);
|
||||
Optional<CompilationUnit> compilationUnit = decl.getAncestorOfType(CompilationUnit.class);
|
||||
|
||||
if (compilationUnit != null)
|
||||
if (compilationUnit.isPresent())
|
||||
{
|
||||
Optional<PackageDeclaration> packageDecl = compilationUnit.getPackageDeclaration();
|
||||
Optional<PackageDeclaration> packageDecl = compilationUnit.get().getPackageDeclaration();
|
||||
if (packageDecl.isPresent())
|
||||
{
|
||||
declName.setParent(getQualifiedName(packageDecl.get().getName()));
|
||||
@@ -108,11 +108,11 @@ public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
}
|
||||
else
|
||||
{
|
||||
CompilationUnit compilationUnit = decl.getAncestorOfType(CompilationUnit.class);
|
||||
Optional<CompilationUnit> compilationUnit = decl.getAncestorOfType(CompilationUnit.class);
|
||||
|
||||
if (compilationUnit != null)
|
||||
if (compilationUnit.isPresent())
|
||||
{
|
||||
Optional<PackageDeclaration> packageDecl = compilationUnit.getPackageDeclaration();
|
||||
Optional<PackageDeclaration> packageDecl = compilationUnit.get().getPackageDeclaration();
|
||||
if (packageDecl.isPresent())
|
||||
{
|
||||
declName.setParent(getQualifiedName(packageDecl.get().getName()));
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -317,7 +317,7 @@ public:
|
||||
);
|
||||
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->errors, "Encountered unexpected token. <1:1 1:1>"
|
||||
client->errors, "Encountered unexpected token. <0:0 0:0>"
|
||||
));
|
||||
}
|
||||
|
||||
@@ -444,7 +444,7 @@ public:
|
||||
));
|
||||
}
|
||||
|
||||
void _JSS_ISSUE_test_javyxcyxca_parser_finds_correct_location_of_qualified_type_usage()
|
||||
void test_parser_finds_usage_of_type_defined_in_base_class()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"public class Foo {\n"
|
||||
@@ -458,8 +458,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->typeUses.size(), 3);
|
||||
TS_ASSERT_EQUALS(client->typeUses[0], "Derived.x -> Base.X ###");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->typeUses, "Foo.Derived.x -> Foo.Base.X <7:10 7:10>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_correct_location_of_qualified_type_usage()
|
||||
@@ -472,13 +473,13 @@ public:
|
||||
" }\n"
|
||||
" void bar()\n"
|
||||
" {\n"
|
||||
" B b = new A.B();\n"
|
||||
" A.B b = new A.B();\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->typeUses, "void A.bar() -> A.B <8:13 8:15>"
|
||||
client->typeUses, "void A.bar() -> A.B <8:3 8:5>"
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user