|
|
|
@@ -24,8 +24,7 @@ import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
import org.jetbrains.jet.asJava.KotlinLightClass;
|
|
|
|
|
import org.jetbrains.jet.asJava.LightClassUtil;
|
|
|
|
|
import org.jetbrains.jet.lang.psi.JetClass;
|
|
|
|
|
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
|
|
|
|
import org.jetbrains.jet.lang.psi.*;
|
|
|
|
|
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
|
|
|
|
import org.jetbrains.jet.plugin.JetLightProjectDescriptor;
|
|
|
|
|
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
|
|
|
@@ -99,6 +98,30 @@ public class JetJavaFacadeTest extends LightCodeInsightFixtureTestCase {
|
|
|
|
|
doTestWrapMethod(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testWrapValTopLevelProperty() {
|
|
|
|
|
doTestWrapProperty(true, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testWrapVarPropertyInClass() {
|
|
|
|
|
doTestWrapProperty(true, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testWrapVarPropertyWithAccessorsInTrait() {
|
|
|
|
|
doTestWrapProperty(true, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testWrapVarTopLevelProperty() {
|
|
|
|
|
doTestWrapProperty(true, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testWrapVarPropertyInLocalClass() {
|
|
|
|
|
doTestWrapProperty(false, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testWrapVarTopLevelAccessor() {
|
|
|
|
|
doTestWrapPropertyAccessor(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testEa38770() {
|
|
|
|
|
myFixture.configureByFile(getTestName(true) + ".kt");
|
|
|
|
|
|
|
|
|
@@ -166,6 +189,37 @@ public class JetJavaFacadeTest extends LightCodeInsightFixtureTestCase {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void doTestWrapMethod(boolean shouldBeWrapped) {
|
|
|
|
|
JetNamedFunction jetFunction = getPreparedElement(JetNamedFunction.class);
|
|
|
|
|
|
|
|
|
|
// Should not fail!
|
|
|
|
|
PsiMethod psiMethod = LightClassUtil.getLightClassMethod(jetFunction);
|
|
|
|
|
|
|
|
|
|
checkDeclarationMethodWrapped(shouldBeWrapped, jetFunction, psiMethod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void doTestWrapProperty(boolean shouldWrapGetter, boolean shouldWrapSetter) {
|
|
|
|
|
JetProperty jetProperty = getPreparedElement(JetProperty.class);
|
|
|
|
|
|
|
|
|
|
// Should not fail!
|
|
|
|
|
LightClassUtil.PropertyAccessorsPsiMethods propertyAccessors = LightClassUtil.getLightClassPropertyMethods(jetProperty);
|
|
|
|
|
|
|
|
|
|
JetPropertyAccessor getter = jetProperty.getGetter();
|
|
|
|
|
JetPropertyAccessor setter = jetProperty.getSetter();
|
|
|
|
|
|
|
|
|
|
checkDeclarationMethodWrapped(shouldWrapGetter, getter != null ? getter : jetProperty, propertyAccessors.getGetter());
|
|
|
|
|
checkDeclarationMethodWrapped(shouldWrapSetter, setter != null ? setter : jetProperty, propertyAccessors.getSetter());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void doTestWrapPropertyAccessor(boolean shouldWrapAccessor) {
|
|
|
|
|
JetPropertyAccessor jetPropertyAccessor = getPreparedElement(JetPropertyAccessor.class);
|
|
|
|
|
|
|
|
|
|
// Should not fail!
|
|
|
|
|
PsiMethod propertyAccessors = LightClassUtil.getLightClassAccessorMethod(jetPropertyAccessor);
|
|
|
|
|
checkDeclarationMethodWrapped(shouldWrapAccessor, jetPropertyAccessor, propertyAccessors);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@NotNull
|
|
|
|
|
private <T extends JetElement> T getPreparedElement(Class<T> elementClass) {
|
|
|
|
|
myFixture.configureByFile(getTestName(true) + ".kt");
|
|
|
|
|
|
|
|
|
|
int offset = myFixture.getEditor().getCaretModel().getOffset();
|
|
|
|
@@ -173,16 +227,20 @@ public class JetJavaFacadeTest extends LightCodeInsightFixtureTestCase {
|
|
|
|
|
|
|
|
|
|
assertNotNull("Caret should be set for tested file", elementAt);
|
|
|
|
|
|
|
|
|
|
JetNamedFunction jetFunction = PsiTreeUtil.getParentOfType(elementAt, JetNamedFunction.class);
|
|
|
|
|
assertNotNull("Caret should be placed to function definition", jetFunction);
|
|
|
|
|
T caretElement = PsiTreeUtil.getParentOfType(elementAt, elementClass);
|
|
|
|
|
assertNotNull(
|
|
|
|
|
String.format("Caret should be placed to element of type: %s, but was at element '%s' of type %s",
|
|
|
|
|
elementClass, elementAt, elementAt.getClass()),
|
|
|
|
|
caretElement);
|
|
|
|
|
|
|
|
|
|
// Should not fail!
|
|
|
|
|
PsiMethod psiMethod = LightClassUtil.getLightClassMethod(jetFunction);
|
|
|
|
|
return caretElement;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void checkDeclarationMethodWrapped(boolean shouldBeWrapped, JetDeclaration declaration, PsiMethod psiMethod) {
|
|
|
|
|
if (shouldBeWrapped) {
|
|
|
|
|
assertNotNull(String.format("Failed to wrap jetFunction '%s' to method", jetFunction.getText()), psiMethod);
|
|
|
|
|
assertNotNull(String.format("Failed to wrap declaration '%s' to method", declaration.getText()), psiMethod);
|
|
|
|
|
assertInstanceOf(psiMethod, PsiCompiledElement.class);
|
|
|
|
|
assertEquals("Invalid original element for generated method", ((PsiCompiledElement) psiMethod).getMirror(), jetFunction);
|
|
|
|
|
assertEquals("Invalid original element for generated method", ((PsiCompiledElement) psiMethod).getMirror(), declaration);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
assertNull("There should be no wrapper for given method", psiMethod);
|
|
|
|
|