src: Apply clang-format and extend use to Java code (#973)
This commit is contained in:
@@ -2,8 +2,7 @@ package com.sourcetrail;
|
||||
|
||||
import org.eclipse.jdt.core.dom.Modifier;
|
||||
|
||||
public enum AccessKind
|
||||
{ // these values need to be the same as AccesKind in C++ code
|
||||
public enum AccessKind { // these values need to be the same as AccesKind in C++ code
|
||||
NONE(0),
|
||||
PUBLIC(1),
|
||||
PROTECTED(2),
|
||||
@@ -11,26 +10,37 @@ public enum AccessKind
|
||||
DEFAULT(4),
|
||||
TEMPLATE_PARAMETER(5),
|
||||
TYPE_PARAMETER(6);
|
||||
|
||||
|
||||
private final int m_value;
|
||||
|
||||
private AccessKind(int value)
|
||||
|
||||
private AccessKind(int value)
|
||||
{
|
||||
this.m_value = value;
|
||||
this.m_value = value;
|
||||
}
|
||||
|
||||
public int getValue()
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
return m_value;
|
||||
return m_value;
|
||||
}
|
||||
|
||||
|
||||
public static AccessKind fromModifiers(int modifiers)
|
||||
{
|
||||
if ((modifiers & Modifier.PUBLIC) != 0) { return AccessKind.PUBLIC; }
|
||||
if ((modifiers & Modifier.PROTECTED) != 0) { return AccessKind.PROTECTED; }
|
||||
if ((modifiers & Modifier.PRIVATE) != 0) { return AccessKind.PRIVATE; }
|
||||
if ((modifiers & Modifier.DEFAULT) != 0) { return AccessKind.DEFAULT; }
|
||||
if ((modifiers & Modifier.PUBLIC) != 0)
|
||||
{
|
||||
return AccessKind.PUBLIC;
|
||||
}
|
||||
if ((modifiers & Modifier.PROTECTED) != 0)
|
||||
{
|
||||
return AccessKind.PROTECTED;
|
||||
}
|
||||
if ((modifiers & Modifier.PRIVATE) != 0)
|
||||
{
|
||||
return AccessKind.PRIVATE;
|
||||
}
|
||||
if ((modifiers & Modifier.DEFAULT) != 0)
|
||||
{
|
||||
return AccessKind.DEFAULT;
|
||||
}
|
||||
return AccessKind.DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,55 +2,57 @@ package com.sourcetrail;
|
||||
|
||||
import com.sourcetrail.name.NameHierarchy;
|
||||
|
||||
public abstract class AstVisitorClient
|
||||
public abstract class AstVisitorClient
|
||||
{
|
||||
public abstract boolean getInterrupted();
|
||||
|
||||
|
||||
public abstract void logInfo(String info);
|
||||
|
||||
|
||||
public abstract void logWarning(String warning);
|
||||
|
||||
|
||||
public abstract void logError(String error);
|
||||
|
||||
public abstract void recordSymbol(
|
||||
NameHierarchy symbolName, SymbolKind symbolKind,
|
||||
AccessKind access, DefinitionKind definitionKind);
|
||||
|
||||
NameHierarchy symbolName,
|
||||
SymbolKind symbolKind,
|
||||
AccessKind access,
|
||||
DefinitionKind definitionKind);
|
||||
|
||||
public abstract void recordSymbolWithLocation(
|
||||
NameHierarchy symbolName, SymbolKind symbolKind,
|
||||
Range range,
|
||||
AccessKind access, DefinitionKind definitionKind);
|
||||
NameHierarchy symbolName,
|
||||
SymbolKind symbolKind,
|
||||
Range range,
|
||||
AccessKind access,
|
||||
DefinitionKind definitionKind);
|
||||
|
||||
public abstract void recordSymbolWithLocationAndScope(
|
||||
NameHierarchy symbolName, SymbolKind symbolKind,
|
||||
Range range,
|
||||
Range scopeRange,
|
||||
AccessKind access, DefinitionKind definitionKind);
|
||||
|
||||
NameHierarchy symbolName,
|
||||
SymbolKind symbolKind,
|
||||
Range range,
|
||||
Range scopeRange,
|
||||
AccessKind access,
|
||||
DefinitionKind definitionKind);
|
||||
|
||||
public abstract void recordSymbolWithLocationAndScopeAndSignature(
|
||||
NameHierarchy symbolName, SymbolKind symbolKind,
|
||||
Range range,
|
||||
Range scopeRange,
|
||||
Range signatureRange,
|
||||
AccessKind access, DefinitionKind definitionKind);
|
||||
NameHierarchy symbolName,
|
||||
SymbolKind symbolKind,
|
||||
Range range,
|
||||
Range scopeRange,
|
||||
Range signatureRange,
|
||||
AccessKind access,
|
||||
DefinitionKind definitionKind);
|
||||
|
||||
public abstract void recordReference(
|
||||
ReferenceKind referenceKind, NameHierarchy referencedName, NameHierarchy contextName,
|
||||
Range range);
|
||||
ReferenceKind referenceKind,
|
||||
NameHierarchy referencedName,
|
||||
NameHierarchy contextName,
|
||||
Range range);
|
||||
|
||||
public abstract void recordQualifierLocation(
|
||||
NameHierarchy qualifierName,
|
||||
Range range);
|
||||
|
||||
public abstract void recordLocalSymbol(
|
||||
NameHierarchy symbolName,
|
||||
Range range);
|
||||
|
||||
public abstract void recordComment(
|
||||
Range range);
|
||||
|
||||
public abstract void recordError(
|
||||
String message, boolean fatal, boolean indexed,
|
||||
Range range);
|
||||
public abstract void recordQualifierLocation(NameHierarchy qualifierName, Range range);
|
||||
|
||||
public abstract void recordLocalSymbol(NameHierarchy symbolName, Range range);
|
||||
|
||||
public abstract void recordComment(Range range);
|
||||
|
||||
public abstract void recordError(String message, boolean fatal, boolean indexed, Range range);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.sourcetrail;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.eclipse.jdt.core.dom.ASTNode;
|
||||
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
|
||||
import org.eclipse.jdt.core.dom.CompilationUnit;
|
||||
@@ -29,17 +28,17 @@ import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
|
||||
public class ContextAwareAstVisitor extends AstVisitor
|
||||
{
|
||||
private Stack<ReferenceKind> m_typeRefKind = new Stack<>();
|
||||
|
||||
public ContextAwareAstVisitor(AstVisitorClient client, File filePath, String fileContent, CompilationUnit compilationUnit)
|
||||
|
||||
public ContextAwareAstVisitor(
|
||||
AstVisitorClient client, File filePath, String fileContent, CompilationUnit compilationUnit)
|
||||
{
|
||||
super(client, filePath, fileContent, compilationUnit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(TypeDeclaration node)
|
||||
|
||||
@Override public boolean visit(TypeDeclaration node)
|
||||
{
|
||||
boolean visitChildren = super.visit(node);
|
||||
|
||||
|
||||
if (visitChildren)
|
||||
{
|
||||
m_typeRefKind.push(ReferenceKind.TYPE_USAGE);
|
||||
@@ -56,12 +55,11 @@ public class ContextAwareAstVisitor extends AstVisitor
|
||||
acceptChildren(node.bodyDeclarations());
|
||||
m_typeRefKind.pop();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(EnumDeclaration node)
|
||||
|
||||
@Override public boolean visit(EnumDeclaration node)
|
||||
{
|
||||
boolean visitChildren = super.visit(node);
|
||||
|
||||
@@ -80,18 +78,17 @@ public class ContextAwareAstVisitor extends AstVisitor
|
||||
acceptChildren(node.bodyDeclarations());
|
||||
m_typeRefKind.pop();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(EnumConstantDeclaration node)
|
||||
|
||||
@Override public boolean visit(EnumConstantDeclaration node)
|
||||
{
|
||||
boolean visitChildren = super.visit(node);
|
||||
|
||||
if (visitChildren)
|
||||
{
|
||||
// we don't visit and record the name of enum constant declarations because
|
||||
// we don't visit and record the name of enum constant declarations because
|
||||
// this would create an unwanted self-reference.
|
||||
m_typeRefKind.push(ReferenceKind.TYPE_USAGE);
|
||||
acceptChild(node.getJavadoc());
|
||||
@@ -100,18 +97,17 @@ public class ContextAwareAstVisitor extends AstVisitor
|
||||
acceptChild(node.getAnonymousClassDeclaration());
|
||||
m_typeRefKind.pop();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(VariableDeclarationFragment node)
|
||||
|
||||
@Override public boolean visit(VariableDeclarationFragment node)
|
||||
{
|
||||
boolean visitChildren = super.visit(node);
|
||||
|
||||
if (visitChildren)
|
||||
{
|
||||
// we don't visit and record the name of field declarations because
|
||||
// we don't visit and record the name of field declarations because
|
||||
// this would create an unwanted self-reference.
|
||||
m_typeRefKind.push(ReferenceKind.TYPE_USAGE);
|
||||
if (!(node.getParent() instanceof FieldDeclaration))
|
||||
@@ -122,20 +118,19 @@ public class ContextAwareAstVisitor extends AstVisitor
|
||||
acceptChild(node.getInitializer());
|
||||
m_typeRefKind.pop();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(final ImportDeclaration node)
|
||||
|
||||
@Override public boolean visit(final ImportDeclaration node)
|
||||
{
|
||||
// We don't want to visit the name of the ImportDeclaration because this could cause a self reference.
|
||||
// We don't want to visit the name of the ImportDeclaration because this could cause a self
|
||||
// reference.
|
||||
super.visit(node);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(ParameterizedType node)
|
||||
|
||||
@Override public boolean visit(ParameterizedType node)
|
||||
{
|
||||
boolean visitChildren = super.visit(node);
|
||||
if (visitChildren)
|
||||
@@ -147,12 +142,11 @@ public class ContextAwareAstVisitor extends AstVisitor
|
||||
m_typeRefKind.pop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(QualifiedType node)
|
||||
|
||||
@Override public boolean visit(QualifiedType node)
|
||||
{
|
||||
// We don't want to visit the qualifier right now.
|
||||
boolean visitChildren = super.visit(node);
|
||||
@@ -164,12 +158,11 @@ public class ContextAwareAstVisitor extends AstVisitor
|
||||
acceptChild(node.getName());
|
||||
m_typeRefKind.pop();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(NameQualifiedType node)
|
||||
|
||||
@Override public boolean visit(NameQualifiedType node)
|
||||
{
|
||||
// We don't want to visit the qualifier right now.
|
||||
boolean visitChildren = super.visit(node);
|
||||
@@ -181,15 +174,14 @@ public class ContextAwareAstVisitor extends AstVisitor
|
||||
acceptChild(node.getName());
|
||||
m_typeRefKind.pop();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MethodInvocation node)
|
||||
|
||||
@Override public boolean visit(MethodInvocation node)
|
||||
{
|
||||
boolean visitChildren = super.visit(node);
|
||||
|
||||
|
||||
if (visitChildren)
|
||||
{
|
||||
m_typeRefKind.push(ReferenceKind.TYPE_USAGE);
|
||||
@@ -199,16 +191,15 @@ public class ContextAwareAstVisitor extends AstVisitor
|
||||
acceptChildren(node.arguments());
|
||||
m_typeRefKind.pop();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SuperMethodInvocation node)
|
||||
|
||||
@Override public boolean visit(SuperMethodInvocation node)
|
||||
{
|
||||
// We don't want to visit the qualifier right now.
|
||||
boolean visitChildren = super.visit(node);
|
||||
|
||||
|
||||
if (visitChildren)
|
||||
{
|
||||
m_typeRefKind.push(ReferenceKind.TYPE_USAGE);
|
||||
@@ -217,15 +208,14 @@ public class ContextAwareAstVisitor extends AstVisitor
|
||||
acceptChildren(node.arguments());
|
||||
m_typeRefKind.pop();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(ConstructorInvocation node)
|
||||
@Override public boolean visit(ConstructorInvocation node)
|
||||
{
|
||||
boolean visitChildren = super.visit(node);
|
||||
|
||||
|
||||
if (visitChildren)
|
||||
{
|
||||
m_typeRefKind.push(ReferenceKind.TYPE_USAGE);
|
||||
@@ -233,15 +223,14 @@ public class ContextAwareAstVisitor extends AstVisitor
|
||||
acceptChildren(node.arguments());
|
||||
m_typeRefKind.pop();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SuperConstructorInvocation node)
|
||||
@Override public boolean visit(SuperConstructorInvocation node)
|
||||
{
|
||||
boolean visitChildren = super.visit(node);
|
||||
|
||||
|
||||
if (visitChildren)
|
||||
{
|
||||
m_typeRefKind.push(ReferenceKind.TYPE_USAGE);
|
||||
@@ -250,32 +239,30 @@ public class ContextAwareAstVisitor extends AstVisitor
|
||||
acceptChildren(node.arguments());
|
||||
m_typeRefKind.pop();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(CreationReference node)
|
||||
|
||||
@Override public boolean visit(CreationReference node)
|
||||
{
|
||||
// We don't want to visit the qualifying type right now.
|
||||
boolean visitChildren = super.visit(node);
|
||||
|
||||
|
||||
if (visitChildren)
|
||||
{
|
||||
m_typeRefKind.push(ReferenceKind.TYPE_USAGE);
|
||||
acceptChildren(node.typeArguments());
|
||||
m_typeRefKind.pop();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(ExpressionMethodReference node)
|
||||
@Override public boolean visit(ExpressionMethodReference node)
|
||||
{
|
||||
// We don't want to visit qualifiers right now.
|
||||
boolean visitChildren = super.visit(node);
|
||||
|
||||
|
||||
if (visitChildren)
|
||||
{
|
||||
m_typeRefKind.push(ReferenceKind.TYPE_USAGE);
|
||||
@@ -284,16 +271,15 @@ public class ContextAwareAstVisitor extends AstVisitor
|
||||
acceptChild(node.getName());
|
||||
m_typeRefKind.pop();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SuperMethodReference node)
|
||||
|
||||
@Override public boolean visit(SuperMethodReference node)
|
||||
{
|
||||
// We don't want to visit qualifiers right now.
|
||||
boolean visitChildren = super.visit(node);
|
||||
|
||||
|
||||
if (visitChildren)
|
||||
{
|
||||
m_typeRefKind.push(ReferenceKind.TYPE_USAGE);
|
||||
@@ -301,38 +287,36 @@ public class ContextAwareAstVisitor extends AstVisitor
|
||||
acceptChild(node.getName());
|
||||
m_typeRefKind.pop();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(TypeMethodReference node)
|
||||
|
||||
@Override public boolean visit(TypeMethodReference node)
|
||||
{
|
||||
// We don't want to visit the qualifying type right now.
|
||||
boolean visitChildren = super.visit(node);
|
||||
|
||||
if (visitChildren)
|
||||
|
||||
if (visitChildren)
|
||||
{
|
||||
m_typeRefKind.push(ReferenceKind.TYPE_USAGE);
|
||||
acceptChildren(node.typeArguments());
|
||||
acceptChild(node.getName());
|
||||
m_typeRefKind.pop();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(ClassInstanceCreation node)
|
||||
|
||||
@Override public boolean visit(ClassInstanceCreation node)
|
||||
{
|
||||
boolean visitChildren = super.visit(node);
|
||||
|
||||
|
||||
if (visitChildren)
|
||||
{
|
||||
m_typeRefKind.push(ReferenceKind.TYPE_USAGE);
|
||||
acceptChild(node.getExpression());
|
||||
acceptChildren(node.typeArguments());
|
||||
|
||||
|
||||
if (node.getAnonymousClassDeclaration() != null)
|
||||
{
|
||||
m_typeRefKind.push(ReferenceKind.INHERITANCE);
|
||||
@@ -343,25 +327,23 @@ public class ContextAwareAstVisitor extends AstVisitor
|
||||
{
|
||||
acceptChild(node.getType());
|
||||
}
|
||||
|
||||
|
||||
acceptChildren(node.arguments());
|
||||
acceptChild(node.getAnonymousClassDeclaration());
|
||||
m_typeRefKind.pop();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(Javadoc node)
|
||||
{
|
||||
// We don't want to visit symbol references inside Javadoc right now.
|
||||
super.visit( node);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReferenceKind getTypeReferenceKind()
|
||||
@Override public boolean visit(Javadoc node)
|
||||
{
|
||||
// We don't want to visit symbol references inside Javadoc right now.
|
||||
super.visit(node);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override protected ReferenceKind getTypeReferenceKind()
|
||||
{
|
||||
if (!m_typeRefKind.isEmpty())
|
||||
{
|
||||
@@ -369,7 +351,7 @@ public class ContextAwareAstVisitor extends AstVisitor
|
||||
}
|
||||
return ReferenceKind.TYPE_USAGE;
|
||||
}
|
||||
|
||||
|
||||
private void acceptChild(ASTNode node)
|
||||
{
|
||||
if (node != null)
|
||||
@@ -377,7 +359,7 @@ public class ContextAwareAstVisitor extends AstVisitor
|
||||
node.accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void acceptChildren(List<?> nodes)
|
||||
{
|
||||
if (nodes != null)
|
||||
@@ -386,10 +368,9 @@ public class ContextAwareAstVisitor extends AstVisitor
|
||||
{
|
||||
if (node instanceof ASTNode)
|
||||
{
|
||||
acceptChild((ASTNode) node);
|
||||
acceptChild((ASTNode)node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,30 +2,29 @@ package com.sourcetrail;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.core.dom.IBinding;
|
||||
|
||||
public class ContextList
|
||||
{
|
||||
private Set<String> m_bindingKeys = new HashSet<>();
|
||||
|
||||
|
||||
public ContextList copy()
|
||||
{
|
||||
ContextList contextList = new ContextList();
|
||||
|
||||
contextList.m_bindingKeys = new HashSet<>(m_bindingKeys);
|
||||
|
||||
|
||||
return contextList;
|
||||
}
|
||||
|
||||
public void add(IBinding v)
|
||||
|
||||
public void add(IBinding v)
|
||||
{
|
||||
if (v != null)
|
||||
{
|
||||
m_bindingKeys.add(v.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean contains(IBinding v)
|
||||
{
|
||||
return v != null && m_bindingKeys.contains(v.getKey());
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
package com.sourcetrail;
|
||||
|
||||
public enum DefinitionKind
|
||||
{ // these values need to be the same as DefinitionKind in C++ code
|
||||
public enum DefinitionKind { // these values need to be the same as DefinitionKind in C++ code
|
||||
NONE(0),
|
||||
IMPLICIT(1),
|
||||
EXPLICIT(2);
|
||||
|
||||
private final int m_value;
|
||||
|
||||
private DefinitionKind(int value)
|
||||
{
|
||||
this.m_value = value;
|
||||
}
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
private final int m_value;
|
||||
|
||||
private DefinitionKind(int value)
|
||||
{
|
||||
this.m_value = value;
|
||||
}
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,20 +3,20 @@ package com.sourcetrail;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class FileContent
|
||||
public class FileContent
|
||||
{
|
||||
private List<String> m_lines;
|
||||
|
||||
|
||||
public FileContent(String text)
|
||||
{
|
||||
m_lines = Arrays.asList(text.split("\\r?\\n"));
|
||||
}
|
||||
|
||||
|
||||
public Position findStartPosition(String s)
|
||||
{
|
||||
return findStartPosition(s, new Position(1, 1));
|
||||
}
|
||||
|
||||
|
||||
public Position findStartPosition(String s, Position from)
|
||||
{
|
||||
int lineIndex = from.line - 1;
|
||||
@@ -43,9 +43,8 @@ public class FileContent
|
||||
public Range findRange(String s, Position from)
|
||||
{
|
||||
Position startPosition = findStartPosition(s, from);
|
||||
|
||||
|
||||
return new Range(
|
||||
startPosition,
|
||||
new Position(startPosition.line, startPosition.column + s.length() - 1));
|
||||
startPosition, new Position(startPosition.line, startPosition.column + s.length() - 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import org.eclipse.jdt.core.JavaCore;
|
||||
import org.eclipse.jdt.core.compiler.IProblem;
|
||||
import org.eclipse.jdt.core.dom.AST;
|
||||
@@ -26,55 +25,77 @@ import org.eclipse.jdt.core.dom.CompilationUnit;
|
||||
import org.eclipse.jdt.core.dom.LineComment;
|
||||
import org.eclipse.jdt.core.dom.PackageDeclaration;
|
||||
|
||||
public class JavaIndexer
|
||||
{
|
||||
public static void processFile(int address, String filePath, String fileContent, String languageStandard, String classPath, int verbose)
|
||||
public class JavaIndexer
|
||||
{
|
||||
public static void processFile(
|
||||
int address,
|
||||
String filePath,
|
||||
String fileContent,
|
||||
String languageStandard,
|
||||
String classPath,
|
||||
int verbose)
|
||||
{
|
||||
processFile(new JavaIndexerAstVisitorClient(address), filePath, fileContent, languageStandard, classPath, verbose);
|
||||
processFile(
|
||||
new JavaIndexerAstVisitorClient(address),
|
||||
filePath,
|
||||
fileContent,
|
||||
languageStandard,
|
||||
classPath,
|
||||
verbose);
|
||||
}
|
||||
|
||||
public static void processFile(AstVisitorClient astVisitorClient, String filePath, String fileContent, String languageStandard, String classPath, int verbose)
|
||||
|
||||
public static void processFile(
|
||||
AstVisitorClient astVisitorClient,
|
||||
String filePath,
|
||||
String fileContent,
|
||||
String languageStandard,
|
||||
String classPath,
|
||||
int verbose)
|
||||
{
|
||||
try
|
||||
{
|
||||
astVisitorClient.logInfo("indexing source file: " + filePath);
|
||||
|
||||
|
||||
Path path = Paths.get(filePath);
|
||||
|
||||
|
||||
ASTParser parser = ASTParser.newParser(AST.JLS12);
|
||||
|
||||
parser.setResolveBindings(true); // solve "bindings" like the declaration of the type used in a var decl
|
||||
parser.setKind(ASTParser.K_COMPILATION_UNIT); // specify to parse the entire compilation unit
|
||||
parser.setBindingsRecovery(true); // also return bindings that are not resolved completely
|
||||
|
||||
parser.setResolveBindings(
|
||||
true); // solve "bindings" like the declaration of the type used in a var decl
|
||||
parser.setKind(
|
||||
ASTParser.K_COMPILATION_UNIT); // specify to parse the entire compilation unit
|
||||
parser.setBindingsRecovery(
|
||||
true); // also return bindings that are not resolved completely
|
||||
parser.setStatementsRecovery(true);
|
||||
|
||||
{
|
||||
String convertedLanguageStandard = convertLanguageStandard(languageStandard);
|
||||
astVisitorClient.logInfo("using language standard " + convertedLanguageStandard);
|
||||
|
||||
|
||||
Hashtable<String, String> options = JavaCore.getOptions();
|
||||
options.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
|
||||
options.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
|
||||
options.put(JavaCore.COMPILER_SOURCE, convertedLanguageStandard);
|
||||
options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, convertedLanguageStandard);
|
||||
options.put(JavaCore.COMPILER_COMPLIANCE, convertedLanguageStandard);
|
||||
options.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
|
||||
options.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
|
||||
options.put(JavaCore.COMPILER_SOURCE, convertedLanguageStandard);
|
||||
options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, convertedLanguageStandard);
|
||||
options.put(JavaCore.COMPILER_COMPLIANCE, convertedLanguageStandard);
|
||||
parser.setCompilerOptions(options);
|
||||
}
|
||||
|
||||
|
||||
parser.setUnitName(path.getFileName().toString());
|
||||
|
||||
|
||||
List<String> classpath = new ArrayList<>();
|
||||
List<String> sources = new ArrayList<>();
|
||||
|
||||
|
||||
for (String classPathEntry: classPath.split("\\;"))
|
||||
{
|
||||
{
|
||||
if (classPathEntry.endsWith(".jar"))
|
||||
{
|
||||
classpath.add(classPathEntry);
|
||||
}
|
||||
else if(classPathEntry.endsWith(".aar"))
|
||||
else if (classPathEntry.endsWith(".aar"))
|
||||
{
|
||||
File extractedJarFile = extractClassesJarFileFromAarFile(Paths.get(classPathEntry), astVisitorClient);
|
||||
File extractedJarFile = extractClassesJarFileFromAarFile(
|
||||
Paths.get(classPathEntry), astVisitorClient);
|
||||
if (extractedJarFile != null)
|
||||
{
|
||||
classpath.add(extractedJarFile.getAbsolutePath());
|
||||
@@ -83,47 +104,50 @@ public class JavaIndexer
|
||||
else if (!classPathEntry.isEmpty())
|
||||
{
|
||||
sources.add(classPathEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parser.setEnvironment(classpath.toArray(new String[0]), sources.toArray(new String[0]), null, true);
|
||||
|
||||
parser.setEnvironment(
|
||||
classpath.toArray(new String[0]), sources.toArray(new String[0]), null, true);
|
||||
parser.setSource(fileContent.toCharArray());
|
||||
|
||||
CompilationUnit cu = (CompilationUnit) parser.createAST(null);
|
||||
|
||||
|
||||
CompilationUnit cu = (CompilationUnit)parser.createAST(null);
|
||||
|
||||
ASTVisitor visitor;
|
||||
if (verbose != 0)
|
||||
{
|
||||
visitor = new VerboseContextAwareAstVisitor(astVisitorClient, path.toFile(), fileContent, cu);
|
||||
visitor = new VerboseContextAwareAstVisitor(
|
||||
astVisitorClient, path.toFile(), fileContent, cu);
|
||||
}
|
||||
else
|
||||
{
|
||||
visitor = new ContextAwareAstVisitor(astVisitorClient, path.toFile(), fileContent, cu);
|
||||
visitor = new ContextAwareAstVisitor(
|
||||
astVisitorClient, path.toFile(), fileContent, cu);
|
||||
}
|
||||
|
||||
|
||||
astVisitorClient.logInfo("starting AST traversal");
|
||||
|
||||
|
||||
cu.accept(visitor);
|
||||
|
||||
|
||||
for (IProblem problem: cu.getProblems())
|
||||
{
|
||||
if (problem.isError())
|
||||
{
|
||||
Range range = new Range(
|
||||
cu.getLineNumber(problem.getSourceStart()),
|
||||
cu.getColumnNumber(problem.getSourceStart() + 1),
|
||||
cu.getLineNumber(problem.getSourceEnd()),
|
||||
cu.getColumnNumber(problem.getSourceEnd()) + 1);
|
||||
|
||||
cu.getLineNumber(problem.getSourceStart()),
|
||||
cu.getColumnNumber(problem.getSourceStart() + 1),
|
||||
cu.getLineNumber(problem.getSourceEnd()),
|
||||
cu.getColumnNumber(problem.getSourceEnd()) + 1);
|
||||
|
||||
astVisitorClient.recordError(problem.getMessage(), false, true, range);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (Object commentObject: cu.getCommentList())
|
||||
{
|
||||
if ((commentObject instanceof LineComment) || (commentObject instanceof BlockComment))
|
||||
{
|
||||
((Comment) commentObject).accept(visitor);
|
||||
((Comment)commentObject).accept(visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,15 +159,16 @@ public class JavaIndexer
|
||||
astVisitorClient.logError(sw.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String getPackageName(String fileContent)
|
||||
{
|
||||
String packageName = "";
|
||||
|
||||
|
||||
ASTParser parser = ASTParser.newParser(AST.JLS12);
|
||||
parser.setKind(ASTParser.K_COMPILATION_UNIT); // specify to parse the entire compilation unit
|
||||
parser.setKind(
|
||||
ASTParser.K_COMPILATION_UNIT); // specify to parse the entire compilation unit
|
||||
parser.setSource(fileContent.toCharArray());
|
||||
CompilationUnit cu = (CompilationUnit) parser.createAST(null);
|
||||
CompilationUnit cu = (CompilationUnit)parser.createAST(null);
|
||||
PackageDeclaration packageDeclaration = cu.getPackage();
|
||||
if (packageDeclaration != null)
|
||||
{
|
||||
@@ -151,138 +176,181 @@ public class JavaIndexer
|
||||
}
|
||||
return packageName;
|
||||
}
|
||||
|
||||
|
||||
public static void clearCaches()
|
||||
{
|
||||
Runtime.getRuntime().gc();
|
||||
}
|
||||
|
||||
|
||||
private static String convertLanguageStandard(String s)
|
||||
{
|
||||
switch (s)
|
||||
{
|
||||
case "1":
|
||||
return JavaCore.VERSION_1_1;
|
||||
case "2":
|
||||
return JavaCore.VERSION_1_2;
|
||||
case "3":
|
||||
return JavaCore.VERSION_1_3;
|
||||
case "4":
|
||||
return JavaCore.VERSION_1_4;
|
||||
case "5":
|
||||
return JavaCore.VERSION_1_5;
|
||||
case "6":
|
||||
return JavaCore.VERSION_1_6;
|
||||
case "7":
|
||||
return JavaCore.VERSION_1_7;
|
||||
case "8":
|
||||
return JavaCore.VERSION_1_8;
|
||||
case "9":
|
||||
return JavaCore.VERSION_9;
|
||||
case "10":
|
||||
return JavaCore.VERSION_10;
|
||||
case "11":
|
||||
return JavaCore.VERSION_11;
|
||||
case "12":
|
||||
default:
|
||||
return JavaCore.VERSION_12;
|
||||
}
|
||||
{
|
||||
case "1":
|
||||
return JavaCore.VERSION_1_1;
|
||||
case "2":
|
||||
return JavaCore.VERSION_1_2;
|
||||
case "3":
|
||||
return JavaCore.VERSION_1_3;
|
||||
case "4":
|
||||
return JavaCore.VERSION_1_4;
|
||||
case "5":
|
||||
return JavaCore.VERSION_1_5;
|
||||
case "6":
|
||||
return JavaCore.VERSION_1_6;
|
||||
case "7":
|
||||
return JavaCore.VERSION_1_7;
|
||||
case "8":
|
||||
return JavaCore.VERSION_1_8;
|
||||
case "9":
|
||||
return JavaCore.VERSION_9;
|
||||
case "10":
|
||||
return JavaCore.VERSION_10;
|
||||
case "11":
|
||||
return JavaCore.VERSION_11;
|
||||
case "12":
|
||||
default:
|
||||
return JavaCore.VERSION_12;
|
||||
}
|
||||
}
|
||||
|
||||
private static File extractClassesJarFileFromAarFile(Path aarFilePath, AstVisitorClient astVisitorClient) throws IOException
|
||||
|
||||
private static File extractClassesJarFileFromAarFile(
|
||||
Path aarFilePath, AstVisitorClient astVisitorClient) throws IOException
|
||||
{
|
||||
JarFile jarFile = new JarFile(aarFilePath.toString());
|
||||
ZipEntry classesJarEntry = jarFile.getEntry("classes.jar");
|
||||
if (classesJarEntry != null)
|
||||
{
|
||||
InputStream inputStream = jarFile.getInputStream(classesJarEntry);
|
||||
File tempFile = File.createTempFile("jar_file_from_" + Utility.getFilenameWithoutExtension(aarFilePath) + "_", ".jar");
|
||||
File tempFile = File.createTempFile(
|
||||
"jar_file_from_" + Utility.getFilenameWithoutExtension(aarFilePath) + "_", ".jar");
|
||||
tempFile.deleteOnExit();
|
||||
|
||||
|
||||
byte[] buffer = new byte[8 * 1024];
|
||||
|
||||
try
|
||||
|
||||
try
|
||||
{
|
||||
OutputStream output = new FileOutputStream(tempFile);
|
||||
try
|
||||
try
|
||||
{
|
||||
int bytesRead;
|
||||
while ((bytesRead = inputStream.read(buffer)) != -1)
|
||||
while ((bytesRead = inputStream.read(buffer)) != -1)
|
||||
{
|
||||
output.write(buffer, 0, bytesRead);
|
||||
}
|
||||
}
|
||||
finally
|
||||
}
|
||||
finally
|
||||
{
|
||||
output.close();
|
||||
}
|
||||
}
|
||||
finally
|
||||
}
|
||||
finally
|
||||
{
|
||||
inputStream.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
astVisitorClient.logInfo(
|
||||
"Extracted classes.jar file from \"" + aarFilePath.toString() + "\" to \"" + tempFile.getAbsolutePath() + "\". " +
|
||||
"This file will be automatically deleted when the session ends.");
|
||||
|
||||
"Extracted classes.jar file from \"" + aarFilePath.toString() + "\" to \"" +
|
||||
tempFile.getAbsolutePath() + "\". "
|
||||
+ "This file will be automatically deleted when the session ends.");
|
||||
|
||||
return tempFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
astVisitorClient.logError("Classpath entry \"" + aarFilePath + "\" is malformed. No internal \"classes.jar\" entry could be found.");
|
||||
astVisitorClient.logError(
|
||||
"Classpath entry \"" + aarFilePath +
|
||||
"\" is malformed. No internal \"classes.jar\" entry could be found.");
|
||||
}
|
||||
jarFile.close();
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// the following methods are defined in the native c++ code
|
||||
|
||||
static public native boolean getInterrupted(int address);
|
||||
|
||||
|
||||
static public native void logInfo(int address, String info);
|
||||
|
||||
|
||||
static public native void logWarning(int address, String warning);
|
||||
|
||||
|
||||
static public native void logError(int address, String error);
|
||||
|
||||
|
||||
static public native void recordSymbol(
|
||||
int address, String symbolName, int symbolType,
|
||||
int access, int definitionKind);
|
||||
int address, String symbolName, int symbolType, int access, int definitionKind);
|
||||
|
||||
static public native void recordSymbolWithLocation(
|
||||
int address, String symbolName, int symbolType,
|
||||
int beginLine, int beginColumn, int endLine, int endColumn,
|
||||
int access, int definitionKind);
|
||||
|
||||
int address,
|
||||
String symbolName,
|
||||
int symbolType,
|
||||
int beginLine,
|
||||
int beginColumn,
|
||||
int endLine,
|
||||
int endColumn,
|
||||
int access,
|
||||
int definitionKind);
|
||||
|
||||
static public native void recordSymbolWithLocationAndScope(
|
||||
int address, String symbolName, int symbolType,
|
||||
int beginLine, int beginColumn, int endLine, int endColumn,
|
||||
int scopeBeginLine, int scopeBeginColumn, int scopeEndLine, int scopeEndColumn,
|
||||
int access, int definitionKind
|
||||
);
|
||||
|
||||
int address,
|
||||
String symbolName,
|
||||
int symbolType,
|
||||
int beginLine,
|
||||
int beginColumn,
|
||||
int endLine,
|
||||
int endColumn,
|
||||
int scopeBeginLine,
|
||||
int scopeBeginColumn,
|
||||
int scopeEndLine,
|
||||
int scopeEndColumn,
|
||||
int access,
|
||||
int definitionKind);
|
||||
|
||||
static public native void recordSymbolWithLocationAndScopeAndSignature(
|
||||
int address, String symbolName, int symbolType,
|
||||
int beginLine, int beginColumn, int endLine, int endColumn,
|
||||
int scopeBeginLine, int scopeBeginColumn, int scopeEndLine, int scopeEndColumn,
|
||||
int signatureBeginLine, int signatureBeginColumn, int signatureEndLine, int signatureEndColumn,
|
||||
int access, int definitionKind
|
||||
);
|
||||
int address,
|
||||
String symbolName,
|
||||
int symbolType,
|
||||
int beginLine,
|
||||
int beginColumn,
|
||||
int endLine,
|
||||
int endColumn,
|
||||
int scopeBeginLine,
|
||||
int scopeBeginColumn,
|
||||
int scopeEndLine,
|
||||
int scopeEndColumn,
|
||||
int signatureBeginLine,
|
||||
int signatureBeginColumn,
|
||||
int signatureEndLine,
|
||||
int signatureEndColumn,
|
||||
int access,
|
||||
int definitionKind);
|
||||
|
||||
static public native void recordReference(
|
||||
int address, int referenceKind, String referencedName, String contextName, int beginLine, int beginColumn, int endLine, int endColumn);
|
||||
int address,
|
||||
int referenceKind,
|
||||
String referencedName,
|
||||
String contextName,
|
||||
int beginLine,
|
||||
int beginColumn,
|
||||
int endLine,
|
||||
int endColumn);
|
||||
|
||||
static public native void recordQualifierLocation(
|
||||
int address, String qualifierName, int beginLine, int beginColumn, int endLine, int endColumn);
|
||||
|
||||
int address, String qualifierName, int beginLine, int beginColumn, int endLine, int endColumn);
|
||||
|
||||
static public native void recordLocalSymbol(
|
||||
int address, String symbolName, int beginLine, int beginColumn, int endLine, int endColumn);
|
||||
|
||||
int address, String symbolName, int beginLine, int beginColumn, int endLine, int endColumn);
|
||||
|
||||
static public native void recordComment(
|
||||
int address, int beginLine, int beginColumn, int endLine, int endColumn);
|
||||
|
||||
int address, int beginLine, int beginColumn, int endLine, int endColumn);
|
||||
|
||||
static public native void recordError(
|
||||
int address, String message, int fatal, int indexed, int beginLine, int beginColumn, int endLine, int endColumn);
|
||||
int address,
|
||||
String message,
|
||||
int fatal,
|
||||
int indexed,
|
||||
int beginLine,
|
||||
int beginColumn,
|
||||
int endLine,
|
||||
int endColumn);
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package com.sourcetrail;
|
||||
import com.sourcetrail.name.NameElement;
|
||||
import com.sourcetrail.name.NameHierarchy;
|
||||
|
||||
public class JavaIndexerAstVisitorClient extends AstVisitorClient
|
||||
public class JavaIndexerAstVisitorClient extends AstVisitorClient
|
||||
{
|
||||
private int m_address;
|
||||
private String m_javaLangPackageName;
|
||||
@@ -12,135 +12,187 @@ public class JavaIndexerAstVisitorClient extends AstVisitorClient
|
||||
public JavaIndexerAstVisitorClient(int address)
|
||||
{
|
||||
m_address = address;
|
||||
|
||||
|
||||
NameHierarchy javaLangPackageNameHierarchy = new NameHierarchy();
|
||||
javaLangPackageNameHierarchy.push(new NameElement("java"));
|
||||
javaLangPackageNameHierarchy.push(new NameElement("lang"));
|
||||
m_javaLangPackageName = javaLangPackageNameHierarchy.serialize();
|
||||
m_javaLangPackageRecorded = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getInterrupted()
|
||||
|
||||
@Override public boolean getInterrupted()
|
||||
{
|
||||
return JavaIndexer.getInterrupted(m_address);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logInfo(String info)
|
||||
|
||||
@Override public void logInfo(String info)
|
||||
{
|
||||
JavaIndexer.logInfo(m_address, info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logWarning(String warning)
|
||||
@Override public void logWarning(String warning)
|
||||
{
|
||||
JavaIndexer.logWarning(m_address, warning);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logError(String error)
|
||||
|
||||
@Override public void logError(String error)
|
||||
{
|
||||
JavaIndexer.logError(m_address, error);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void recordSymbol(
|
||||
NameHierarchy symbolName, SymbolKind symbolKind,
|
||||
AccessKind access, DefinitionKind definitionKind)
|
||||
NameHierarchy symbolName, SymbolKind symbolKind, AccessKind access, DefinitionKind definitionKind)
|
||||
{
|
||||
JavaIndexer.recordSymbol(
|
||||
m_address, symbolName.serialize(), symbolKind.getValue(),
|
||||
access.getValue(), definitionKind.getValue());
|
||||
m_address,
|
||||
symbolName.serialize(),
|
||||
symbolKind.getValue(),
|
||||
access.getValue(),
|
||||
definitionKind.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordSymbolWithLocation(
|
||||
NameHierarchy symbolName, SymbolKind symbolKind, Range range,
|
||||
AccessKind access, DefinitionKind definitionKind)
|
||||
NameHierarchy symbolName,
|
||||
SymbolKind symbolKind,
|
||||
Range range,
|
||||
AccessKind access,
|
||||
DefinitionKind definitionKind)
|
||||
{
|
||||
JavaIndexer.recordSymbolWithLocation(
|
||||
m_address, symbolName.serialize(), symbolKind.getValue(),
|
||||
range.begin.line, range.begin.column, range.end.line, range.end.column,
|
||||
access.getValue(), definitionKind.getValue());
|
||||
m_address,
|
||||
symbolName.serialize(),
|
||||
symbolKind.getValue(),
|
||||
range.begin.line,
|
||||
range.begin.column,
|
||||
range.end.line,
|
||||
range.end.column,
|
||||
access.getValue(),
|
||||
definitionKind.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordSymbolWithLocationAndScope(
|
||||
NameHierarchy symbolName, SymbolKind symbolKind, Range range,
|
||||
Range scopeRange, AccessKind access, DefinitionKind definitionKind)
|
||||
NameHierarchy symbolName,
|
||||
SymbolKind symbolKind,
|
||||
Range range,
|
||||
Range scopeRange,
|
||||
AccessKind access,
|
||||
DefinitionKind definitionKind)
|
||||
{
|
||||
JavaIndexer.recordSymbolWithLocationAndScope(
|
||||
m_address, symbolName.serialize(), symbolKind.getValue(),
|
||||
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(), definitionKind.getValue());
|
||||
m_address,
|
||||
symbolName.serialize(),
|
||||
symbolKind.getValue(),
|
||||
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(),
|
||||
definitionKind.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordSymbolWithLocationAndScopeAndSignature(
|
||||
NameHierarchy symbolName, SymbolKind symbolKind, Range range,
|
||||
Range scopeRange, Range signatureRange, AccessKind access, DefinitionKind definitionKind)
|
||||
NameHierarchy symbolName,
|
||||
SymbolKind symbolKind,
|
||||
Range range,
|
||||
Range scopeRange,
|
||||
Range signatureRange,
|
||||
AccessKind access,
|
||||
DefinitionKind definitionKind)
|
||||
{
|
||||
JavaIndexer.recordSymbolWithLocationAndScopeAndSignature(
|
||||
m_address, symbolName.serialize(), symbolKind.getValue(),
|
||||
range.begin.line, range.begin.column, range.end.line, range.end.column,
|
||||
scopeRange.begin.line, scopeRange.begin.column, scopeRange.end.line, scopeRange.end.column,
|
||||
signatureRange.begin.line, signatureRange.begin.column, signatureRange.end.line, signatureRange.end.column,
|
||||
access.getValue(), definitionKind.getValue());
|
||||
m_address,
|
||||
symbolName.serialize(),
|
||||
symbolKind.getValue(),
|
||||
range.begin.line,
|
||||
range.begin.column,
|
||||
range.end.line,
|
||||
range.end.column,
|
||||
scopeRange.begin.line,
|
||||
scopeRange.begin.column,
|
||||
scopeRange.end.line,
|
||||
scopeRange.end.column,
|
||||
signatureRange.begin.line,
|
||||
signatureRange.begin.column,
|
||||
signatureRange.end.line,
|
||||
signatureRange.end.column,
|
||||
access.getValue(),
|
||||
definitionKind.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordReference(
|
||||
ReferenceKind referenceKind, NameHierarchy referencedName,
|
||||
NameHierarchy contextName, Range range)
|
||||
ReferenceKind referenceKind, NameHierarchy referencedName, NameHierarchy contextName, Range range)
|
||||
{
|
||||
String serializedReferencedName = referencedName.serialize();
|
||||
if (!m_javaLangPackageRecorded && serializedReferencedName.startsWith(m_javaLangPackageName))
|
||||
{
|
||||
JavaIndexer.recordSymbol(
|
||||
m_address, m_javaLangPackageName, SymbolKind.PACKAGE.getValue(),
|
||||
AccessKind.NONE.getValue(), DefinitionKind.NONE.getValue());
|
||||
|
||||
m_address,
|
||||
m_javaLangPackageName,
|
||||
SymbolKind.PACKAGE.getValue(),
|
||||
AccessKind.NONE.getValue(),
|
||||
DefinitionKind.NONE.getValue());
|
||||
|
||||
m_javaLangPackageRecorded = true;
|
||||
}
|
||||
|
||||
|
||||
JavaIndexer.recordReference(
|
||||
m_address, referenceKind.getValue(), serializedReferencedName, contextName.serialize(),
|
||||
range.begin.line, range.begin.column, range.end.line, range.end.column);
|
||||
m_address,
|
||||
referenceKind.getValue(),
|
||||
serializedReferencedName,
|
||||
contextName.serialize(),
|
||||
range.begin.line,
|
||||
range.begin.column,
|
||||
range.end.line,
|
||||
range.end.column);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordQualifierLocation(
|
||||
NameHierarchy qualifierName,
|
||||
Range range)
|
||||
@Override public void recordQualifierLocation(NameHierarchy qualifierName, Range range)
|
||||
{
|
||||
JavaIndexer.recordQualifierLocation(
|
||||
m_address, qualifierName.serialize(),
|
||||
range.begin.line, range.begin.column, range.end.line, range.end.column);
|
||||
m_address,
|
||||
qualifierName.serialize(),
|
||||
range.begin.line,
|
||||
range.begin.column,
|
||||
range.end.line,
|
||||
range.end.column);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordLocalSymbol(NameHierarchy symbolName, Range range)
|
||||
@Override public void recordLocalSymbol(NameHierarchy symbolName, Range range)
|
||||
{
|
||||
JavaIndexer.recordLocalSymbol(
|
||||
m_address, symbolName.serialize(),
|
||||
range.begin.line, range.begin.column, range.end.line, range.end.column);
|
||||
m_address,
|
||||
symbolName.serialize(),
|
||||
range.begin.line,
|
||||
range.begin.column,
|
||||
range.end.line,
|
||||
range.end.column);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordComment(Range range)
|
||||
@Override public void recordComment(Range range)
|
||||
{
|
||||
JavaIndexer.recordComment(
|
||||
m_address,
|
||||
range.begin.line, range.begin.column, range.end.line, range.end.column);
|
||||
m_address, range.begin.line, range.begin.column, range.end.line, range.end.column);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordError(String message, boolean fatal, boolean indexed, Range range)
|
||||
@Override public void recordError(String message, boolean fatal, boolean indexed, Range range)
|
||||
{
|
||||
JavaIndexer.recordError(
|
||||
m_address, message, (fatal ? 1 : 0), (indexed ? 1 : 0),
|
||||
range.begin.line, range.begin.column, range.end.line, range.end.column);
|
||||
m_address,
|
||||
message,
|
||||
(fatal ? 1 : 0),
|
||||
(indexed ? 1 : 0),
|
||||
range.begin.line,
|
||||
range.begin.column,
|
||||
range.end.line,
|
||||
range.end.column);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package com.sourcetrail;
|
||||
|
||||
public class Position
|
||||
public class Position
|
||||
{
|
||||
public int line = 0;
|
||||
public int column = 0;
|
||||
|
||||
public Position()
|
||||
{
|
||||
}
|
||||
|
||||
public Position() {}
|
||||
|
||||
public Position(int line, int column)
|
||||
{
|
||||
this.line = line;
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.sourcetrail;
|
||||
|
||||
import com.sourcetrail.name.DeclName;
|
||||
import com.sourcetrail.name.NameHierarchy;
|
||||
import com.sourcetrail.name.TypeName;
|
||||
import com.sourcetrail.name.resolver.BindingNameResolver;
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.jdt.core.dom.ASTNode;
|
||||
import org.eclipse.jdt.core.dom.CompilationUnit;
|
||||
import org.eclipse.jdt.core.dom.CreationReference;
|
||||
@@ -27,45 +30,41 @@ import org.eclipse.jdt.core.dom.ThisExpression;
|
||||
import org.eclipse.jdt.core.dom.Type;
|
||||
import org.eclipse.jdt.core.dom.TypeMethodReference;
|
||||
|
||||
import com.sourcetrail.name.DeclName;
|
||||
import com.sourcetrail.name.NameHierarchy;
|
||||
import com.sourcetrail.name.TypeName;
|
||||
import com.sourcetrail.name.resolver.BindingNameResolver;
|
||||
|
||||
public class QualifierVisitor
|
||||
public class QualifierVisitor
|
||||
{
|
||||
protected AstVisitorClient m_client = null;
|
||||
private File m_filePath;
|
||||
private CompilationUnit m_compilationUnit;
|
||||
private boolean m_recordSymbolKinds = false;
|
||||
|
||||
public QualifierVisitor(AstVisitorClient client, File filePath, CompilationUnit compilationUnit, boolean recordSymbolKinds)
|
||||
{
|
||||
|
||||
public QualifierVisitor(
|
||||
AstVisitorClient client, File filePath, CompilationUnit compilationUnit, boolean recordSymbolKinds)
|
||||
{
|
||||
m_client = client;
|
||||
m_filePath = filePath;
|
||||
m_compilationUnit = compilationUnit;
|
||||
m_recordSymbolKinds = recordSymbolKinds;
|
||||
}
|
||||
|
||||
public void recordQualifierOfNode(ImportDeclaration node)
|
||||
public void recordQualifierOfNode(ImportDeclaration node)
|
||||
{
|
||||
if (node != null && node.getName() instanceof QualifiedName)
|
||||
{
|
||||
recordNodeAsQualifier(((QualifiedName) node.getName()).getQualifier());
|
||||
recordNodeAsQualifier(((QualifiedName)node.getName()).getQualifier());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void recordQualifierOfNode(SimpleType node)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
if (node.getName() instanceof QualifiedName)
|
||||
{
|
||||
recordNodeAsQualifier(((QualifiedName) node.getName()).getQualifier());
|
||||
recordNodeAsQualifier(((QualifiedName)node.getName()).getQualifier());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void recordQualifierOfNode(QualifiedType node)
|
||||
{
|
||||
if (node != null)
|
||||
@@ -73,7 +72,7 @@ public class QualifierVisitor
|
||||
recordNodeAsQualifier(node.getQualifier());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void recordQualifierOfNode(NameQualifiedType node)
|
||||
{
|
||||
if (node != null)
|
||||
@@ -121,11 +120,11 @@ public class QualifierVisitor
|
||||
recordNodeAsQualifier(node.getExpression(), fileContent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void recordQualifierOfNode(SuperMethodInvocation node, FileContent fileContent)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
{
|
||||
IMethodBinding methodBinding = node.resolveMethodBinding();
|
||||
if (methodBinding != null)
|
||||
{
|
||||
@@ -133,23 +132,23 @@ public class QualifierVisitor
|
||||
if (typeBinding != null)
|
||||
{
|
||||
m_client.recordQualifierLocation(
|
||||
BindingNameResolver
|
||||
.getQualifiedName(typeBinding, m_filePath, m_compilationUnit)
|
||||
.orElse(TypeName.unsolved())
|
||||
.toDeclName()
|
||||
.toNameHierarchy(),
|
||||
fileContent.findRange("super", getRange(node).begin));
|
||||
BindingNameResolver
|
||||
.getQualifiedName(typeBinding, m_filePath, m_compilationUnit)
|
||||
.orElse(TypeName.unsolved())
|
||||
.toDeclName()
|
||||
.toNameHierarchy(),
|
||||
fileContent.findRange("super", getRange(node).begin));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
recordNodeAsQualifier(node.getQualifier());
|
||||
}
|
||||
}
|
||||
|
||||
public void recordQualifierOfNode(CreationReference node)
|
||||
public void recordQualifierOfNode(CreationReference node)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
{
|
||||
recordNodeAsQualifier(node.getType());
|
||||
}
|
||||
}
|
||||
@@ -165,7 +164,7 @@ public class QualifierVisitor
|
||||
public void recordQualifierOfNode(SuperMethodReference node, FileContent fileContent)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
{
|
||||
IMethodBinding methodBinding = node.resolveMethodBinding();
|
||||
if (methodBinding != null)
|
||||
{
|
||||
@@ -173,15 +172,15 @@ public class QualifierVisitor
|
||||
if (typeBinding != null)
|
||||
{
|
||||
m_client.recordQualifierLocation(
|
||||
BindingNameResolver
|
||||
.getQualifiedName(typeBinding, m_filePath, m_compilationUnit)
|
||||
.orElse(TypeName.unsolved())
|
||||
.toDeclName()
|
||||
.toNameHierarchy(),
|
||||
fileContent.findRange("super", getRange(node).begin));
|
||||
BindingNameResolver
|
||||
.getQualifiedName(typeBinding, m_filePath, m_compilationUnit)
|
||||
.orElse(TypeName.unsolved())
|
||||
.toDeclName()
|
||||
.toNameHierarchy(),
|
||||
fileContent.findRange("super", getRange(node).begin));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
recordNodeAsQualifier(node.getQualifier());
|
||||
}
|
||||
}
|
||||
@@ -193,79 +192,80 @@ public class QualifierVisitor
|
||||
recordNodeAsQualifier(node.getType());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void recordNodeAsQualifier(Expression node, FileContent fileContent) {
|
||||
|
||||
|
||||
private void recordNodeAsQualifier(Expression node, FileContent fileContent)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
if (node instanceof Name)
|
||||
{
|
||||
recordNodeAsQualifier((Name) node);
|
||||
recordNodeAsQualifier((Name)node);
|
||||
}
|
||||
else if (node instanceof SuperFieldAccess)
|
||||
{
|
||||
SuperFieldAccess expression = (SuperFieldAccess) node;
|
||||
SuperFieldAccess expression = (SuperFieldAccess)node;
|
||||
IVariableBinding fieldBinding = expression.resolveFieldBinding();
|
||||
|
||||
|
||||
if (fieldBinding != null)
|
||||
{
|
||||
m_client.recordQualifierLocation(
|
||||
BindingNameResolver
|
||||
.getQualifiedName(fieldBinding.getDeclaringClass(), m_filePath, m_compilationUnit)
|
||||
.orElse(TypeName.unsolved())
|
||||
.toDeclName()
|
||||
.toNameHierarchy(),
|
||||
fileContent.findRange(
|
||||
"super",
|
||||
expression.getQualifier() != null
|
||||
? getRange(expression.getQualifier()).end
|
||||
: getRange(expression).begin));
|
||||
BindingNameResolver
|
||||
.getQualifiedName(
|
||||
fieldBinding.getDeclaringClass(), m_filePath, m_compilationUnit)
|
||||
.orElse(TypeName.unsolved())
|
||||
.toDeclName()
|
||||
.toNameHierarchy(),
|
||||
fileContent.findRange(
|
||||
"super",
|
||||
expression.getQualifier() != null ? getRange(expression.getQualifier()).end
|
||||
: getRange(expression).begin));
|
||||
}
|
||||
|
||||
|
||||
recordNodeAsQualifier(expression.getQualifier());
|
||||
}
|
||||
else if (node instanceof ThisExpression)
|
||||
{
|
||||
ThisExpression expression = (ThisExpression) node;
|
||||
|
||||
ThisExpression expression = (ThisExpression)node;
|
||||
|
||||
m_client.recordQualifierLocation(
|
||||
BindingNameResolver
|
||||
.getQualifiedName(expression.resolveTypeBinding(), m_filePath, m_compilationUnit)
|
||||
.orElse(TypeName.unsolved())
|
||||
.toDeclName()
|
||||
.toNameHierarchy(),
|
||||
fileContent.findRange(
|
||||
"this",
|
||||
expression.getQualifier() != null
|
||||
? getRange(expression.getQualifier()).end
|
||||
: getRange(expression).begin));
|
||||
|
||||
BindingNameResolver
|
||||
.getQualifiedName(
|
||||
expression.resolveTypeBinding(), m_filePath, m_compilationUnit)
|
||||
.orElse(TypeName.unsolved())
|
||||
.toDeclName()
|
||||
.toNameHierarchy(),
|
||||
fileContent.findRange(
|
||||
"this",
|
||||
expression.getQualifier() != null ? getRange(expression.getQualifier()).end
|
||||
: getRange(expression).begin));
|
||||
|
||||
recordNodeAsQualifier(expression.getQualifier());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void recordNodeAsQualifier(Type node)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
{
|
||||
if (node instanceof SimpleType)
|
||||
{
|
||||
recordNodeAsQualifier(((SimpleType) node).getName());
|
||||
recordNodeAsQualifier(((SimpleType)node).getName());
|
||||
}
|
||||
else if (node instanceof QualifiedType)
|
||||
{
|
||||
recordNodeAsQualifier(((QualifiedType) node).getName());
|
||||
recordNodeAsQualifier(((QualifiedType) node).getQualifier());
|
||||
recordNodeAsQualifier(((QualifiedType)node).getName());
|
||||
recordNodeAsQualifier(((QualifiedType)node).getQualifier());
|
||||
}
|
||||
else if (node instanceof NameQualifiedType)
|
||||
{
|
||||
recordNodeAsQualifier(((NameQualifiedType) node).getName());
|
||||
recordNodeAsQualifier(((NameQualifiedType) node).getQualifier());
|
||||
recordNodeAsQualifier(((NameQualifiedType)node).getName());
|
||||
recordNodeAsQualifier(((NameQualifiedType)node).getQualifier());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void recordNodeAsQualifier(Name node)
|
||||
{
|
||||
if (node != null)
|
||||
@@ -276,47 +276,47 @@ public class QualifierVisitor
|
||||
Range range = getRange(node);
|
||||
if (node instanceof QualifiedName)
|
||||
{
|
||||
range = getRange(((QualifiedName) node).getName());
|
||||
range = getRange(((QualifiedName)node).getName());
|
||||
}
|
||||
|
||||
|
||||
m_client.recordQualifierLocation(
|
||||
BindingNameResolver
|
||||
.getQualifiedName((ITypeBinding) binding, m_filePath, m_compilationUnit)
|
||||
.orElse(TypeName.unsolved())
|
||||
.toDeclName()
|
||||
.toNameHierarchy(),
|
||||
range);
|
||||
BindingNameResolver
|
||||
.getQualifiedName((ITypeBinding)binding, m_filePath, m_compilationUnit)
|
||||
.orElse(TypeName.unsolved())
|
||||
.toDeclName()
|
||||
.toNameHierarchy(),
|
||||
range);
|
||||
}
|
||||
else if (binding instanceof IPackageBinding)
|
||||
{
|
||||
Range range = getRange(node);
|
||||
if (node instanceof QualifiedName)
|
||||
{
|
||||
range = getRange(((QualifiedName) node).getName());
|
||||
range = getRange(((QualifiedName)node).getName());
|
||||
}
|
||||
|
||||
NameHierarchy symbolName = BindingNameResolver
|
||||
.getQualifiedName((IPackageBinding) binding, m_filePath, m_compilationUnit)
|
||||
|
||||
NameHierarchy symbolName =
|
||||
BindingNameResolver
|
||||
.getQualifiedName((IPackageBinding)binding, m_filePath, m_compilationUnit)
|
||||
.orElse(DeclName.unsolved())
|
||||
.toNameHierarchy();
|
||||
|
||||
|
||||
if (m_recordSymbolKinds)
|
||||
{
|
||||
m_client.recordSymbol(symbolName, SymbolKind.PACKAGE, AccessKind.NONE, DefinitionKind.NONE);
|
||||
m_client.recordSymbol(
|
||||
symbolName, SymbolKind.PACKAGE, AccessKind.NONE, DefinitionKind.NONE);
|
||||
}
|
||||
|
||||
m_client.recordQualifierLocation(
|
||||
symbolName,
|
||||
range);
|
||||
|
||||
m_client.recordQualifierLocation(symbolName, range);
|
||||
}
|
||||
|
||||
|
||||
if (node instanceof QualifiedName)
|
||||
{
|
||||
recordNodeAsQualifier(((QualifiedName) node).getQualifier());
|
||||
recordNodeAsQualifier(((QualifiedName)node).getQualifier());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Range getRange(ASTNode node)
|
||||
{
|
||||
return Utility.getRange(node, m_compilationUnit);
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
package com.sourcetrail;
|
||||
|
||||
public class Range
|
||||
public class Range
|
||||
{
|
||||
public Position begin = new Position();
|
||||
public Position end = new Position();
|
||||
|
||||
public Range()
|
||||
{
|
||||
}
|
||||
|
||||
public Range(int beginLine, int beginColumn, int endLine, int endColumn)
|
||||
|
||||
public Range() {}
|
||||
|
||||
public Range(int beginLine, int beginColumn, int endLine, int endColumn)
|
||||
{
|
||||
this.begin.line = beginLine;
|
||||
this.begin.column = beginColumn;
|
||||
this.end.line = endLine;
|
||||
this.end.column = endColumn;
|
||||
}
|
||||
|
||||
public Range(Position begin, Position end)
|
||||
|
||||
public Range(Position begin, Position end)
|
||||
{
|
||||
this.begin.line = begin.line;
|
||||
this.begin.column = begin.column;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.sourcetrail;
|
||||
|
||||
public enum ReferenceKind
|
||||
{ // these values need to be the same as ReferenceKind in C++ code
|
||||
public enum ReferenceKind { // these values need to be the same as ReferenceKind in C++ code
|
||||
UNDEFINED(0),
|
||||
TYPE_USAGE(1),
|
||||
USAGE(2),
|
||||
@@ -14,16 +13,16 @@ public enum ReferenceKind
|
||||
IMPORT(9),
|
||||
MACRO_USAGE(10),
|
||||
ANNOTATION_USAGE(11);
|
||||
|
||||
private final int m_value;
|
||||
|
||||
private ReferenceKind(int value)
|
||||
{
|
||||
this.m_value = value;
|
||||
}
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
private final int m_value;
|
||||
|
||||
private ReferenceKind(int value)
|
||||
{
|
||||
this.m_value = value;
|
||||
}
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.sourcetrail;
|
||||
|
||||
public enum SymbolKind
|
||||
{ // these values need to be the same as SymbolKind in C++ code
|
||||
public enum SymbolKind { // these values need to be the same as SymbolKind in C++ code
|
||||
ANNOTATION(1),
|
||||
BUILTIN_TYPE(2),
|
||||
CLASS(3),
|
||||
@@ -21,16 +20,16 @@ public enum SymbolKind
|
||||
TYPE_PARAMETER(17),
|
||||
UNION(18),
|
||||
TYPE_MAX(19);
|
||||
|
||||
private final int m_value;
|
||||
|
||||
private SymbolKind(int value)
|
||||
{
|
||||
this.m_value = value;
|
||||
}
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
private final int m_value;
|
||||
|
||||
private SymbolKind(int value)
|
||||
{
|
||||
this.m_value = value;
|
||||
}
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,31 @@
|
||||
package com.sourcetrail;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.eclipse.jdt.core.dom.ASTNode;
|
||||
import org.eclipse.jdt.core.dom.BodyDeclaration;
|
||||
import org.eclipse.jdt.core.dom.CompilationUnit;
|
||||
import org.eclipse.jdt.core.dom.Javadoc;
|
||||
|
||||
public class Utility
|
||||
public class Utility
|
||||
{
|
||||
public static Range getRange(ASTNode node, CompilationUnit compilationUnit)
|
||||
{
|
||||
int startPosition = node.getStartPosition() + 1;
|
||||
int endPosition = node.getStartPosition() + node.getLength() - 1;
|
||||
|
||||
if (node instanceof BodyDeclaration && ((BodyDeclaration) node).getJavadoc() != null)
|
||||
|
||||
if (node instanceof BodyDeclaration && ((BodyDeclaration)node).getJavadoc() != null)
|
||||
{
|
||||
Javadoc javadoc = ((BodyDeclaration) node).getJavadoc();
|
||||
Javadoc javadoc = ((BodyDeclaration)node).getJavadoc();
|
||||
startPosition = javadoc.getStartPosition() + javadoc.getLength() + 2;
|
||||
}
|
||||
|
||||
|
||||
return new Range(
|
||||
compilationUnit.getLineNumber(startPosition),
|
||||
compilationUnit.getColumnNumber(startPosition),
|
||||
compilationUnit.getLineNumber(endPosition),
|
||||
compilationUnit.getColumnNumber(endPosition) + 1);
|
||||
compilationUnit.getLineNumber(startPosition),
|
||||
compilationUnit.getColumnNumber(startPosition),
|
||||
compilationUnit.getLineNumber(endPosition),
|
||||
compilationUnit.getColumnNumber(endPosition) + 1);
|
||||
}
|
||||
|
||||
|
||||
public static String getFilenameWithoutExtension(Path filePath)
|
||||
{
|
||||
return filePath.getFileName().toString().replaceFirst("[.][^.]+$", "");
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package com.sourcetrail;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.jdt.core.dom.ASTNode;
|
||||
import org.eclipse.jdt.core.dom.CompilationUnit;
|
||||
|
||||
public class VerboseContextAwareAstVisitor extends ContextAwareAstVisitor
|
||||
public class VerboseContextAwareAstVisitor extends ContextAwareAstVisitor
|
||||
{
|
||||
private String indentation = "";
|
||||
|
||||
public VerboseContextAwareAstVisitor(AstVisitorClient client, File filePath, String fileContent, CompilationUnit compilationUnit)
|
||||
|
||||
public VerboseContextAwareAstVisitor(
|
||||
AstVisitorClient client, File filePath, String fileContent, CompilationUnit compilationUnit)
|
||||
{
|
||||
super(client, filePath, fileContent, compilationUnit);
|
||||
}
|
||||
@@ -17,10 +17,12 @@ public class VerboseContextAwareAstVisitor extends ContextAwareAstVisitor
|
||||
public void preVisit(ASTNode node)
|
||||
{
|
||||
Range range = getRange(node);
|
||||
m_client.logInfo(indentation + node.getClass().toString() + "[" + range.begin.line + ":" + range.begin.column + "|" + range.end.line + ":" + range.end.column + "]");
|
||||
m_client.logInfo(
|
||||
indentation + node.getClass().toString() + "[" + range.begin.line + ":" +
|
||||
range.begin.column + "|" + range.end.line + ":" + range.end.column + "]");
|
||||
indentation += "| ";
|
||||
}
|
||||
|
||||
|
||||
public void postVisit(ASTNode node)
|
||||
{
|
||||
indentation = indentation.substring(0, indentation.length() - 2);
|
||||
|
||||
@@ -9,20 +9,19 @@ import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.gradle.api.GradleException;
|
||||
import org.gradle.tooling.BuildLauncher;
|
||||
import org.gradle.tooling.GradleConnector;
|
||||
import org.gradle.tooling.ProjectConnection;
|
||||
|
||||
public class InfoRetriever
|
||||
public class InfoRetriever
|
||||
{
|
||||
public static String getMainSrcDirs(String projectRootPath, String initScriptPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
String ret = "";
|
||||
|
||||
|
||||
List<String> srcDirs = getSrcDirs("printMainSrcDirs", projectRootPath, initScriptPath);
|
||||
for (int i = 0; i < srcDirs.size(); i++)
|
||||
{
|
||||
@@ -32,7 +31,7 @@ public class InfoRetriever
|
||||
}
|
||||
ret += srcDirs.get(i);
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
catch (GradleException e)
|
||||
@@ -40,7 +39,7 @@ public class InfoRetriever
|
||||
return "[ERROR] " + e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String getTestSrcDirs(String projectRootPath, String initScriptPath)
|
||||
{
|
||||
try
|
||||
@@ -56,7 +55,7 @@ public class InfoRetriever
|
||||
}
|
||||
ret += srcDirs.get(i);
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
catch (GradleException e)
|
||||
@@ -64,50 +63,58 @@ public class InfoRetriever
|
||||
return "[ERROR] " + e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void copyCompileLibs(String projectRootPath, String initScriptPath, String targetPath)
|
||||
{
|
||||
executeTask("copyCompileLibs", projectRootPath, initScriptPath, Arrays.asList("-Psourcetrail_lib_path=" + targetPath));
|
||||
executeTask(
|
||||
"copyCompileLibs",
|
||||
projectRootPath,
|
||||
initScriptPath,
|
||||
Arrays.asList("-Psourcetrail_lib_path=" + targetPath));
|
||||
}
|
||||
|
||||
|
||||
public static void copyTestCompileLibs(String projectRootPath, String initScriptPath, String targetPath)
|
||||
{
|
||||
executeTask("copyTestCompileLibs", projectRootPath, initScriptPath, Arrays.asList("-Psourcetrail_lib_path=" + targetPath));
|
||||
executeTask(
|
||||
"copyTestCompileLibs",
|
||||
projectRootPath,
|
||||
initScriptPath,
|
||||
Arrays.asList("-Psourcetrail_lib_path=" + targetPath));
|
||||
}
|
||||
|
||||
|
||||
private static List<String> getSrcDirs(String taskName, String projectRootPath, String initScriptPath)
|
||||
{
|
||||
{
|
||||
String output = executeTask(taskName, projectRootPath, initScriptPath, null);
|
||||
|
||||
|
||||
List<String> paths = new ArrayList<>();
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new StringReader(output)))
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new StringReader(output)))
|
||||
{
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null)
|
||||
{
|
||||
paths.add(line);
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null)
|
||||
{
|
||||
paths.add(line);
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// TODO: LOGERROR
|
||||
}
|
||||
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
private static String executeTask(String taskName, String projectRootPath, String initScriptPath, List<String> additionalArguments) throws GradleException
|
||||
{
|
||||
ProjectConnection connection = GradleConnector
|
||||
.newConnector()
|
||||
.forProjectDirectory(new File(projectRootPath))
|
||||
.connect();
|
||||
|
||||
|
||||
private static String executeTask(
|
||||
String taskName, String projectRootPath, String initScriptPath, List<String> additionalArguments)
|
||||
throws GradleException
|
||||
{
|
||||
ProjectConnection connection =
|
||||
GradleConnector.newConnector().forProjectDirectory(new File(projectRootPath)).connect();
|
||||
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
|
||||
|
||||
try
|
||||
|
||||
try
|
||||
{
|
||||
List<String> arguments = new ArrayList<>();
|
||||
arguments.add("--init-script");
|
||||
@@ -118,28 +125,29 @@ public class InfoRetriever
|
||||
{
|
||||
arguments.addAll(additionalArguments);
|
||||
}
|
||||
|
||||
BuildLauncher Launcher = connection.newBuild().forTasks(taskName)
|
||||
.withArguments(arguments)
|
||||
.setStandardOutput(new PrintStream(outputStream))
|
||||
.setStandardError(new PrintStream(errorStream));
|
||||
|
||||
|
||||
BuildLauncher Launcher = connection.newBuild()
|
||||
.forTasks(taskName)
|
||||
.withArguments(arguments)
|
||||
.setStandardOutput(new PrintStream(outputStream))
|
||||
.setStandardError(new PrintStream(errorStream));
|
||||
|
||||
Launcher.run();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// TODO: LOGERROR
|
||||
}
|
||||
finally
|
||||
finally
|
||||
{
|
||||
connection.close();
|
||||
}
|
||||
|
||||
|
||||
if (!errorStream.toString().isEmpty())
|
||||
{
|
||||
throw new GradleException(errorStream.toString());
|
||||
}
|
||||
|
||||
|
||||
return outputStream.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package com.sourcetrail.name;
|
||||
|
||||
import com.sourcetrail.Position;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import com.sourcetrail.Position;
|
||||
|
||||
public class DeclName implements SymbolName
|
||||
{
|
||||
private DeclName m_parent = null;
|
||||
@@ -21,34 +20,36 @@ public class DeclName implements SymbolName
|
||||
declName.m_isUnsolved = true;
|
||||
return declName;
|
||||
}
|
||||
|
||||
|
||||
public static DeclName anonymousClass(File filePath, int line, int col)
|
||||
{
|
||||
DeclName declName = new DeclName("anonymous class (" + filePath.getName() + "<" + line + ":" + col + ">)");
|
||||
DeclName declName = new DeclName(
|
||||
"anonymous class (" + filePath.getName() + "<" + line + ":" + col + ">)");
|
||||
declName.m_isAnonymous = true;
|
||||
return declName;
|
||||
}
|
||||
|
||||
|
||||
public static DeclName localSymbol(DeclName methodContextName, int id)
|
||||
{
|
||||
DeclName declName = new DeclName(methodContextName + "<" + id + ">");
|
||||
declName.m_isLocal = true;
|
||||
return declName;
|
||||
}
|
||||
|
||||
|
||||
public static DeclName globalSymbol(File fileContext, int id)
|
||||
{
|
||||
DeclName declName = new DeclName(fileContext.getName() + "<" + id + ">");
|
||||
declName.m_isGlobal = true;
|
||||
return declName;
|
||||
}
|
||||
|
||||
|
||||
public static DeclName scope(File fileContext, Position begin)
|
||||
{
|
||||
DeclName declName = new DeclName(fileContext.getName() + "<" + begin.line + ":" + begin.column + ">");
|
||||
DeclName declName = new DeclName(
|
||||
fileContext.getName() + "<" + begin.line + ":" + begin.column + ">");
|
||||
return declName;
|
||||
}
|
||||
|
||||
|
||||
public static DeclName fromDotSeparatedString(String s)
|
||||
{
|
||||
DeclName declName = null;
|
||||
@@ -63,60 +64,60 @@ public class DeclName implements SymbolName
|
||||
{
|
||||
declName = new DeclName(s, null);
|
||||
}
|
||||
|
||||
|
||||
return declName;
|
||||
}
|
||||
|
||||
|
||||
public DeclName(String name)
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
|
||||
public DeclName(String name, List<String> typeParameterNames)
|
||||
{
|
||||
m_name = name;
|
||||
m_typeParameterNames = typeParameterNames;
|
||||
}
|
||||
|
||||
|
||||
public void setParent(DeclName parent)
|
||||
{
|
||||
m_parent = parent;
|
||||
}
|
||||
|
||||
|
||||
public DeclName getParent()
|
||||
{
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
|
||||
public boolean getIsUnsolved()
|
||||
{
|
||||
return m_isUnsolved;
|
||||
}
|
||||
|
||||
|
||||
public boolean getIsAnonymous()
|
||||
{
|
||||
return m_isAnonymous;
|
||||
}
|
||||
|
||||
|
||||
public boolean getIsLocal()
|
||||
{
|
||||
return m_isLocal;
|
||||
}
|
||||
|
||||
|
||||
public boolean getIsGlobal()
|
||||
{
|
||||
return m_isGlobal;
|
||||
}
|
||||
|
||||
|
||||
public NameHierarchy toNameHierarchy()
|
||||
{
|
||||
NameHierarchy nameHierarchy;
|
||||
|
||||
|
||||
if (m_parent != null)
|
||||
{
|
||||
nameHierarchy = m_parent.toNameHierarchy();
|
||||
@@ -125,12 +126,12 @@ public class DeclName implements SymbolName
|
||||
{
|
||||
nameHierarchy = new NameHierarchy();
|
||||
}
|
||||
|
||||
|
||||
nameHierarchy.push(new NameElement(m_name + getTypeParameterString()));
|
||||
|
||||
|
||||
return nameHierarchy;
|
||||
}
|
||||
|
||||
|
||||
public String toString()
|
||||
{
|
||||
String string = "";
|
||||
@@ -139,13 +140,13 @@ public class DeclName implements SymbolName
|
||||
string = m_parent.toString();
|
||||
string += ".";
|
||||
}
|
||||
|
||||
|
||||
string += m_name;
|
||||
string += getTypeParameterString();
|
||||
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
public String getTypeParameterString()
|
||||
{
|
||||
String string = "";
|
||||
@@ -165,7 +166,8 @@ public class DeclName implements SymbolName
|
||||
return string;
|
||||
}
|
||||
|
||||
public List<String> getTypeParameterNames() {
|
||||
public List<String> getTypeParameterNames()
|
||||
{
|
||||
return m_typeParameterNames;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,7 @@ public class FileName implements SymbolName
|
||||
m_filePath = filePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NameHierarchy toNameHierarchy()
|
||||
@Override public NameHierarchy toNameHierarchy()
|
||||
{
|
||||
NameHierarchy nameHierarchy;
|
||||
if (m_filePath != null)
|
||||
|
||||
@@ -9,27 +9,34 @@ public class FunctionDeclName extends DeclName
|
||||
private TypeName m_returnTypeName = null;
|
||||
private List<TypeName> m_parameterTypeNames = new ArrayList<>();
|
||||
private boolean m_isStatic = false;
|
||||
|
||||
public FunctionDeclName(String name, TypeName returnTypeName, List<TypeName> parameterTypeNames, boolean isStatic)
|
||||
|
||||
public FunctionDeclName(
|
||||
String name, TypeName returnTypeName, List<TypeName> parameterTypeNames, boolean isStatic)
|
||||
{
|
||||
super(name);
|
||||
|
||||
|
||||
m_returnTypeName = returnTypeName;
|
||||
if (parameterTypeNames != null) m_parameterTypeNames = parameterTypeNames;
|
||||
if (parameterTypeNames != null)
|
||||
m_parameterTypeNames = parameterTypeNames;
|
||||
m_isStatic = isStatic;
|
||||
}
|
||||
|
||||
public FunctionDeclName(String name, List<String> typeParameterNames, TypeName returnTypeName, List<TypeName> parameterTypeNames, boolean isStatic)
|
||||
|
||||
public FunctionDeclName(
|
||||
String name,
|
||||
List<String> typeParameterNames,
|
||||
TypeName returnTypeName,
|
||||
List<TypeName> parameterTypeNames,
|
||||
boolean isStatic)
|
||||
{
|
||||
super(name, typeParameterNames);
|
||||
|
||||
|
||||
m_returnTypeName = returnTypeName;
|
||||
if (parameterTypeNames != null) m_parameterTypeNames = parameterTypeNames;
|
||||
if (parameterTypeNames != null)
|
||||
m_parameterTypeNames = parameterTypeNames;
|
||||
m_isStatic = isStatic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NameHierarchy toNameHierarchy()
|
||||
|
||||
@Override public NameHierarchy toNameHierarchy()
|
||||
{
|
||||
String prefix = "";
|
||||
if (m_isStatic)
|
||||
@@ -40,23 +47,23 @@ public class FunctionDeclName extends DeclName
|
||||
{
|
||||
prefix += m_returnTypeName.toString();
|
||||
}
|
||||
|
||||
|
||||
String postfix = getParameterString();
|
||||
|
||||
|
||||
NameHierarchy nameHierarchy = super.toNameHierarchy();
|
||||
|
||||
|
||||
Optional<NameElement> nameElement = nameHierarchy.peek();
|
||||
if (nameElement.isPresent())
|
||||
{
|
||||
String name = nameElement.get().getName();
|
||||
|
||||
|
||||
nameHierarchy.pop();
|
||||
nameHierarchy.push(new NameElement(name, prefix, postfix));
|
||||
}
|
||||
|
||||
|
||||
return nameHierarchy;
|
||||
}
|
||||
|
||||
|
||||
private String getParameterString()
|
||||
{
|
||||
String string = "(";
|
||||
|
||||
@@ -1,33 +1,37 @@
|
||||
package com.sourcetrail.name;
|
||||
|
||||
public class NameElement
|
||||
public class NameElement
|
||||
{
|
||||
private String m_name = "";
|
||||
private String m_prefix = "";
|
||||
private String m_postfix = "";
|
||||
|
||||
|
||||
|
||||
|
||||
public NameElement(String name)
|
||||
{
|
||||
if (name != null) m_name = name;
|
||||
if (name != null)
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
|
||||
public NameElement(String name, String prefix, String postfix)
|
||||
{
|
||||
if (name != null) m_name = name;
|
||||
if (prefix != null) m_prefix = prefix;
|
||||
if (postfix != null) m_postfix = postfix;
|
||||
if (name != null)
|
||||
m_name = name;
|
||||
if (prefix != null)
|
||||
m_prefix = prefix;
|
||||
if (postfix != null)
|
||||
m_postfix = postfix;
|
||||
}
|
||||
|
||||
|
||||
String getName()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
|
||||
String getNameWithSignature()
|
||||
{
|
||||
String nameWithSignature = m_name;
|
||||
|
||||
|
||||
if (m_prefix.length() > 0 || m_postfix.length() > 0)
|
||||
{
|
||||
nameWithSignature = m_prefix;
|
||||
@@ -41,10 +45,10 @@ public class NameElement
|
||||
}
|
||||
nameWithSignature += m_postfix;
|
||||
}
|
||||
|
||||
|
||||
return nameWithSignature;
|
||||
}
|
||||
|
||||
|
||||
String serialize()
|
||||
{
|
||||
return m_name + "\ts" + m_prefix + "\tp" + m_postfix;
|
||||
|
||||
@@ -4,40 +4,38 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class NameHierarchy
|
||||
public class NameHierarchy
|
||||
{
|
||||
private List<NameElement> m_elements = new ArrayList<>();
|
||||
private char m_separatpr = '.';
|
||||
|
||||
public NameHierarchy()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public NameHierarchy() {}
|
||||
|
||||
public NameHierarchy(String name)
|
||||
{
|
||||
m_elements.add(new NameElement(name));
|
||||
}
|
||||
|
||||
|
||||
public NameHierarchy(NameElement name)
|
||||
{
|
||||
m_elements.add(name);
|
||||
}
|
||||
|
||||
|
||||
public NameHierarchy(List<NameElement> names)
|
||||
{
|
||||
m_elements.addAll(names);
|
||||
}
|
||||
|
||||
|
||||
public void setSeparator(char separator)
|
||||
{
|
||||
m_separatpr = separator;
|
||||
}
|
||||
|
||||
|
||||
public void push(NameElement element)
|
||||
{
|
||||
m_elements.add(element);
|
||||
}
|
||||
|
||||
|
||||
public void pop()
|
||||
{
|
||||
if (!m_elements.isEmpty())
|
||||
@@ -45,7 +43,7 @@ public class NameHierarchy
|
||||
m_elements.remove(m_elements.size() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Optional<NameElement> peek()
|
||||
{
|
||||
if (!m_elements.isEmpty())
|
||||
@@ -54,22 +52,21 @@ public class NameHierarchy
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
public String serialize()
|
||||
{
|
||||
String serialized = m_separatpr + "\tm";
|
||||
|
||||
|
||||
for (int i = 0; i < m_elements.size(); i++)
|
||||
{
|
||||
if (i != 0)
|
||||
{
|
||||
serialized += "\tn";
|
||||
}
|
||||
|
||||
|
||||
serialized += m_elements.get(i).serialize();
|
||||
}
|
||||
|
||||
return serialized;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.sourcetrail.name;
|
||||
|
||||
public interface SymbolName
|
||||
{
|
||||
public interface SymbolName {
|
||||
public NameHierarchy toNameHierarchy();
|
||||
}
|
||||
|
||||
@@ -16,64 +16,67 @@ public class TypeName implements SymbolName
|
||||
typeName.m_isUnsolved = true;
|
||||
return typeName;
|
||||
}
|
||||
|
||||
public static TypeName fromDotSeparatedString(String s)
|
||||
|
||||
public static TypeName fromDotSeparatedString(String s)
|
||||
{
|
||||
TypeName typeName = null;
|
||||
|
||||
int separatorIndex = s.lastIndexOf('.');
|
||||
if (separatorIndex != -1)
|
||||
{
|
||||
typeName = new TypeName(s.substring(separatorIndex + 1), DeclName.fromDotSeparatedString(s.substring(0, separatorIndex)));
|
||||
typeName = new TypeName(
|
||||
s.substring(separatorIndex + 1),
|
||||
DeclName.fromDotSeparatedString(s.substring(0, separatorIndex)));
|
||||
}
|
||||
else
|
||||
{
|
||||
typeName = new TypeName(s, null);
|
||||
}
|
||||
|
||||
|
||||
return typeName;
|
||||
}
|
||||
|
||||
|
||||
public TypeName(String name, DeclName parent)
|
||||
{
|
||||
m_parent = parent;
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
public TypeName(String name, List<String> typeParameterNames, List<TypeName> typeArguments, DeclName parent)
|
||||
|
||||
public TypeName(
|
||||
String name, List<String> typeParameterNames, List<TypeName> typeArguments, DeclName parent)
|
||||
{
|
||||
m_parent = parent;
|
||||
m_name = name;
|
||||
m_typeParameterNames = typeParameterNames;
|
||||
m_typeArguments = typeArguments;
|
||||
}
|
||||
|
||||
|
||||
public DeclName getParent()
|
||||
{
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
|
||||
public boolean getIsUnsolved()
|
||||
{
|
||||
return m_isUnsolved;
|
||||
}
|
||||
|
||||
|
||||
public DeclName toDeclName()
|
||||
{
|
||||
DeclName declName = new DeclName(m_name, m_typeParameterNames);
|
||||
declName.setParent(m_parent);
|
||||
return declName;
|
||||
}
|
||||
|
||||
|
||||
public NameHierarchy toNameHierarchy()
|
||||
{
|
||||
NameHierarchy nameHierarchy;
|
||||
|
||||
|
||||
if (m_parent != null)
|
||||
{
|
||||
nameHierarchy = m_parent.toNameHierarchy();
|
||||
@@ -82,12 +85,12 @@ public class TypeName implements SymbolName
|
||||
{
|
||||
nameHierarchy = new NameHierarchy();
|
||||
}
|
||||
|
||||
|
||||
nameHierarchy.push(new NameElement(m_name + getTypeArgumentString()));
|
||||
|
||||
|
||||
return nameHierarchy;
|
||||
}
|
||||
|
||||
|
||||
public String toString()
|
||||
{
|
||||
String string = "";
|
||||
@@ -96,13 +99,13 @@ public class TypeName implements SymbolName
|
||||
string = m_parent.toString();
|
||||
string += ".";
|
||||
}
|
||||
|
||||
|
||||
string += m_name;
|
||||
string += getTypeArgumentString();
|
||||
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
private String getTypeArgumentString()
|
||||
{
|
||||
String string = "";
|
||||
|
||||
@@ -6,17 +6,16 @@ public class VariableDeclName extends DeclName
|
||||
{
|
||||
private TypeName m_typeName = null;
|
||||
private boolean m_isStatic = false;
|
||||
|
||||
|
||||
public VariableDeclName(String name, TypeName typeName, boolean isStatic)
|
||||
{
|
||||
super(name);
|
||||
|
||||
|
||||
m_typeName = typeName;
|
||||
m_isStatic = isStatic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NameHierarchy toNameHierarchy()
|
||||
|
||||
@Override public NameHierarchy toNameHierarchy()
|
||||
{
|
||||
String prefix = "";
|
||||
if (m_isStatic)
|
||||
@@ -27,13 +26,13 @@ public class VariableDeclName extends DeclName
|
||||
{
|
||||
prefix += m_typeName.toString();
|
||||
}
|
||||
|
||||
|
||||
NameHierarchy nameHierarchy = super.toNameHierarchy();
|
||||
Optional<NameElement> nameElement = nameHierarchy.peek();
|
||||
if (nameElement.isPresent())
|
||||
{
|
||||
String name = nameElement.get().getName();
|
||||
|
||||
|
||||
nameHierarchy.pop();
|
||||
nameHierarchy.push(new NameElement(name, prefix, ""));
|
||||
}
|
||||
|
||||
+122
-77
@@ -1,10 +1,14 @@
|
||||
package com.sourcetrail.name.resolver;
|
||||
|
||||
import com.sourcetrail.ContextList;
|
||||
import com.sourcetrail.name.DeclName;
|
||||
import com.sourcetrail.name.FunctionDeclName;
|
||||
import com.sourcetrail.name.TypeName;
|
||||
import com.sourcetrail.name.VariableDeclName;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.core.dom.ASTNode;
|
||||
import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
|
||||
import org.eclipse.jdt.core.dom.CompilationUnit;
|
||||
@@ -15,38 +19,32 @@ import org.eclipse.jdt.core.dom.ITypeBinding;
|
||||
import org.eclipse.jdt.core.dom.IVariableBinding;
|
||||
import org.eclipse.jdt.core.dom.Modifier;
|
||||
|
||||
import com.sourcetrail.ContextList;
|
||||
import com.sourcetrail.name.DeclName;
|
||||
import com.sourcetrail.name.FunctionDeclName;
|
||||
import com.sourcetrail.name.TypeName;
|
||||
import com.sourcetrail.name.VariableDeclName;
|
||||
|
||||
public class BindingNameResolver extends NameResolver
|
||||
{
|
||||
public static IBinding getParentBinding(IBinding binding)
|
||||
{
|
||||
if (binding instanceof ITypeBinding)
|
||||
{
|
||||
return getParentBinding((ITypeBinding) binding);
|
||||
return getParentBinding((ITypeBinding)binding);
|
||||
}
|
||||
if (binding instanceof IMethodBinding)
|
||||
{
|
||||
return ((IMethodBinding) binding).getDeclaringClass();
|
||||
return ((IMethodBinding)binding).getDeclaringClass();
|
||||
}
|
||||
if (binding instanceof IVariableBinding)
|
||||
{
|
||||
return ((IVariableBinding) binding).getDeclaringClass();
|
||||
return ((IVariableBinding)binding).getDeclaringClass();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static IBinding getParentBinding(ITypeBinding binding)
|
||||
{
|
||||
if (binding.isLocal() || binding.isAnonymous())
|
||||
{
|
||||
if (binding.getDeclaringMember() instanceof IVariableBinding)
|
||||
{
|
||||
IVariableBinding variableBinding = (IVariableBinding) binding.getDeclaringMember();
|
||||
IVariableBinding variableBinding = (IVariableBinding)binding.getDeclaringMember();
|
||||
if (variableBinding.getDeclaringClass() != null)
|
||||
{
|
||||
return variableBinding.getDeclaringClass();
|
||||
@@ -60,7 +58,7 @@ public class BindingNameResolver extends NameResolver
|
||||
{
|
||||
return binding.getDeclaringMethod();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (binding.isMember())
|
||||
{
|
||||
return binding.getDeclaringClass();
|
||||
@@ -80,33 +78,40 @@ public class BindingNameResolver extends NameResolver
|
||||
{
|
||||
return binding.getPackage();
|
||||
}
|
||||
|
||||
return null; // we don't have a parent (like void doesn't have a parent)
|
||||
|
||||
return null; // we don't have a parent (like void doesn't have a parent)
|
||||
}
|
||||
|
||||
public BindingNameResolver(File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts)
|
||||
|
||||
public BindingNameResolver(
|
||||
File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts)
|
||||
{
|
||||
super(currentFile, compilationUnit, ignoredContexts);
|
||||
}
|
||||
|
||||
public static Optional<TypeName> getQualifiedName(ITypeBinding binding, File currentFile, CompilationUnit compilationUnit)
|
||||
|
||||
public static Optional<TypeName> getQualifiedName(
|
||||
ITypeBinding binding, File currentFile, CompilationUnit compilationUnit)
|
||||
{
|
||||
return getQualifiedName(binding, currentFile, compilationUnit, null);
|
||||
}
|
||||
|
||||
public static Optional<TypeName> getQualifiedName(ITypeBinding binding, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts)
|
||||
|
||||
public static Optional<TypeName> getQualifiedName(
|
||||
ITypeBinding binding,
|
||||
File currentFile,
|
||||
CompilationUnit compilationUnit,
|
||||
ContextList ignoredContexts)
|
||||
{
|
||||
BindingNameResolver resolver = new BindingNameResolver(currentFile, compilationUnit, ignoredContexts);
|
||||
BindingNameResolver resolver = new BindingNameResolver(
|
||||
currentFile, compilationUnit, ignoredContexts);
|
||||
return resolver.getQualifiedName(binding);
|
||||
}
|
||||
|
||||
|
||||
public Optional<TypeName> getQualifiedName(ITypeBinding binding)
|
||||
{
|
||||
if (binding == null)
|
||||
{
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
if (binding.isArray())
|
||||
{
|
||||
return getQualifiedName(binding.getElementType());
|
||||
@@ -116,15 +121,20 @@ public class BindingNameResolver extends NameResolver
|
||||
ASTNode node = m_compilationUnit.findDeclaringNode(binding);
|
||||
if (node instanceof AnonymousClassDeclaration)
|
||||
{
|
||||
DeclName decl = DeclNameResolver.getQualifiedDeclName((AnonymousClassDeclaration) node, m_currentFile, m_compilationUnit, m_ignoredContexts);
|
||||
return Optional.of(new TypeName(decl.getName(), decl.getTypeParameterNames(), null, decl.getParent()));
|
||||
DeclName decl = DeclNameResolver.getQualifiedDeclName(
|
||||
(AnonymousClassDeclaration)node,
|
||||
m_currentFile,
|
||||
m_compilationUnit,
|
||||
m_ignoredContexts);
|
||||
return Optional.of(new TypeName(
|
||||
decl.getName(), decl.getTypeParameterNames(), null, decl.getParent()));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (binding.isParameterizedType())
|
||||
{
|
||||
List<TypeName> typeArguments = new ArrayList<>();
|
||||
@@ -136,19 +146,23 @@ public class BindingNameResolver extends NameResolver
|
||||
typeArguments.add(typeArgument.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Optional<TypeName> typeName = getQualifiedName(binding.getTypeDeclaration());
|
||||
if (typeName.isPresent())
|
||||
{
|
||||
DeclName declName = typeName.get().toDeclName();
|
||||
return Optional.of(new TypeName(declName.getName(), declName.getTypeParameterNames(), typeArguments, declName.getParent()));
|
||||
return Optional.of(new TypeName(
|
||||
declName.getName(),
|
||||
declName.getTypeParameterNames(),
|
||||
typeArguments,
|
||||
declName.getParent()));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String name = binding.getName();
|
||||
List<String> typeParameterNames = null;
|
||||
if (binding.isGenericType())
|
||||
@@ -158,38 +172,44 @@ public class BindingNameResolver extends NameResolver
|
||||
{
|
||||
typeParameterNames.add(typeParameter.getName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DeclName parentDeclName = getQualifiedContextName(binding);
|
||||
if (parentDeclName != null && parentDeclName.getIsUnsolved())
|
||||
{
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
// type arguments will be set in caller (which is this same method)
|
||||
return Optional.of(new TypeName(name, typeParameterNames, null, parentDeclName));
|
||||
}
|
||||
|
||||
public static Optional<DeclName> getQualifiedName(IMethodBinding binding, File currentFile, CompilationUnit compilationUnit)
|
||||
|
||||
public static Optional<DeclName> getQualifiedName(
|
||||
IMethodBinding binding, File currentFile, CompilationUnit compilationUnit)
|
||||
{
|
||||
return getQualifiedName(binding, currentFile, compilationUnit, null);
|
||||
}
|
||||
|
||||
public static Optional<DeclName> getQualifiedName(IMethodBinding binding, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts)
|
||||
|
||||
public static Optional<DeclName> getQualifiedName(
|
||||
IMethodBinding binding,
|
||||
File currentFile,
|
||||
CompilationUnit compilationUnit,
|
||||
ContextList ignoredContexts)
|
||||
{
|
||||
BindingNameResolver resolver = new BindingNameResolver(currentFile, compilationUnit, ignoredContexts);
|
||||
BindingNameResolver resolver = new BindingNameResolver(
|
||||
currentFile, compilationUnit, ignoredContexts);
|
||||
return resolver.getQualifiedName(binding);
|
||||
}
|
||||
|
||||
|
||||
public Optional<DeclName> getQualifiedName(IMethodBinding binding)
|
||||
{
|
||||
if (binding == null)
|
||||
{
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
String name = binding.getName();
|
||||
|
||||
|
||||
List<String> typeParameterNames = null;
|
||||
if (binding.isGenericMethod())
|
||||
{
|
||||
@@ -199,32 +219,40 @@ public class BindingNameResolver extends NameResolver
|
||||
typeParameterNames.add(typeParameter.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DeclName declName = null;
|
||||
{
|
||||
boolean isStatic = Modifier.isStatic(binding.getModifiers());
|
||||
|
||||
ContextList ignoredContexts = m_ignoredContexts.copy();
|
||||
ignoredContexts.add(binding);
|
||||
|
||||
TypeName returnTypeName = binding.isConstructor() ? null : getQualifiedName(binding.getReturnType(), m_currentFile, m_compilationUnit, ignoredContexts).orElse(TypeName.unsolved());
|
||||
|
||||
|
||||
TypeName returnTypeName = binding.isConstructor()
|
||||
? null
|
||||
: getQualifiedName(
|
||||
binding.getReturnType(), m_currentFile, m_compilationUnit, ignoredContexts)
|
||||
.orElse(TypeName.unsolved());
|
||||
|
||||
if (binding.isAnnotationMember())
|
||||
{
|
||||
declName = new VariableDeclName(name, returnTypeName, isStatic);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<TypeName> parameterTypeNames = new ArrayList<>();
|
||||
List<TypeName> parameterTypeNames = new ArrayList<>();
|
||||
for (ITypeBinding parameterType: binding.getParameterTypes())
|
||||
{
|
||||
parameterTypeNames.add(getQualifiedName(parameterType, m_currentFile, m_compilationUnit, ignoredContexts).orElse(TypeName.unsolved()));
|
||||
parameterTypeNames.add(
|
||||
getQualifiedName(
|
||||
parameterType, m_currentFile, m_compilationUnit, ignoredContexts)
|
||||
.orElse(TypeName.unsolved()));
|
||||
}
|
||||
|
||||
declName = new FunctionDeclName(name, typeParameterNames, returnTypeName, parameterTypeNames, isStatic);
|
||||
|
||||
declName = new FunctionDeclName(
|
||||
name, typeParameterNames, returnTypeName, parameterTypeNames, isStatic);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DeclName parentDeclName = getQualifiedContextName(binding);
|
||||
if (parentDeclName != null)
|
||||
{
|
||||
@@ -238,47 +266,59 @@ public class BindingNameResolver extends NameResolver
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.of(declName);
|
||||
return Optional.of(declName);
|
||||
}
|
||||
|
||||
public static Optional<DeclName> getQualifiedName(IPackageBinding binding, File currentFile, CompilationUnit compilationUnit)
|
||||
|
||||
public static Optional<DeclName> getQualifiedName(
|
||||
IPackageBinding binding, File currentFile, CompilationUnit compilationUnit)
|
||||
{
|
||||
return getQualifiedName(binding, currentFile, compilationUnit, null);
|
||||
}
|
||||
|
||||
public static Optional<DeclName> getQualifiedName(IPackageBinding binding, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts)
|
||||
|
||||
public static Optional<DeclName> getQualifiedName(
|
||||
IPackageBinding binding,
|
||||
File currentFile,
|
||||
CompilationUnit compilationUnit,
|
||||
ContextList ignoredContexts)
|
||||
{
|
||||
BindingNameResolver resolver = new BindingNameResolver(currentFile, compilationUnit, ignoredContexts);
|
||||
BindingNameResolver resolver = new BindingNameResolver(
|
||||
currentFile, compilationUnit, ignoredContexts);
|
||||
return resolver.getQualifiedName(binding);
|
||||
}
|
||||
|
||||
|
||||
public Optional<DeclName> getQualifiedName(IPackageBinding binding)
|
||||
{
|
||||
if (!binding.isUnnamed())
|
||||
{
|
||||
return Optional.of(DeclName.fromDotSeparatedString(binding.getName()));
|
||||
}
|
||||
return Optional.empty();
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public static DeclName getQualifiedName(IVariableBinding binding, File currentFile, CompilationUnit compilationUnit)
|
||||
|
||||
public static DeclName getQualifiedName(
|
||||
IVariableBinding binding, File currentFile, CompilationUnit compilationUnit)
|
||||
{
|
||||
return getQualifiedName(binding, currentFile, compilationUnit, null);
|
||||
}
|
||||
|
||||
public static DeclName getQualifiedName(IVariableBinding binding, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts)
|
||||
|
||||
public static DeclName getQualifiedName(
|
||||
IVariableBinding binding,
|
||||
File currentFile,
|
||||
CompilationUnit compilationUnit,
|
||||
ContextList ignoredContexts)
|
||||
{
|
||||
BindingNameResolver resolver = new BindingNameResolver(currentFile, compilationUnit, ignoredContexts);
|
||||
BindingNameResolver resolver = new BindingNameResolver(
|
||||
currentFile, compilationUnit, ignoredContexts);
|
||||
return resolver.getQualifiedName(binding);
|
||||
}
|
||||
|
||||
|
||||
public DeclName getQualifiedName(IVariableBinding binding)
|
||||
{
|
||||
if (binding == null)
|
||||
{
|
||||
return DeclName.unsolved();
|
||||
}
|
||||
|
||||
|
||||
if (binding.isField() || binding.isEnumConstant())
|
||||
{
|
||||
DeclName declName;
|
||||
@@ -289,9 +329,10 @@ public class BindingNameResolver extends NameResolver
|
||||
else
|
||||
{
|
||||
TypeName typeName = getQualifiedName(binding.getType()).orElse(TypeName.unsolved());
|
||||
declName = new VariableDeclName(binding.getName(), typeName, Modifier.isStatic(binding.getModifiers()));
|
||||
declName = new VariableDeclName(
|
||||
binding.getName(), typeName, Modifier.isStatic(binding.getModifiers()));
|
||||
}
|
||||
|
||||
|
||||
DeclName parentDeclName = getQualifiedContextName(binding);
|
||||
if (parentDeclName != null)
|
||||
{
|
||||
@@ -304,14 +345,16 @@ public class BindingNameResolver extends NameResolver
|
||||
declName = DeclName.unsolved();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return declName;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (binding.getDeclaringMethod() != null)
|
||||
{
|
||||
return DeclName.localSymbol(getQualifiedName(binding.getDeclaringMethod()).orElse(DeclName.unsolved()), binding.getVariableId());
|
||||
return DeclName.localSymbol(
|
||||
getQualifiedName(binding.getDeclaringMethod()).orElse(DeclName.unsolved()),
|
||||
binding.getVariableId());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -319,33 +362,35 @@ public class BindingNameResolver extends NameResolver
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private DeclName getQualifiedContextName(IBinding binding)
|
||||
{
|
||||
IBinding parentBinding = getParentBinding(binding);
|
||||
|
||||
|
||||
if (parentBinding == null || m_ignoredContexts.contains(parentBinding))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if (parentBinding instanceof ITypeBinding)
|
||||
{
|
||||
return getQualifiedName((ITypeBinding) parentBinding).map(tn ->tn.toDeclName()).orElse(DeclName.unsolved());
|
||||
return getQualifiedName((ITypeBinding)parentBinding)
|
||||
.map(tn -> tn.toDeclName())
|
||||
.orElse(DeclName.unsolved());
|
||||
}
|
||||
else if (parentBinding instanceof IMethodBinding)
|
||||
{
|
||||
return getQualifiedName((IMethodBinding) parentBinding).orElse(DeclName.unsolved());
|
||||
return getQualifiedName((IMethodBinding)parentBinding).orElse(DeclName.unsolved());
|
||||
}
|
||||
else if (parentBinding instanceof IVariableBinding)
|
||||
{
|
||||
return getQualifiedName((IVariableBinding) parentBinding);
|
||||
return getQualifiedName((IVariableBinding)parentBinding);
|
||||
}
|
||||
else if (parentBinding instanceof IPackageBinding)
|
||||
{
|
||||
return getQualifiedName((IPackageBinding) parentBinding).orElse(null);
|
||||
return getQualifiedName((IPackageBinding)parentBinding).orElse(null);
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
package com.sourcetrail.name.resolver;
|
||||
|
||||
import com.sourcetrail.ContextList;
|
||||
import com.sourcetrail.Position;
|
||||
import com.sourcetrail.Utility;
|
||||
import com.sourcetrail.name.DeclName;
|
||||
import com.sourcetrail.name.FunctionDeclName;
|
||||
import com.sourcetrail.name.TypeName;
|
||||
import com.sourcetrail.name.VariableDeclName;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.core.dom.ASTNode;
|
||||
import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
|
||||
import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration;
|
||||
@@ -27,32 +33,30 @@ import org.eclipse.jdt.core.dom.TypeDeclaration;
|
||||
import org.eclipse.jdt.core.dom.TypeParameter;
|
||||
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
|
||||
|
||||
import com.sourcetrail.ContextList;
|
||||
import com.sourcetrail.Position;
|
||||
import com.sourcetrail.Utility;
|
||||
import com.sourcetrail.name.DeclName;
|
||||
import com.sourcetrail.name.FunctionDeclName;
|
||||
import com.sourcetrail.name.TypeName;
|
||||
import com.sourcetrail.name.VariableDeclName;
|
||||
|
||||
public class DeclNameResolver extends NameResolver
|
||||
{
|
||||
public DeclNameResolver(File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts)
|
||||
{
|
||||
public DeclNameResolver(File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts)
|
||||
{
|
||||
super(currentFile, compilationUnit, ignoredContexts);
|
||||
}
|
||||
|
||||
public static DeclName getQualifiedDeclName(VariableDeclarationFragment decl, File currentFile, CompilationUnit compilationUnit)
|
||||
public static DeclName getQualifiedDeclName(
|
||||
VariableDeclarationFragment decl, File currentFile, CompilationUnit compilationUnit)
|
||||
{
|
||||
return getQualifiedDeclName(decl, currentFile, compilationUnit, null);
|
||||
}
|
||||
|
||||
public static DeclName getQualifiedDeclName(VariableDeclarationFragment decl, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts)
|
||||
|
||||
public static DeclName getQualifiedDeclName(
|
||||
VariableDeclarationFragment decl,
|
||||
File currentFile,
|
||||
CompilationUnit compilationUnit,
|
||||
ContextList ignoredContexts)
|
||||
{
|
||||
DeclNameResolver resolver = new DeclNameResolver(currentFile, compilationUnit, ignoredContexts);
|
||||
DeclNameResolver resolver = new DeclNameResolver(
|
||||
currentFile, compilationUnit, ignoredContexts);
|
||||
return resolver.getQualifiedDeclName(decl);
|
||||
}
|
||||
|
||||
|
||||
public DeclName getQualifiedDeclName(VariableDeclarationFragment decl)
|
||||
{
|
||||
DeclName declName = DeclName.unsolved();
|
||||
@@ -78,11 +82,11 @@ public class DeclNameResolver extends NameResolver
|
||||
}
|
||||
return declName;
|
||||
}
|
||||
|
||||
|
||||
public DeclName getDeclName(VariableDeclarationFragment decl)
|
||||
{
|
||||
TypeName typeName = TypeName.unsolved();
|
||||
|
||||
|
||||
boolean isStatic = false;
|
||||
Optional<FieldDeclaration> fieldDeclaration = getAncestorOfType(decl, FieldDeclaration.class);
|
||||
if (fieldDeclaration.isPresent())
|
||||
@@ -95,31 +99,39 @@ public class DeclNameResolver extends NameResolver
|
||||
{
|
||||
isStatic = Modifier.isStatic(fieldDeclaration.get().getModifiers());
|
||||
}
|
||||
typeName = BindingNameResolver.getQualifiedName(
|
||||
fieldDeclaration.get().getType().resolveBinding(),
|
||||
m_currentFile,
|
||||
m_compilationUnit,
|
||||
m_ignoredContexts.copy()).orElse(TypeName.unsolved());
|
||||
typeName = BindingNameResolver
|
||||
.getQualifiedName(
|
||||
fieldDeclaration.get().getType().resolveBinding(),
|
||||
m_currentFile,
|
||||
m_compilationUnit,
|
||||
m_ignoredContexts.copy())
|
||||
.orElse(TypeName.unsolved());
|
||||
}
|
||||
|
||||
|
||||
return new VariableDeclName(decl.getName().getIdentifier(), typeName, isStatic);
|
||||
}
|
||||
|
||||
public static DeclName getQualifiedDeclName(BodyDeclaration decl, File currentFile, CompilationUnit compilationUnit)
|
||||
|
||||
public static DeclName getQualifiedDeclName(
|
||||
BodyDeclaration decl, File currentFile, CompilationUnit compilationUnit)
|
||||
{
|
||||
return getQualifiedDeclName(decl, currentFile, compilationUnit, null);
|
||||
}
|
||||
|
||||
public static DeclName getQualifiedDeclName(BodyDeclaration decl, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts)
|
||||
|
||||
public static DeclName getQualifiedDeclName(
|
||||
BodyDeclaration decl,
|
||||
File currentFile,
|
||||
CompilationUnit compilationUnit,
|
||||
ContextList ignoredContexts)
|
||||
{
|
||||
DeclNameResolver resolver = new DeclNameResolver(currentFile, compilationUnit, ignoredContexts);
|
||||
DeclNameResolver resolver = new DeclNameResolver(
|
||||
currentFile, compilationUnit, ignoredContexts);
|
||||
return resolver.getQualifiedDeclName(decl);
|
||||
}
|
||||
|
||||
|
||||
public DeclName getQualifiedDeclName(BodyDeclaration decl)
|
||||
{
|
||||
DeclName declName = DeclName.unsolved();
|
||||
|
||||
|
||||
if (decl != null)
|
||||
{
|
||||
declName = getDeclName(decl);
|
||||
@@ -139,46 +151,49 @@ public class DeclNameResolver extends NameResolver
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return declName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public DeclName getDeclName(BodyDeclaration decl)
|
||||
{
|
||||
DeclName declName = DeclName.unsolved();
|
||||
|
||||
|
||||
if (decl != null)
|
||||
{
|
||||
if (decl instanceof AnnotationTypeDeclaration)
|
||||
{
|
||||
declName = new DeclName(((AnnotationTypeDeclaration) decl).getName().getIdentifier());
|
||||
declName = new DeclName(((AnnotationTypeDeclaration)decl).getName().getIdentifier());
|
||||
}
|
||||
else if (decl instanceof EnumDeclaration)
|
||||
{
|
||||
declName = new DeclName(((EnumDeclaration) decl).getName().getIdentifier());
|
||||
declName = new DeclName(((EnumDeclaration)decl).getName().getIdentifier());
|
||||
}
|
||||
else if (decl instanceof TypeDeclaration)
|
||||
{
|
||||
TypeDeclaration typeDeclaration = (TypeDeclaration) decl;
|
||||
TypeDeclaration typeDeclaration = (TypeDeclaration)decl;
|
||||
|
||||
List<String> typeParameterNames = new ArrayList<>();
|
||||
for (Object typeParameter: typeDeclaration.typeParameters())
|
||||
{
|
||||
if (typeParameter instanceof TypeParameter)
|
||||
{
|
||||
typeParameterNames.add(((TypeParameter) typeParameter).getName().getIdentifier());
|
||||
typeParameterNames.add(
|
||||
((TypeParameter)typeParameter).getName().getIdentifier());
|
||||
}
|
||||
}
|
||||
|
||||
declName = new DeclName(typeDeclaration.getName().getIdentifier(), typeParameterNames);
|
||||
|
||||
declName = new DeclName(
|
||||
typeDeclaration.getName().getIdentifier(), typeParameterNames);
|
||||
}
|
||||
else if (decl instanceof AnnotationTypeMemberDeclaration)
|
||||
{
|
||||
declName = new DeclName(((AnnotationTypeMemberDeclaration) decl).getName().getIdentifier());
|
||||
declName = new DeclName(
|
||||
((AnnotationTypeMemberDeclaration)decl).getName().getIdentifier());
|
||||
}
|
||||
else if (decl instanceof EnumConstantDeclaration)
|
||||
{
|
||||
declName = new DeclName(((EnumConstantDeclaration) decl).getName().getIdentifier());
|
||||
declName = new DeclName(((EnumConstantDeclaration)decl).getName().getIdentifier());
|
||||
}
|
||||
else if (decl instanceof FieldDeclaration)
|
||||
{
|
||||
@@ -190,56 +205,76 @@ public class DeclNameResolver extends NameResolver
|
||||
}
|
||||
else if (decl instanceof MethodDeclaration)
|
||||
{
|
||||
MethodDeclaration methodDeclaration = (MethodDeclaration) decl;
|
||||
|
||||
MethodDeclaration methodDeclaration = (MethodDeclaration)decl;
|
||||
|
||||
List<String> typeParameterNames = new ArrayList<>();
|
||||
for (Object typeParameter: methodDeclaration.typeParameters())
|
||||
{
|
||||
if (typeParameter instanceof TypeParameter)
|
||||
{
|
||||
typeParameterNames.add(((TypeParameter) typeParameter).getName().getIdentifier());
|
||||
typeParameterNames.add(
|
||||
((TypeParameter)typeParameter).getName().getIdentifier());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ContextList ignoredContexts = m_ignoredContexts.copy();
|
||||
ignoredContexts.add(((MethodDeclaration) decl).resolveBinding());
|
||||
|
||||
TypeName returnTypeName = methodDeclaration.isConstructor() ? null : BindingNameResolver.getQualifiedName(
|
||||
methodDeclaration.getReturnType2().resolveBinding(), m_currentFile, m_compilationUnit, ignoredContexts).orElse(TypeName.unsolved());
|
||||
|
||||
List<TypeName> parameterTypeNames = new ArrayList<>();
|
||||
ignoredContexts.add(((MethodDeclaration)decl).resolveBinding());
|
||||
|
||||
TypeName returnTypeName = methodDeclaration.isConstructor()
|
||||
? null
|
||||
: BindingNameResolver
|
||||
.getQualifiedName(
|
||||
methodDeclaration.getReturnType2().resolveBinding(),
|
||||
m_currentFile,
|
||||
m_compilationUnit,
|
||||
ignoredContexts)
|
||||
.orElse(TypeName.unsolved());
|
||||
|
||||
List<TypeName> parameterTypeNames = new ArrayList<>();
|
||||
for (Object parameter: methodDeclaration.parameters())
|
||||
{
|
||||
if (parameter instanceof SingleVariableDeclaration)
|
||||
{
|
||||
parameterTypeNames.add(BindingNameResolver.getQualifiedName(
|
||||
((SingleVariableDeclaration) parameter).getType().resolveBinding(), m_currentFile, m_compilationUnit, ignoredContexts).orElse(TypeName.unsolved()));
|
||||
parameterTypeNames.add(
|
||||
BindingNameResolver
|
||||
.getQualifiedName(
|
||||
((SingleVariableDeclaration)parameter).getType().resolveBinding(),
|
||||
m_currentFile,
|
||||
m_compilationUnit,
|
||||
ignoredContexts)
|
||||
.orElse(TypeName.unsolved()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
declName = new FunctionDeclName(
|
||||
methodDeclaration.getName().getIdentifier(),
|
||||
typeParameterNames,
|
||||
returnTypeName,
|
||||
parameterTypeNames,
|
||||
Modifier.isStatic(methodDeclaration.getModifiers()));
|
||||
methodDeclaration.getName().getIdentifier(),
|
||||
typeParameterNames,
|
||||
returnTypeName,
|
||||
parameterTypeNames,
|
||||
Modifier.isStatic(methodDeclaration.getModifiers()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return declName;
|
||||
}
|
||||
|
||||
public static DeclName getQualifiedDeclName(AnonymousClassDeclaration decl, File currentFile, CompilationUnit compilationUnit)
|
||||
|
||||
public static DeclName getQualifiedDeclName(
|
||||
AnonymousClassDeclaration decl, File currentFile, CompilationUnit compilationUnit)
|
||||
{
|
||||
return getQualifiedDeclName(decl, currentFile, compilationUnit, null);
|
||||
}
|
||||
|
||||
public static DeclName getQualifiedDeclName(AnonymousClassDeclaration decl, File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts)
|
||||
|
||||
public static DeclName getQualifiedDeclName(
|
||||
AnonymousClassDeclaration decl,
|
||||
File currentFile,
|
||||
CompilationUnit compilationUnit,
|
||||
ContextList ignoredContexts)
|
||||
{
|
||||
DeclNameResolver resolver = new DeclNameResolver(currentFile, compilationUnit, ignoredContexts);
|
||||
DeclNameResolver resolver = new DeclNameResolver(
|
||||
currentFile, compilationUnit, ignoredContexts);
|
||||
return resolver.getQualifiedDeclName(decl);
|
||||
}
|
||||
|
||||
|
||||
public DeclName getQualifiedDeclName(AnonymousClassDeclaration decl)
|
||||
{
|
||||
DeclName declName = DeclName.unsolved();
|
||||
@@ -265,28 +300,28 @@ public class DeclNameResolver extends NameResolver
|
||||
}
|
||||
return declName;
|
||||
}
|
||||
|
||||
|
||||
public DeclName getDeclName(AnonymousClassDeclaration decl)
|
||||
{
|
||||
Position pos = Utility.getRange(decl, m_compilationUnit).begin;
|
||||
return DeclName.anonymousClass(m_currentFile, pos.line, pos.column);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static DeclName getQualifiedName(Name name)
|
||||
{
|
||||
if (name.isSimpleName())
|
||||
{
|
||||
return new DeclName(((SimpleName) name).getIdentifier());
|
||||
return new DeclName(((SimpleName)name).getIdentifier());
|
||||
}
|
||||
else
|
||||
{
|
||||
DeclName declName = new DeclName(((QualifiedName) name).getName().getIdentifier());
|
||||
declName.setParent(getQualifiedName(((QualifiedName) name).getQualifier()));
|
||||
DeclName declName = new DeclName(((QualifiedName)name).getName().getIdentifier());
|
||||
declName.setParent(getQualifiedName(((QualifiedName)name).getQualifier()));
|
||||
return declName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private DeclName getQualifiedContextName(ASTNode decl)
|
||||
{
|
||||
ASTNode parentNode = decl.getParent();
|
||||
@@ -294,25 +329,25 @@ public class DeclNameResolver extends NameResolver
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if (parentNode instanceof BodyDeclaration && !(parentNode instanceof FieldDeclaration))
|
||||
{
|
||||
return getQualifiedDeclName((BodyDeclaration) parentNode);
|
||||
return getQualifiedDeclName((BodyDeclaration)parentNode);
|
||||
}
|
||||
else if (parentNode instanceof AnonymousClassDeclaration)
|
||||
{
|
||||
return getQualifiedDeclName((AnonymousClassDeclaration) parentNode);
|
||||
return getQualifiedDeclName((AnonymousClassDeclaration)parentNode);
|
||||
}
|
||||
else if (parentNode instanceof CompilationUnit)
|
||||
{
|
||||
PackageDeclaration packageDecl = ((CompilationUnit) parentNode).getPackage();
|
||||
PackageDeclaration packageDecl = ((CompilationUnit)parentNode).getPackage();
|
||||
if (packageDecl != null)
|
||||
{
|
||||
return getQualifiedName(packageDecl.getName());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return getQualifiedContextName(parentNode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
package com.sourcetrail.name.resolver;
|
||||
|
||||
import com.sourcetrail.ContextList;
|
||||
import java.io.File;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.core.dom.ASTNode;
|
||||
import org.eclipse.jdt.core.dom.CompilationUnit;
|
||||
|
||||
import com.sourcetrail.ContextList;
|
||||
|
||||
public abstract class NameResolver
|
||||
public abstract class NameResolver
|
||||
{
|
||||
protected File m_currentFile = null;
|
||||
protected ContextList m_ignoredContexts = null;
|
||||
protected CompilationUnit m_compilationUnit = null;
|
||||
|
||||
static protected <N> Optional<N> getAncestorOfType(ASTNode node, Class<N> classType)
|
||||
|
||||
static protected <N> Optional<N> getAncestorOfType(ASTNode node, Class<N> classType)
|
||||
{
|
||||
ASTNode parent = node.getParent();
|
||||
while (parent != null)
|
||||
while (parent != null)
|
||||
{
|
||||
if (classType.isAssignableFrom(parent.getClass()))
|
||||
{
|
||||
@@ -27,12 +25,12 @@ public abstract class NameResolver
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
public NameResolver(File currentFile, CompilationUnit compilationUnit, ContextList ignoredContexts)
|
||||
{
|
||||
m_currentFile = currentFile;
|
||||
m_compilationUnit = compilationUnit;
|
||||
|
||||
|
||||
if (ignoredContexts != null)
|
||||
{
|
||||
m_ignoredContexts = ignoredContexts;
|
||||
@@ -41,5 +39,5 @@ public abstract class NameResolver
|
||||
{
|
||||
m_ignoredContexts = new ContextList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user