Move util methods from K2JSTranslator to FacadeUtils class
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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.k2js.facade;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public class FacadeUtils {
|
||||
|
||||
private FacadeUtils() {
|
||||
}
|
||||
|
||||
public static void writeCodeToFile(@NotNull String outputPath, @NotNull String programCode) throws IOException {
|
||||
File file = new File(outputPath);
|
||||
FileUtil.createParentDirs(file);
|
||||
FileWriter writer = new FileWriter(file);
|
||||
try {
|
||||
writer.write(programCode);
|
||||
}
|
||||
finally {
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<String> parseString(@NotNull String argumentString) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
StringTokenizer stringTokenizer = new StringTokenizer(argumentString);
|
||||
while (stringTokenizer.hasMoreTokens()) {
|
||||
result.add(stringTokenizer.nextToken());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,6 @@ package org.jetbrains.k2js.facade;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.dart.compiler.backend.js.ast.JsProgram;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
@@ -31,10 +30,12 @@ import org.jetbrains.k2js.generate.CodeGenerator;
|
||||
import org.jetbrains.k2js.translate.general.Translation;
|
||||
import org.jetbrains.k2js.utils.JetFileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.k2js.facade.FacadeUtils.parseString;
|
||||
import static org.jetbrains.k2js.facade.FacadeUtils.writeCodeToFile;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
@@ -51,18 +52,6 @@ public final class K2JSTranslator {
|
||||
writeCodeToFile(outputPath, programCode);
|
||||
}
|
||||
|
||||
private static void writeCodeToFile(@NotNull String outputPath, @NotNull String programCode) throws IOException {
|
||||
File file = new File(outputPath);
|
||||
FileUtil.createParentDirs(file);
|
||||
FileWriter writer = new FileWriter(file);
|
||||
try {
|
||||
writer.write(programCode);
|
||||
}
|
||||
finally {
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final Config config;
|
||||
|
||||
@@ -107,17 +96,6 @@ public final class K2JSTranslator {
|
||||
return Translation.generateAst(bindingContext, Lists.newArrayList(files), mainCallParameters, config.getTarget());
|
||||
}
|
||||
|
||||
//TODO: util
|
||||
@NotNull
|
||||
private static List<String> parseString(@NotNull String argumentString) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
StringTokenizer stringTokenizer = new StringTokenizer(argumentString);
|
||||
while (stringTokenizer.hasMoreTokens()) {
|
||||
result.add(stringTokenizer.nextToken());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Project getProject() {
|
||||
return config.getProject();
|
||||
|
||||
Reference in New Issue
Block a user