use of org.python.pydev.ast.codecompletion.revisited.visitors.AbstractVisitor.ImportPartSourceToken in project Pydev by fabioz.
the class MessagesManager method addUnusedMessage.
/**
* adds a message for something that was not used
*
* @param node the node representing the scope being closed when adding the
* unused message
*/
public void addUnusedMessage(SimpleNode node, Found f) {
List<GenAndTok> all = f.getAll();
int len = all.size();
for (int i = 0; i < len; i++) {
GenAndTok g = all.get(i);
if (g.generator instanceof SourceToken) {
SimpleNode ast = ((SourceToken) g.generator).getAst();
// it can be an unused import
boolean isFromImport = ast instanceof ImportFrom;
if (isFromImport || ast instanceof Import) {
if (isFromImport && AbstractVisitor.isWildImport((ImportFrom) ast)) {
addMessage(IAnalysisPreferences.TYPE_UNUSED_WILD_IMPORT, g.generator, g.tok);
} else if (!(g.generator instanceof ImportPartSourceToken)) {
addMessage(IAnalysisPreferences.TYPE_UNUSED_IMPORT, g.generator, g.tok);
}
// finish it...
continue;
}
}
// we have to check if this is a name we should ignore
if (startsWithNamesToIgnore(g)) {
int type = IAnalysisPreferences.TYPE_UNUSED_VARIABLE;
if (g.tok instanceof SourceToken) {
SourceToken t = (SourceToken) g.tok;
SimpleNode ast = t.getAst();
if (ast instanceof NameTok) {
NameTok n = (NameTok) ast;
if (n.ctx == NameTok.KwArg || n.ctx == NameTok.VarArg || n.ctx == NameTok.KeywordName) {
type = IAnalysisPreferences.TYPE_UNUSED_PARAMETER;
}
} else if (ast instanceof Name) {
Name n = (Name) ast;
if (n.ctx == Name.Param || n.ctx == Name.KwOnlyParam) {
type = IAnalysisPreferences.TYPE_UNUSED_PARAMETER;
}
}
}
boolean addMessage = true;
if (type == IAnalysisPreferences.TYPE_UNUSED_PARAMETER) {
if (node instanceof FunctionDef) {
addMessage = false;
FunctionDef def = (FunctionDef) node;
for (stmtType b : def.body) {
if (b instanceof Pass) {
continue;
}
if (b instanceof Expr) {
Expr expr = (Expr) b;
if (expr.value instanceof Str) {
continue;
}
}
addMessage = true;
break;
}
}
}
if (addMessage) {
addMessage(type, g.generator, g.tok);
}
}
}
}
Aggregations