在编写声纳插件规则时,如何在另一个 java 源文件中获取 Tree.Kind.VARIABLE 的类型定义?
How Can I get Tree.Kind.VARIABLE's Type defined in another java source file when writting sonar plugin rules?
我正在编写声纳插件规则,如何获得在另一个 java 源文件中定义的 Tree.Kind.VARIABLE 类型?
//Cursor.java:
public interface Cursor extends Closeable {
// TODO.
};
//Engine.java:
public class Engine extends HandlerThread {
private Cursor mCursor;
public List<Suggestion> getSuggestions(){
Cursor photoCursor = contentResolver.query();
// TODO.
}
}
当声纳插件规则分析Engine.java时,我如何获得 mCursor 的类型?和 photoCursor 的类型?
我的密码是:
public class VarCheck extends IssuableSubscriptionVisitor
{
@Override
public List<Tree.Kind> nodesToVisit()
{
return ImmutableList.of(Tree.Kind.VARIABLE);
}
@Override
public void visitNode(Tree tree)
{
if (tree.is(Tree.Kind.VARIABLE))
{
VariableTree vart = (VariableTree)tree;
System.out.println("visitNode 02: " + vart.symbol().name() +" "+ vart.symbol().type().name());
if (vart.symbol().isVariableSymbol())
{
VariableSymbol varSymbol = (VariableSymbol)vart.symbol();
System.out.println("visitNode 03: " + varSymbol.name()
+" "+ varSymbol.type().name()
+" "+ varSymbol.type().isSubtypeOf("java.io.Closeable"));
// Why varSymbol.type().name() is unknownSymbol?
}
// vart.accept(visitor);
}
}
}
订阅Tree.Kind.VARIABLE,将节点投射到VariableTree,访问此类VariableTree的symbol().type()。
我正在编写声纳插件规则,如何获得在另一个 java 源文件中定义的 Tree.Kind.VARIABLE 类型?
//Cursor.java:
public interface Cursor extends Closeable {
// TODO.
};
//Engine.java:
public class Engine extends HandlerThread {
private Cursor mCursor;
public List<Suggestion> getSuggestions(){
Cursor photoCursor = contentResolver.query();
// TODO.
}
}
当声纳插件规则分析Engine.java时,我如何获得 mCursor 的类型?和 photoCursor 的类型?
我的密码是:
public class VarCheck extends IssuableSubscriptionVisitor
{
@Override
public List<Tree.Kind> nodesToVisit()
{
return ImmutableList.of(Tree.Kind.VARIABLE);
}
@Override
public void visitNode(Tree tree)
{
if (tree.is(Tree.Kind.VARIABLE))
{
VariableTree vart = (VariableTree)tree;
System.out.println("visitNode 02: " + vart.symbol().name() +" "+ vart.symbol().type().name());
if (vart.symbol().isVariableSymbol())
{
VariableSymbol varSymbol = (VariableSymbol)vart.symbol();
System.out.println("visitNode 03: " + varSymbol.name()
+" "+ varSymbol.type().name()
+" "+ varSymbol.type().isSubtypeOf("java.io.Closeable"));
// Why varSymbol.type().name() is unknownSymbol?
}
// vart.accept(visitor);
}
}
}
订阅Tree.Kind.VARIABLE,将节点投射到VariableTree,访问此类VariableTree的symbol().type()。