logic: updated Java indexer
this fixes a lot of unsolved-symbol issues.
This commit is contained in:
@@ -30,4 +30,5 @@
|
||||
<source_path>./target/generated-sources/javacc</source_path>
|
||||
</source_paths>
|
||||
</source>
|
||||
<version>1</version>
|
||||
</config>
|
||||
|
||||
@@ -41,6 +41,9 @@ Edge.cpp ERROR: Nodes are not plain copies.
|
||||
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
|
||||
INFO: Indexer - indexing source file: input.cc
|
||||
INFO: Indexer - indexing source file: input.cc
|
||||
INFO: send MessageStatus Enabled console and file logging.
|
||||
INFO: send TestMessage
|
||||
INFO: send TestMessage
|
||||
|
||||
@@ -2,7 +2,8 @@ package io.coati;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.github.javaparser.ast.TypeParameter;
|
||||
import com.github.javaparser.ast.type.TypeParameter;
|
||||
import com.github.javaparser.ast.NodeList;
|
||||
import com.github.javaparser.ast.body.BodyDeclaration;
|
||||
import com.github.javaparser.ast.body.ConstructorDeclaration;
|
||||
import com.github.javaparser.ast.body.Parameter;
|
||||
@@ -25,15 +26,15 @@ public class CallableConstructorDecl implements CallableDecl
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return m_decl.getName();
|
||||
return m_decl.getNameAsString();
|
||||
}
|
||||
|
||||
public List<TypeParameter> getTypeParameters()
|
||||
public NodeList<TypeParameter> getTypeParameters()
|
||||
{
|
||||
return m_decl.getTypeParameters();
|
||||
}
|
||||
|
||||
public List<Parameter> getParameters()
|
||||
public NodeList<Parameter> getParameters()
|
||||
{
|
||||
return m_decl.getParameters();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ package io.coati;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.github.javaparser.ast.TypeParameter;
|
||||
import com.github.javaparser.ast.type.TypeParameter;
|
||||
import com.github.javaparser.ast.NodeList;
|
||||
import com.github.javaparser.ast.body.BodyDeclaration;
|
||||
import com.github.javaparser.ast.body.Parameter;
|
||||
import com.github.javaparser.ast.type.Type;
|
||||
@@ -11,7 +12,7 @@ public interface CallableDecl
|
||||
{
|
||||
public BodyDeclaration getWrappedNode();
|
||||
public String getName();
|
||||
public List<TypeParameter> getTypeParameters();
|
||||
public List<Parameter> getParameters();
|
||||
public NodeList<TypeParameter> getTypeParameters();
|
||||
public NodeList<Parameter> getParameters();
|
||||
public Type getType();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ package io.coati;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.github.javaparser.ast.TypeParameter;
|
||||
import com.github.javaparser.ast.type.TypeParameter;
|
||||
import com.github.javaparser.ast.NodeList;
|
||||
import com.github.javaparser.ast.body.BodyDeclaration;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.body.Parameter;
|
||||
@@ -24,15 +25,15 @@ public class CallableMethodDecl implements CallableDecl
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return m_decl.getName();
|
||||
return m_decl.getNameAsString();
|
||||
}
|
||||
|
||||
public List<TypeParameter> getTypeParameters()
|
||||
public NodeList<TypeParameter> getTypeParameters()
|
||||
{
|
||||
return m_decl.getTypeParameters();
|
||||
}
|
||||
|
||||
public List<Parameter> getParameters()
|
||||
public NodeList<Parameter> getParameters()
|
||||
{
|
||||
return m_decl.getParameters();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@ package io.coati;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.github.javaparser.Position;
|
||||
|
||||
public class FileContent
|
||||
{
|
||||
@@ -26,13 +29,18 @@ public class FileContent
|
||||
|
||||
public Location find(String s)
|
||||
{
|
||||
return find(s, 1, 1);
|
||||
return find(s, Position.pos(1, 1));
|
||||
}
|
||||
|
||||
public Location find(String s, int fromLine, int fromColumn)
|
||||
public Location find(String s, Optional<Position> from)
|
||||
{
|
||||
int lineIndex = fromLine - 1;
|
||||
int startColumn = fromColumn - 1;
|
||||
return find(s, from.orElse(Position.pos(1, 1)));
|
||||
}
|
||||
|
||||
public Location find(String s, Position from)
|
||||
{
|
||||
int lineIndex = from.line - 1;
|
||||
int startColumn = from.column - 1;
|
||||
int column = -1;
|
||||
while (lineIndex < m_lines.size())
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.coati;
|
||||
|
||||
import java.lang.String;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
@@ -12,37 +13,42 @@ import com.github.javaparser.ast.body.FieldDeclaration;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.body.Parameter;
|
||||
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.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.QualifiedNameExpr;
|
||||
import com.github.javaparser.ast.expr.SimpleName;
|
||||
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;
|
||||
import com.github.javaparser.ast.type.TypeParameter;
|
||||
import com.github.javaparser.ast.type.VoidType;
|
||||
import com.github.javaparser.ast.ImportDeclaration;
|
||||
import com.github.javaparser.ast.imports.*;
|
||||
import com.github.javaparser.Position;
|
||||
import com.github.javaparser.Range;
|
||||
import com.github.javaparser.ast.Modifier;
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.PackageDeclaration;
|
||||
import com.github.javaparser.ast.TypeParameter;
|
||||
|
||||
import me.tomassetti.symbolsolver.javaparsermodel.JavaParserFacade;
|
||||
import me.tomassetti.symbolsolver.javaparsermodel.UnsolvedSymbolException;
|
||||
import me.tomassetti.symbolsolver.javaparsermodel.declarations.JavaParserMethodDeclaration;
|
||||
import me.tomassetti.symbolsolver.javaparsermodel.declarations.JavaParserSymbolDeclaration;
|
||||
import me.tomassetti.symbolsolver.model.declarations.MethodAmbiguityException;
|
||||
import me.tomassetti.symbolsolver.model.declarations.TypeDeclaration;
|
||||
import me.tomassetti.symbolsolver.model.declarations.ValueDeclaration;
|
||||
import me.tomassetti.symbolsolver.model.invokations.MethodUsage;
|
||||
import me.tomassetti.symbolsolver.model.resolution.SymbolReference;
|
||||
import me.tomassetti.symbolsolver.model.resolution.TypeSolver;
|
||||
import me.tomassetti.symbolsolver.model.typesystem.*;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserFieldDeclaration;
|
||||
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.model.declarations.MethodAmbiguityException;
|
||||
import com.github.javaparser.symbolsolver.model.declarations.ReferenceTypeDeclaration;
|
||||
import com.github.javaparser.symbolsolver.model.declarations.ValueDeclaration;
|
||||
import com.github.javaparser.symbolsolver.model.methods.MethodUsage;
|
||||
import com.github.javaparser.symbolsolver.model.resolution.SymbolReference;
|
||||
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
|
||||
import com.github.javaparser.symbolsolver.model.resolution.UnsolvedSymbolException;
|
||||
import com.github.javaparser.symbolsolver.model.typesystem.*;
|
||||
import com.github.javaparser.symbolsolver.resolution.MethodResolutionLogic;
|
||||
|
||||
public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
{
|
||||
@@ -64,19 +70,19 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
m_context.add(new DeclContext(fileName + "\ts\tp"));
|
||||
}
|
||||
|
||||
|
||||
// --- record declarations ---
|
||||
|
||||
@Override public void visit(final PackageDeclaration n, final Void v)
|
||||
{
|
||||
NameExpr nameExpr = n.getName();
|
||||
Name name = n.getName();
|
||||
|
||||
String packageName = JavaparserDeclNameResolver.getQualifiedName(nameExpr).toSerializedNameHierarchy();
|
||||
String packageName = JavaparserDeclNameResolver.getQualifiedName(name).toSerializedNameHierarchy();
|
||||
Optional<Position> as = name.getBegin();
|
||||
|
||||
JavaIndexer.recordSymbolWithLocationAndScope(
|
||||
m_callbackId, packageName, SymbolType.PACKAGE,
|
||||
nameExpr.getBegin().line, nameExpr.getBegin().column, nameExpr.getEnd().line, nameExpr.getEnd().column,
|
||||
n.getBegin().line, n.getBegin().column, n.getEnd().line, n.getEnd().column,
|
||||
name.getRange(),
|
||||
n.getRange(),
|
||||
AccessKind.NONE, false
|
||||
);
|
||||
|
||||
@@ -85,19 +91,22 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
|
||||
@Override public void visit(final ClassOrInterfaceDeclaration n, final Void v)
|
||||
{
|
||||
NameExpr nameExpr = n.getNameExpr();
|
||||
SimpleName name = n.getName();
|
||||
|
||||
String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(n, m_typeSolver).toSerializedNameHierarchy();
|
||||
|
||||
JavaIndexer.recordSymbolWithLocationAndScope(
|
||||
m_callbackId, qualifiedName, (n.isInterface() ? SymbolType.INTERFACE : SymbolType.CLASS),
|
||||
nameExpr.getBegin().line, nameExpr.getBegin().column, nameExpr.getEnd().line, nameExpr.getEnd().column,
|
||||
n.getBegin().line, n.getBegin().column, n.getEnd().line, n.getEnd().column,
|
||||
name.getRange(),
|
||||
n.getRange(),
|
||||
AccessKind.fromAccessSpecifier(Modifier.getAccessSpecifier(n.getModifiers())), false
|
||||
);
|
||||
|
||||
FileContent.Location scopeStartLocation = m_fileContent.find("{", n.getBegin().line, n.getBegin().column);
|
||||
recordScope(scopeStartLocation.line, scopeStartLocation.column, n.getEnd().line, n.getEnd().column);
|
||||
if (n.getRange().isPresent())
|
||||
{
|
||||
FileContent.Location scopeStartLocation = m_fileContent.find("{", n.getBegin());
|
||||
recordScope(Range.range(scopeStartLocation.line, scopeStartLocation.column, n.getRange().get().end.line, n.getRange().get().end.column));
|
||||
}
|
||||
|
||||
List<DeclContext> parentContext = m_context;
|
||||
m_context = new ArrayList<DeclContext>();
|
||||
@@ -121,9 +130,21 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
qualifiedName += "\tn";
|
||||
qualifiedName += n.getName() + "\ts\tp";
|
||||
|
||||
|
||||
Optional<Range> range = Optional.empty();
|
||||
if (n.getBegin().isPresent())
|
||||
{
|
||||
range = Optional.of(Range.range(
|
||||
n.getBegin().get().line,
|
||||
n.getBegin().get().column,
|
||||
n.getBegin().get().line,
|
||||
n.getBegin().get().column + n.getNameAsString().length() - 1
|
||||
));
|
||||
}
|
||||
|
||||
JavaIndexer.recordSymbolWithLocation(
|
||||
m_callbackId, qualifiedName, SymbolType.TYPE_PARAMETER,
|
||||
n.getBegin().line, n.getBegin().column, n.getBegin().line, n.getBegin().column + n.getName().length() - 1,
|
||||
range,
|
||||
AccessKind.TYPE_PARAMETER, false
|
||||
);
|
||||
|
||||
@@ -136,19 +157,22 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
|
||||
@Override public void visit(final EnumDeclaration n, final Void v)
|
||||
{
|
||||
NameExpr nameExpr = n.getNameExpr();
|
||||
SimpleName name = n.getName();
|
||||
|
||||
String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(n, m_typeSolver).toSerializedNameHierarchy();
|
||||
|
||||
JavaIndexer.recordSymbolWithLocationAndScope(
|
||||
m_callbackId, qualifiedName, SymbolType.ENUM,
|
||||
nameExpr.getBegin().line, nameExpr.getBegin().column, nameExpr.getEnd().line, nameExpr.getEnd().column,
|
||||
n.getBegin().line, n.getBegin().column, n.getEnd().line, n.getEnd().column,
|
||||
name.getRange(),
|
||||
n.getRange(),
|
||||
AccessKind.fromAccessSpecifier(Modifier.getAccessSpecifier(n.getModifiers())), false
|
||||
);
|
||||
|
||||
FileContent.Location scopeStartLocation = m_fileContent.find("{", n.getBegin().line, n.getBegin().column);
|
||||
recordScope(scopeStartLocation.line, scopeStartLocation.column, n.getEnd().line, n.getEnd().column);
|
||||
|
||||
if (n.getRange().isPresent())
|
||||
{
|
||||
FileContent.Location scopeStartLocation = m_fileContent.find("{", n.getBegin());
|
||||
recordScope(Range.range(scopeStartLocation.line, scopeStartLocation.column, n.getRange().get().end.line, n.getRange().get().end.column));
|
||||
}
|
||||
|
||||
List<DeclContext> parentContext = m_context;
|
||||
m_context = new ArrayList<DeclContext>();
|
||||
@@ -163,7 +187,7 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
|
||||
JavaIndexer.recordSymbolWithLocation(
|
||||
m_callbackId, qualifiedName, SymbolType.ENUM_CONSTANT,
|
||||
n.getBegin().line, n.getBegin().column, n.getEnd().line, n.getEnd().column,
|
||||
n.getRange(),
|
||||
AccessKind.NONE, false
|
||||
);
|
||||
|
||||
@@ -176,14 +200,14 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
|
||||
@Override public void visit(final ConstructorDeclaration n, final Void v)
|
||||
{
|
||||
NameExpr nameExpr = n.getNameExpr();
|
||||
SimpleName name = n.getName();
|
||||
|
||||
String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(n, m_typeSolver).toSerializedNameHierarchy();
|
||||
|
||||
JavaIndexer.recordSymbolWithLocationAndScope(
|
||||
m_callbackId, qualifiedName, SymbolType.METHOD,
|
||||
nameExpr.getBegin().line, nameExpr.getBegin().column, nameExpr.getEnd().line, nameExpr.getEnd().column,
|
||||
n.getBegin().line, n.getBegin().column, n.getEnd().line, n.getEnd().column,
|
||||
name.getRange(),
|
||||
n.getRange(),
|
||||
AccessKind.fromAccessSpecifier(Modifier.getAccessSpecifier(n.getModifiers())), false
|
||||
);
|
||||
|
||||
@@ -196,27 +220,27 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
|
||||
@Override public void visit(final MethodDeclaration n, final Void v)
|
||||
{
|
||||
NameExpr nameExpr = n.getNameExpr();
|
||||
SimpleName name = n.getName();
|
||||
|
||||
String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(n, m_typeSolver).toSerializedNameHierarchy();
|
||||
|
||||
JavaIndexer.recordSymbolWithLocationAndScope(
|
||||
m_callbackId, qualifiedName, SymbolType.METHOD,
|
||||
nameExpr.getBegin().line, nameExpr.getBegin().column, nameExpr.getEnd().line, nameExpr.getEnd().column,
|
||||
n.getBegin().line, n.getBegin().column, n.getEnd().line, n.getEnd().column,
|
||||
name.getRange(),
|
||||
n.getRange(),
|
||||
AccessKind.fromAccessSpecifier(Modifier.getAccessSpecifier(n.getModifiers())), false
|
||||
);
|
||||
|
||||
|
||||
// test this!
|
||||
me.tomassetti.symbolsolver.model.declarations.MethodDeclaration overridden = getOverridden(n);
|
||||
com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration overridden = getOverridden(n);
|
||||
if (overridden != null && (overridden instanceof JavaParserMethodDeclaration))
|
||||
{
|
||||
String overriddenName = JavaparserDeclNameResolver.getQualifiedDeclName(((JavaParserMethodDeclaration)overridden).getWrappedNode(), m_typeSolver).toSerializedNameHierarchy();
|
||||
|
||||
JavaIndexer.recordReference(
|
||||
m_callbackId, ReferenceKind.OVERRIDE, overriddenName, qualifiedName,
|
||||
nameExpr.getBegin().line, nameExpr.getBegin().column, nameExpr.getEnd().line, nameExpr.getEnd().column
|
||||
name.getRange()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -227,12 +251,12 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
m_context = parentContext;
|
||||
}
|
||||
|
||||
private me.tomassetti.symbolsolver.model.declarations.MethodDeclaration getOverridden(MethodDeclaration overrider)
|
||||
private com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration getOverridden(MethodDeclaration overrider)
|
||||
{
|
||||
com.github.javaparser.ast.body.TypeDeclaration<?> scopeNode = overrider.getParentNodeOfType(com.github.javaparser.ast.body.TypeDeclaration.class);
|
||||
com.github.javaparser.ast.body.TypeDeclaration<?> scopeNode = overrider.getAncestorOfType(com.github.javaparser.ast.body.TypeDeclaration.class);
|
||||
if (scopeNode instanceof ClassOrInterfaceDeclaration)
|
||||
{
|
||||
List<TypeUsage> parameterTypes = new ArrayList<>();
|
||||
List<com.github.javaparser.symbolsolver.model.typesystem.Type> parameterTypes = new ArrayList<>();
|
||||
try
|
||||
{
|
||||
for (Parameter parameter: overrider.getParameters())
|
||||
@@ -241,12 +265,18 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
parameterTypes.add(JavaParserFacade.get(m_typeSolver).convert(parameterType, parameterType));
|
||||
}
|
||||
|
||||
TypeDeclaration scopeDecl = JavaParserFacade.get(m_typeSolver).getTypeDeclaration((ClassOrInterfaceDeclaration)scopeNode);
|
||||
for (ReferenceTypeUsage ancestor: scopeDecl.getAllAncestors())
|
||||
ReferenceTypeDeclaration scopeDecl = JavaParserFacade.get(m_typeSolver).getTypeDeclaration((ClassOrInterfaceDeclaration)scopeNode);
|
||||
for (ReferenceType ancestor: scopeDecl.getAllAncestors())
|
||||
{
|
||||
try
|
||||
{
|
||||
SymbolReference<me.tomassetti.symbolsolver.model.declarations.MethodDeclaration> solvedMethod = ancestor.solveMethod(overrider.getName(), parameterTypes);
|
||||
SymbolReference<com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration> solvedMethod = MethodResolutionLogic.solveMethodInType(
|
||||
ancestor.getTypeDeclaration(),
|
||||
overrider.getNameAsString(),
|
||||
parameterTypes,
|
||||
m_typeSolver
|
||||
);
|
||||
|
||||
if (solvedMethod.isSolved())
|
||||
{
|
||||
return solvedMethod.getCorrespondingDeclaration();
|
||||
@@ -267,6 +297,14 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
{
|
||||
return null;
|
||||
}
|
||||
catch (ClassCastException e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -276,16 +314,14 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
List<DeclContext> parentContext = m_context;
|
||||
m_context = new ArrayList<DeclContext>();
|
||||
|
||||
List<VariableDeclarator> variableDeclarators = n.getVariables();
|
||||
for (int i = 0; i < variableDeclarators.size(); i++)
|
||||
for (VariableDeclarator declarator: n.getVariables())
|
||||
{
|
||||
VariableDeclarator varDecl = variableDeclarators.get(i);
|
||||
String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(varDecl, m_typeSolver).toSerializedNameHierarchy();
|
||||
VariableDeclaratorId varDeclId = varDecl.getId();
|
||||
String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(declarator, m_typeSolver).toSerializedNameHierarchy();
|
||||
SimpleName name = declarator.getName();
|
||||
|
||||
JavaIndexer.recordSymbolWithLocation(
|
||||
m_callbackId, qualifiedName, SymbolType.FIELD,
|
||||
varDeclId.getBegin().line, varDeclId.getBegin().column, varDeclId.getEnd().line, varDeclId.getEnd().column,
|
||||
name.getRange(),
|
||||
AccessKind.fromAccessSpecifier(Modifier.getAccessSpecifier(n.getModifiers())), false
|
||||
);
|
||||
|
||||
@@ -298,16 +334,19 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
|
||||
@Override public void visit(final VariableDeclarationExpr n, final Void v)
|
||||
{
|
||||
for (VariableDeclarator declarator: n.getVars())
|
||||
for (VariableDeclarator declarator: n.getVariables())
|
||||
{
|
||||
VariableDeclaratorId identifier = declarator.getId();
|
||||
String qualifiedName = m_filePath + "<" + identifier.getBegin().line + ":" + identifier.getBegin().column + ">";
|
||||
|
||||
JavaIndexer.recordLocalSymbol(
|
||||
m_callbackId, qualifiedName,
|
||||
identifier.getBegin().line, identifier.getBegin().column, identifier.getEnd().line, identifier.getEnd().column
|
||||
);
|
||||
|
||||
SimpleName name = declarator.getName();
|
||||
|
||||
if (name.getBegin().isPresent())
|
||||
{
|
||||
String qualifiedName = m_filePath + "<" + name.getBegin().get().line + ":" + name.getBegin().get().column + ">";
|
||||
|
||||
JavaIndexer.recordLocalSymbol(
|
||||
m_callbackId, qualifiedName,
|
||||
name.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// don't change the context here.
|
||||
@@ -316,13 +355,17 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
|
||||
@Override public void visit(final Parameter n, final Void v)
|
||||
{
|
||||
VariableDeclaratorId identifier = n.getId();
|
||||
String qualifiedName = m_filePath + "<" + identifier.getBegin().line + ":" + identifier.getBegin().column + ">";
|
||||
SimpleName name = n.getName();
|
||||
|
||||
JavaIndexer.recordLocalSymbol(
|
||||
m_callbackId, qualifiedName,
|
||||
identifier.getBegin().line, identifier.getBegin().column, identifier.getEnd().line, identifier.getEnd().column
|
||||
);
|
||||
if (name.getBegin().isPresent())
|
||||
{
|
||||
String qualifiedName = m_filePath + "<" + name.getBegin().get().line + ":" + name.getBegin().get().column + ">";
|
||||
|
||||
JavaIndexer.recordLocalSymbol(
|
||||
m_callbackId, qualifiedName,
|
||||
name.getRange()
|
||||
);
|
||||
}
|
||||
|
||||
// don't change the context here.
|
||||
super.visit(n, v);
|
||||
@@ -332,99 +375,135 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
// --- record references ---
|
||||
|
||||
|
||||
@Override public void visit(final ImportDeclaration n, final Void v)
|
||||
@Override
|
||||
public void visit(SingleStaticImportDeclaration n, Void arg)
|
||||
{
|
||||
if (n.isAsterisk())
|
||||
try
|
||||
{
|
||||
NameExpr nameExpr = n.getName();
|
||||
String importedName = JavaparserDeclNameResolver.getQualifiedName(nameExpr).toSerializedNameHierarchy();
|
||||
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(),
|
||||
nameExpr.getBegin().line, nameExpr.getBegin().column, nameExpr.getEnd().line, nameExpr.getEnd().column
|
||||
type.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (Exception e)
|
||||
{
|
||||
try
|
||||
{
|
||||
NameExpr nameExpr = n.getName();
|
||||
List<JavaDeclName> importedDeclNames = new ArrayList<>();
|
||||
recordException(e, n);
|
||||
}
|
||||
}
|
||||
|
||||
SymbolReference<TypeDeclaration> symbolReference = m_typeSolver.tryToSolveType(
|
||||
JavaparserDeclNameResolver.getQualifiedName(nameExpr).toString()
|
||||
);
|
||||
if (symbolReference.isSolved())
|
||||
{
|
||||
importedDeclNames.add(JavaSymbolSolverDeclNameResolver.getQualifiedDeclName(
|
||||
symbolReference.getCorrespondingDeclaration(), m_typeSolver
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (nameExpr instanceof QualifiedNameExpr)
|
||||
{
|
||||
String typeName = ((QualifiedNameExpr)nameExpr).getQualifier().toString();
|
||||
String memberName = nameExpr.getName();
|
||||
|
||||
me.tomassetti.symbolsolver.model.declarations.TypeDeclaration ref = m_typeSolver.solveType(typeName);
|
||||
|
||||
for (me.tomassetti.symbolsolver.model.declarations.MethodDeclaration methodDecl: ref.getDeclaredMethods()) // look for method
|
||||
{
|
||||
if (methodDecl.getName().equals(memberName))
|
||||
{
|
||||
importedDeclNames.add(
|
||||
JavaSymbolSolverDeclNameResolver.getQualifiedDeclName(methodDecl, m_typeSolver
|
||||
));
|
||||
}
|
||||
}
|
||||
if (importedDeclNames.isEmpty() && ref.hasField(memberName)) // look for field
|
||||
{
|
||||
JavaDeclName importedTypeDeclName = JavaSymbolSolverDeclNameResolver.getQualifiedDeclName(ref, 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(),
|
||||
nameExpr.getBegin().line, nameExpr.getBegin().column, nameExpr.getEnd().line, nameExpr.getEnd().column
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JavaIndexer.recordError(
|
||||
m_callbackId, "Import not found.", true, true,
|
||||
nameExpr.getBegin().line, nameExpr.getBegin().column, nameExpr.getEnd().line, nameExpr.getEnd().column
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
@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)
|
||||
{
|
||||
recordException(e, n);
|
||||
JavaIndexer.recordReference(
|
||||
m_callbackId, ReferenceKind.IMPORT,
|
||||
importedName, context.getName(),
|
||||
type.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
super.visit(n, v);
|
||||
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)
|
||||
{
|
||||
JavaIndexer.recordReference(
|
||||
m_callbackId, ReferenceKind.IMPORT,
|
||||
importedName, context.getName(),
|
||||
name.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
recordException(e, n);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void visit(final ClassOrInterfaceType n, final Void v)
|
||||
{
|
||||
try
|
||||
@@ -433,20 +512,30 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
{
|
||||
String referencedName = JavaparserTypeNameResolver.getQualifiedTypeName(n, m_typeSolver).toSerializedNameHierarchy();
|
||||
|
||||
int beginLine = n.getBegin().line;
|
||||
int beginColumn = n.getBegin().column;
|
||||
int endLine = n.getBegin().line;
|
||||
int endColumn = n.getBegin().column + n.getName().length() - 1;
|
||||
Range range = Range.range(0, 0, 0, 0);
|
||||
|
||||
if (n.getScope() != null)
|
||||
if (n.getRange().isPresent())
|
||||
{
|
||||
endLine = n.getScope().getEnd().line;
|
||||
endColumn = n.getScope().getEnd().column + n.getName().length() + 1; // +1 for separator
|
||||
range = Range.range(
|
||||
n.getRange().get().begin.line,
|
||||
n.getRange().get().begin.column,
|
||||
n.getRange().get().begin.line,
|
||||
n.getRange().get().begin.column + n.getNameAsString().length() - 1
|
||||
);
|
||||
}
|
||||
|
||||
Optional<ClassOrInterfaceType> scope = n.getScope();
|
||||
if (scope.isPresent() && scope.get().getEnd().isPresent())
|
||||
{
|
||||
range = range.withEnd(
|
||||
Position.pos(scope.get().getEnd().get().line,
|
||||
scope.get().getEnd().get().column + n.getNameAsString().length() + 1 // +1 for separator
|
||||
));
|
||||
}
|
||||
|
||||
JavaIndexer.recordReference(
|
||||
m_callbackId, getTypeReferenceKind(), referencedName, context.getName(),
|
||||
beginLine, beginColumn, endLine, endColumn
|
||||
range
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -472,7 +561,7 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
{
|
||||
JavaIndexer.recordReference(
|
||||
m_callbackId, getTypeReferenceKind(), referencedName, context.getName(),
|
||||
n.getBegin().line, n.getBegin().column, n.getEnd().line, n.getEnd().column
|
||||
n.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -499,7 +588,7 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
{
|
||||
JavaIndexer.recordReference(
|
||||
m_callbackId, getTypeReferenceKind(), referencedName, context.getName(),
|
||||
n.getBegin().line, n.getBegin().column, n.getEnd().line, n.getEnd().column
|
||||
n.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -511,6 +600,50 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
super.visit(n, v);
|
||||
}
|
||||
|
||||
@Override public void visit(final FieldAccessExpr n, final Void v)
|
||||
{
|
||||
SimpleName fieldName = n.getField();
|
||||
|
||||
try
|
||||
{
|
||||
SymbolReference<? extends ValueDeclaration> ref = JavaParserFacade.get(m_typeSolver).solve(fieldName);
|
||||
if (ref.isSolved())
|
||||
{
|
||||
ValueDeclaration valueDecl = ref.getCorrespondingDeclaration();
|
||||
|
||||
Node wrappedNode = null;
|
||||
if (valueDecl instanceof JavaParserFieldDeclaration)
|
||||
{
|
||||
wrappedNode = ((JavaParserFieldDeclaration)valueDecl).getWrappedNode();
|
||||
}
|
||||
if (wrappedNode != null && wrappedNode instanceof FieldDeclaration)
|
||||
{
|
||||
|
||||
for (VariableDeclarator var: ((FieldDeclaration)wrappedNode).getVariables())
|
||||
{
|
||||
if (var.getName().getIdentifier().equals(fieldName.getIdentifier()))
|
||||
{
|
||||
String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(var, m_typeSolver).toSerializedNameHierarchy();
|
||||
for (DeclContext context: m_context)
|
||||
{
|
||||
JavaIndexer.recordReference(
|
||||
m_callbackId, ReferenceKind.USAGE, qualifiedName, context.getName(),
|
||||
fieldName.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
recordException(e, n);
|
||||
}
|
||||
|
||||
super.visit(n, v);
|
||||
}
|
||||
|
||||
@Override public void visit(final NameExpr n, final Void v)
|
||||
{
|
||||
try
|
||||
@@ -531,47 +664,56 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
if (ref.isSolved())
|
||||
{
|
||||
ValueDeclaration valueDecl = ref.getCorrespondingDeclaration();
|
||||
|
||||
Node wrappedNode = null;
|
||||
if (valueDecl instanceof JavaParserSymbolDeclaration)
|
||||
{
|
||||
Node wrappedNode = null;
|
||||
if (valueDecl instanceof JavaParserSymbolDeclaration)
|
||||
wrappedNode = ((JavaParserSymbolDeclaration)valueDecl).getWrappedNode();
|
||||
}
|
||||
else if (valueDecl instanceof JavaParserParameterDeclaration)
|
||||
{
|
||||
wrappedNode = ((JavaParserParameterDeclaration)valueDecl).getWrappedNode();
|
||||
}
|
||||
|
||||
if (wrappedNode != null)
|
||||
{
|
||||
if (wrappedNode instanceof Parameter)
|
||||
{
|
||||
wrappedNode = ((JavaParserSymbolDeclaration)valueDecl).getWrappedNode();
|
||||
}
|
||||
if (wrappedNode != null)
|
||||
{
|
||||
if (wrappedNode instanceof Parameter)
|
||||
SimpleName name = ((Parameter)wrappedNode).getName();
|
||||
if (name.getBegin().isPresent())
|
||||
{
|
||||
VariableDeclaratorId identifier = ((Parameter)wrappedNode).getId();
|
||||
String qualifiedName = m_filePath + "<" + identifier.getBegin().line + ":" + identifier.getBegin().column + ">";
|
||||
String qualifiedName = m_filePath + "<" + name.getBegin().get().line + ":" + name.getBegin().get().column + ">";
|
||||
|
||||
JavaIndexer.recordLocalSymbol(
|
||||
m_callbackId, qualifiedName,
|
||||
e.getBegin().line, e.getBegin().column, e.getEnd().line, e.getEnd().column
|
||||
e.getRange()
|
||||
);
|
||||
}
|
||||
else if (wrappedNode instanceof VariableDeclarator)
|
||||
}
|
||||
else if (wrappedNode instanceof VariableDeclarator)
|
||||
{
|
||||
if (wrappedNode.getAncestorOfType(FieldDeclaration.class) != null)
|
||||
{
|
||||
if (getFieldDeclarationInParentHierarchy(wrappedNode) != null)
|
||||
String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName((VariableDeclarator)wrappedNode, m_typeSolver).toSerializedNameHierarchy();
|
||||
|
||||
for (DeclContext context: m_context)
|
||||
{
|
||||
String qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName((VariableDeclarator)wrappedNode, m_typeSolver).toSerializedNameHierarchy();
|
||||
|
||||
for (DeclContext context: m_context)
|
||||
{
|
||||
JavaIndexer.recordReference(
|
||||
m_callbackId, ReferenceKind.USAGE, qualifiedName, context.getName(),
|
||||
e.getBegin().line, e.getBegin().column, e.getEnd().line, e.getEnd().column
|
||||
);
|
||||
}
|
||||
JavaIndexer.recordReference(
|
||||
m_callbackId, ReferenceKind.USAGE, qualifiedName, context.getName(),
|
||||
e.getRange()
|
||||
);
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
SimpleName name = ((VariableDeclarator)wrappedNode).getName();
|
||||
if (name.getBegin().isPresent())
|
||||
{
|
||||
VariableDeclaratorId identifier = ((VariableDeclarator)wrappedNode).getId();
|
||||
String qualifiedName = m_filePath + "<" + identifier.getBegin().line + ":" + identifier.getBegin().column + ">";
|
||||
String qualifiedName = m_filePath + "<" + name.getBegin().get().line + ":" + name.getBegin().get().column + ">";
|
||||
|
||||
JavaIndexer.recordLocalSymbol(
|
||||
m_callbackId, qualifiedName,
|
||||
e.getBegin().line, e.getBegin().column, e.getEnd().line, e.getEnd().column
|
||||
e.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -579,24 +721,6 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static FieldDeclaration getFieldDeclarationInParentHierarchy(Node decl)
|
||||
{
|
||||
FieldDeclaration context = null;
|
||||
{
|
||||
Node parentNode = decl.getParentNode();
|
||||
while (parentNode != null && !(parentNode instanceof FieldDeclaration))
|
||||
{
|
||||
parentNode = parentNode.getParentNode();
|
||||
}
|
||||
|
||||
if (parentNode != null)
|
||||
{
|
||||
context = (FieldDeclaration)parentNode;
|
||||
}
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
@Override public void visit(final MethodCallExpr n, final Void v)
|
||||
{
|
||||
@@ -605,8 +729,15 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
MethodUsage solvedMethod = JavaParserFacade.get(m_typeSolver).solveMethodAsUsage(n);
|
||||
qualifiedName = getQualifiedName(solvedMethod);
|
||||
SymbolReference<com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration> solvedMethod = JavaParserFacade.get(m_typeSolver).solve(n);
|
||||
if (solvedMethod.isSolved())
|
||||
{
|
||||
qualifiedName = getQualifiedName(solvedMethod.getCorrespondingDeclaration());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnsolvedSymbolException(n.getNameAsString());
|
||||
}
|
||||
}
|
||||
catch (UnsupportedOperationException e)
|
||||
{
|
||||
@@ -628,12 +759,12 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
|
||||
if (!qualifiedName.isEmpty())
|
||||
{
|
||||
NameExpr nameExpr = n.getNameExpr();
|
||||
SimpleName name = n.getName();
|
||||
for (DeclContext context: m_context)
|
||||
{
|
||||
JavaIndexer.recordReference(
|
||||
m_callbackId, ReferenceKind.CALL, qualifiedName, context.getName(),
|
||||
nameExpr.getBegin().line, nameExpr.getBegin().column, nameExpr.getEnd().line, nameExpr.getEnd().column
|
||||
name.getRange()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -644,20 +775,29 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
|
||||
private void recordException(Exception e, Node n)
|
||||
{
|
||||
JavaIndexer.logError(m_callbackId, e.getClass() + " at " + m_filePath + "<"+ n.getBegin().line + ", " + n.getBegin().column + ">");
|
||||
JavaIndexer.recordSymbolWithLocation(
|
||||
m_callbackId, "unsolved-symbol\ts\tp", SymbolType.TYPE_MAX,
|
||||
n.getBegin().line, n.getBegin().column, n.getEnd().line, n.getEnd().column,
|
||||
AccessKind.DEFAULT, false
|
||||
);
|
||||
recordExceptionOrError(e.getClass().getSimpleName(), n);
|
||||
}
|
||||
|
||||
private void recordError(Error e, Node n)
|
||||
{
|
||||
JavaIndexer.logError(m_callbackId, e.getClass() + " at " + m_filePath + "<"+ n.getBegin().line + ", " + n.getBegin().column + ">");
|
||||
recordExceptionOrError(e.getClass().getSimpleName(), n);
|
||||
}
|
||||
|
||||
private void recordExceptionOrError(String e, Node n)
|
||||
{
|
||||
String beginLine = "?";
|
||||
String beginColumn = "?";
|
||||
|
||||
if (n.getBegin().isPresent())
|
||||
{
|
||||
beginLine = n.getBegin().get().line + "";
|
||||
beginColumn = n.getBegin().get().column + "";
|
||||
}
|
||||
|
||||
JavaIndexer.logError(m_callbackId, e + " at " + m_filePath + "<"+ beginLine + ", " + beginColumn + ">");
|
||||
JavaIndexer.recordSymbolWithLocation(
|
||||
m_callbackId, "unsolved-symbol\ts\tp", SymbolType.TYPE_MAX,
|
||||
n.getBegin().line, n.getBegin().column, n.getEnd().line, n.getEnd().column,
|
||||
n.getRange(),
|
||||
AccessKind.DEFAULT, false
|
||||
);
|
||||
}
|
||||
@@ -740,13 +880,12 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
super.visit(n, v);
|
||||
}
|
||||
*/
|
||||
private String getQualifiedName(MethodUsage solvedMethod)
|
||||
private String getQualifiedName(com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration solvedMethod)
|
||||
{
|
||||
me.tomassetti.symbolsolver.model.declarations.MethodDeclaration methodDecl = solvedMethod.getDeclaration();
|
||||
String qualifiedName = "";
|
||||
if (methodDecl instanceof JavaParserMethodDeclaration)
|
||||
if (solvedMethod instanceof JavaParserMethodDeclaration)
|
||||
{
|
||||
MethodDeclaration wrappedNode = ((JavaParserMethodDeclaration)methodDecl).getWrappedNode();
|
||||
MethodDeclaration wrappedNode = ((JavaParserMethodDeclaration)solvedMethod).getWrappedNode();
|
||||
qualifiedName = JavaparserDeclNameResolver.getQualifiedDeclName(wrappedNode, m_typeSolver).toSerializedNameHierarchy();
|
||||
}
|
||||
else // todo: move this implementation somewhere else
|
||||
@@ -756,18 +895,18 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
|
||||
qualifiedName += "\ts\tp\tn" + solvedMethod.getName() + "\ts";
|
||||
|
||||
String returnType = solvedMethod.returnType().describe();
|
||||
String returnType = solvedMethod.getReturnType().describe();
|
||||
qualifiedName += returnType;
|
||||
// qualifiedName += returnType.substring(returnType.lastIndexOf(".") + 1);
|
||||
|
||||
qualifiedName += "\tp(";
|
||||
for (int i = 0; i < solvedMethod.getParamTypes().size(); i++)
|
||||
for (int i = 0; i < solvedMethod.getNumberOfParams(); i++)
|
||||
{
|
||||
if(i != 0)
|
||||
{
|
||||
qualifiedName += (", ");
|
||||
}
|
||||
String paramType = solvedMethod.getParamTypes().get(i).describe();
|
||||
String paramType = solvedMethod.getParam(i).describeType();
|
||||
qualifiedName += paramType;
|
||||
// qualifiedName += paramType.substring(paramType.lastIndexOf(".") + 1);
|
||||
}
|
||||
@@ -778,35 +917,46 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
|
||||
@Override public void visit(final BlockStmt n, final Void v)
|
||||
{
|
||||
recordScope(n.getBegin().line, n.getBegin().column, n.getEnd().line, n.getEnd().column);
|
||||
recordScope(n.getRange());
|
||||
super.visit(n, v);
|
||||
}
|
||||
|
||||
@Override public void visit(final ArrayInitializerExpr n, final Void v)
|
||||
{
|
||||
recordScope(n.getBegin().line, n.getBegin().column, n.getEnd().line, n.getEnd().column);
|
||||
recordScope(n.getRange());
|
||||
super.visit(n, v);
|
||||
}
|
||||
|
||||
@Override public void visit(final SwitchStmt n, final Void v)
|
||||
{
|
||||
FileContent.Location scopeStartLocation = m_fileContent.find("{", n.getBegin().line, n.getBegin().column);
|
||||
recordScope(scopeStartLocation.line, scopeStartLocation.column, n.getEnd().line, n.getEnd().column);
|
||||
if (n.getRange().isPresent())
|
||||
{
|
||||
FileContent.Location scopeStartLocation = m_fileContent.find("{", n.getBegin());
|
||||
recordScope(Range.range(scopeStartLocation.line, scopeStartLocation.column, n.getRange().get().end.line, n.getRange().get().end.column));
|
||||
}
|
||||
super.visit(n, v);
|
||||
}
|
||||
|
||||
private void recordScope(int beginLine, int beginColumn, int endLine, int endColumn)
|
||||
private void recordScope(Optional<Range> range)
|
||||
{
|
||||
String qualifiedName = m_filePath + "<" + beginLine + ":" + beginColumn + ">";
|
||||
JavaIndexer.recordLocalSymbol(m_callbackId, qualifiedName, beginLine, beginColumn, beginLine, beginColumn);
|
||||
JavaIndexer.recordLocalSymbol(m_callbackId, qualifiedName, endLine, endColumn, endLine, endColumn);
|
||||
if (range.isPresent())
|
||||
{
|
||||
recordScope(range.get());
|
||||
}
|
||||
}
|
||||
|
||||
private void recordScope(Range range)
|
||||
{
|
||||
String qualifiedName = m_filePath + "<" + range.begin.line + ":" + range.begin.column + ">";
|
||||
JavaIndexer.recordLocalSymbol(m_callbackId, qualifiedName, range.begin.line, range.begin.column, range.begin.line, range.begin.column);
|
||||
JavaIndexer.recordLocalSymbol(m_callbackId, qualifiedName, range.end.line, range.end.column, range.end.line, range.end.column);
|
||||
}
|
||||
|
||||
@Override public void visit(final LineComment n, final Void v)
|
||||
{
|
||||
JavaIndexer.recordComment(
|
||||
m_callbackId,
|
||||
n.getBegin().line, n.getBegin().column, n.getEnd().line, n.getEnd().column
|
||||
n.getRange()
|
||||
);
|
||||
super.visit(n, v);
|
||||
}
|
||||
@@ -815,7 +965,7 @@ public class JavaAstVisitor extends JavaAstVisitorAdapter
|
||||
{
|
||||
JavaIndexer.recordComment(
|
||||
m_callbackId,
|
||||
n.getBegin().line, n.getBegin().column, n.getEnd().line, n.getEnd().column
|
||||
n.getRange()
|
||||
);
|
||||
super.visit(n, v);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,19 +4,20 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.lang.String;
|
||||
import java.util.Optional;
|
||||
|
||||
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.Problem;
|
||||
|
||||
import me.tomassetti.symbolsolver.javaparser.Navigator;
|
||||
import me.tomassetti.symbolsolver.javaparsermodel.JavaParserFacade;
|
||||
import me.tomassetti.symbolsolver.resolution.typesolvers.CombinedTypeSolver;
|
||||
import me.tomassetti.symbolsolver.resolution.typesolvers.JarTypeSolver;
|
||||
import me.tomassetti.symbolsolver.resolution.typesolvers.JavaParserTypeSolver;
|
||||
import me.tomassetti.symbolsolver.resolution.typesolvers.JreTypeSolver;
|
||||
import com.github.javaparser.Range;
|
||||
import com.github.javaparser.symbolsolver.javaparser.Navigator;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade;
|
||||
import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver;
|
||||
import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver;
|
||||
import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver;
|
||||
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;
|
||||
|
||||
public class JavaIndexer
|
||||
{
|
||||
@@ -28,7 +29,7 @@ public class JavaIndexer
|
||||
{
|
||||
CombinedTypeSolver typeSolver = new CombinedTypeSolver();
|
||||
|
||||
typeSolver.add(new JreTypeSolver());
|
||||
typeSolver.add(new ReflectionTypeSolver());
|
||||
for (String path: classPath.split("\\;"))
|
||||
{
|
||||
if (path.endsWith(".jar"))
|
||||
@@ -49,7 +50,7 @@ public class JavaIndexer
|
||||
typeSolver.add(solver);
|
||||
}
|
||||
}
|
||||
CompilationUnit cu = JavaParser.parse(new StringReader(fileContent), true);
|
||||
CompilationUnit cu = JavaParser.parse(new StringReader(fileContent));
|
||||
|
||||
JavaAstVisitor astVisitor = (
|
||||
verbose == 1 ?
|
||||
@@ -61,33 +62,36 @@ public class JavaIndexer
|
||||
}
|
||||
catch (ParseProblemException e)
|
||||
{
|
||||
for (Problem problem: e.problems)
|
||||
for (Problem problem: e.getProblems())
|
||||
{
|
||||
if (problem.message.startsWith("Encountered unexpected token"))
|
||||
String message = problem.getMessage();
|
||||
if (message.startsWith("Encountered unexpected token"))
|
||||
{
|
||||
int startLine = Integer.parseInt(problem.message.substring(
|
||||
problem.message.indexOf("line ") + ("line ").length(),
|
||||
problem.message.indexOf(",")
|
||||
int startLine = Integer.parseInt(message.substring(
|
||||
message.indexOf("line ") + ("line ").length(),
|
||||
message.indexOf(",")
|
||||
));
|
||||
|
||||
int startColumn = Integer.parseInt(problem.message.substring(
|
||||
problem.message.indexOf("column ") + ("column ").length(),
|
||||
problem.message.indexOf(".")
|
||||
int startColumn = Integer.parseInt(message.substring(
|
||||
message.indexOf("column ") + ("column ").length(),
|
||||
message.indexOf(".")
|
||||
));
|
||||
|
||||
recordError(
|
||||
address, "Encountered unexpected token.", true, true,
|
||||
startLine, startColumn,
|
||||
startLine, startColumn
|
||||
Range.range(startLine, startColumn, startLine, startColumn)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
recordError(
|
||||
address, problem.toString(), true, true,
|
||||
problem.range.begin.line, problem.range.begin.column,
|
||||
problem.range.end.line, problem.range.end.column
|
||||
);
|
||||
{
|
||||
Optional<Range> range = problem.getRange();
|
||||
if (range.isPresent())
|
||||
{
|
||||
recordError(
|
||||
address, problem.toString(), true, true,
|
||||
range.get()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,7 +104,7 @@ public class JavaIndexer
|
||||
String packageName = "";
|
||||
try
|
||||
{
|
||||
CompilationUnit cu = JavaParser.parse(new StringReader(fileContent), true);
|
||||
CompilationUnit cu = JavaParser.parse(new StringReader(fileContent));
|
||||
PackageDeclaration pd = Navigator.findNodeOfGivenClass(cu, PackageDeclaration.class);
|
||||
if (pd != null)
|
||||
{
|
||||
@@ -134,50 +138,139 @@ public class JavaIndexer
|
||||
|
||||
static public void recordSymbolWithLocation(
|
||||
int address, String symbolName, SymbolType symbolType,
|
||||
int beginLine, int beginColumn, int endLine, int endColumn,
|
||||
Optional<Range> range,
|
||||
AccessKind access, boolean isImplicit
|
||||
)
|
||||
{
|
||||
recordSymbolWithLocation(
|
||||
address, symbolName, symbolType,
|
||||
range.orElse(Range.range(0, 0, 0, 0)),
|
||||
access, isImplicit
|
||||
);
|
||||
}
|
||||
|
||||
static public void recordSymbolWithLocation(
|
||||
int address, String symbolName, SymbolType symbolType,
|
||||
Range range,
|
||||
AccessKind access, boolean isImplicit
|
||||
)
|
||||
{
|
||||
recordSymbolWithLocation(
|
||||
address, symbolName, symbolType.getValue(),
|
||||
beginLine, beginColumn, endLine, endColumn,
|
||||
range.begin.line, range.begin.column, range.end.line, range.end.column,
|
||||
access.getValue(), (isImplicit ? 1 : 0)
|
||||
);
|
||||
}
|
||||
|
||||
static public void recordSymbolWithLocationAndScope(
|
||||
int address, String symbolName, SymbolType symbolType,
|
||||
int beginLine, int beginColumn, int endLine, int endColumn,
|
||||
int scopeBeginLine, int scopeBeginColumn, int scopeEndLine, int scopeEndColumn,
|
||||
Optional<Range> range,
|
||||
Optional<Range> scopeRange,
|
||||
AccessKind access, boolean isImplicit
|
||||
)
|
||||
{
|
||||
recordSymbolWithLocationAndScope(
|
||||
address, symbolName, symbolType,
|
||||
range.orElse(Range.range(0, 0, 0, 0)),
|
||||
scopeRange.orElse(Range.range(0, 0, 0, 0)),
|
||||
access, isImplicit
|
||||
);
|
||||
}
|
||||
|
||||
static public void recordSymbolWithLocationAndScope(
|
||||
int address, String symbolName, SymbolType symbolType,
|
||||
Range range,
|
||||
Range scopeRange,
|
||||
AccessKind access, boolean isImplicit
|
||||
)
|
||||
{
|
||||
recordSymbolWithLocationAndScope(
|
||||
address, symbolName, symbolType.getValue(),
|
||||
beginLine, beginColumn, endLine, endColumn,
|
||||
scopeBeginLine, scopeBeginColumn, scopeEndLine, scopeEndColumn,
|
||||
range.begin.line, range.begin.column, range.end.line, range.end.column,
|
||||
scopeRange.begin.line, scopeRange.begin.column, scopeRange.end.line, scopeRange.end.column,
|
||||
access.getValue(), (isImplicit ? 1 : 0)
|
||||
);
|
||||
}
|
||||
|
||||
static public void recordReference(
|
||||
int address, ReferenceKind referenceKind, String referencedName, String contextName,
|
||||
int beginLine, int beginColumn, int endLine, int endColumn
|
||||
Optional<Range> range
|
||||
)
|
||||
{
|
||||
recordReference(
|
||||
address, referenceKind, referencedName, contextName,
|
||||
range.orElse(Range.range(0, 0, 0, 0))
|
||||
);
|
||||
}
|
||||
|
||||
static public void recordReference(
|
||||
int address, ReferenceKind referenceKind, String referencedName, String contextName,
|
||||
Range range
|
||||
)
|
||||
{
|
||||
recordReference(
|
||||
address, referenceKind.getValue(), referencedName, contextName,
|
||||
beginLine, beginColumn, endLine, endColumn
|
||||
range.begin.line, range.begin.column, range.end.line, range.end.column
|
||||
);
|
||||
}
|
||||
|
||||
static public void recordLocalSymbol(
|
||||
int address, String symbolName,
|
||||
Optional<Range> range
|
||||
)
|
||||
{
|
||||
recordLocalSymbol(address, symbolName, range.orElse(Range.range(0, 0, 0, 0)));
|
||||
}
|
||||
|
||||
static public void recordLocalSymbol(
|
||||
int address, String symbolName,
|
||||
Range range
|
||||
)
|
||||
{
|
||||
recordLocalSymbol(
|
||||
address, symbolName,
|
||||
range.begin.line, range.begin.column, range.end.line, range.end.column
|
||||
);
|
||||
}
|
||||
|
||||
static public void recordComment(
|
||||
int address,
|
||||
Optional<Range> range
|
||||
)
|
||||
{
|
||||
recordComment(address, range.orElse(Range.range(0, 0, 0, 0)));
|
||||
}
|
||||
|
||||
static public void recordComment(
|
||||
int address,
|
||||
Range range
|
||||
)
|
||||
{
|
||||
recordComment(
|
||||
address,
|
||||
range.begin.line, range.begin.column, range.end.line, range.end.column
|
||||
);
|
||||
}
|
||||
|
||||
static public void recordError(
|
||||
int address, String message, boolean fatal, boolean indexed, int beginLine, int beginColumn, int endLine, int endColumn
|
||||
int address, String message, boolean fatal, boolean indexed,
|
||||
Optional<Range> range
|
||||
)
|
||||
{
|
||||
recordError(
|
||||
address, message, fatal, indexed,
|
||||
range.orElse(Range.range(0, 0, 0, 0))
|
||||
);
|
||||
}
|
||||
|
||||
static public void recordError(
|
||||
int address, String message, boolean fatal, boolean indexed,
|
||||
Range range
|
||||
)
|
||||
{
|
||||
recordError(
|
||||
address, message, (fatal ? 1 : 0), (indexed ? 1 : 0),
|
||||
beginLine, beginColumn, endLine, endColumn
|
||||
range.begin.line, range.begin.column, range.end.line, range.end.column
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.ArrayList;
|
||||
|
||||
import com.github.javaparser.ast.body.BodyDeclaration;
|
||||
|
||||
import me.tomassetti.symbolsolver.model.resolution.TypeSolver;
|
||||
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
|
||||
|
||||
public abstract class JavaNameResolver
|
||||
{
|
||||
|
||||
@@ -5,17 +5,15 @@ import java.util.List;
|
||||
|
||||
import com.github.javaparser.ast.body.BodyDeclaration;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.ast.body.Parameter;
|
||||
|
||||
import me.tomassetti.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration;
|
||||
import me.tomassetti.symbolsolver.javaparsermodel.declarations.JavaParserInterfaceDeclaration;
|
||||
import me.tomassetti.symbolsolver.javaparsermodel.declarations.JavaParserMethodDeclaration;
|
||||
import me.tomassetti.symbolsolver.model.declarations.Declaration;
|
||||
import me.tomassetti.symbolsolver.model.declarations.MethodDeclaration;
|
||||
import me.tomassetti.symbolsolver.model.declarations.ParameterDeclaration;
|
||||
import me.tomassetti.symbolsolver.model.declarations.TypeDeclaration;
|
||||
import me.tomassetti.symbolsolver.model.resolution.TypeParameter;
|
||||
import me.tomassetti.symbolsolver.model.resolution.TypeSolver;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserInterfaceDeclaration;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserMethodDeclaration;
|
||||
import com.github.javaparser.symbolsolver.model.declarations.Declaration;
|
||||
import com.github.javaparser.symbolsolver.model.declarations.MethodDeclaration;
|
||||
import com.github.javaparser.symbolsolver.model.declarations.TypeDeclaration;
|
||||
import com.github.javaparser.symbolsolver.model.declarations.TypeParameterDeclaration;
|
||||
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
|
||||
|
||||
public class JavaSymbolSolverDeclNameResolver extends JavaNameResolver
|
||||
{
|
||||
@@ -81,7 +79,7 @@ public class JavaSymbolSolverDeclNameResolver extends JavaNameResolver
|
||||
// TODO: what about endless recursion regarding type parameters and return type??
|
||||
|
||||
List<JavaTypeName> parameterNames = new ArrayList<>();
|
||||
for (int i = 0; i < methodDecl.getNoParams(); i++)
|
||||
for (int i = 0; i < methodDecl.getNumberOfParams(); i++)
|
||||
{
|
||||
parameterNames.add(JavaSymbolSolverTypeNameResolver.getQualifiedTypeName(
|
||||
methodDecl.getParam(i).getType(), m_typeSolver, m_ignoredContexts
|
||||
@@ -105,7 +103,7 @@ public class JavaSymbolSolverDeclNameResolver extends JavaNameResolver
|
||||
return declName;
|
||||
}
|
||||
|
||||
private static List<String> getTypeParameterNames(List<TypeParameter> typeParameters)
|
||||
private static List<String> getTypeParameterNames(List<TypeParameterDeclaration> typeParameters)
|
||||
{
|
||||
List<String> typeParameterNames = new ArrayList<>();
|
||||
if (typeParameters != null && typeParameters.size() > 0)
|
||||
|
||||
@@ -1,40 +1,23 @@
|
||||
package io.coati;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.body.BodyDeclaration;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.ast.type.ClassOrInterfaceType;
|
||||
import com.github.javaparser.ast.type.IntersectionType;
|
||||
import com.github.javaparser.ast.type.PrimitiveType;
|
||||
import com.github.javaparser.ast.type.ReferenceType;
|
||||
import com.github.javaparser.ast.type.Type;
|
||||
import com.github.javaparser.ast.type.UnionType;
|
||||
import com.github.javaparser.ast.type.UnknownType;
|
||||
import com.github.javaparser.ast.type.VoidType;
|
||||
import com.github.javaparser.ast.type.WildcardType;
|
||||
|
||||
import me.tomassetti.symbolsolver.javaparsermodel.JavaParserFacade;
|
||||
import me.tomassetti.symbolsolver.javaparsermodel.LambdaArgumentTypeUsagePlaceholder;
|
||||
import me.tomassetti.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration;
|
||||
import me.tomassetti.symbolsolver.javaparsermodel.declarations.JavaParserInterfaceDeclaration;
|
||||
import me.tomassetti.symbolsolver.javaparsermodel.declarations.JavaParserMethodDeclaration;
|
||||
import me.tomassetti.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter;
|
||||
import me.tomassetti.symbolsolver.model.declarations.Declaration;
|
||||
import me.tomassetti.symbolsolver.model.declarations.MethodDeclaration;
|
||||
import me.tomassetti.symbolsolver.model.declarations.TypeDeclaration;
|
||||
import me.tomassetti.symbolsolver.model.resolution.TypeParameter;
|
||||
import me.tomassetti.symbolsolver.model.resolution.TypeSolver;
|
||||
import me.tomassetti.symbolsolver.model.typesystem.ArrayTypeUsage;
|
||||
import me.tomassetti.symbolsolver.model.typesystem.NullTypeUsage;
|
||||
import me.tomassetti.symbolsolver.model.typesystem.PrimitiveTypeUsage;
|
||||
import me.tomassetti.symbolsolver.model.typesystem.ReferenceTypeUsage;
|
||||
import me.tomassetti.symbolsolver.model.typesystem.TypeParameterUsage;
|
||||
import me.tomassetti.symbolsolver.model.typesystem.TypeUsage;
|
||||
import me.tomassetti.symbolsolver.model.typesystem.VoidTypeUsage;
|
||||
import me.tomassetti.symbolsolver.model.typesystem.WildcardUsage;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter;
|
||||
import com.github.javaparser.symbolsolver.logic.InferenceVariableType;
|
||||
import com.github.javaparser.symbolsolver.model.declarations.TypeParameterDeclaration;
|
||||
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
|
||||
import com.github.javaparser.symbolsolver.model.typesystem.ArrayType;
|
||||
import com.github.javaparser.symbolsolver.model.typesystem.NullType;
|
||||
import com.github.javaparser.symbolsolver.model.typesystem.PrimitiveType;
|
||||
import com.github.javaparser.symbolsolver.model.typesystem.ReferenceType;
|
||||
import com.github.javaparser.symbolsolver.model.typesystem.Type;
|
||||
import com.github.javaparser.symbolsolver.model.typesystem.TypeVariable;
|
||||
import com.github.javaparser.symbolsolver.model.typesystem.VoidType;
|
||||
import com.github.javaparser.symbolsolver.model.typesystem.Wildcard;
|
||||
|
||||
public class JavaSymbolSolverTypeNameResolver extends JavaNameResolver
|
||||
{
|
||||
@@ -43,38 +26,42 @@ public class JavaSymbolSolverTypeNameResolver extends JavaNameResolver
|
||||
super(typeSolver, ignoredContexts);
|
||||
}
|
||||
|
||||
public static JavaTypeName getQualifiedTypeName(TypeUsage typeUsage, TypeSolver typeSolver)
|
||||
public static JavaTypeName getQualifiedTypeName(Type type, TypeSolver typeSolver)
|
||||
{
|
||||
return getQualifiedTypeName(typeUsage, typeSolver, null);
|
||||
return getQualifiedTypeName(type, typeSolver, null);
|
||||
}
|
||||
|
||||
public static JavaTypeName getQualifiedTypeName(TypeUsage typeUsage, TypeSolver typeSolver, ArrayList<BodyDeclaration> ignoredContexts)
|
||||
public static JavaTypeName getQualifiedTypeName(Type type, TypeSolver typeSolver, ArrayList<BodyDeclaration> ignoredContexts)
|
||||
{
|
||||
JavaSymbolSolverTypeNameResolver resolver = new JavaSymbolSolverTypeNameResolver(typeSolver, ignoredContexts);
|
||||
return resolver.getQualifiedTypeName(typeUsage);
|
||||
return resolver.getQualifiedTypeName(type);
|
||||
}
|
||||
|
||||
public JavaTypeName getQualifiedTypeName(TypeUsage typeUsage)
|
||||
{
|
||||
if (typeUsage instanceof ArrayTypeUsage)
|
||||
public JavaTypeName getQualifiedTypeName(Type type)
|
||||
{ // , inferencevariabletype, , , , , typevar,
|
||||
if (type instanceof ArrayType)
|
||||
{
|
||||
return getQualifiedTypeName(((ArrayTypeUsage)typeUsage).getComponentType());
|
||||
return getQualifiedTypeName(((ArrayType)type).getComponentType());
|
||||
}
|
||||
else if (typeUsage instanceof LambdaArgumentTypeUsagePlaceholder)
|
||||
else if (type instanceof LambdaArgumentTypePlaceholder)
|
||||
{
|
||||
|
||||
}
|
||||
else if (typeUsage instanceof NullTypeUsage)
|
||||
else if (type instanceof InferenceVariableType)
|
||||
{
|
||||
return JavaTypeName.fromDotSeparatedString(typeUsage.describe());
|
||||
|
||||
}
|
||||
else if (typeUsage instanceof PrimitiveTypeUsage)
|
||||
else if (type instanceof NullType)
|
||||
{
|
||||
return JavaTypeName.fromDotSeparatedString(typeUsage.describe());
|
||||
return JavaTypeName.fromDotSeparatedString(type.describe());
|
||||
}
|
||||
else if (typeUsage instanceof ReferenceTypeUsage)
|
||||
else if (type instanceof PrimitiveType)
|
||||
{
|
||||
ReferenceTypeUsage refTypeUsage = (ReferenceTypeUsage)typeUsage;
|
||||
return JavaTypeName.fromDotSeparatedString(type.describe());
|
||||
}
|
||||
else if (type instanceof ReferenceType)
|
||||
{
|
||||
ReferenceType refTypeUsage = (ReferenceType)type;
|
||||
|
||||
JavaDeclName declName = JavaSymbolSolverDeclNameResolver.getQualifiedDeclName(
|
||||
refTypeUsage.getTypeDeclaration(),
|
||||
@@ -96,13 +83,13 @@ public class JavaSymbolSolverTypeNameResolver extends JavaNameResolver
|
||||
}
|
||||
*/
|
||||
}
|
||||
else if (typeUsage instanceof TypeParameterUsage)
|
||||
else if (type instanceof TypeVariable)
|
||||
{
|
||||
TypeParameter typeParam = ((TypeParameterUsage)typeUsage).asTypeParameter();
|
||||
TypeParameterDeclaration typeParam = ((TypeVariable)type).asTypeParameter();
|
||||
if (typeParam instanceof JavaParserTypeParameter)
|
||||
{
|
||||
com.github.javaparser.ast.TypeParameter jpTypeParameter = ((JavaParserTypeParameter)typeParam).getWrappedNode();
|
||||
Node genericDecl = jpTypeParameter.getParentNode();
|
||||
com.github.javaparser.ast.type.TypeParameter jpTypeParameter = ((JavaParserTypeParameter)typeParam).getWrappedNode();
|
||||
BodyDeclaration<?> genericDecl = jpTypeParameter.getAncestorOfType(BodyDeclaration.class);
|
||||
if (genericDecl instanceof BodyDeclaration)
|
||||
{
|
||||
JavaDeclName genericName = null;
|
||||
@@ -110,7 +97,7 @@ public class JavaSymbolSolverTypeNameResolver extends JavaNameResolver
|
||||
{
|
||||
genericName = JavaparserDeclNameResolver.getQualifiedDeclName((BodyDeclaration)genericDecl, m_typeSolver, m_ignoredContexts);
|
||||
}
|
||||
return new JavaTypeName(jpTypeParameter.getName(), genericName);
|
||||
return new JavaTypeName(jpTypeParameter.getName().getId(), genericName);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -118,16 +105,16 @@ public class JavaSymbolSolverTypeNameResolver extends JavaNameResolver
|
||||
// do we need to handle using type parameters of external code? YES! so: TODO: do this!
|
||||
}
|
||||
}
|
||||
else if (typeUsage instanceof VoidTypeUsage)
|
||||
else if (type instanceof VoidType)
|
||||
{
|
||||
return JavaTypeName.fromDotSeparatedString(typeUsage.describe());
|
||||
return JavaTypeName.fromDotSeparatedString(type.describe());
|
||||
}
|
||||
else if (typeUsage instanceof WildcardUsage)
|
||||
else if (type instanceof Wildcard)
|
||||
{
|
||||
return new JavaTypeName("?", null);
|
||||
}
|
||||
|
||||
System.out.println("Unable to resolve qualified name of " + typeUsage.getClass().toString() + ": " + typeUsage.toString());
|
||||
System.out.println("Unable to resolve qualified name of " + type.getClass().toString() + ": " + type.toString());
|
||||
return new JavaTypeName("unresolved-type", null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@ 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.*;
|
||||
|
||||
import me.tomassetti.symbolsolver.model.resolution.TypeSolver;
|
||||
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
|
||||
|
||||
public class JavaVerboseAstVisitor extends JavaAstVisitor{
|
||||
|
||||
@@ -44,9 +44,13 @@ public class JavaVerboseAstVisitor extends JavaAstVisitor{
|
||||
line += n.getClass().getName();
|
||||
if (n instanceof NodeWithName<?>)
|
||||
{
|
||||
line += " [" + obfuscate(((NodeWithName<?>)n).getName()) + "]";
|
||||
line += " [" + obfuscate(((NodeWithName<?>)n).getNameAsString()) + "]";
|
||||
}
|
||||
|
||||
if (n.getBegin().isPresent())
|
||||
{
|
||||
line += " line: " + n.getBegin().get().line;
|
||||
}
|
||||
line += " line: " + n.getBegin().line;
|
||||
|
||||
JavaIndexer.logInfo(m_callbackId, line);
|
||||
}
|
||||
@@ -57,8 +61,16 @@ public class JavaVerboseAstVisitor extends JavaAstVisitor{
|
||||
|
||||
public void visit(PackageDeclaration 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(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(TypeParameter n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(LineComment n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
@@ -71,8 +83,6 @@ public class JavaVerboseAstVisitor extends JavaAstVisitor{
|
||||
|
||||
public void visit(EnumDeclaration n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(EmptyTypeDeclaration n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(EnumConstantDeclaration n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(AnnotationDeclaration n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
@@ -83,8 +93,6 @@ public class JavaVerboseAstVisitor extends JavaAstVisitor{
|
||||
|
||||
public void visit(VariableDeclarator n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(VariableDeclaratorId n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(ConstructorDeclaration n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(MethodDeclaration n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
@@ -103,7 +111,9 @@ public class JavaVerboseAstVisitor extends JavaAstVisitor{
|
||||
|
||||
public void visit(PrimitiveType n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(ReferenceType n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
public void visit(ArrayType n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(ArrayCreationLevel n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(IntersectionType n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
@@ -145,10 +155,6 @@ public class JavaVerboseAstVisitor extends JavaAstVisitor{
|
||||
|
||||
public void visit(LongLiteralExpr n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(IntegerLiteralMinValueExpr n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(LongLiteralMinValueExpr n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(CharLiteralExpr n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(DoubleLiteralExpr n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
@@ -163,8 +169,6 @@ public class JavaVerboseAstVisitor extends JavaAstVisitor{
|
||||
|
||||
public void visit(ObjectCreationExpr n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(QualifiedNameExpr n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(ThisExpr n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
public void visit(SuperExpr n, Void v) { dump(n); indent++; super.visit(n, v); indent--; }
|
||||
|
||||
@@ -2,11 +2,12 @@ package io.coati;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.NodeList;
|
||||
import com.github.javaparser.ast.PackageDeclaration;
|
||||
import com.github.javaparser.ast.TypeParameter;
|
||||
import com.github.javaparser.ast.body.AnnotationMemberDeclaration;
|
||||
import com.github.javaparser.ast.body.BodyDeclaration;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
@@ -19,12 +20,9 @@ import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
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.NameExpr;
|
||||
import com.github.javaparser.ast.expr.QualifiedNameExpr;
|
||||
|
||||
import me.tomassetti.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration;
|
||||
import me.tomassetti.symbolsolver.javaparsermodel.declarations.JavaParserInterfaceDeclaration;
|
||||
import me.tomassetti.symbolsolver.model.resolution.TypeSolver;
|
||||
import com.github.javaparser.ast.expr.Name;
|
||||
import com.github.javaparser.ast.type.TypeParameter;
|
||||
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
|
||||
|
||||
public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
{
|
||||
@@ -62,14 +60,14 @@ public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
}
|
||||
else
|
||||
{
|
||||
CompilationUnit compilationUnit = getCompilationUnitContext(decl);
|
||||
CompilationUnit compilationUnit = decl.getAncestorOfType(CompilationUnit.class);
|
||||
|
||||
if (compilationUnit != null)
|
||||
{
|
||||
PackageDeclaration packageDecl = compilationUnit.getPackage();
|
||||
if (packageDecl != null)
|
||||
Optional<PackageDeclaration> packageDecl = compilationUnit.getPackageDeclaration();
|
||||
if (packageDecl.isPresent())
|
||||
{
|
||||
declName.setParent(getQualifiedName(packageDecl.getName()));
|
||||
declName.setParent(getQualifiedName(packageDecl.get().getName()));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -92,7 +90,7 @@ public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
return resolver.getQualifiedDeclName(decl);
|
||||
}
|
||||
|
||||
public JavaDeclName getQualifiedDeclName(BodyDeclaration decl)
|
||||
public JavaDeclName getQualifiedDeclName(BodyDeclaration<?> decl)
|
||||
{
|
||||
JavaDeclName declName = null;
|
||||
|
||||
@@ -110,14 +108,14 @@ public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
}
|
||||
else
|
||||
{
|
||||
CompilationUnit compilationUnit = getCompilationUnitContext(decl);
|
||||
CompilationUnit compilationUnit = decl.getAncestorOfType(CompilationUnit.class);
|
||||
|
||||
if (compilationUnit != null)
|
||||
{
|
||||
PackageDeclaration packageDecl = compilationUnit.getPackage();
|
||||
if (packageDecl != null)
|
||||
Optional<PackageDeclaration> packageDecl = compilationUnit.getPackageDeclaration();
|
||||
if (packageDecl.isPresent())
|
||||
{
|
||||
declName.setParent(getQualifiedName(packageDecl.getName()));
|
||||
declName.setParent(getQualifiedName(packageDecl.get().getName()));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -131,7 +129,7 @@ public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
|
||||
public JavaDeclName getDeclName(VariableDeclarator decl)
|
||||
{
|
||||
return new JavaDeclName(decl.getId().getName());
|
||||
return new JavaDeclName(decl.getNameAsString());
|
||||
}
|
||||
|
||||
public JavaDeclName getDeclName(BodyDeclaration decl)
|
||||
@@ -155,7 +153,7 @@ public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
}
|
||||
else if (decl instanceof EnumConstantDeclaration)
|
||||
{
|
||||
declName = new JavaDeclName(((EnumConstantDeclaration)decl).getName());
|
||||
declName = new JavaDeclName(((EnumConstantDeclaration)decl).getNameAsString());
|
||||
}
|
||||
else if (decl instanceof FieldDeclaration)
|
||||
{
|
||||
@@ -172,7 +170,7 @@ public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
}
|
||||
else if (decl instanceof TypeDeclaration)
|
||||
{
|
||||
declName = new JavaDeclName(((TypeDeclaration)decl).getName(), getTypeParameterNames((TypeDeclaration)decl));
|
||||
declName = new JavaDeclName(((TypeDeclaration)decl).getNameAsString(), getTypeParameterNames((TypeDeclaration)decl));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,34 +179,34 @@ public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
|
||||
private static List<String> getTypeParameterNames(TypeDeclaration decl)
|
||||
{
|
||||
List<TypeParameter> typeParameters = null;
|
||||
NodeList<TypeParameter> typeParameters = null;
|
||||
if (decl instanceof ClassOrInterfaceDeclaration)
|
||||
{
|
||||
typeParameters = ((ClassOrInterfaceDeclaration)decl).getTypeParameters();
|
||||
typeParameters = (NodeList<TypeParameter>) ((ClassOrInterfaceDeclaration)decl).getTypeParameters();
|
||||
}
|
||||
|
||||
return getTypeParameterNames(typeParameters);
|
||||
}
|
||||
|
||||
private static List<String> getTypeParameterNames(List<TypeParameter> typeParameters)
|
||||
private static List<String> getTypeParameterNames(NodeList<TypeParameter> typeParameters)
|
||||
{
|
||||
List<String> typeParameterNames = new ArrayList<>();
|
||||
if (typeParameters != null && typeParameters.size() > 0)
|
||||
{
|
||||
for (int i = 0; i < typeParameters.size(); i++)
|
||||
{
|
||||
typeParameterNames.add(typeParameters.get(i).getName());
|
||||
typeParameterNames.add(typeParameters.get(i).getNameAsString());
|
||||
}
|
||||
}
|
||||
return typeParameterNames;
|
||||
}
|
||||
|
||||
public static JavaDeclName getQualifiedName(NameExpr nameExpr)
|
||||
public static JavaDeclName getQualifiedName(Name name)
|
||||
{
|
||||
JavaDeclName declName = new JavaDeclName(nameExpr.getName());
|
||||
if (nameExpr instanceof QualifiedNameExpr)
|
||||
JavaDeclName declName = new JavaDeclName(name.getId());
|
||||
if (name.getQualifier().isPresent())
|
||||
{
|
||||
declName.setParent(getQualifiedName(((QualifiedNameExpr)nameExpr).getQualifier()));
|
||||
declName.setParent(getQualifiedName(name.getQualifier().get()));
|
||||
}
|
||||
return declName;
|
||||
}
|
||||
@@ -234,41 +232,23 @@ public class JavaparserDeclNameResolver extends JavaNameResolver
|
||||
{
|
||||
BodyDeclaration context = null;
|
||||
|
||||
Node parentNode = decl.getParentNode();
|
||||
Optional<Node> parentNode = decl.getParentNode();
|
||||
while (
|
||||
parentNode != null &&
|
||||
parentNode.isPresent() &&
|
||||
!(
|
||||
parentNode instanceof BodyDeclaration &&
|
||||
(!(parentNode instanceof FieldDeclaration))
|
||||
parentNode.get() instanceof BodyDeclaration &&
|
||||
(!(parentNode.get() instanceof FieldDeclaration))
|
||||
)
|
||||
)
|
||||
{
|
||||
parentNode = parentNode.getParentNode();
|
||||
parentNode = parentNode.get().getParentNode();
|
||||
}
|
||||
|
||||
if (parentNode != null)
|
||||
if (parentNode.isPresent())
|
||||
{
|
||||
context = (BodyDeclaration)parentNode;
|
||||
context = (BodyDeclaration)parentNode.get();
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
private static CompilationUnit getCompilationUnitContext(Node decl)
|
||||
{
|
||||
CompilationUnit context = null;
|
||||
{
|
||||
Node parentNode = decl.getParentNode();
|
||||
while (parentNode != null && !(parentNode instanceof CompilationUnit))
|
||||
{
|
||||
parentNode = parentNode.getParentNode();
|
||||
}
|
||||
|
||||
if (parentNode != null)
|
||||
{
|
||||
context = (CompilationUnit)parentNode;
|
||||
}
|
||||
}
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
package io.coati;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.body.BodyDeclaration;
|
||||
import com.github.javaparser.ast.type.*;
|
||||
|
||||
import me.tomassetti.symbolsolver.javaparsermodel.JavaParserFacade;
|
||||
import me.tomassetti.symbolsolver.javaparsermodel.declarations.JavaParserTypeParameter;
|
||||
import me.tomassetti.symbolsolver.model.resolution.TypeParameter;
|
||||
import me.tomassetti.symbolsolver.model.resolution.TypeSolver;
|
||||
import me.tomassetti.symbolsolver.model.typesystem.TypeParameterUsage;
|
||||
import me.tomassetti.symbolsolver.model.typesystem.TypeUsage;
|
||||
import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade;
|
||||
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
|
||||
|
||||
public class JavaparserTypeNameResolver extends JavaNameResolver
|
||||
{
|
||||
@@ -35,20 +29,37 @@ public class JavaparserTypeNameResolver extends JavaNameResolver
|
||||
public JavaTypeName getQualifiedTypeName(Type type)
|
||||
{
|
||||
String fallbackTypeName = type.toString();
|
||||
|
||||
|
||||
if (type instanceof ClassOrInterfaceType)
|
||||
{
|
||||
try
|
||||
{
|
||||
TypeUsage typeUsage = JavaParserFacade.get(m_typeSolver).convert(type, type);
|
||||
|
||||
return JavaSymbolSolverTypeNameResolver.getQualifiedTypeName(typeUsage, m_typeSolver, m_ignoredContexts);
|
||||
return JavaSymbolSolverTypeNameResolver.getQualifiedTypeName(
|
||||
JavaParserFacade.get(m_typeSolver).convert(type, type),
|
||||
m_typeSolver,
|
||||
m_ignoredContexts
|
||||
);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// log...
|
||||
}
|
||||
}
|
||||
else if (type instanceof ArrayType)
|
||||
{
|
||||
ArrayType arrayType = (ArrayType)type;
|
||||
|
||||
// TODO: regard array info!
|
||||
return getQualifiedTypeName(arrayType.getComponentType());
|
||||
}
|
||||
else if (type instanceof TypeParameter)
|
||||
{
|
||||
return JavaSymbolSolverTypeNameResolver.getQualifiedTypeName(
|
||||
JavaParserFacade.get(m_typeSolver).convert(type, type),
|
||||
m_typeSolver,
|
||||
m_ignoredContexts
|
||||
);
|
||||
}
|
||||
else if (type instanceof IntersectionType)
|
||||
{
|
||||
// System.out.println(" IntersectionType: " + fallbackTypeName);
|
||||
@@ -59,13 +70,6 @@ public class JavaparserTypeNameResolver extends JavaNameResolver
|
||||
{
|
||||
return JavaTypeName.fromDotSeparatedString(type.toString());
|
||||
}
|
||||
else if (type instanceof ReferenceType)
|
||||
{
|
||||
ReferenceType referenceType = (ReferenceType)type;
|
||||
|
||||
boolean isArray = (referenceType.getArrayCount() == 0); // TODO: regard array info!
|
||||
return getQualifiedTypeName(referenceType.getType());
|
||||
}
|
||||
else if (type instanceof UnionType)
|
||||
{
|
||||
// System.out.println(" UnionType: " + fallbackTypeName);
|
||||
|
||||
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.
+171
-152
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "utility/file/FileRegister.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
#include "utility/utility.h"
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
#include "data/parser/java/JavaEnvironmentFactory.h"
|
||||
@@ -32,8 +33,9 @@ public:
|
||||
"package foo;\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->packages.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->packages[0], "foo <1:1 <1:9 1:11> 1:12>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->packages, "foo <1:1 <1:9 1:11> 1:12>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_class_declaration_in_defaut_package()
|
||||
@@ -44,8 +46,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->classes.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->classes[0], "public A <1:1 <1:14 1:14> 3:1>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->classes, "public A <1:1 <1:14 1:14> 3:1>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_interface_declaration_in_defaut_package()
|
||||
@@ -56,8 +59,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->interfaces.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->interfaces[0], "public A <1:1 <1:18 1:18> 3:1>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->interfaces, "public A <1:1 <1:18 1:18> 3:1>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_class_declaration_in_named_package()
|
||||
@@ -69,8 +73,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->classes.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->classes[0], "public foo.A <2:1 <2:14 2:14> 4:1>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->classes, "public foo.A <2:1 <2:14 2:14> 4:1>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_class_declaration_in_nested_named_package()
|
||||
@@ -82,8 +87,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->classes.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->classes[0], "public foo.bar.A <2:1 <2:14 2:14> 4:1>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->classes, "public foo.bar.A <2:1 <2:14 2:14> 4:1>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_enum_declaration_in_named_package()
|
||||
@@ -95,8 +101,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->enums.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->enums[0], "public foo.A <2:1 <2:13 2:13> 4:1>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->enums, "public foo.A <2:1 <2:13 2:13> 4:1>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_enum_constant_declaration()
|
||||
@@ -109,8 +116,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->enumConstants.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->enumConstants[0], "foo.A.A_TEST <4:2 4:10>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->enumConstants, "foo.A.A_TEST <4:2 4:10>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_constructor_declaration_without_parameters()
|
||||
@@ -125,8 +133,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->methods.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->methods[0], "public foo.A.A() <4:2 <4:9 4:9> 6:2>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->methods, "public foo.A.A() <4:2 <4:9 4:9> 6:2>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_method_declaration_with_custom_type_in_signature()
|
||||
@@ -141,8 +150,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->methods.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->methods[0], "public void foo.A.bar(foo.A) <4:2 <4:14 4:16> 6:2>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->methods, "public void foo.A.bar(foo.A) <4:2 <4:14 4:16> 6:2>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_field_declaration_with_initial_assignment()
|
||||
@@ -155,8 +165,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->fields.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->fields[0], "default foo.A.bar <4:6 4:8>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->fields, "default foo.A.bar <4:6 4:8>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_public_access_specifier_in_field_declaration()
|
||||
@@ -169,8 +180,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->fields.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->fields[0], "public foo.A.bar <4:13 4:15>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->fields, "public foo.A.bar <4:13 4:15>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_protected_access_specifier_in_field_declaration()
|
||||
@@ -183,8 +195,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->fields.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->fields[0], "protected foo.A.bar <4:16 4:18>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->fields, "protected foo.A.bar <4:16 4:18>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_private_access_specifier_in_field_declaration()
|
||||
@@ -197,8 +210,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->fields.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->fields[0], "private foo.A.bar <4:14 4:16>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->fields, "private foo.A.bar <4:14 4:16>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_definition_of_method_parameter()
|
||||
@@ -213,12 +227,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->localSymbols.size(), 5);
|
||||
TS_ASSERT_EQUALS(client->localSymbols[0], "input.cc<3:1> <3:1 3:1>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[1], "input.cc<3:1> <7:1 7:1>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[2], "input.cc<4:15> <4:15 4:15>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[3], "input.cc<5:2> <5:2 5:2>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[4], "input.cc<5:2> <6:2 6:2>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->localSymbols, "input.cc<4:15> <4:15 4:15>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_definition_of_local_variable()
|
||||
@@ -234,27 +245,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->localSymbols.size(), 5);
|
||||
TS_ASSERT_EQUALS(client->localSymbols[0], "input.cc<3:1> <3:1 3:1>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[1], "input.cc<3:1> <8:1 8:1>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[2], "input.cc<5:2> <5:2 5:2>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[3], "input.cc<5:2> <7:2 7:2>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[4], "input.cc<6:7> <6:7 6:7>");
|
||||
}
|
||||
|
||||
void test_java_parser_finds_type_argument_name_in_signature_of_method()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"public class A <T>\n"
|
||||
"{\n"
|
||||
" public A<Void> foo(A<Void> a){\n"
|
||||
" return a;\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->typeParameters.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->typeParameters[0], "A<T>.T <1:17 1:17>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->localSymbols, "input.cc<6:7> <6:7 6:7>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_definition_of_type_parameter_of_class()
|
||||
@@ -265,8 +258,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->typeParameters.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->typeParameters[0], "A<T>.T <1:17 1:17>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->typeParameters, "A<T>.T <1:17 1:17>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_definition_of_type_parameter_of_method()
|
||||
@@ -280,14 +274,11 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->typeParameters.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->typeParameters[0], "A.foo<T>.T <3:10 3:10>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->typeParameters, "A.foo<T>.T <3:10 3:10>"
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void test_java_parser_finds_line_comment()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
@@ -295,8 +286,9 @@ public:
|
||||
"package foo;\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->comments.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->comments[0], "comment <1:1 1:26>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->comments, "comment <1:1 1:26>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_block_comment()
|
||||
@@ -306,8 +298,9 @@ public:
|
||||
"package foo;\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->comments.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->comments[0], "comment <1:1 1:28>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->comments, "comment <1:1 1:27>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_missing_semicolon_as_parse_error()
|
||||
@@ -316,8 +309,9 @@ public:
|
||||
"package foo\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->errors.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->errors[0], "Encountered unexpected token. <1:1 1:1>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->errors, "Encountered unexpected token. <1:1 1:1>"
|
||||
));
|
||||
}
|
||||
|
||||
//void _test_java_parser_finds_missing_import_as_error()
|
||||
@@ -348,9 +342,9 @@ public:
|
||||
"};\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->classes.size(), 2);
|
||||
TS_ASSERT_EQUALS(client->classes[0], "public foo.bar.A <2:1 <2:14 2:14> 7:1>");
|
||||
TS_ASSERT_EQUALS(client->classes[1], "public foo.bar.A.B <4:2 <4:15 4:15> 6:2>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->classes, "public foo.bar.A.B <4:2 <4:15 4:15> 6:2>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_class_declaration_nested_in_method()
|
||||
@@ -368,9 +362,9 @@ public:
|
||||
"};\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->classes.size(), 2);
|
||||
TS_ASSERT_EQUALS(client->classes[0], "public foo.bar.A <2:1 <2:14 2:14> 10:1>");
|
||||
TS_ASSERT_EQUALS(client->classes[1], "default foo.bar.A.bar.B <6:3 <6:9 6:9> 8:3>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->classes, "default foo.bar.A.bar.B <6:3 <6:9 6:9> 8:3>"
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -383,8 +377,9 @@ public:
|
||||
"import foo.bar.*;\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->imports.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->imports[0], "input.cc -> foo.bar <1:8 1:14>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->imports, "input.cc -> foo.bar <1:8 1:14>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_inheritance_using_extends_keyword()
|
||||
@@ -400,8 +395,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->inheritances.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->inheritances[0], "foo.B -> foo.A <6:24 6:24>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->inheritances, "foo.B -> foo.A <6:24 6:24>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_inheritance_using_implements_keyword()
|
||||
@@ -417,12 +413,31 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->inheritances.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->inheritances[0], "foo.B -> foo.A <6:27 6:27>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->inheritances, "foo.B -> foo.A <6:27 6:27>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_type_parameter_in_signature_of_method()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"public class A <T>\n"
|
||||
"{\n"
|
||||
" public A<Void> foo(A<Void> a){\n"
|
||||
" return a;\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
void _SYMBOLSOLVERISSUE_test_java_parser_finds_correct_location_of_qualified_type_usage()
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->typeUses, "A<T> A<T>.foo(A<T>) -> A<T> <3:9 3:9>"
|
||||
));
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->typeUses, "A<T> A<T>.foo(A<T>) -> A<T> <3:21 3:21>"
|
||||
));
|
||||
}
|
||||
|
||||
void _JSS_ISSUE_test_javyxcyxca_parser_finds_correct_location_of_qualified_type_usage()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"public class Foo {\n"
|
||||
@@ -455,13 +470,12 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->typeUses.size(), 3);
|
||||
TS_ASSERT_EQUALS(client->typeUses[0], "void A.bar() -> void <6:2 6:5>");
|
||||
TS_ASSERT_EQUALS(client->typeUses[1], "void A.bar() -> A.B <8:3 8:3>");
|
||||
TS_ASSERT_EQUALS(client->typeUses[2], "void A.bar() -> A.B <8:13 8:15>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->typeUses, "void A.bar() -> A.B <8:13 8:15>"
|
||||
));
|
||||
}
|
||||
|
||||
void ___test_java_parser_finds_method_call_to_super()
|
||||
void test_java_parser_finds_method_call_to_super()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"package foo;\n"
|
||||
@@ -484,11 +498,12 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->calls.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->calls[0], "void foo.A.bar() -> void foo.A.bar() <6:3 6:5>");
|
||||
}
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->calls, "void foo.X.B.bar() -> void foo.X.A.bar() <15:10 15:12>"
|
||||
));
|
||||
}
|
||||
|
||||
void ___test_java_parser_finds_usage_of_field_with_same_name_as_method_parameter()
|
||||
void test_java_parser_finds_usage_of_field_with_same_name_as_method_parameter()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"package foo;\n"
|
||||
@@ -502,11 +517,12 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->calls.size(), 1);
|
||||
// TS_ASSERT_EQUALS(client->calls[0], "void foo.A.bar() -> void foo.A.bar() <6:3 6:5>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->usages, "foo.X.X(int) -> foo.X.t <7:8 7:8>"
|
||||
));
|
||||
}
|
||||
|
||||
void ___test_java_parser_does_not_confuse_method_name_with_field_name()
|
||||
void test_java_parser_does_not_confuse_method_name_with_field_name()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"package foo;\n"
|
||||
@@ -520,8 +536,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->calls.size(), 1);
|
||||
// TS_ASSERT_EQUALS(client->calls[0], "void foo.A.bar() -> void foo.A.bar() <6:3 6:5>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->usages, "foo.X.foo() -> foo.X.foo <7:8 7:10>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_assignment_of_method_argument()
|
||||
@@ -537,13 +554,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->localSymbols.size(), 6);
|
||||
TS_ASSERT_EQUALS(client->localSymbols[0], "input.cc<3:1> <3:1 3:1>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[1], "input.cc<3:1> <8:1 8:1>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[2], "input.cc<4:15> <4:15 4:15>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[3], "input.cc<5:2> <5:2 5:2>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[4], "input.cc<5:2> <7:2 7:2>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[5], "input.cc<4:15> <6:3 6:3>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->localSymbols, "input.cc<4:15> <6:3 6:3>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_assignment_of_local_variable()
|
||||
@@ -560,13 +573,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->localSymbols.size(), 6);
|
||||
TS_ASSERT_EQUALS(client->localSymbols[0], "input.cc<3:1> <3:1 3:1>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[1], "input.cc<3:1> <9:1 9:1>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[2], "input.cc<5:2> <5:2 5:2>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[3], "input.cc<5:2> <8:2 8:2>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[4], "input.cc<6:7> <6:7 6:7>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[5], "input.cc<6:7> <7:3 7:3>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->localSymbols, "input.cc<6:7> <7:3 7:3>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_scope_of_class_declaration()
|
||||
@@ -577,9 +586,12 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->localSymbols.size(), 2);
|
||||
TS_ASSERT_EQUALS(client->localSymbols[0], "input.cc<2:1> <2:1 2:1>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[1], "input.cc<2:1> <3:1 3:1>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->localSymbols, "input.cc<2:1> <2:1 2:1>"
|
||||
));
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->localSymbols, "input.cc<2:1> <3:1 3:1>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_scope_of_enum_declaration()
|
||||
@@ -590,9 +602,12 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->localSymbols.size(), 2);
|
||||
TS_ASSERT_EQUALS(client->localSymbols[0], "input.cc<2:1> <2:1 2:1>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[1], "input.cc<2:1> <3:1 3:1>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->localSymbols, "input.cc<2:1> <2:1 2:1>"
|
||||
));
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->localSymbols, "input.cc<2:1> <3:1 3:1>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_scope_of_constructor_declaration()
|
||||
@@ -606,11 +621,12 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->localSymbols.size(), 4);
|
||||
TS_ASSERT_EQUALS(client->localSymbols[0], "input.cc<2:1> <2:1 2:1>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[1], "input.cc<2:1> <6:1 6:1>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[2], "input.cc<4:2> <4:2 4:2>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[3], "input.cc<4:2> <5:2 5:2>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->localSymbols, "input.cc<4:2> <4:2 4:2>"
|
||||
));
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->localSymbols, "input.cc<4:2> <5:2 5:2>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_scope_of_method_declaration()
|
||||
@@ -624,11 +640,12 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->localSymbols.size(), 4);
|
||||
TS_ASSERT_EQUALS(client->localSymbols[0], "input.cc<2:1> <2:1 2:1>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[1], "input.cc<2:1> <6:1 6:1>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[2], "input.cc<4:2> <4:2 4:2>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[3], "input.cc<4:2> <5:2 5:2>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->localSymbols, "input.cc<4:2> <4:2 4:2>"
|
||||
));
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->localSymbols, "input.cc<4:2> <5:2 5:2>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_scope_of_switch_statement()
|
||||
@@ -647,13 +664,12 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->localSymbols.size(), 6);
|
||||
TS_ASSERT_EQUALS(client->localSymbols[0], "input.cc<2:1> <2:1 2:1>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[1], "input.cc<2:1> <11:1 11:1>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[2], "input.cc<4:2> <4:2 4:2>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[3], "input.cc<4:2> <10:2 10:2>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[4], "input.cc<6:3> <6:3 6:3>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[5], "input.cc<6:3> <9:3 9:3>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->localSymbols, "input.cc<6:3> <6:3 6:3>"
|
||||
));
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->localSymbols, "input.cc<6:3> <9:3 9:3>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_scope_of_block_statement()
|
||||
@@ -669,13 +685,12 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->localSymbols.size(), 6);
|
||||
TS_ASSERT_EQUALS(client->localSymbols[0], "input.cc<2:1> <2:1 2:1>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[1], "input.cc<2:1> <8:1 8:1>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[2], "input.cc<4:2> <4:2 4:2>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[3], "input.cc<4:2> <7:2 7:2>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[4], "input.cc<5:3> <5:3 5:3>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[5], "input.cc<5:3> <6:3 6:3>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->localSymbols, "input.cc<5:3> <5:3 5:3>"
|
||||
));
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->localSymbols, "input.cc<5:3> <6:3 6:3>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_scope_of_array_initialization_list()
|
||||
@@ -687,11 +702,12 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->localSymbols.size(), 4);
|
||||
TS_ASSERT_EQUALS(client->localSymbols[0], "input.cc<2:1> <2:1 2:1>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[1], "input.cc<2:1> <4:1 4:1>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[2], "input.cc<3:24> <3:24 3:24>");
|
||||
TS_ASSERT_EQUALS(client->localSymbols[3], "input.cc<3:24> <3:29 3:29>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->localSymbols, "input.cc<3:24> <3:24 3:24>"
|
||||
));
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->localSymbols, "input.cc<3:24> <3:29 3:29>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_usage_of_type_parameter_of_class()
|
||||
@@ -703,8 +719,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->typeUses.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->typeUses[0], "A<T>.t -> A<T>.T <3:2 3:2>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->typeUses, "A<T>.t -> A<T>.T <3:2 3:2>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_usage_of_type_parameter_of_method()
|
||||
@@ -716,9 +733,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->typeUses.size(), 2);
|
||||
TS_ASSERT_EQUALS(client->typeUses[0], "void A.foo<T>(T) -> void <3:13 3:16>");
|
||||
TS_ASSERT_EQUALS(client->typeUses[1], "void A.foo<T>(T) -> A.foo<T>.T <3:22 3:22>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->typeUses, "void A.foo<T>(T) -> A.foo<T>.T <3:22 3:22>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_correct_location_of_generic_type_usage()
|
||||
@@ -730,8 +747,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->typeUses.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->typeUses[0], "A<T>.t -> A<T> <3:2 3:2>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->typeUses, "A<T>.t -> A<T> <3:2 3:2>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_java_parser_finds_bound_type_of_type_parameter()
|
||||
@@ -742,8 +760,9 @@ public:
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->typeUses.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->typeUses[0], "A<T>.T -> java.lang.Void <1:27 1:30>");
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->typeUses, "A<T>.T -> java.lang.Void <1:27 1:30>"
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user