logic: name qualifiers of symbols are clickable now
This commit is contained in:
@@ -19,6 +19,7 @@ import org.eclipse.jdt.core.dom.CreationReference;
|
||||
import org.eclipse.jdt.core.dom.EnumConstantDeclaration;
|
||||
import org.eclipse.jdt.core.dom.EnumDeclaration;
|
||||
import org.eclipse.jdt.core.dom.ExpressionMethodReference;
|
||||
import org.eclipse.jdt.core.dom.FieldAccess;
|
||||
import org.eclipse.jdt.core.dom.FieldDeclaration;
|
||||
import org.eclipse.jdt.core.dom.IBinding;
|
||||
import org.eclipse.jdt.core.dom.IMethodBinding;
|
||||
@@ -39,9 +40,11 @@ import org.eclipse.jdt.core.dom.QualifiedType;
|
||||
import org.eclipse.jdt.core.dom.SimpleName;
|
||||
import org.eclipse.jdt.core.dom.SimpleType;
|
||||
import org.eclipse.jdt.core.dom.SuperConstructorInvocation;
|
||||
import org.eclipse.jdt.core.dom.SuperFieldAccess;
|
||||
import org.eclipse.jdt.core.dom.SuperMethodInvocation;
|
||||
import org.eclipse.jdt.core.dom.SuperMethodReference;
|
||||
import org.eclipse.jdt.core.dom.SwitchStatement;
|
||||
import org.eclipse.jdt.core.dom.ThisExpression;
|
||||
import org.eclipse.jdt.core.dom.TypeDeclaration;
|
||||
import org.eclipse.jdt.core.dom.TypeMethodReference;
|
||||
import org.eclipse.jdt.core.dom.TypeParameter;
|
||||
@@ -85,10 +88,17 @@ public abstract class AstVisitor extends ASTVisitor
|
||||
public boolean visit(PackageDeclaration node)
|
||||
{
|
||||
Name name = node.getName();
|
||||
|
||||
Range range = getRange(name);
|
||||
if (name instanceof QualifiedName)
|
||||
{
|
||||
range = getRange(((QualifiedName) name).getName());
|
||||
}
|
||||
|
||||
m_client.recordSymbolWithLocation(
|
||||
DeclNameResolver.getQualifiedName(name).toNameHierarchy(),
|
||||
SymbolKind.PACKAGE,
|
||||
getRange(node.getName()),
|
||||
range,
|
||||
AccessKind.NONE,
|
||||
DefinitionKind.EXPLICIT);
|
||||
|
||||
@@ -102,6 +112,8 @@ public abstract class AstVisitor extends ASTVisitor
|
||||
DefinitionKind.EXPLICIT);
|
||||
}
|
||||
|
||||
// qualifiers are visited and recorded because the "name" is a QualifiedName
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -325,10 +337,16 @@ public abstract class AstVisitor extends ASTVisitor
|
||||
|
||||
for (SymbolName context: m_contextStack.peek())
|
||||
{
|
||||
Range range = getRange(node.getName());
|
||||
if (node.getName() instanceof QualifiedName)
|
||||
{
|
||||
range = getRange(((QualifiedName) node.getName()).getName());
|
||||
}
|
||||
|
||||
m_client.recordReference(
|
||||
ReferenceKind.IMPORT,
|
||||
symbolName.toNameHierarchy(), context.toNameHierarchy(),
|
||||
getRange(node.getName()));
|
||||
range);
|
||||
}
|
||||
|
||||
Optional<DeclName> packageName = BindingNameResolver.getQualifiedName(getDeclaringPackage(binding), m_filePath, m_compilationUnit);
|
||||
@@ -337,6 +355,8 @@ public abstract class AstVisitor extends ASTVisitor
|
||||
m_client.recordSymbol(packageName.get().toNameHierarchy(),
|
||||
SymbolKind.PACKAGE, AccessKind.NONE, DefinitionKind.NONE);
|
||||
}
|
||||
|
||||
new QualifierVisitor(m_client, m_filePath, m_compilationUnit).recordQualifierOfNode(node);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -352,12 +372,21 @@ public abstract class AstVisitor extends ASTVisitor
|
||||
binding = binding.getTypeDeclaration();
|
||||
}
|
||||
|
||||
Range range = getRange(node.getName());
|
||||
if (node.getName() instanceof QualifiedName)
|
||||
{
|
||||
range = getRange(((QualifiedName) node.getName()).getName());
|
||||
}
|
||||
|
||||
m_client.recordReference(
|
||||
getTypeReferenceKind(),
|
||||
BindingNameResolver.getQualifiedName(binding, m_filePath, m_compilationUnit).orElse(TypeName.unsolved()).toDeclName().toNameHierarchy(),
|
||||
context.toNameHierarchy(),
|
||||
getRange(node));
|
||||
range);
|
||||
}
|
||||
|
||||
new QualifierVisitor(m_client, m_filePath, m_compilationUnit).recordQualifierOfNode(node);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -376,8 +405,11 @@ public abstract class AstVisitor extends ASTVisitor
|
||||
getTypeReferenceKind(),
|
||||
BindingNameResolver.getQualifiedName(binding, m_filePath, m_compilationUnit).orElse(TypeName.unsolved()).toDeclName().toNameHierarchy(),
|
||||
context.toNameHierarchy(),
|
||||
getRange(node));
|
||||
getRange(node.getName()));
|
||||
}
|
||||
|
||||
new QualifierVisitor(m_client, m_filePath, m_compilationUnit).recordQualifierOfNode(node);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -396,8 +428,11 @@ public abstract class AstVisitor extends ASTVisitor
|
||||
getTypeReferenceKind(),
|
||||
BindingNameResolver.getQualifiedName(binding, m_filePath, m_compilationUnit).orElse(TypeName.unsolved()).toDeclName().toNameHierarchy(),
|
||||
context.toNameHierarchy(),
|
||||
getRange(node));
|
||||
getRange(node.getName()));
|
||||
}
|
||||
|
||||
new QualifierVisitor(m_client, m_filePath, m_compilationUnit).recordQualifierOfNode(node);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -458,10 +493,45 @@ public abstract class AstVisitor extends ASTVisitor
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(QualifiedName node)
|
||||
{
|
||||
new QualifierVisitor(m_client, m_filePath, m_compilationUnit).recordQualifierOfNode(node);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(FieldAccess node)
|
||||
{
|
||||
new QualifierVisitor(m_client, m_filePath, m_compilationUnit).recordQualifierOfNode(node, m_fileContent);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SuperFieldAccess node)
|
||||
{
|
||||
new QualifierVisitor(m_client, m_filePath, m_compilationUnit).recordQualifierOfNode(node, m_fileContent);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(ThisExpression node)
|
||||
{
|
||||
new QualifierVisitor(m_client, m_filePath, m_compilationUnit).recordQualifierOfNode(node, m_fileContent);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MethodInvocation node)
|
||||
{
|
||||
recordReferenceToMethodDeclaration(node.resolveMethodBinding(), getRange(node.getName()), ReferenceKind.CALL, m_contextStack.peek());
|
||||
|
||||
new QualifierVisitor(m_client, m_filePath, m_compilationUnit).recordQualifierOfNode(node, m_fileContent);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -469,6 +539,9 @@ public abstract class AstVisitor extends ASTVisitor
|
||||
public boolean visit(SuperMethodInvocation node)
|
||||
{
|
||||
recordReferenceToMethodDeclaration(node.resolveMethodBinding(), getRange(node.getName()), ReferenceKind.CALL, m_contextStack.peek());
|
||||
|
||||
new QualifierVisitor(m_client, m_filePath, m_compilationUnit).recordQualifierOfNode(node, m_fileContent);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -504,6 +577,9 @@ public abstract class AstVisitor extends ASTVisitor
|
||||
m_fileContent.findRange("new", getRange(node).begin),
|
||||
ReferenceKind.USAGE,
|
||||
m_contextStack.peek());
|
||||
|
||||
new QualifierVisitor(m_client, m_filePath, m_compilationUnit).recordQualifierOfNode(node);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -515,6 +591,8 @@ public abstract class AstVisitor extends ASTVisitor
|
||||
getRange(node.getName()),
|
||||
ReferenceKind.USAGE,
|
||||
m_contextStack.peek());
|
||||
|
||||
new QualifierVisitor(m_client, m_filePath, m_compilationUnit).recordQualifierOfNode(node, m_fileContent);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -527,6 +605,8 @@ public abstract class AstVisitor extends ASTVisitor
|
||||
getRange(node.getName()),
|
||||
ReferenceKind.USAGE,
|
||||
m_contextStack.peek());
|
||||
|
||||
new QualifierVisitor(m_client, m_filePath, m_compilationUnit).recordQualifierOfNode(node, m_fileContent);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -546,6 +626,8 @@ public abstract class AstVisitor extends ASTVisitor
|
||||
getRange(node.getName()),
|
||||
ReferenceKind.USAGE,
|
||||
m_contextStack.peek());
|
||||
|
||||
new QualifierVisitor(m_client, m_filePath, m_compilationUnit).recordQualifierOfNode(node);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -26,10 +26,14 @@ public abstract class AstVisitorClient
|
||||
Range range,
|
||||
Range scopeRange,
|
||||
AccessKind access, DefinitionKind definitionKind);
|
||||
|
||||
|
||||
public abstract void recordReference(
|
||||
ReferenceKind referenceKind, NameHierarchy referencedName, NameHierarchy contextName,
|
||||
Range range);
|
||||
|
||||
public abstract void recordQualifierLocation(
|
||||
NameHierarchy qualifierName,
|
||||
Range range);
|
||||
|
||||
public abstract void recordLocalSymbol(
|
||||
NameHierarchy symbolName,
|
||||
|
||||
@@ -147,9 +147,12 @@ public class JavaIndexer
|
||||
int scopeBeginLine, int scopeBeginColumn, int scopeEndLine, int scopeEndColumn,
|
||||
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);
|
||||
|
||||
static public native void recordQualifierLocation(
|
||||
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);
|
||||
|
||||
@@ -78,6 +78,16 @@ public class JavaIndexerAstVisitorClient extends AstVisitorClient
|
||||
range.begin.line, range.begin.column, range.end.line, range.end.column);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordLocalSymbol(NameHierarchy symbolName, Range range)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,309 @@
|
||||
package com.sourcetrail;
|
||||
|
||||
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;
|
||||
import org.eclipse.jdt.core.dom.Expression;
|
||||
import org.eclipse.jdt.core.dom.ExpressionMethodReference;
|
||||
import org.eclipse.jdt.core.dom.FieldAccess;
|
||||
import org.eclipse.jdt.core.dom.IBinding;
|
||||
import org.eclipse.jdt.core.dom.IMethodBinding;
|
||||
import org.eclipse.jdt.core.dom.IPackageBinding;
|
||||
import org.eclipse.jdt.core.dom.ITypeBinding;
|
||||
import org.eclipse.jdt.core.dom.ImportDeclaration;
|
||||
import org.eclipse.jdt.core.dom.MethodInvocation;
|
||||
import org.eclipse.jdt.core.dom.Name;
|
||||
import org.eclipse.jdt.core.dom.NameQualifiedType;
|
||||
import org.eclipse.jdt.core.dom.QualifiedName;
|
||||
import org.eclipse.jdt.core.dom.QualifiedType;
|
||||
import org.eclipse.jdt.core.dom.SimpleType;
|
||||
import org.eclipse.jdt.core.dom.SuperFieldAccess;
|
||||
import org.eclipse.jdt.core.dom.SuperMethodInvocation;
|
||||
import org.eclipse.jdt.core.dom.SuperMethodReference;
|
||||
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.TypeName;
|
||||
import com.sourcetrail.name.resolver.BindingNameResolver;
|
||||
|
||||
public class QualifierVisitor
|
||||
{
|
||||
protected AstVisitorClient m_client = null;
|
||||
private File m_filePath;
|
||||
private CompilationUnit m_compilationUnit;
|
||||
|
||||
public QualifierVisitor(AstVisitorClient client, File filePath, CompilationUnit compilationUnit)
|
||||
{
|
||||
m_client = client;
|
||||
m_filePath = filePath;
|
||||
m_compilationUnit = compilationUnit;
|
||||
}
|
||||
|
||||
public void recordQualifierOfNode(ImportDeclaration node)
|
||||
{
|
||||
if (node != null && node.getName() instanceof QualifiedName)
|
||||
{
|
||||
recordNodeAsQualifier(((QualifiedName) node.getName()).getQualifier());
|
||||
}
|
||||
}
|
||||
|
||||
public void recordQualifierOfNode(SimpleType node)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
if (node.getName() instanceof QualifiedName)
|
||||
{
|
||||
recordNodeAsQualifier(((QualifiedName) node.getName()).getQualifier());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void recordQualifierOfNode(QualifiedType node)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
recordNodeAsQualifier(node.getQualifier());
|
||||
}
|
||||
}
|
||||
|
||||
public void recordQualifierOfNode(NameQualifiedType node)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
recordNodeAsQualifier(node.getQualifier());
|
||||
}
|
||||
}
|
||||
|
||||
public void recordQualifierOfNode(QualifiedName node)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
recordNodeAsQualifier(node.getQualifier());
|
||||
}
|
||||
}
|
||||
|
||||
public void recordQualifierOfNode(FieldAccess node, FileContent fileContent)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
recordNodeAsQualifier(node.getExpression(), fileContent);
|
||||
}
|
||||
}
|
||||
|
||||
public void recordQualifierOfNode(SuperFieldAccess node, FileContent fileContent)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
recordNodeAsQualifier(node, fileContent);
|
||||
}
|
||||
}
|
||||
|
||||
public void recordQualifierOfNode(ThisExpression node, FileContent fileContent)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
recordNodeAsQualifier(node.getQualifier());
|
||||
}
|
||||
}
|
||||
|
||||
public void recordQualifierOfNode(MethodInvocation node, FileContent fileContent)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
recordNodeAsQualifier(node.getExpression(), fileContent);
|
||||
}
|
||||
}
|
||||
|
||||
public void recordQualifierOfNode(SuperMethodInvocation node, FileContent fileContent)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
IMethodBinding methodBinding = node.resolveMethodBinding();
|
||||
if (methodBinding != null)
|
||||
{
|
||||
ITypeBinding typeBinding = methodBinding.getDeclaringClass();
|
||||
if (typeBinding != null)
|
||||
{
|
||||
m_client.recordQualifierLocation(
|
||||
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)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
recordNodeAsQualifier(node.getType());
|
||||
}
|
||||
}
|
||||
|
||||
public void recordQualifierOfNode(ExpressionMethodReference node, FileContent fileContent)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
recordNodeAsQualifier(node.getExpression(), fileContent);
|
||||
}
|
||||
}
|
||||
|
||||
public void recordQualifierOfNode(SuperMethodReference node, FileContent fileContent)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
IMethodBinding methodBinding = node.resolveMethodBinding();
|
||||
if (methodBinding != null)
|
||||
{
|
||||
ITypeBinding typeBinding = methodBinding.getDeclaringClass();
|
||||
if (typeBinding != null)
|
||||
{
|
||||
m_client.recordQualifierLocation(
|
||||
BindingNameResolver
|
||||
.getQualifiedName(typeBinding, m_filePath, m_compilationUnit)
|
||||
.orElse(TypeName.unsolved())
|
||||
.toDeclName()
|
||||
.toNameHierarchy(),
|
||||
fileContent.findRange("super", getRange(node).begin));
|
||||
}
|
||||
}
|
||||
|
||||
recordNodeAsQualifier(node.getQualifier());
|
||||
}
|
||||
}
|
||||
|
||||
public void recordQualifierOfNode(TypeMethodReference node)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
recordNodeAsQualifier(node.getType());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void recordNodeAsQualifier(Expression node, FileContent fileContent) {
|
||||
if (node != null)
|
||||
{
|
||||
if (node instanceof Name)
|
||||
{
|
||||
recordNodeAsQualifier((Name) node);
|
||||
}
|
||||
else if (node instanceof SuperFieldAccess)
|
||||
{
|
||||
SuperFieldAccess expression = (SuperFieldAccess) node;
|
||||
|
||||
m_client.recordQualifierLocation(
|
||||
BindingNameResolver
|
||||
.getQualifiedName(expression.resolveFieldBinding().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;
|
||||
|
||||
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));
|
||||
|
||||
recordNodeAsQualifier(expression.getQualifier());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void recordNodeAsQualifier(Type node)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
if (node instanceof SimpleType)
|
||||
{
|
||||
recordNodeAsQualifier(((SimpleType) node).getName());
|
||||
}
|
||||
else if (node instanceof QualifiedType)
|
||||
{
|
||||
recordNodeAsQualifier(((QualifiedType) node).getName());
|
||||
recordNodeAsQualifier(((QualifiedType) node).getQualifier());
|
||||
}
|
||||
else if (node instanceof NameQualifiedType)
|
||||
{
|
||||
recordNodeAsQualifier(((NameQualifiedType) node).getName());
|
||||
recordNodeAsQualifier(((NameQualifiedType) node).getQualifier());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void recordNodeAsQualifier(Name node)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
IBinding binding = node.resolveBinding();
|
||||
if (binding instanceof ITypeBinding)
|
||||
{
|
||||
Range range = getRange(node);
|
||||
if (node instanceof QualifiedName)
|
||||
{
|
||||
range = getRange(((QualifiedName) node).getName());
|
||||
}
|
||||
|
||||
m_client.recordQualifierLocation(
|
||||
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());
|
||||
}
|
||||
|
||||
m_client.recordQualifierLocation(
|
||||
BindingNameResolver
|
||||
.getQualifiedName((IPackageBinding) binding, m_filePath, m_compilationUnit)
|
||||
.orElse(DeclName.unsolved())
|
||||
.toNameHierarchy(),
|
||||
range);
|
||||
}
|
||||
|
||||
if (node instanceof QualifiedName)
|
||||
{
|
||||
recordNodeAsQualifier(((QualifiedName) node).getQualifier());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Range getRange(ASTNode node)
|
||||
{
|
||||
return Utility.getRange(node, m_compilationUnit);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user