Conversion on copy paste:
Introduce tests for conversion on copy paste Don't insert additional end of line after each converted element (not needed since converter takes care of formatting) Add test for some of the trivial cases of conversion on copy paste
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
fun main(args: Array<String>) {
|
||||
A()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class A {
|
||||
public static void main(String[] args) {
|
||||
<selection>new A()</selection>;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun main(args: Array<String>) {
|
||||
<caret>
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import a.b.c
|
||||
import g.e.v
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<selection>import java.util.List;
|
||||
import a.b.c;
|
||||
import java.util.Set;
|
||||
import g.e.v;</selection>
|
||||
@@ -0,0 +1,5 @@
|
||||
<caret>
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import java.util.List
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<selection>import java.util.List;</selection>
|
||||
import a.b.c;
|
||||
import java.util.Set;
|
||||
import g.e.v;
|
||||
@@ -0,0 +1,5 @@
|
||||
<caret>
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fun main(args: Array<String>) {
|
||||
val buffer = getSelectedElements(code.getFile(), code.getStartOffsets(), code.getEndOffsets())
|
||||
|
||||
val project = file.getProject()
|
||||
val converter = Converter(project, J2kPackage.getPluginSettings())
|
||||
val result = StringBuilder()
|
||||
for (e in buffer)
|
||||
{
|
||||
result.append(converter.elementToKotlin(e))
|
||||
}
|
||||
|
||||
return StringUtil.convertLineSeparators(result.toString())
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
class A {
|
||||
private static String convertCopiedCodeToKotlin(CopiedCode code, PsiFile file) {
|
||||
<selection>List<PsiElement> buffer = getSelectedElements(code.getFile(), code.getStartOffsets(), code.getEndOffsets());
|
||||
|
||||
Project project = file.getProject();
|
||||
Converter converter = new Converter(project, J2kPackage.getPluginSettings());
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (PsiElement e : buffer) {
|
||||
result.append(converter.elementToKotlin(e));
|
||||
}
|
||||
|
||||
return StringUtil.convertLineSeparators(result.toString());</selection>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun main(args: Array<String>) {
|
||||
<caret>
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
class A {
|
||||
fun someOther() = false
|
||||
|
||||
private fun formatElement(var element : PsiElement) : String {
|
||||
element = JetPsiUtil.ascendIfPropertyAccessor(element)
|
||||
if (element is JetNamedFunction || element is JetProperty)
|
||||
{
|
||||
val bindingContext = AnalyzerFacadeWithCache.analyzeFileWithCache((element.getContainingFile() as JetFile)).getBindingContext()
|
||||
|
||||
val declarationDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element)
|
||||
if (declarationDescriptor is CallableMemberDescriptor)
|
||||
{
|
||||
val containingDescriptor = declarationDescriptor.getContainingDeclaration()
|
||||
if (containingDescriptor is ClassDescriptor)
|
||||
{
|
||||
return JetBundle.message("x.in.y", DescriptorRenderer.COMPACT.render(declarationDescriptor), DescriptorRenderer.SOURCE_CODE_SHORT_NAMES_IN_TYPES.render(containingDescriptor))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert(element is PsiMethod) {"Method accepts only kotlin functions/properties and java methods, but '" + element.getText() + "' was found"}
|
||||
return JetRefactoringUtil.formatPsiMethod((element as PsiMethod), true, false)
|
||||
}
|
||||
|
||||
protected fun getDimensionServiceKey() : String {
|
||||
return "#org.jetbrains.jet.plugin.refactoring.safeDelete.KotlinOverridingDialog"
|
||||
}
|
||||
|
||||
public fun getSelected() : ArrayList<UsageInfo> {
|
||||
val result = ArrayList<UsageInfo>()
|
||||
for (i in 0..myChecked.length - 1) {
|
||||
if (myChecked[i])
|
||||
{
|
||||
result.add(myOverridingMethods.get(i))
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
class A {
|
||||
<selection>private static String formatElement(PsiElement element) {
|
||||
element = JetPsiUtil.ascendIfPropertyAccessor(element);
|
||||
if (element instanceof JetNamedFunction || element instanceof JetProperty) {
|
||||
BindingContext bindingContext =
|
||||
AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) element.getContainingFile()).getBindingContext();
|
||||
|
||||
DeclarationDescriptor declarationDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element);
|
||||
if (declarationDescriptor instanceof CallableMemberDescriptor) {
|
||||
DeclarationDescriptor containingDescriptor = declarationDescriptor.getContainingDeclaration();
|
||||
if (containingDescriptor instanceof ClassDescriptor) {
|
||||
return JetBundle.message(
|
||||
"x.in.y",
|
||||
DescriptorRenderer.COMPACT.render(declarationDescriptor),
|
||||
DescriptorRenderer.SOURCE_CODE_SHORT_NAMES_IN_TYPES.render(containingDescriptor)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert element instanceof PsiMethod
|
||||
: "Method accepts only kotlin functions/properties and java methods, but '" + element.getText() + "' was found";
|
||||
return JetRefactoringUtil.formatPsiMethod((PsiMethod) element, true, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDimensionServiceKey() {
|
||||
return "#org.jetbrains.jet.plugin.refactoring.safeDelete.KotlinOverridingDialog";
|
||||
}
|
||||
|
||||
public ArrayList<UsageInfo> getSelected() {
|
||||
ArrayList<UsageInfo> result = new ArrayList<UsageInfo>();
|
||||
for (int i = 0; i < myChecked.length; i++) {
|
||||
if (myChecked[i]) {
|
||||
result.add(myOverridingMethods.get(i));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}</selection>
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class A {
|
||||
fun someOther() = false
|
||||
|
||||
<caret>
|
||||
}
|
||||
Reference in New Issue
Block a user