diff --git a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightClassForExplicitDeclaration.java b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightClassForExplicitDeclaration.java index 5929d6c5d01..21c77dfc234 100644 --- a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightClassForExplicitDeclaration.java +++ b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightClassForExplicitDeclaration.java @@ -31,7 +31,6 @@ import com.intellij.psi.impl.compiled.ClsFileImpl; import com.intellij.psi.impl.java.stubs.PsiJavaFileStub; import com.intellij.psi.impl.light.LightClass; import com.intellij.psi.impl.light.LightMethod; -import com.intellij.psi.impl.light.LightModifierList; import com.intellij.psi.stubs.PsiClassHolderFileStub; import com.intellij.psi.util.CachedValue; import com.intellij.psi.util.CachedValuesManager; @@ -387,7 +386,12 @@ public class KotlinLightClassForExplicitDeclaration extends KotlinWrappingLightC @Override public PsiModifierList getModifierList() { if (modifierList == null) { - modifierList = new KotlinLightModifierList(computeModifiers()); + modifierList = new KotlinLightModifierList(this.getManager(), computeModifiers()) { + @Override + public PsiAnnotationOwner getDelegate() { + return KotlinLightClassForExplicitDeclaration.this.getDelegate().getModifierList(); + } + }; } return modifierList; } @@ -565,38 +569,4 @@ public class KotlinLightClassForExplicitDeclaration extends KotlinWrappingLightC 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); - } - } } diff --git a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightModifierList.java b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightModifierList.java new file mode 100644 index 00000000000..f44cbc46820 --- /dev/null +++ b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightModifierList.java @@ -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); + } +} diff --git a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightParameter.java b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightParameter.java index 736d8bf89ad..f639eedf905 100644 --- a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightParameter.java +++ b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/KotlinLightParameter.java @@ -16,7 +16,10 @@ package org.jetbrains.jet.asJava; +import com.intellij.psi.PsiAnnotationOwner; +import com.intellij.psi.PsiModifierList; import com.intellij.psi.PsiParameter; +import com.intellij.util.ArrayUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.asJava.light.LightParameter; @@ -34,15 +37,30 @@ public class KotlinLightParameter extends LightParameter implements KotlinLightE return name != null ? name : "p" + index; } + private final PsiModifierList modifierList; private final PsiParameter delegate; private final int index; 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); + this.delegate = delegate; this.index = index; 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 diff --git a/idea/testData/codeInsight/overrideImplement/functionFromTraitInJava/foo/JavaClass.java.after b/idea/testData/codeInsight/overrideImplement/functionFromTraitInJava/foo/JavaClass.java.after index ef80e945355..af636c63cdf 100644 --- a/idea/testData/codeInsight/overrideImplement/functionFromTraitInJava/foo/JavaClass.java.after +++ b/idea/testData/codeInsight/overrideImplement/functionFromTraitInJava/foo/JavaClass.java.after @@ -1,12 +1,13 @@ package foo; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; class JavaClass { @NotNull @Override - public void bar(String price) { + public void bar(@Nullable String price) { } } diff --git a/idea/testData/kotlinAndJavaChecker/NoNotNullOnParameterInOverride.java b/idea/testData/kotlinAndJavaChecker/NoNotNullOnParameterInOverride.java new file mode 100644 index 00000000000..65fe81e5b49 --- /dev/null +++ b/idea/testData/kotlinAndJavaChecker/NoNotNullOnParameterInOverride.java @@ -0,0 +1,6 @@ +import org.jetbrains.annotations.NotNull; + +public class Small { + void test(@NotNull String hi) { + } +} diff --git a/idea/testData/kotlinAndJavaChecker/NoNotNullOnParameterInOverride.kt b/idea/testData/kotlinAndJavaChecker/NoNotNullOnParameterInOverride.kt new file mode 100644 index 00000000000..ec2fc8349d2 --- /dev/null +++ b/idea/testData/kotlinAndJavaChecker/NoNotNullOnParameterInOverride.kt @@ -0,0 +1,4 @@ +public class Foo: Small() { + override fun test(hi: String) { + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/checkers/KotlinAndJavaCheckerTest.java b/idea/tests/org/jetbrains/jet/checkers/KotlinAndJavaCheckerTest.java index 6dae9d7007a..8d67cf13b72 100644 --- a/idea/tests/org/jetbrains/jet/checkers/KotlinAndJavaCheckerTest.java +++ b/idea/tests/org/jetbrains/jet/checkers/KotlinAndJavaCheckerTest.java @@ -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"); * 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.codeInspection.LocalInspectionTool; +import com.intellij.codeInspection.nullable.NullableStuffInspection; import com.intellij.openapi.projectRoots.Sdk; import com.siyeh.ig.bugs.StaticCallOnSubclassInspection; import com.siyeh.ig.bugs.StaticFieldReferenceOnSubclassInspection; @@ -27,7 +28,11 @@ import org.jetbrains.jet.plugin.PluginTestCaseBase; public class KotlinAndJavaCheckerTest extends DaemonAnalyzerTestCase { @Override protected LocalInspectionTool[] configureLocalInspectionTools() { - return new LocalInspectionTool[] { new StaticCallOnSubclassInspection(), new StaticFieldReferenceOnSubclassInspection()}; + return new LocalInspectionTool[] { + new StaticCallOnSubclassInspection(), + new StaticFieldReferenceOnSubclassInspection(), + new NullableStuffInspection() + }; } @Override @@ -44,6 +49,10 @@ public class KotlinAndJavaCheckerTest extends DaemonAnalyzerTestCase { doTest(false, false, "ClassObjects.java", "ClassObjects.kt"); } + public void testNoNotNullOnParameterInOverride() throws Exception { + doTest(true, true, "NoNotNullOnParameterInOverride.java", "NoNotNullOnParameterInOverride.kt"); + } + public void testUsingKotlinPackageDeclarations() throws Exception { doTest(true, true, "UsingKotlinPackageDeclarations.java", "UsingKotlinPackageDeclarations.kt"); }