I am writting sonar plugin rules, How Can I get Tree.Kind.VARIABLE's Type defined in another java source file?
//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.
}
}
when sonar plugin rules analysis Engine.java, how cane i get mCursor's type? and photoCursor's type?
My Code is:
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()。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.