J2K Translator migrated onto Leda

This commit is contained in:
Andrey Breslav
2012-07-24 22:29:07 +04:00
parent cee77c3b7e
commit d8632f81aa
2 changed files with 52 additions and 47 deletions
@@ -1,21 +1,22 @@
/* /*
* Copyright 2010-2012 JetBrains s.r.o. * Copyright 2010-2012 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.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.jet.j2k; package org.jetbrains.jet.j2k;
import com.intellij.core.JavaCoreEnvironment; import com.intellij.core.JavaCoreApplicationEnvironment;
import com.intellij.core.JavaCoreProjectEnvironment;
import com.intellij.lang.java.JavaLanguage; import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.Disposable; import com.intellij.openapi.Disposable;
import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.util.text.StringUtil;
@@ -35,41 +36,45 @@ import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
/** /**
* @author ignatov * @author ignatov
*/ */
public class JavaToKotlinTranslator { public class JavaToKotlinTranslator {
private JavaToKotlinTranslator() {
} private static final Disposable DISPOSABLE = new Disposable() {
@Override
public void dispose() {
}
};
private static final Converter CONVERTER = new Converter(); private static final Converter CONVERTER = new Converter();
private JavaToKotlinTranslator() {
}
@Nullable @Nullable
private static PsiFile createFile(@NotNull String text) { private static PsiFile createFile(@NotNull String text) {
JavaCoreEnvironment javaCoreEnvironment = setUpJavaCoreEnvironment(); JavaCoreProjectEnvironment javaCoreEnvironment = setUpJavaCoreEnvironment();
return PsiFileFactory.getInstance(javaCoreEnvironment.getProject()).createFileFromText( return PsiFileFactory.getInstance(javaCoreEnvironment.getProject()).createFileFromText(
"test.java", JavaLanguage.INSTANCE, text "test.java", JavaLanguage.INSTANCE, text
); );
} }
@Nullable @Nullable
static PsiFile createFile(@NotNull JavaCoreEnvironment javaCoreEnvironment, @NotNull String text) { static PsiFile createFile(@NotNull JavaCoreProjectEnvironment javaCoreEnvironment, @NotNull String text) {
return PsiFileFactory.getInstance(javaCoreEnvironment.getProject()).createFileFromText( return PsiFileFactory.getInstance(javaCoreEnvironment.getProject()).createFileFromText(
"test.java", JavaLanguage.INSTANCE, text "test.java", JavaLanguage.INSTANCE, text
); );
} }
@NotNull @NotNull
static JavaCoreEnvironment setUpJavaCoreEnvironment() { static JavaCoreProjectEnvironment setUpJavaCoreEnvironment() {
JavaCoreEnvironment javaCoreEnvironment = new JavaCoreEnvironment(new Disposable() { JavaCoreApplicationEnvironment applicationEnvironment = new JavaCoreApplicationEnvironment(DISPOSABLE);
@Override JavaCoreProjectEnvironment javaCoreEnvironment = new JavaCoreProjectEnvironment(DISPOSABLE, applicationEnvironment);
public void dispose() {
}
});
javaCoreEnvironment.addToClasspath(findRtJar()); javaCoreEnvironment.addJarToClassPath(findRtJar());
File annotations = findAnnotations(); File annotations = findAnnotations();
if (annotations != null && annotations.exists()) { if (annotations != null && annotations.exists()) {
javaCoreEnvironment.addToClasspath(annotations); javaCoreEnvironment.addJarToClassPath(annotations);
} }
return javaCoreEnvironment; return javaCoreEnvironment;
} }
@@ -1,22 +1,22 @@
/* /*
* Copyright 2010-2012 JetBrains s.r.o. * Copyright 2010-2012 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.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.jet.j2k; package org.jetbrains.jet.j2k;
import com.intellij.core.JavaCoreEnvironment; import com.intellij.core.JavaCoreProjectEnvironment;
import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.FileUtil;
import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiJavaFile; import com.intellij.psi.PsiJavaFile;
@@ -31,13 +31,13 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
/** /**
* @author ignatov * @author ignatov
*/ */
public class StandaloneJavaToKotlinConverterTest extends TestCase { public class StandaloneJavaToKotlinConverterTest extends TestCase {
private final String myDataPath; private final String myDataPath;
private final String myName; private final String myName;
@NotNull @NotNull
private final static JavaCoreEnvironment myJavaCoreEnvironment = JavaToKotlinTranslator.setUpJavaCoreEnvironment(); private final static JavaCoreProjectEnvironment myJavaCoreEnvironment = JavaToKotlinTranslator.setUpJavaCoreEnvironment();
public StandaloneJavaToKotlinConverterTest(String dataPath, String name) { public StandaloneJavaToKotlinConverterTest(String dataPath, String name) {
myDataPath = dataPath; myDataPath = dataPath;