Let test run
This commit is contained in:
parent
e1603619fd
commit
32a997148e
5 changed files with 56 additions and 48 deletions
|
@ -1,5 +0,0 @@
|
||||||
package net.osmand.translator;
|
|
||||||
|
|
||||||
public class TranslatorMain {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +1,11 @@
|
||||||
package net.osmand.translator.handlers;
|
package net.osmand.translator.handlers;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
|
||||||
import net.osmand.translator.utils.FieldsHandler;
|
import net.osmand.translator.utils.FieldsHandler;
|
||||||
import net.osmand.translator.utils.MethodHandler;
|
import net.osmand.translator.utils.MethodHandler;
|
||||||
|
|
||||||
|
@ -10,6 +16,7 @@ import org.eclipse.core.resources.IWorkspaceRoot;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.jdt.core.ICompilationUnit;
|
import org.eclipse.jdt.core.ICompilationUnit;
|
||||||
import org.eclipse.jdt.core.IJavaProject;
|
import org.eclipse.jdt.core.IJavaProject;
|
||||||
import org.eclipse.jdt.core.IMethod;
|
import org.eclipse.jdt.core.IMethod;
|
||||||
|
@ -22,45 +29,40 @@ import org.eclipse.jdt.core.dom.AST;
|
||||||
import org.eclipse.jdt.core.dom.ASTParser;
|
import org.eclipse.jdt.core.dom.ASTParser;
|
||||||
import org.eclipse.jdt.core.dom.CompilationUnit;
|
import org.eclipse.jdt.core.dom.CompilationUnit;
|
||||||
import org.eclipse.jface.text.Document;
|
import org.eclipse.jface.text.Document;
|
||||||
//import org.eclipse.jface.text.Document;
|
|
||||||
|
|
||||||
public class TranslationHandler {
|
public class TranslationHandler {
|
||||||
|
|
||||||
public static void execute() {
|
public static void execute(String inFile, PrintStream out) throws IOException {
|
||||||
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
|
||||||
IWorkspaceRoot root = workspace.getRoot();
|
|
||||||
IPath path = root.getProject("DataExtactionOSM").getFile("src/net/osmand/osm/MapUtils.java").getFullPath();
|
|
||||||
// parse "MapUtils.java"
|
// parse "MapUtils.java"
|
||||||
// IPath path = Path.fromOSString("/DataExtractionOSM/src/net/osmand/osm/MapUtils.java");
|
BufferedReader fr = new BufferedReader(new FileReader(new File(inFile)));
|
||||||
IFile iFile = root.getFileForLocation(path);
|
String readLine;
|
||||||
ICompilationUnit unit = (ICompilationUnit) JavaCore.create(iFile);
|
String buf = "";
|
||||||
CompilationUnit parse = parse(unit);
|
while ((readLine = fr.readLine()) != null) {
|
||||||
FieldsHandler.printFieldsInfo(parse);
|
buf += readLine;
|
||||||
System.out.println();
|
|
||||||
MethodHandler.printMethodsInfo(parse);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static CompilationUnit parse(ICompilationUnit unit) {
|
|
||||||
ASTParser parser = ASTParser.newParser(AST.JLS3);
|
|
||||||
parser.setKind(ASTParser.K_COMPILATION_UNIT);
|
|
||||||
parser.setSource(unit);
|
|
||||||
parser.setResolveBindings(true);
|
|
||||||
return (CompilationUnit) parser.createAST(null); // parse
|
|
||||||
}
|
|
||||||
|
|
||||||
// ///////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
private void getProjects(IWorkspaceRoot root) {
|
|
||||||
IProject[] projects = root.getProjects();
|
|
||||||
for (IProject project : projects) {
|
|
||||||
try {
|
|
||||||
printProjectInfo(project);
|
|
||||||
} catch (CoreException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
fr.close();
|
||||||
|
CompilationUnit parse = parse(buf);
|
||||||
|
FieldsHandler.printFieldsInfo(parse, out);
|
||||||
|
out.println();
|
||||||
|
MethodHandler.printMethodsInfo(parse, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static CompilationUnit parse(String source) {
|
||||||
|
ASTParser parser = ASTParser.newParser(AST.JLS3);
|
||||||
|
parser.setResolveBindings(true);
|
||||||
|
// parser.setCompilerOptions(Options.getCompilerOptions());
|
||||||
|
parser.setSource(source.toCharArray());
|
||||||
|
parser.setResolveBindings(true);
|
||||||
|
// parser.setUnitName(name + ".java");
|
||||||
|
// parser.setEnvironment(new String[] { getComGoogleDevtoolsJ2objcPath() },
|
||||||
|
// new String[] { tempDir.getAbsolutePath() }, null, true);
|
||||||
|
CompilationUnit unit = (CompilationUnit) parser.createAST(null);
|
||||||
|
// assertNoCompilationErrors(unit);
|
||||||
|
return unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void printProjectInfo(IProject project) throws CoreException, JavaModelException {
|
private void printProjectInfo(IProject project) throws CoreException, JavaModelException {
|
||||||
System.out.println("Working in project " + project.getName());
|
System.out.println("Working in project " + project.getName());
|
||||||
// Check if we have a Java project
|
// Check if we have a Java project
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package net.osmand.translator.utils;
|
package net.osmand.translator.utils;
|
||||||
|
|
||||||
|
import java.io.PrintStream;
|
||||||
|
|
||||||
import net.osmand.translator.visitor.FieldVisitor;
|
import net.osmand.translator.visitor.FieldVisitor;
|
||||||
|
|
||||||
import org.eclipse.jdt.core.dom.CompilationUnit;
|
import org.eclipse.jdt.core.dom.CompilationUnit;
|
||||||
|
@ -10,7 +12,7 @@ import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
|
||||||
|
|
||||||
public class FieldsHandler extends AbstractHandler{
|
public class FieldsHandler extends AbstractHandler{
|
||||||
|
|
||||||
public static void printFieldsInfo(CompilationUnit parse) {
|
public static void printFieldsInfo(CompilationUnit parse, PrintStream out) {
|
||||||
FieldVisitor fVisitor = new FieldVisitor();
|
FieldVisitor fVisitor = new FieldVisitor();
|
||||||
parse.accept(fVisitor);
|
parse.accept(fVisitor);
|
||||||
for (FieldDeclaration field : fVisitor.getFields()) {
|
for (FieldDeclaration field : fVisitor.getFields()) {
|
||||||
|
@ -23,6 +25,9 @@ public class FieldsHandler extends AbstractHandler{
|
||||||
// type
|
// type
|
||||||
applyType(field.getType(), buffer);
|
applyType(field.getType(), buffer);
|
||||||
// name
|
// name
|
||||||
|
if(binding == null){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
buffer.append(binding.getJavaElement().getElementName());
|
buffer.append(binding.getJavaElement().getElementName());
|
||||||
// array brackets
|
// array brackets
|
||||||
if (binding.getType().isArray()) {
|
if (binding.getType().isArray()) {
|
||||||
|
@ -34,8 +39,8 @@ public class FieldsHandler extends AbstractHandler{
|
||||||
}
|
}
|
||||||
// end of string
|
// end of string
|
||||||
buffer.append(";");
|
buffer.append(";");
|
||||||
System.out.println(buffer);
|
out.println(buffer);
|
||||||
// System.out.println();
|
// out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package net.osmand.translator.utils;
|
package net.osmand.translator.utils;
|
||||||
|
|
||||||
|
import java.io.PrintStream;
|
||||||
|
|
||||||
import net.osmand.translator.visitor.MethodVisitor;
|
import net.osmand.translator.visitor.MethodVisitor;
|
||||||
|
|
||||||
import org.eclipse.jdt.core.dom.Block;
|
import org.eclipse.jdt.core.dom.Block;
|
||||||
|
@ -9,7 +11,7 @@ import org.eclipse.jdt.core.dom.Type;
|
||||||
|
|
||||||
public class MethodHandler extends AbstractHandler{
|
public class MethodHandler extends AbstractHandler{
|
||||||
|
|
||||||
public static void printMethodsInfo(CompilationUnit parse) {
|
public static void printMethodsInfo(CompilationUnit parse, PrintStream out) {
|
||||||
MethodVisitor mVisitor = new MethodVisitor();
|
MethodVisitor mVisitor = new MethodVisitor();
|
||||||
parse.accept(mVisitor);
|
parse.accept(mVisitor);
|
||||||
for (MethodDeclaration method : mVisitor.getMethods()) {
|
for (MethodDeclaration method : mVisitor.getMethods()) {
|
||||||
|
@ -29,8 +31,8 @@ public class MethodHandler extends AbstractHandler{
|
||||||
buffer.append("{");
|
buffer.append("{");
|
||||||
fillBody(method, buffer);
|
fillBody(method, buffer);
|
||||||
buffer.append("}");
|
buffer.append("}");
|
||||||
System.out.println(buffer);
|
out.println(buffer);
|
||||||
System.out.println();
|
out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,9 +41,9 @@ public class MethodHandler extends AbstractHandler{
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void fillBody(MethodDeclaration method, StringBuffer buffer) {
|
private static void fillBody(MethodDeclaration method, StringBuffer buffer) {
|
||||||
Block body = method.getBody();
|
|
||||||
|
|
||||||
System.out.println(body);
|
Block body = method.getBody();
|
||||||
|
buffer.append(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseSimpleForStatement() {
|
private void parseSimpleForStatement() {
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
package net.osmand.translator.test;
|
package net.osmand.translator.test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import net.osmand.translator.handlers.TranslationHandler;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TranslatorTest {
|
public class TranslatorTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void simpleTest(){
|
public void simpleTest() throws IOException{
|
||||||
|
TranslationHandler.execute(new File("test/resources/MapUtils.java").getAbsolutePath(), System.out);
|
||||||
System.out.println("SUCCESS !!!!! ");
|
System.out.println("SUCCESS !!!!! ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue