forked from JavaTX/JavaCompilerCore
Generate Package names in .class files
This commit is contained in:
parent
a3b4ea9b1c
commit
c82abcaae5
@ -161,7 +161,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
className = classOrInterface.getClassName();
|
className = classOrInterface.getClassName();
|
||||||
|
|
||||||
cw.visitSource(className + ".jav", null);
|
cw.visitSource(className.getClassName() + ".jav", null);
|
||||||
|
|
||||||
isInterface = (classOrInterface.getModifiers() & 512) == 512;
|
isInterface = (classOrInterface.getModifiers() & 512) == 512;
|
||||||
|
|
||||||
@ -200,7 +200,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
System.out.println("Signature: => " + sig);
|
System.out.println("Signature: => " + sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
cw.visit(Opcodes.V1_8, acc, classOrInterface.getClassName().toString(), sig,
|
cw.visit(Opcodes.V1_8, acc, classOrInterface.getClassName().toString().replace(".", "/"), sig,
|
||||||
classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()), null);
|
classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()), null);
|
||||||
|
|
||||||
isVisited = true;
|
isVisited = true;
|
||||||
|
@ -623,7 +623,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
}
|
}
|
||||||
String newDesc = addUsedVarsToDesugaredMethodDescriptor(lamDesc);
|
String newDesc = addUsedVarsToDesugaredMethodDescriptor(lamDesc);
|
||||||
// first check if capturing lambda then invokestatic or invokespecial
|
// first check if capturing lambda then invokestatic or invokespecial
|
||||||
Handle arg2 = new Handle(staticOrSpecial, this.className.toString(), desugaredMethodName, newDesc, false);
|
Handle arg2 = new Handle(staticOrSpecial, this.className.getClassName(), desugaredMethodName, newDesc, false);
|
||||||
// Descriptor of functional interface methode
|
// Descriptor of functional interface methode
|
||||||
SamMethod samMethod = new SamMethod(kindOfLambda.getArgumentList(), lambdaExpression.getType());
|
SamMethod samMethod = new SamMethod(kindOfLambda.getArgumentList(), lambdaExpression.getType());
|
||||||
// Desc: (this/nothing)TargetType
|
// Desc: (this/nothing)TargetType
|
||||||
@ -798,7 +798,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(methodRefl == null) {
|
if(methodRefl == null) {
|
||||||
boolean toCreate = !receiverName.equals(className.toString()) && helper.isInCurrPkg(clazz);
|
boolean toCreate = !receiverName.equals(className.getClassName()) && helper.isInCurrPkg(clazz);
|
||||||
if(toCreate) {
|
if(toCreate) {
|
||||||
try {
|
try {
|
||||||
mDesc = helper.getDesc(clazz);
|
mDesc = helper.getDesc(clazz);
|
||||||
@ -833,7 +833,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
System.out.println("Methodcall type : " + resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor()));
|
System.out.println("Methodcall type : " + resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor()));
|
||||||
List<Boolean> argListMethCall = new LinkedList<>();
|
List<Boolean> argListMethCall = new LinkedList<>();
|
||||||
String receiverRefl="";
|
String receiverRefl="";
|
||||||
if(methodRefl == null && receiverName.equals(className.toString())) {
|
if(methodRefl == null && receiverName.equals(className.getClassName())) {
|
||||||
MethodFromMethodCall method = new MethodFromMethodCall(methodCall.arglist, methodCall.getType(),
|
MethodFromMethodCall method = new MethodFromMethodCall(methodCall.arglist, methodCall.getType(),
|
||||||
receiverName, genericsAndBoundsMethod, genericsAndBounds);
|
receiverName, genericsAndBoundsMethod, genericsAndBounds);
|
||||||
mDesc = method.accept(new DescriptorToString(resultSet));
|
mDesc = method.accept(new DescriptorToString(resultSet));
|
||||||
|
@ -6,33 +6,45 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
public class Bytecode extends TestCase {
|
public class Bytecode extends TestCase {
|
||||||
|
|
||||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/de/test/";
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/";
|
||||||
@Test
|
@Test
|
||||||
public void testSetPackageNameInBytecode() throws IOException, ClassNotFoundException {
|
public void testSetPackageNameInBytecode() throws Exception {
|
||||||
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"packageNameTest.jav"));
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"de/test/TestClass.jav"));
|
||||||
compiler.typeInference();
|
compiler.typeInference();
|
||||||
File f = new File(rootDirectory + "TestClass.class");
|
File f = new File(rootDirectory + "de/test/TestClass.class");
|
||||||
if(f.exists() && !f.isDirectory()) {
|
if(f.exists() && !f.isDirectory()) {
|
||||||
f.delete();
|
f.delete();
|
||||||
}
|
}
|
||||||
compiler.generateBytecode(null);
|
compiler.generateBytecode(null);
|
||||||
f = new File(rootDirectory + "TestClass.class");
|
f = new File(rootDirectory + "de/test/TestClass.class");
|
||||||
assertTrue(f.exists());
|
assertTrue(f.exists());
|
||||||
|
|
||||||
|
|
||||||
|
URLClassLoader loader = new URLClassLoader(new URL[]{new URL("file://" + rootDirectory)});
|
||||||
|
Class<?> classToTest = loader.loadClass("de.test.TestClass");
|
||||||
|
Object instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetPackageNameInBytecodeAndOutputFolder() throws IOException, ClassNotFoundException {
|
public void testSetPackageNameInBytecodeAndOutputFolder() throws Exception {
|
||||||
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"packageNameTest.jav"));
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"de/test/TestClass.jav"));
|
||||||
compiler.typeInference();
|
compiler.typeInference();
|
||||||
File f = new File(rootDirectory + "output/de/test/TestClass.class");
|
File f = new File(rootDirectory + "de/test/output/de/test/TestClass.class");
|
||||||
if(f.exists() && !f.isDirectory()) {
|
if(f.exists() && !f.isDirectory()) {
|
||||||
f.delete();
|
f.delete();
|
||||||
}
|
}
|
||||||
compiler.generateBytecode(rootDirectory + "output/");
|
compiler.generateBytecode(rootDirectory + "de/test/output/");
|
||||||
f = new File(rootDirectory + "output/de/test/TestClass.class");
|
f = new File(rootDirectory + "de/test/output/de/test/TestClass.class");
|
||||||
assertTrue(f.exists());
|
assertTrue(f.exists());
|
||||||
|
|
||||||
|
URLClassLoader loader = new URLClassLoader(new URL[]{new URL("file://" + rootDirectory + "de/test/output/")});
|
||||||
|
Class<?> classToTest = loader.loadClass("de.test.TestClass");
|
||||||
|
Object instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ public class ParsePackageName {
|
|||||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/de/test/";
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/de/test/";
|
||||||
@Test
|
@Test
|
||||||
public void parsePackage() throws IOException, ClassNotFoundException {
|
public void parsePackage() throws IOException, ClassNotFoundException {
|
||||||
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"packageNameTest.jav"));
|
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"TestClass.jav"));
|
||||||
for(File f : compiler.sourceFiles.keySet()){
|
for(File f : compiler.sourceFiles.keySet()){
|
||||||
SourceFile sf = compiler.sourceFiles.get(f);
|
SourceFile sf = compiler.sourceFiles.get(f);
|
||||||
assert sf.getPkgName().equals("de.test");
|
assert sf.getPkgName().equals("de.test");
|
||||||
|
@ -28,6 +28,10 @@ public class JavaTXCompilerTest {
|
|||||||
execute(new File(rootDirectory+"fc.jav"));
|
execute(new File(rootDirectory+"fc.jav"));
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
|
public void importTest() throws IOException, ClassNotFoundException {
|
||||||
|
execute(new File(rootDirectory+"Import.jav"));
|
||||||
|
}
|
||||||
|
@Test
|
||||||
public void lambda() throws IOException, ClassNotFoundException {
|
public void lambda() throws IOException, ClassNotFoundException {
|
||||||
execute(new File(rootDirectory+"Lambda.jav"));
|
execute(new File(rootDirectory+"Lambda.jav"));
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import java.util.Vector;
|
|||||||
|
|
||||||
class Import {
|
class Import {
|
||||||
void methode(){
|
void methode(){
|
||||||
Vector v;
|
var v;
|
||||||
v.add(v);
|
v.add(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
package de.test;
|
||||||
|
|
||||||
|
public class TestClass{}
|
@ -1,3 +0,0 @@
|
|||||||
package de.test;
|
|
||||||
|
|
||||||
class TestClass{}
|
|
@ -34,6 +34,10 @@
|
|||||||
* Ohne Pfad, direkt neben die Source File legen
|
* Ohne Pfad, direkt neben die Source File legen
|
||||||
* wenn Source File nicht in richtigem Ordner -> Warnung ausgeben
|
* wenn Source File nicht in richtigem Ordner -> Warnung ausgeben
|
||||||
|
|
||||||
|
### Stand ###
|
||||||
|
* Beinahe abgeschlossen
|
||||||
|
* TODO: Tests schreiben
|
||||||
|
|
||||||
## Class files einlesen
|
## Class files einlesen
|
||||||
* Wenn Classpath übergeben
|
* Wenn Classpath übergeben
|
||||||
* Suchen in Classpath + packageName
|
* Suchen in Classpath + packageName
|
||||||
@ -41,6 +45,9 @@
|
|||||||
* dann currentDirectory + packageName
|
* dann currentDirectory + packageName
|
||||||
* Für die Tests muss korrekter Classpath gesetzt werden
|
* Für die Tests muss korrekter Classpath gesetzt werden
|
||||||
|
|
||||||
|
### Stand ###
|
||||||
|
TODO
|
||||||
|
|
||||||
## Class files mit packageNamen versehen
|
## Class files mit packageNamen versehen
|
||||||
* In die Class file muss noch der korrekte name geschrieben werden
|
* In die Class file muss noch der korrekte name geschrieben werden
|
||||||
* kann möglicherweise ASM
|
* kann möglicherweise ASM
|
||||||
|
Loading…
Reference in New Issue
Block a user