forked from JavaTX/JavaCompilerCore
Merge branch 'bigRefactoring' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecode2
This commit is contained in:
commit
8870bc326c
6
pom.xml
6
pom.xml
@ -42,6 +42,12 @@
|
|||||||
<artifactId>asm-all</artifactId>
|
<artifactId>asm-all</artifactId>
|
||||||
<version>[4.0.0,)</version>
|
<version>[4.0.0,)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bitbucket.mstrobel</groupId>
|
||||||
|
<artifactId>procyon-reflection</artifactId>
|
||||||
|
<version>[0.5.32,)</version>
|
||||||
|
</dependency> -->
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -89,14 +89,21 @@ public class ASTFactory {
|
|||||||
return new Field(field.getName(), createType(field.getType(), jreClass, null), field.getModifiers(), new NullToken());
|
return new Field(field.getName(), createType(field.getType(), jreClass, null), field.getModifiers(), new NullToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//private static RefType createType(Class classType) {
|
||||||
|
// return createClass(classType).getType();
|
||||||
|
//}
|
||||||
|
|
||||||
private static de.dhbwstuttgart.syntaxtree.Constructor createConstructor(Constructor constructor, Class inClass) {
|
private static de.dhbwstuttgart.syntaxtree.Constructor createConstructor(Constructor constructor, Class inClass) {
|
||||||
String name = constructor.getName();
|
String name = constructor.getName();
|
||||||
RefTypeOrTPHOrWildcardOrGeneric returnType = createType(inClass, new JavaClassName(inClass.getName()), name);
|
RefTypeOrTPHOrWildcardOrGeneric returnType = createType(inClass, new JavaClassName(inClass.getName()), name);
|
||||||
Parameter[] jreParams = constructor.getParameters();
|
Parameter[] jreParams = constructor.getParameters();
|
||||||
|
Type[] jreGenericParams = constructor.getGenericParameterTypes();
|
||||||
List<FormalParameter> params = new ArrayList<>();
|
List<FormalParameter> params = new ArrayList<>();
|
||||||
for(Parameter jreParam : jreParams){
|
int i = 0;
|
||||||
RefTypeOrTPHOrWildcardOrGeneric paramType = createType(jreParam.getType(),new JavaClassName(inClass.getName()), name);
|
for(Type jreParam : jreGenericParams){
|
||||||
params.add(new FormalParameter(jreParam.getName(),paramType, new NullToken()));
|
RefTypeOrTPHOrWildcardOrGeneric paramType = createType(jreParam,new JavaClassName(inClass.getName()), name);
|
||||||
|
params.add(new FormalParameter(jreParams[i].getName(),paramType, new NullToken()));
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
ParameterList parameterList = new ParameterList(params, new NullToken());
|
ParameterList parameterList = new ParameterList(params, new NullToken());
|
||||||
Block block = new Block(new ArrayList<Statement>(), new NullToken());
|
Block block = new Block(new ArrayList<Statement>(), new NullToken());
|
||||||
@ -109,21 +116,26 @@ public class ASTFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new de.dhbwstuttgart.syntaxtree.Constructor(modifier, name,returnType, parameterList, block, gtvDeclarations, offset, new ArrayList<>());
|
return new de.dhbwstuttgart.syntaxtree.Constructor(modifier, name,returnType, parameterList, block, gtvDeclarations, offset, new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
//private static RefType createType(Class classType) {
|
|
||||||
// return createClass(classType).getType();
|
|
||||||
//}
|
|
||||||
|
|
||||||
public static Method createMethod(java.lang.reflect.Method jreMethod, java.lang.Class inClass){
|
public static Method createMethod(java.lang.reflect.Method jreMethod, java.lang.Class inClass){
|
||||||
String name = jreMethod.getName();
|
String name = jreMethod.getName();
|
||||||
RefTypeOrTPHOrWildcardOrGeneric returnType;
|
RefTypeOrTPHOrWildcardOrGeneric returnType;
|
||||||
returnType = createType(jreMethod.getReturnType(),new JavaClassName(inClass.getName()), name);
|
Type jreRetType;
|
||||||
|
if(jreMethod.getGenericReturnType()!=null){
|
||||||
|
jreRetType = jreMethod.getGenericReturnType();
|
||||||
|
}else{
|
||||||
|
jreRetType = jreMethod.getReturnType();
|
||||||
|
}
|
||||||
|
returnType = createType(jreRetType,new JavaClassName(inClass.getName()), name);
|
||||||
Parameter[] jreParams = jreMethod.getParameters();
|
Parameter[] jreParams = jreMethod.getParameters();
|
||||||
|
Type[] jreGenericParams = jreMethod.getGenericParameterTypes();
|
||||||
List<FormalParameter> params = new ArrayList<>();
|
List<FormalParameter> params = new ArrayList<>();
|
||||||
for(Parameter jreParam : jreParams){
|
int i = 0;
|
||||||
RefTypeOrTPHOrWildcardOrGeneric paramType = createType(jreParam.getType(),new JavaClassName(inClass.getName()), name);
|
for(Type jreParam : jreGenericParams){
|
||||||
params.add(new FormalParameter(jreParam.getName(),paramType, new NullToken()));
|
RefTypeOrTPHOrWildcardOrGeneric paramType = createType(jreParam,new JavaClassName(inClass.getName()), name);
|
||||||
|
params.add(new FormalParameter(jreParams[i].getName(),paramType, new NullToken()));
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
ParameterList parameterList = new ParameterList(params, new NullToken());
|
ParameterList parameterList = new ParameterList(params, new NullToken());
|
||||||
Block block = new Block(new ArrayList<Statement>(), new NullToken());
|
Block block = new Block(new ArrayList<Statement>(), new NullToken());
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package de.dhbwstuttgart.typeinference.assumptions;
|
package de.dhbwstuttgart.typeinference.assumptions;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.TypeScope;
|
import de.dhbwstuttgart.syntaxtree.TypeScope;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
@ -25,7 +26,7 @@ public class FieldAssumption extends Assumption{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RefTypeOrTPHOrWildcardOrGeneric getReceiverType(GenericsResolver resolver) {
|
public RefTypeOrTPHOrWildcardOrGeneric getReceiverType(GenericsResolver resolver) {
|
||||||
|
//TODO
|
||||||
return null;
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,8 @@ public class MethodAssumption extends Assumption{
|
|||||||
return receiver;
|
return receiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
public RefTypeOrTPHOrWildcardOrGeneric getReturnType(GenericsResolver resolver) {
|
||||||
|
if(retType instanceof GenericRefType)return resolver.resolve(retType);
|
||||||
return retType;
|
return retType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,7 +349,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
*/
|
*/
|
||||||
methodConstraint.add(new Pair(forMethod.receiver.getType(), assumption.getReceiverType(resolver),
|
methodConstraint.add(new Pair(forMethod.receiver.getType(), assumption.getReceiverType(resolver),
|
||||||
PairOperator.SMALLERDOT));
|
PairOperator.SMALLERDOT));
|
||||||
methodConstraint.add(new Pair(assumption.getReturnType(), forMethod.getType(),
|
methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(),
|
||||||
PairOperator.EQUALSDOT));
|
PairOperator.EQUALSDOT));
|
||||||
methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info, resolver));
|
methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info, resolver));
|
||||||
return methodConstraint;
|
return methodConstraint;
|
||||||
@ -393,7 +393,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
for(Method m : cl.getMethods()){
|
for(Method m : cl.getMethods()){
|
||||||
if(m.getName().equals(name) &&
|
if(m.getName().equals(name) &&
|
||||||
m.getParameterList().getFormalparalist().size() == numArgs){
|
m.getParameterList().getFormalparalist().size() == numArgs){
|
||||||
RefTypeOrTPHOrWildcardOrGeneric retType = info.checkGTV(m.getReturnType());
|
RefTypeOrTPHOrWildcardOrGeneric retType = m.getReturnType();//info.checkGTV(m.getReturnType());
|
||||||
|
|
||||||
ret.add(new MethodAssumption(cl, retType, convertParams(m.getParameterList(),info),
|
ret.add(new MethodAssumption(cl, retType, convertParams(m.getParameterList(),info),
|
||||||
createTypeScope(cl, m)));
|
createTypeScope(cl, m)));
|
||||||
@ -442,7 +442,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
protected Constraint<Pair> generateConstructorConstraint(NewClass forConstructor, MethodAssumption assumption,
|
protected Constraint<Pair> generateConstructorConstraint(NewClass forConstructor, MethodAssumption assumption,
|
||||||
TypeInferenceBlockInformation info, GenericsResolver resolver){
|
TypeInferenceBlockInformation info, GenericsResolver resolver){
|
||||||
Constraint methodConstraint = new Constraint();
|
Constraint methodConstraint = new Constraint();
|
||||||
methodConstraint.add(new Pair(assumption.getReturnType(), forConstructor.getType(),
|
methodConstraint.add(new Pair(assumption.getReturnType(resolver), forConstructor.getType(),
|
||||||
PairOperator.SMALLERDOT));
|
PairOperator.SMALLERDOT));
|
||||||
methodConstraint.addAll(generateParameterConstraints(forConstructor, assumption, info, resolver));
|
methodConstraint.addAll(generateParameterConstraints(forConstructor, assumption, info, resolver));
|
||||||
return methodConstraint;
|
return methodConstraint;
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
import java.lang.Runnable;
|
||||||
|
import java.lang.String;
|
||||||
|
import java.lang.System;
|
||||||
|
|
||||||
public class LamRunnable{
|
public class LamRunnable{
|
||||||
|
|
||||||
|
@ -3,10 +3,6 @@ import java.util.Vector;
|
|||||||
class MyVector{
|
class MyVector{
|
||||||
|
|
||||||
id(x){
|
id(x){
|
||||||
return id2(x);
|
return (x.elementAt(0));
|
||||||
}
|
|
||||||
|
|
||||||
id2(x){
|
|
||||||
return id(x);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -49,6 +49,10 @@ public class JavaTXCompilerTest {
|
|||||||
execute(new File(rootDirectory+"Generics.jav"));
|
execute(new File(rootDirectory+"Generics.jav"));
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
|
public void genericsMethodCall() throws IOException, ClassNotFoundException {
|
||||||
|
execute(new File(rootDirectory+"MethodCallGenerics.jav"));
|
||||||
|
}
|
||||||
|
@Test
|
||||||
public void faculty() throws IOException, ClassNotFoundException {
|
public void faculty() throws IOException, ClassNotFoundException {
|
||||||
execute(new File(rootDirectory+"Faculty.jav"));
|
execute(new File(rootDirectory+"Faculty.jav"));
|
||||||
}
|
}
|
||||||
|
5
test/visualisation/ToString.java
Normal file
5
test/visualisation/ToString.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package visualisation;
|
||||||
|
|
||||||
|
public class ToString {
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user