mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
get rid of ParentMatcher and Matcher altogether
This commit is contained in:
@@ -1,22 +1,18 @@
|
||||
package com.jetbrains.python.validation;
|
||||
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.psi.PyClass;
|
||||
import com.jetbrains.python.psi.PyFromImportStatement;
|
||||
import com.jetbrains.python.psi.PyFunction;
|
||||
import com.jetbrains.python.psi.patterns.Matcher;
|
||||
import com.jetbrains.python.psi.patterns.ParentMatcher;
|
||||
|
||||
/**
|
||||
* Checks for non-top-level star imports.
|
||||
*/
|
||||
public class ImportAnnotator extends PyAnnotator {
|
||||
|
||||
private static Matcher INAPPROPRIATE = new ParentMatcher(PyClass.class, PyFunction.class);
|
||||
|
||||
@Override
|
||||
public void visitPyFromImportStatement(final PyFromImportStatement node) {
|
||||
if (node.isStarImport() && INAPPROPRIATE.search(node) != null) {
|
||||
if (node.isStarImport() && PsiTreeUtil.getParentOfType(node, PyFunction.class, PyClass.class) != null) {
|
||||
getHolder().createWarningAnnotation(node, PyBundle.message("ANN.star.import.at.top.only"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
def foo():
|
||||
<warning descr="'import *' only allowed at module level">from sys import *</warning>
|
||||
@@ -88,6 +88,10 @@ public class PythonHighlightingTest extends PyLightFixtureTestCase {
|
||||
public void testYieldOutsideOfFunction() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testImportStarAtTopLevel() {
|
||||
doTest(true, false);
|
||||
}
|
||||
|
||||
public void testMalformedStringUnterminated() {
|
||||
doTest();
|
||||
|
||||
Reference in New Issue
Block a user