KT-4344 "Overridden method parameters are not annotated" warnings from Java
#KT-4344 Fixed
This commit is contained in:
+6
-36
@@ -31,7 +31,6 @@ import com.intellij.psi.impl.compiled.ClsFileImpl;
|
|||||||
import com.intellij.psi.impl.java.stubs.PsiJavaFileStub;
|
import com.intellij.psi.impl.java.stubs.PsiJavaFileStub;
|
||||||
import com.intellij.psi.impl.light.LightClass;
|
import com.intellij.psi.impl.light.LightClass;
|
||||||
import com.intellij.psi.impl.light.LightMethod;
|
import com.intellij.psi.impl.light.LightMethod;
|
||||||
import com.intellij.psi.impl.light.LightModifierList;
|
|
||||||
import com.intellij.psi.stubs.PsiClassHolderFileStub;
|
import com.intellij.psi.stubs.PsiClassHolderFileStub;
|
||||||
import com.intellij.psi.util.CachedValue;
|
import com.intellij.psi.util.CachedValue;
|
||||||
import com.intellij.psi.util.CachedValuesManager;
|
import com.intellij.psi.util.CachedValuesManager;
|
||||||
@@ -387,7 +386,12 @@ public class KotlinLightClassForExplicitDeclaration extends KotlinWrappingLightC
|
|||||||
@Override
|
@Override
|
||||||
public PsiModifierList getModifierList() {
|
public PsiModifierList getModifierList() {
|
||||||
if (modifierList == null) {
|
if (modifierList == null) {
|
||||||
modifierList = new KotlinLightModifierList(computeModifiers());
|
modifierList = new KotlinLightModifierList(this.getManager(), computeModifiers()) {
|
||||||
|
@Override
|
||||||
|
public PsiAnnotationOwner getDelegate() {
|
||||||
|
return KotlinLightClassForExplicitDeclaration.this.getDelegate().getModifierList();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return modifierList;
|
return modifierList;
|
||||||
}
|
}
|
||||||
@@ -565,38 +569,4 @@ public class KotlinLightClassForExplicitDeclaration extends KotlinWrappingLightC
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class KotlinLightModifierList extends LightModifierList {
|
|
||||||
public KotlinLightModifierList(@NotNull String[] modifiers) {
|
|
||||||
super(KotlinLightClassForExplicitDeclaration.this.getManager(), JetLanguage.INSTANCE, modifiers);
|
|
||||||
}
|
|
||||||
|
|
||||||
private PsiAnnotationOwner getDelegate() {
|
|
||||||
return KotlinLightClassForExplicitDeclaration.this.getDelegate().getModifierList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public PsiAnnotation[] getAnnotations() {
|
|
||||||
return getDelegate().getAnnotations();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public PsiAnnotation[] getApplicableAnnotations() {
|
|
||||||
return getDelegate().getApplicableAnnotations();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public PsiAnnotation findAnnotation(@NotNull @NonNls String qualifiedName) {
|
|
||||||
return getDelegate().findAnnotation(qualifiedName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public PsiAnnotation addAnnotation(@NotNull @NonNls String qualifiedName) {
|
|
||||||
return getDelegate().addAnnotation(qualifiedName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.asJava;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiAnnotation;
|
||||||
|
import com.intellij.psi.PsiAnnotationOwner;
|
||||||
|
import com.intellij.psi.PsiManager;
|
||||||
|
import com.intellij.psi.impl.light.LightModifierList;
|
||||||
|
import org.jetbrains.annotations.NonNls;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.plugin.JetLanguage;
|
||||||
|
|
||||||
|
public abstract class KotlinLightModifierList extends LightModifierList {
|
||||||
|
public KotlinLightModifierList(PsiManager psiManager, @NotNull String[] modifiers) {
|
||||||
|
super(psiManager, JetLanguage.INSTANCE, modifiers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract PsiAnnotationOwner getDelegate();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public PsiAnnotation[] getAnnotations() {
|
||||||
|
return getDelegate().getAnnotations();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public PsiAnnotation[] getApplicableAnnotations() {
|
||||||
|
return getDelegate().getApplicableAnnotations();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public PsiAnnotation findAnnotation(@NotNull @NonNls String qualifiedName) {
|
||||||
|
return getDelegate().findAnnotation(qualifiedName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public PsiAnnotation addAnnotation(@NotNull @NonNls String qualifiedName) {
|
||||||
|
return getDelegate().addAnnotation(qualifiedName);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,7 +16,10 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.asJava;
|
package org.jetbrains.jet.asJava;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiAnnotationOwner;
|
||||||
|
import com.intellij.psi.PsiModifierList;
|
||||||
import com.intellij.psi.PsiParameter;
|
import com.intellij.psi.PsiParameter;
|
||||||
|
import com.intellij.util.ArrayUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.asJava.light.LightParameter;
|
import org.jetbrains.jet.asJava.light.LightParameter;
|
||||||
@@ -34,15 +37,30 @@ public class KotlinLightParameter extends LightParameter implements KotlinLightE
|
|||||||
return name != null ? name : "p" + index;
|
return name != null ? name : "p" + index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final PsiModifierList modifierList;
|
||||||
private final PsiParameter delegate;
|
private final PsiParameter delegate;
|
||||||
private final int index;
|
private final int index;
|
||||||
private final KotlinLightMethod method;
|
private final KotlinLightMethod method;
|
||||||
|
|
||||||
public KotlinLightParameter(PsiParameter delegate, int index, KotlinLightMethod method) {
|
public KotlinLightParameter(final PsiParameter delegate, int index, KotlinLightMethod method) {
|
||||||
super(getName(delegate, index), delegate.getType(), method, JetLanguage.INSTANCE);
|
super(getName(delegate, index), delegate.getType(), method, JetLanguage.INSTANCE);
|
||||||
|
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.method = method;
|
this.method = method;
|
||||||
|
|
||||||
|
this.modifierList = new KotlinLightModifierList(method.getManager(), ArrayUtil.EMPTY_STRING_ARRAY) {
|
||||||
|
@Override
|
||||||
|
public PsiAnnotationOwner getDelegate() {
|
||||||
|
return delegate.getModifierList();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public PsiModifierList getModifierList() {
|
||||||
|
return modifierList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+2
-1
@@ -1,12 +1,13 @@
|
|||||||
package foo;
|
package foo;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
class JavaClass {
|
class JavaClass {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public void bar(String price) {
|
public void bar(@Nullable String price) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class Small {
|
||||||
|
void test(@NotNull String hi) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
public class Foo: Small() {
|
||||||
|
override fun test(hi: String) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2013 JetBrains s.r.o.
|
* Copyright 2010-2014 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -18,6 +18,7 @@ package org.jetbrains.jet.checkers;
|
|||||||
|
|
||||||
import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase;
|
import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase;
|
||||||
import com.intellij.codeInspection.LocalInspectionTool;
|
import com.intellij.codeInspection.LocalInspectionTool;
|
||||||
|
import com.intellij.codeInspection.nullable.NullableStuffInspection;
|
||||||
import com.intellij.openapi.projectRoots.Sdk;
|
import com.intellij.openapi.projectRoots.Sdk;
|
||||||
import com.siyeh.ig.bugs.StaticCallOnSubclassInspection;
|
import com.siyeh.ig.bugs.StaticCallOnSubclassInspection;
|
||||||
import com.siyeh.ig.bugs.StaticFieldReferenceOnSubclassInspection;
|
import com.siyeh.ig.bugs.StaticFieldReferenceOnSubclassInspection;
|
||||||
@@ -27,7 +28,11 @@ import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
|||||||
public class KotlinAndJavaCheckerTest extends DaemonAnalyzerTestCase {
|
public class KotlinAndJavaCheckerTest extends DaemonAnalyzerTestCase {
|
||||||
@Override
|
@Override
|
||||||
protected LocalInspectionTool[] configureLocalInspectionTools() {
|
protected LocalInspectionTool[] configureLocalInspectionTools() {
|
||||||
return new LocalInspectionTool[] { new StaticCallOnSubclassInspection(), new StaticFieldReferenceOnSubclassInspection()};
|
return new LocalInspectionTool[] {
|
||||||
|
new StaticCallOnSubclassInspection(),
|
||||||
|
new StaticFieldReferenceOnSubclassInspection(),
|
||||||
|
new NullableStuffInspection()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -44,6 +49,10 @@ public class KotlinAndJavaCheckerTest extends DaemonAnalyzerTestCase {
|
|||||||
doTest(false, false, "ClassObjects.java", "ClassObjects.kt");
|
doTest(false, false, "ClassObjects.java", "ClassObjects.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testNoNotNullOnParameterInOverride() throws Exception {
|
||||||
|
doTest(true, true, "NoNotNullOnParameterInOverride.java", "NoNotNullOnParameterInOverride.kt");
|
||||||
|
}
|
||||||
|
|
||||||
public void testUsingKotlinPackageDeclarations() throws Exception {
|
public void testUsingKotlinPackageDeclarations() throws Exception {
|
||||||
doTest(true, true, "UsingKotlinPackageDeclarations.java", "UsingKotlinPackageDeclarations.kt");
|
doTest(true, true, "UsingKotlinPackageDeclarations.java", "UsingKotlinPackageDeclarations.kt");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user