src: Apply clang-format and extend use to Java code (#973)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user