Uast: Allow to search for a static members (in Kotlin static members are located inside the companion objects).
Companion objects support.
This commit is contained in:
@@ -36,6 +36,7 @@ import org.jetbrains.uast.*;
|
||||
import org.jetbrains.uast.check.UastAndroidUtils;
|
||||
import org.jetbrains.uast.check.UastAndroidContext;
|
||||
import org.jetbrains.uast.check.UastScanner;
|
||||
import org.jetbrains.uast.kinds.UastClassKind;
|
||||
|
||||
/**
|
||||
* Checks that Fragment subclasses can be instantiated via
|
||||
@@ -90,7 +91,7 @@ public class FragmentDetector extends Detector implements UastScanner {
|
||||
|
||||
@Override
|
||||
public void visitClass(UastAndroidContext context, UClass cls) {
|
||||
if (cls.hasModifier(UastModifier.ABSTRACT) || cls.isInterface()) {
|
||||
if (cls.hasModifier(UastModifier.ABSTRACT) || cls.getKind() != UastClassKind.CLASS) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -101,7 +102,7 @@ public class FragmentDetector extends Detector implements UastScanner {
|
||||
return;
|
||||
}
|
||||
|
||||
if (UastUtils.getContainingClass(cls) != null && cls.hasModifier(UastModifier.INNER)) {
|
||||
if (UastUtils.getContainingClass(cls) != null && !cls.hasModifier(UastModifier.STATIC)) {
|
||||
String message = String.format(
|
||||
"This fragment inner class should be static (%1$s)", cls.getName());
|
||||
context.report(ISSUE, cls, UastAndroidUtils.getLocation(cls.getNameElement()), message);
|
||||
|
||||
@@ -84,8 +84,7 @@ public class HandlerDetector extends Detector implements UastScanner {
|
||||
|
||||
@Override
|
||||
public void visitClass(UastAndroidContext context, UClass node) {
|
||||
boolean x = node.hasModifier(UastModifier.INNER);
|
||||
if (!node.hasModifier(UastModifier.INNER)) {
|
||||
if (node.hasModifier(UastModifier.STATIC)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.jetbrains.uast.*;
|
||||
import org.jetbrains.uast.check.UastAndroidUtils;
|
||||
import org.jetbrains.uast.check.UastAndroidContext;
|
||||
import org.jetbrains.uast.check.UastScanner;
|
||||
import org.jetbrains.uast.kinds.UastClassKind;
|
||||
import org.jetbrains.uast.visitor.UastVisitor;
|
||||
|
||||
/**
|
||||
@@ -82,14 +83,14 @@ public class ParcelDetector extends Detector implements UastScanner {
|
||||
@Override
|
||||
public boolean visitClass(@NotNull UClass node) {
|
||||
// Only applies to concrete classes
|
||||
if (node.isInterface() || node.hasModifier(UastModifier.ABSTRACT)) {
|
||||
if (node.getKind() != UastClassKind.CLASS || node.hasModifier(UastModifier.ABSTRACT)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (UType reference : node.getSuperTypes()) {
|
||||
String name = reference.getName();
|
||||
if (name.equals("Parcelable")) {
|
||||
UVariable field = UastUtils.findProperty(node, "CREATOR");
|
||||
UVariable field = UastUtils.findStaticMemberOfType(node, "CREATOR", UVariable.class);
|
||||
if (field == null) {
|
||||
// Make doubly sure that we're really implementing
|
||||
// android.os.Parcelable
|
||||
|
||||
+4
-2
@@ -38,6 +38,7 @@ import org.jetbrains.uast.*;
|
||||
import org.jetbrains.uast.check.UastAndroidUtils;
|
||||
import org.jetbrains.uast.check.UastAndroidContext;
|
||||
import org.jetbrains.uast.check.UastScanner;
|
||||
import org.jetbrains.uast.kinds.UastClassKind;
|
||||
|
||||
/**
|
||||
* Looks for custom views that do not define the view constructors needed by UI builders
|
||||
@@ -114,11 +115,12 @@ public class ViewConstructorDetector extends Detector implements UastScanner {
|
||||
@Override
|
||||
public void visitClass(UastAndroidContext context, UClass node) {
|
||||
// Only applies to concrete and not abstract classes
|
||||
if (node.isObject() || node.isInterface() || node.isEnum() || node.hasModifier(UastModifier.ABSTRACT)) {
|
||||
UastClassKind kind = node.getKind();
|
||||
if (kind != UastClassKind.CLASS || node.hasModifier(UastModifier.ABSTRACT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (UastUtils.getContainingClass(node) != null && node.hasModifier(UastModifier.INNER)) {
|
||||
if (UastUtils.getContainingClass(node) != null && !node.hasModifier(UastModifier.STATIC)) {
|
||||
// Ignore inner classes that aren't static: we can't create these
|
||||
// anyway since we'd need the outer instance
|
||||
return;
|
||||
|
||||
+2
-1
@@ -29,6 +29,7 @@ import org.jetbrains.uast.UastUtils;
|
||||
import org.jetbrains.uast.check.UastAndroidContext;
|
||||
import org.jetbrains.uast.check.UastAndroidUtils;
|
||||
import org.jetbrains.uast.check.UastScanner;
|
||||
import org.jetbrains.uast.kinds.UastClassKind;
|
||||
import org.jetbrains.uast.visitor.UastVisitor;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -74,7 +75,7 @@ public class IntellijRegistrationDetector extends RegistrationDetector implement
|
||||
private void check(UastAndroidContext context, UClass clz) {
|
||||
for (UClass current = clz.getSuperClass(context); current != null; current = current.getSuperClass(context)) {
|
||||
// Ignore abstract classes
|
||||
if (clz.hasModifier(UastModifier.ABSTRACT) || clz.isObject() || clz.isInterface() || clz.isEnum() || clz.isAnnotation()) {
|
||||
if (clz.hasModifier(UastModifier.ABSTRACT) || clz.getKind() != UastClassKind.CLASS) {
|
||||
continue;
|
||||
}
|
||||
String fqcn = current.getFqName();
|
||||
|
||||
Reference in New Issue
Block a user