Rename package jet -> kotlin in light-classes
org.jetbrains.jet.asJava -> org.jetbrains.kotlin.asJava Also fix some minor warnings and deprecated API usage
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.kotlin.asJava;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.impl.compiled.ClsElementImpl;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.checkers.KotlinMultiFileTestWithWithJava;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public abstract class AbstractKotlinLightClassTest extends KotlinMultiFileTestWithWithJava<Void, Void> {
|
||||
private static final Pattern SUBJECT_FQ_NAME_PATTERN = Pattern.compile("^//\\s*(.*)$", Pattern.MULTILINE);
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected File getKotlinSourceRoot() {
|
||||
return createTmpDir("kotlin-src");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JavaElementFinder createFinder(@NotNull JetCoreEnvironment environment) throws IOException {
|
||||
// We need to resolve all the files in order too fill in the trace that sits inside LightClassGenerationSupport
|
||||
JetTestUtils.resolveAllKotlinFiles(environment);
|
||||
|
||||
return JavaElementFinder.getInstance(environment.getProject());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doMultiFileTest(File file, Map<String, ModuleAndDependencies> modules, List<Void> files) throws IOException {
|
||||
String text = FileUtil.loadFile(file, true);
|
||||
Matcher matcher = SUBJECT_FQ_NAME_PATTERN.matcher(text);
|
||||
assertTrue("No FqName specified. First line of the form '// f.q.Name' expected", matcher.find());
|
||||
String fqName = matcher.group(1);
|
||||
|
||||
JavaElementFinder finder = createFinder(getEnvironment());
|
||||
|
||||
PsiClass psiClass = finder.findClass(fqName, GlobalSearchScope.allScope(getEnvironment().getProject()));
|
||||
if (!(psiClass instanceof KotlinLightClass)) {
|
||||
throw new IllegalStateException("Not a light class: " + psiClass + " (" + fqName + ")");
|
||||
}
|
||||
|
||||
PsiClass delegate = ((KotlinLightClass) psiClass).getDelegate();
|
||||
if (!(delegate instanceof ClsElementImpl)) {
|
||||
throw new IllegalStateException("Not a CLS element: " + delegate);
|
||||
}
|
||||
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
((ClsElementImpl) delegate).appendMirrorText(0, buffer);
|
||||
String actual = buffer.toString();
|
||||
|
||||
JetTestUtils.assertEqualsToFile(JetTestUtils.replaceExtension(file, "java"), actual);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void createTestModule(@NotNull String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void createTestFile(Void module, String fileName, String text, Map<String, String> directives) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.kotlin.asJava;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class JavaElementFinderTest extends KotlinAsJavaTestBase {
|
||||
|
||||
@Override
|
||||
protected List<File> getKotlinSourceRoots() {
|
||||
return Collections.singletonList(
|
||||
new File("compiler/testData/asJava/findClasses/" + getTestName(false) + ".kt")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
finder = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testFromEnumEntry() {
|
||||
assertClass("Direction");
|
||||
assertNoClass("Direction.NORTH");
|
||||
assertNoClass("Direction.SOUTH");
|
||||
assertNoClass("Direction.WEST");
|
||||
// TODO: assertClass("Direction.SOUTH.Hello");
|
||||
// TODO: assertClass("Direction.WEST.Some");
|
||||
}
|
||||
|
||||
private void assertClass(String qualifiedName) {
|
||||
PsiClass psiClass = finder.findClass(qualifiedName, GlobalSearchScope.allScope(getProject()));
|
||||
assertNotNull(String.format("Class with fqn='%s' wasn't found.", qualifiedName), psiClass);
|
||||
assertTrue(String.format("Class with fqn='%s' is not valid.", qualifiedName), psiClass.isValid());
|
||||
}
|
||||
|
||||
private void assertNoClass(String qualifiedName) {
|
||||
assertNull(String.format("Class with fqn='%s' isn't expected to be found.", qualifiedName),
|
||||
finder.findClass(qualifiedName, GlobalSearchScope.allScope(getProject())));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.kotlin.asJava;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.config.CommonConfigurationKeys;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.KotlinTestWithEnvironment;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class KotlinAsJavaTestBase extends KotlinTestWithEnvironment {
|
||||
protected JavaElementFinder finder;
|
||||
|
||||
@Override
|
||||
protected JetCoreEnvironment createEnvironment() {
|
||||
CompilerConfiguration configuration = new CompilerConfiguration();
|
||||
|
||||
for (File root : getKotlinSourceRoots()) {
|
||||
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, root.getPath());
|
||||
}
|
||||
|
||||
extraConfiguration(configuration);
|
||||
|
||||
return JetCoreEnvironment.createForTests(getTestRootDisposable(), configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
|
||||
}
|
||||
|
||||
protected void extraConfiguration(@NotNull CompilerConfiguration configuration) {
|
||||
}
|
||||
|
||||
protected abstract List<File> getKotlinSourceRoots();
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
finder = AbstractKotlinLightClassTest.createFinder(getEnvironment());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
finder = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.kotlin.asJava;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import junit.framework.ComparisonFailure;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class KotlinLightClassCoherenceTest extends KotlinAsJavaTestBase {
|
||||
|
||||
@Override
|
||||
protected List<File> getKotlinSourceRoots() {
|
||||
return Lists.newArrayList(
|
||||
new File("compiler/testData/asJava/lightClassStructure/Declared.kt"),
|
||||
new File("compiler/testData/asJava/lightClassStructure/Package.kt"),
|
||||
new File("compiler/testData/asJava/lightClassStructure/ClassObject.kt")
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected PsiClass doTest() {
|
||||
return doTest("test." + getTestName(false));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected PsiClass doTest(String qualifiedName) {
|
||||
KotlinLightClass psiClass = (KotlinLightClass) finder.findClass(qualifiedName, GlobalSearchScope.allScope(getProject()));
|
||||
assertNotNull("Class not found: " + qualifiedName, psiClass);
|
||||
|
||||
Asserter asserter = new Asserter();
|
||||
|
||||
asserter.assertModifiersCoherent(psiClass);
|
||||
|
||||
asserter.assertPropertyCoherent(psiClass, "isInterface");
|
||||
asserter.assertPropertyCoherent(psiClass, "isAnnotationType");
|
||||
asserter.assertPropertyCoherent(psiClass, "isEnum");
|
||||
asserter.assertPropertyCoherent(psiClass, "hasTypeParameters");
|
||||
asserter.assertPropertyCoherent(psiClass, "isDeprecated");
|
||||
|
||||
asserter.reportFailures();
|
||||
|
||||
return psiClass;
|
||||
}
|
||||
|
||||
static class Asserter {
|
||||
private final List<ComparisonFailure> failures = Lists.newArrayList();
|
||||
|
||||
private void assertEquals(String message, Object expected, Object actual) {
|
||||
if (!Comparing.equal(expected, actual)) {
|
||||
failures.add(new ComparisonFailure(message, String.valueOf(expected), String.valueOf(actual)));
|
||||
}
|
||||
}
|
||||
|
||||
public void assertModifiersCoherent(KotlinLightClass lightClass) {
|
||||
PsiClass delegate = lightClass.getDelegate();
|
||||
for (String modifier : PsiModifier.MODIFIERS) {
|
||||
assertEquals("Incoherent modifier: " + modifier,
|
||||
delegate.hasModifierProperty(modifier),
|
||||
lightClass.hasModifierProperty(modifier));
|
||||
}
|
||||
}
|
||||
|
||||
public void assertPropertyCoherent(KotlinLightClass lightClass, String methodName) {
|
||||
Class<?> reflect = PsiClass.class;
|
||||
try {
|
||||
Method method = reflect.getMethod(methodName);
|
||||
Object lightResult = method.invoke(lightClass);
|
||||
Object delegateResult = method.invoke(lightClass.getDelegate());
|
||||
assertEquals("Result of method " + methodName + "() differs in light class and its delegate", delegateResult, lightResult);
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void reportFailures() {
|
||||
if (failures.size() == 1) {
|
||||
throw failures.get(0);
|
||||
}
|
||||
if (!failures.isEmpty()) {
|
||||
StringBuilder builder = new StringBuilder("\n");
|
||||
for (ComparisonFailure failure : failures) {
|
||||
builder.append(failure.getMessage()).append("\n");
|
||||
}
|
||||
fail(builder.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testPackage() throws Exception {
|
||||
doTest("test.TestPackage");
|
||||
}
|
||||
|
||||
public void testNoModifiers() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testPublic() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testPrivate() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInternal() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNestedPublic() throws Exception {
|
||||
doTest("test.Outer.Public");
|
||||
}
|
||||
|
||||
public void testNestedProtected() throws Exception {
|
||||
doTest("test.Outer.Protected");
|
||||
}
|
||||
|
||||
public void testNestedInternal() throws Exception {
|
||||
doTest("test.Outer.Internal");
|
||||
}
|
||||
|
||||
public void testNestedPrivate() throws Exception {
|
||||
doTest("test.Outer.Private");
|
||||
}
|
||||
|
||||
public void testInner() throws Exception {
|
||||
doTest("test.Outer.Inner");
|
||||
}
|
||||
|
||||
public void testAbstract() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testOpen() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testFinal() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAnnotation() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testEnum() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTrait() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDeprecated() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDeprecatedFQN() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDeprecatedFQNSpaces() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDeprecatedWithBrackets() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDeprecatedWithBracketsFQN() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDeprecatedWithBracketsFQNSpaces() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testClassObject() throws Exception {
|
||||
doTest("test.WithClassObject.object");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,318 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.kotlin.asJava;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.cli.jvm.JVMConfigurationKeys.CLASSPATH_KEY;
|
||||
import static org.jetbrains.kotlin.asJava.KotlinLightClassStructureTest.ClassProperty.*;
|
||||
|
||||
@SuppressWarnings("JUnitTestClassNamingConvention")
|
||||
public abstract class KotlinLightClassStructureTest extends KotlinAsJavaTestBase {
|
||||
|
||||
public static class Declared extends KotlinLightClassStructureTest {
|
||||
|
||||
@Override
|
||||
protected List<File> getKotlinSourceRoots() {
|
||||
return Collections.singletonList(
|
||||
new File("compiler/testData/asJava/lightClassStructure/Declared.kt")
|
||||
);
|
||||
}
|
||||
|
||||
public void testNoModifiers() {
|
||||
checkModifiers("test.NoModifiers", PUBLIC, FINAL);
|
||||
}
|
||||
|
||||
public void testTopLevelVisibilities() {
|
||||
checkModifiers("test.Public", PUBLIC, FINAL);
|
||||
checkModifiers("test.Private", PUBLIC, FINAL);
|
||||
checkModifiers("test.Internal", PUBLIC, FINAL);
|
||||
}
|
||||
|
||||
public void testNestedVisibilities() {
|
||||
checkModifiers("test.Outer.Public", PUBLIC, STATIC, FINAL, NESTED);
|
||||
checkModifiers("test.Outer.Protected", PROTECTED, STATIC, FINAL, NESTED);
|
||||
checkModifiers("test.Outer.Internal", PUBLIC, STATIC, FINAL, NESTED);
|
||||
checkModifiers("test.Outer.Private", PRIVATE, STATIC, FINAL, NESTED);
|
||||
|
||||
checkModifiers("test.Outer.Inner", PUBLIC, FINAL, NESTED);
|
||||
}
|
||||
public void testModalities() {
|
||||
checkModifiers("test.Abstract", PUBLIC, ABSTRACT);
|
||||
checkModifiers("test.Open", PUBLIC);
|
||||
checkModifiers("test.Final", PUBLIC, FINAL);
|
||||
}
|
||||
|
||||
public void testAnnotation() {
|
||||
checkModifiers("test.Annotation", PUBLIC, ANNOTATION, ABSTRACT, INTERFACE);
|
||||
}
|
||||
|
||||
public void testEnum() {
|
||||
checkModifiers("test.Enum", PUBLIC, ENUM);
|
||||
}
|
||||
|
||||
public void testTrait() {
|
||||
checkModifiers("test.Trait", PUBLIC, ABSTRACT, INTERFACE);
|
||||
}
|
||||
|
||||
public void testDeprecation() {
|
||||
checkModifiers("test.Deprecated", PUBLIC, FINAL, DEPRECATED);
|
||||
checkModifiers("test.DeprecatedFQN", PUBLIC, FINAL, DEPRECATED);
|
||||
checkModifiers("test.DeprecatedFQNSpaces", PUBLIC, FINAL, DEPRECATED);
|
||||
checkModifiers("test.DeprecatedWithBrackets", PUBLIC, FINAL, DEPRECATED);
|
||||
checkModifiers("test.DeprecatedWithBracketsFQN", PUBLIC, FINAL, DEPRECATED);
|
||||
checkModifiers("test.DeprecatedWithBracketsFQNSpaces", PUBLIC, FINAL, DEPRECATED);
|
||||
}
|
||||
|
||||
public void testGenericity() {
|
||||
checkModifiers("test.Generic1", PUBLIC, FINAL, GENERIC);
|
||||
checkModifiers("test.Generic2", PUBLIC, FINAL, GENERIC);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DeclaredWithGenerics extends KotlinLightClassStructureTest {
|
||||
|
||||
@Override
|
||||
protected List<File> getKotlinSourceRoots() {
|
||||
return Collections.singletonList(
|
||||
new File("compiler/testData/asJava/lightClassStructure/DeclaredWithGenerics.kt")
|
||||
);
|
||||
}
|
||||
|
||||
public void testGeneric1() throws Exception {
|
||||
checkClassGenericParameter("test.Generic1", 0, "T");
|
||||
}
|
||||
|
||||
public void testGeneric1WithBounds() throws Exception {
|
||||
checkClassGenericParameter("test.Generic1WithBounds", 0, "T", "test.Bound1");
|
||||
}
|
||||
|
||||
public void testGeneric2() throws Exception {
|
||||
checkClassGenericParameter("test.Generic2", 0, "A");
|
||||
checkClassGenericParameter("test.Generic2", 1, "B");
|
||||
}
|
||||
|
||||
public void testGeneric2WithBounds() throws Exception {
|
||||
checkClassGenericParameter("test.Generic2WithBounds", 0, "A", "test.Bound1", "test.Bound2");
|
||||
checkClassGenericParameter("test.Generic2WithBounds", 1, "B", "test.Generic1<A>");
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlatformStaticMethodsWithGenerics extends KotlinLightClassStructureTest {
|
||||
@Override
|
||||
protected List<File> getKotlinSourceRoots() {
|
||||
return Collections.singletonList(
|
||||
new File("compiler/testData/asJava/lightClassStructure/PlatformStaticMethodsGenerics.kt")
|
||||
);
|
||||
}
|
||||
|
||||
public void testInClassObjectSynthetic() throws Exception {
|
||||
checkMethodGenericParameter("test.PlatformStaticClass", "inClassObject", 0, "T");
|
||||
}
|
||||
|
||||
public void testInClassObjectActual() throws Exception {
|
||||
checkMethodGenericParameter("test.PlatformStaticClass.object", "inClassObject", 0, "T");
|
||||
}
|
||||
|
||||
public void testInClass() throws Exception {
|
||||
checkMethodGenericParameter("test.PlatformStaticClass", "inClass", 0, "T");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void extraConfiguration(@NotNull CompilerConfiguration configuration) {
|
||||
configuration.add(CLASSPATH_KEY, ForTestCompileRuntime.runtimeJarForTests());
|
||||
}
|
||||
}
|
||||
|
||||
public static class Package extends KotlinLightClassStructureTest {
|
||||
|
||||
@Override
|
||||
protected List<File> getKotlinSourceRoots() {
|
||||
return Collections.singletonList(
|
||||
new File("compiler/testData/asJava/lightClassStructure/Package.kt")
|
||||
);
|
||||
}
|
||||
|
||||
public void testPackage() throws Exception {
|
||||
checkModifiers("test.TestPackage", PUBLIC, FINAL);
|
||||
}
|
||||
}
|
||||
|
||||
public static class CodeWithErrors extends KotlinLightClassStructureTest {
|
||||
@Override
|
||||
protected List<File> getKotlinSourceRoots() {
|
||||
return Collections.singletonList(new File("compiler/testData/asJava/lightClassStructure/CodeWithErrors.kt"));
|
||||
}
|
||||
|
||||
public void testClassWithErrors() {
|
||||
assertTrue(findMethodsOfClass("test.C").length == 2);
|
||||
}
|
||||
|
||||
public void testPackageWithErrors() {
|
||||
assertTrue(findMethodsOfClass("test.TestPackage").length == 1);
|
||||
}
|
||||
|
||||
private PsiMethod[] findMethodsOfClass(String qualifiedName) {
|
||||
return findClass(qualifiedName).getMethods();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected PsiClass findClass(String qualifiedName) {
|
||||
PsiClass psiClass = finder.findClass(qualifiedName, GlobalSearchScope.allScope(getProject()));
|
||||
assertNotNull(psiClass);
|
||||
|
||||
assertEquals("Wrong fqn", qualifiedName, psiClass.getQualifiedName());
|
||||
|
||||
return psiClass;
|
||||
}
|
||||
|
||||
protected static void checkModifiers(PsiClass psiClass, ClassProperty... properties) {
|
||||
Set<ClassProperty> modifiersSet = Sets.newHashSet(properties);
|
||||
for (ClassProperty property : values()) {
|
||||
boolean present = property.present(psiClass);
|
||||
if (modifiersSet.contains(property)) {
|
||||
assertTrue("Property " + property + " not present on " + psiClass, present);
|
||||
}
|
||||
else {
|
||||
assertFalse("Property " + property + " must not be present on " + psiClass, present);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkModifiers(String classFqName, ClassProperty... properties) {
|
||||
checkModifiers(findClass(classFqName), properties);
|
||||
}
|
||||
|
||||
protected void checkClassGenericParameter(String classFqName, int index, String name, String... bounds) {
|
||||
checkGenericParameter(findClass(classFqName).getTypeParameters()[index], index, name, bounds);
|
||||
}
|
||||
|
||||
protected void checkMethodGenericParameter(String classFqName, String methodName, int index, String name, String... bounds) {
|
||||
PsiClass aClass = findClass(classFqName);
|
||||
|
||||
PsiMethod method = null;
|
||||
for (PsiMethod psiMethod : aClass.getMethods()) {
|
||||
if (methodName.equals(psiMethod.getName())) {
|
||||
assertNull(String.format("Several methods with name '%s' found in class '%s'", methodName, classFqName), method);
|
||||
method = psiMethod;
|
||||
}
|
||||
}
|
||||
|
||||
assertNotNull(String.format("Methods name '%s' wasn't found in class '%s'", methodName, classFqName), method);
|
||||
|
||||
checkGenericParameter(method.getTypeParameters()[index], index, name, bounds);
|
||||
}
|
||||
|
||||
protected static void checkGenericParameter(PsiTypeParameter typeParameter, int index, String name, String[] bounds) {
|
||||
assertEquals(name, typeParameter.getName());
|
||||
assertEquals(index, typeParameter.getIndex());
|
||||
Set<String> expectedBounds = Sets.newHashSet(bounds);
|
||||
Set<String> actualBounds = Sets.newHashSet(Collections2.transform(
|
||||
Arrays.asList(typeParameter.getExtendsListTypes()),
|
||||
new Function<PsiClassType, String>() {
|
||||
@Override
|
||||
public String apply(PsiClassType input) {
|
||||
return input.getCanonicalText();
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
assertEquals(expectedBounds, actualBounds);
|
||||
}
|
||||
|
||||
enum ClassProperty {
|
||||
PUBLIC(PsiModifier.PUBLIC),
|
||||
PROTECTED(PsiModifier.PROTECTED),
|
||||
PRIVATE(PsiModifier.PRIVATE),
|
||||
STATIC(PsiModifier.STATIC),
|
||||
ABSTRACT(PsiModifier.ABSTRACT),
|
||||
FINAL(PsiModifier.FINAL),
|
||||
NATIVE(PsiModifier.NATIVE),
|
||||
SYNCHRONIZED(PsiModifier.SYNCHRONIZED),
|
||||
STRICTFP(PsiModifier.STRICTFP),
|
||||
TRANSIENT(PsiModifier.TRANSIENT),
|
||||
VOLATILE(PsiModifier.VOLATILE),
|
||||
DEFAULT(PsiModifier.DEFAULT),
|
||||
INTERFACE {
|
||||
@Override
|
||||
public boolean present(@NotNull PsiClass psiClass) {
|
||||
return psiClass.isInterface();
|
||||
}
|
||||
},
|
||||
ENUM {
|
||||
@Override
|
||||
public boolean present(@NotNull PsiClass psiClass) {
|
||||
return psiClass.isEnum();
|
||||
}
|
||||
},
|
||||
ANNOTATION {
|
||||
@Override
|
||||
public boolean present(@NotNull PsiClass psiClass) {
|
||||
return psiClass.isAnnotationType();
|
||||
}
|
||||
},
|
||||
DEPRECATED {
|
||||
@Override
|
||||
public boolean present(@NotNull PsiClass psiClass) {
|
||||
return psiClass.isDeprecated();
|
||||
}
|
||||
},
|
||||
NESTED {
|
||||
@Override
|
||||
public boolean present(@NotNull PsiClass psiClass) {
|
||||
return psiClass.getContainingClass() != null;
|
||||
}
|
||||
},
|
||||
GENERIC {
|
||||
@Override
|
||||
public boolean present(@NotNull PsiClass psiClass) {
|
||||
return psiClass.hasTypeParameters();
|
||||
}
|
||||
};
|
||||
|
||||
private final String modifier;
|
||||
|
||||
private ClassProperty(@Nullable String modifier) {
|
||||
this.modifier = modifier;
|
||||
}
|
||||
|
||||
private ClassProperty() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public boolean present(@NotNull PsiClass psiClass) {
|
||||
assert modifier != null : "No modifier specified for " + this + ". Override this method.";
|
||||
return psiClass.hasModifierProperty(modifier);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.kotlin.asJava;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.jet.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("compiler/testData/asJava/lightClasses")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@InnerTestClasses({KotlinLightClassTestGenerated.Delegation.class, KotlinLightClassTestGenerated.NullabilityAnnotations.class})
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class KotlinLightClassTestGenerated extends AbstractKotlinLightClassTest {
|
||||
public void testAllFilesPresentInLightClasses() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/asJava/lightClasses/delegation")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Delegation extends AbstractKotlinLightClassTest {
|
||||
public void testAllFilesPresentInDelegation() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/delegation"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("ExternalAnnotations.kt")
|
||||
public void testExternalAnnotations() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/delegation/ExternalAnnotations.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Function.kt")
|
||||
public void testFunction() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/delegation/Function.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Property.kt")
|
||||
public void testProperty() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/delegation/Property.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("WithPlatformTypes.kt")
|
||||
public void testWithPlatformTypes() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/delegation/WithPlatformTypes.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class NullabilityAnnotations extends AbstractKotlinLightClassTest {
|
||||
public void testAllFilesPresentInNullabilityAnnotations() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/nullabilityAnnotations"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("Class.kt")
|
||||
public void testClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/Class.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ClassObjectField.kt")
|
||||
public void testClassObjectField() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/ClassObjectField.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ClassWithConstructor.kt")
|
||||
public void testClassWithConstructor() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/ClassWithConstructor.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ClassWithConstructorAndProperties.kt")
|
||||
public void testClassWithConstructorAndProperties() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/ClassWithConstructorAndProperties.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Generic.kt")
|
||||
public void testGeneric() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/Generic.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("IntOverridesAny.kt")
|
||||
public void testIntOverridesAny() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/IntOverridesAny.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NullableUnitReturn.kt")
|
||||
public void testNullableUnitReturn() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/NullableUnitReturn.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("OverrideAnyWithUnit.kt")
|
||||
public void testOverrideAnyWithUnit() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/OverrideAnyWithUnit.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PlatformTypes.kt")
|
||||
public void testPlatformTypes() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/PlatformTypes.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Primitives.kt")
|
||||
public void testPrimitives() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/Primitives.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PrivateInClass.kt")
|
||||
public void testPrivateInClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/PrivateInClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PrivateInTrait.kt")
|
||||
public void testPrivateInTrait() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/PrivateInTrait.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Synthetic.kt")
|
||||
public void testSynthetic() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/Synthetic.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Trait.kt")
|
||||
public void testTrait() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/Trait.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("TraitClassObjectField.kt")
|
||||
public void testTraitClassObjectField() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/TraitClassObjectField.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("UnitAsGenericArgument.kt")
|
||||
public void testUnitAsGenericArgument() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/UnitAsGenericArgument.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("UnitParameter.kt")
|
||||
public void testUnitParameter() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/UnitParameter.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("VoidReturn.kt")
|
||||
public void testVoidReturn() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/VoidReturn.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("_DefaultPackage.kt")
|
||||
public void test_DefaultPackage() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/_DefaultPackage.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.kotlin.asJava;
|
||||
|
||||
import com.intellij.psi.PsiAnnotation;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiModifierList;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class LightClassAnnotationsTest extends KotlinAsJavaTestBase {
|
||||
private final File testDir = new File("compiler/testData/asJava/annotations");
|
||||
|
||||
@Override
|
||||
protected List<File> getKotlinSourceRoots() {
|
||||
return Collections.singletonList(new File(testDir, getTestName(false) + ".kt"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void extraConfiguration(@NotNull CompilerConfiguration configuration) {
|
||||
configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, JetTestUtils.getAnnotationsJar());
|
||||
}
|
||||
|
||||
public void testExtraAnnotations() throws Exception {
|
||||
doTest(getTestName(false));
|
||||
}
|
||||
|
||||
public void testNestedClass() throws Exception {
|
||||
doTest("Outer.Nested");
|
||||
}
|
||||
|
||||
private void doTest(@NotNull String fqName) {
|
||||
PsiClass psiClass = finder.findClass(fqName, GlobalSearchScope.allScope(getProject()));
|
||||
if (!(psiClass instanceof KotlinLightClass)) {
|
||||
throw new IllegalStateException("Not a light class: " + psiClass + " (" + fqName + ")");
|
||||
}
|
||||
|
||||
PsiModifierList modifierList = psiClass.getModifierList();
|
||||
assert modifierList != null : "No modifier list for " + psiClass.getText();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (PsiAnnotation annotation : modifierList.getAnnotations()) {
|
||||
sb.append(annotation.getText()).append("\n");
|
||||
}
|
||||
|
||||
JetTestUtils.assertEqualsToFile(new File(testDir, getTestName(false) + ".annotations.txt"), sb.toString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user