forked from JavaTX/JavaCompilerCore
Merge branch 'bytecodeGenericsSecond' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecodeGenericsSecond
This commit is contained in:
commit
b942e508fc
@ -3,16 +3,14 @@
|
|||||||
*/
|
*/
|
||||||
package de.dhbwstuttgart.bytecode.genericsGenerator;
|
package de.dhbwstuttgart.bytecode.genericsGenerator;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.*;
|
||||||
|
import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint;
|
||||||
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
|
import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics;
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResultForClass;
|
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.MethodAndConstraints;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.MethodUtility;
|
import de.dhbwstuttgart.bytecode.utilities.MethodUtility;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.Resolver;
|
import de.dhbwstuttgart.bytecode.utilities.Resolver;
|
||||||
@ -127,6 +125,7 @@ public class GeneratedGenericsFinder implements ASTVisitor {
|
|||||||
|
|
||||||
ConstraintsSimplierResult simplifiedConstraints = null;
|
ConstraintsSimplierResult simplifiedConstraints = null;
|
||||||
GenericsGeneratorResultForClass ggResult = null;
|
GenericsGeneratorResultForClass ggResult = null;
|
||||||
|
GenericsGeneratorResultForClass ggResultAlternative = null;
|
||||||
|
|
||||||
for (int i = 0; i < listOfResultSetsList.size(); i++) {
|
for (int i = 0; i < listOfResultSetsList.size(); i++) {
|
||||||
resultSet = listOfResultSetsList.get(i);
|
resultSet = listOfResultSetsList.get(i);
|
||||||
@ -160,7 +159,35 @@ public class GeneratedGenericsFinder implements ASTVisitor {
|
|||||||
|
|
||||||
if(ggResult != null)
|
if(ggResult != null)
|
||||||
generatedGenericsForSF.addGenericGeneratorResultClass(ggResult);
|
generatedGenericsForSF.addGenericGeneratorResultClass(ggResult);
|
||||||
System.out.println("ddd");
|
|
||||||
|
|
||||||
|
List<GenericsGeneratorResult> listOfClassCons = new ArrayList<>();
|
||||||
|
for(TPHConstraint clCons: fogg.classConstraints) {
|
||||||
|
// ExtendsConstraint ec = new ExtendsConstraint(clCons.getLeft(), clCons.getRight());
|
||||||
|
GenericsGeneratorResult ggR = new GenericsGeneratorResult(clCons, new HashSet<>());
|
||||||
|
listOfClassCons.add(ggR);
|
||||||
|
}
|
||||||
|
|
||||||
|
GenericGeneratorResultsForAllMethods ggRfaM = null;
|
||||||
|
List<MethodAndConstraints> listOfMethAndCons = new ArrayList<>();
|
||||||
|
for(String methID: fogg.methodConstraintsWithPosition.keySet()) {
|
||||||
|
List<GenericsGeneratorResult> listOfGGR = new ArrayList<>();
|
||||||
|
for(TPHConstraint methCons: fogg.methodConstraintsWithPosition.get(methID)) {
|
||||||
|
// ExtendsConstraint ec = new ExtendsConstraint(methCons.getLeft(),methCons.getRight());
|
||||||
|
GenericsGeneratorResult ggR = new GenericsGeneratorResult(methCons, new HashSet<>());
|
||||||
|
listOfGGR.add(ggR);
|
||||||
|
}
|
||||||
|
MethodAndConstraints mac = new MethodAndConstraints(methID, listOfGGR);
|
||||||
|
listOfMethAndCons.add(mac);
|
||||||
|
}
|
||||||
|
ggRfaM = new GenericGeneratorResultsForAllMethods(listOfMethAndCons);
|
||||||
|
ggResultAlternative = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM);
|
||||||
|
|
||||||
|
if(ggResultAlternative != null) {
|
||||||
|
generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative);
|
||||||
|
System.out.println(generatedGenericsForSF);
|
||||||
|
}
|
||||||
|
System.out.println(ggResultAlternative);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,8 +128,8 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
for(String curMeth: tempMethodConstraintsWithPosition.keySet()){
|
for(String curMeth: tempMethodConstraintsWithPosition.keySet()){
|
||||||
for(int i=0; i<tempMethodConstraintsWithPosition.get(curMeth).size(); i++) {
|
for(int i=0; i<tempMethodConstraintsWithPosition.get(curMeth).size(); i++) {
|
||||||
MethodConstraint currentMC = tempMethodConstraintsWithPosition.get(curMeth).get(i);
|
MethodConstraint currentMC = tempMethodConstraintsWithPosition.get(curMeth).get(i);
|
||||||
if(currentMC.getRight()!= "Object" && !compareTphsOfConstraints(currentMC.getRight(), cs_cl) && !compareTphsOfConstraints(currentMC.getRight(), tempMethodConstraintsWithPosition.get(curMeth))) {
|
if(currentMC.getRight()!= Object.class.getTypeName() && !compareTphsOfConstraints(currentMC.getRight(), cs_cl) && !compareTphsOfConstraints(currentMC.getRight(), tempMethodConstraintsWithPosition.get(curMeth))) {
|
||||||
MethodConstraint mc = new MethodConstraint(currentMC.getRight(), "Object", Relation.EXTENDS);
|
MethodConstraint mc = new MethodConstraint(currentMC.getRight(), Object.class.getTypeName(), Relation.EXTENDS);
|
||||||
tempMethodConstraintsWithPosition.get(curMeth).add(mc);
|
tempMethodConstraintsWithPosition.get(curMeth).add(mc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,7 +212,7 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
boolean hasSmallerTVInClCons = (posOfTphs.containsKey(cCons.getRight()) && cCons.getRight() == tph && cCons.getLeft() != null);
|
boolean hasSmallerTVInClCons = (posOfTphs.containsKey(cCons.getRight()) && cCons.getRight() == tph && cCons.getLeft() != null);
|
||||||
if( ((tvInField || hasSmallerTVInClCons) && cCons.getRel()==Relation.EXTENDS) &&
|
if( ((tvInField || hasSmallerTVInClCons) && cCons.getRel()==Relation.EXTENDS) &&
|
||||||
!checkUpperBound(allConstraints, tph) && allCons.getRel()==Relation.EXTENDS) {
|
!checkUpperBound(allConstraints, tph) && allCons.getRel()==Relation.EXTENDS) {
|
||||||
ClassConstraint consToAdd = new ClassConstraint(tph, "Object", Relation.EXTENDS);
|
ClassConstraint consToAdd = new ClassConstraint(tph, Object.class.getTypeName(), Relation.EXTENDS);
|
||||||
if (!checkForDuplicates(consToAdd, tempCC)){
|
if (!checkForDuplicates(consToAdd, tempCC)){
|
||||||
tempCC.add(consToAdd);
|
tempCC.add(consToAdd);
|
||||||
}
|
}
|
||||||
@ -312,7 +312,7 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
for(PairTphMethod pair: posOfTphs.get(tph)) {
|
for(PairTphMethod pair: posOfTphs.get(tph)) {
|
||||||
for(TPHConstraint allCons: allConstraints) {
|
for(TPHConstraint allCons: allConstraints) {
|
||||||
if((pair.fst.equals(PositionFinder.Position.METHOD) || pair.fst.equals(PositionFinder.Position.CONSTRUCTOR)) && !checkUpperBound(allConstraints,tph)) {
|
if((pair.fst.equals(PositionFinder.Position.METHOD) || pair.fst.equals(PositionFinder.Position.CONSTRUCTOR)) && !checkUpperBound(allConstraints,tph)) {
|
||||||
MethodConstraint consToAdd = new MethodConstraint(tph, "Object", Relation.EXTENDS);
|
MethodConstraint consToAdd = new MethodConstraint(tph, Object.class.getTypeName(), Relation.EXTENDS);
|
||||||
if (!checkForDuplicates(consToAdd, tempMC)) {
|
if (!checkForDuplicates(consToAdd, tempMC)) {
|
||||||
tempMC.add(consToAdd);
|
tempMC.add(consToAdd);
|
||||||
}
|
}
|
||||||
@ -326,7 +326,7 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
}
|
}
|
||||||
for(TPHConstraint mc1: tempMCObject1) {
|
for(TPHConstraint mc1: tempMCObject1) {
|
||||||
if(tph==mc1.getRight() && !checkUpperBound(tempMCObject1,tph)) {
|
if(tph==mc1.getRight() && !checkUpperBound(tempMCObject1,tph)) {
|
||||||
MethodConstraint consToAdd = new MethodConstraint(tph, "Object", Relation.EXTENDS);
|
MethodConstraint consToAdd = new MethodConstraint(tph, Object.class.getTypeName(), Relation.EXTENDS);
|
||||||
if (!checkForDuplicates(consToAdd, tempMC)) {
|
if (!checkForDuplicates(consToAdd, tempMC)) {
|
||||||
tempMC.add(consToAdd);
|
tempMC.add(consToAdd);
|
||||||
}
|
}
|
||||||
|
@ -215,6 +215,7 @@ public abstract class AbstractASTWalker implements ASTVisitor{
|
|||||||
@Override
|
@Override
|
||||||
public void visit(Return aReturn) {
|
public void visit(Return aReturn) {
|
||||||
aReturn.retexpr.accept(this);
|
aReturn.retexpr.accept(this);
|
||||||
|
aReturn.retexpr.getType().accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
package insertGenerics;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.genericsGenerator.GeneratedGenericsFinder;
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|
||||||
import junit.framework.TestResult;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MethodsTest {
|
|
||||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
|
||||||
public static final String fileDirectory = rootDirectory + "TestGGFinder.jav";
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testVisit(ClassOrInterface coi) throws IOException, ClassNotFoundException {
|
|
||||||
JavaTXCompiler compiler = new JavaTXCompiler(new File(fileDirectory));
|
|
||||||
SourceFile sf = compiler.sourceFiles.get(compiler.sourceFiles.keySet());
|
|
||||||
List<ResultSet> results = compiler.typeInference();
|
|
||||||
|
|
||||||
GeneratedGenericsFinder ggf = new GeneratedGenericsFinder(sf, results);
|
|
||||||
ClassOrInterface coiHere = coi;
|
|
||||||
ggf.visit(coiHere);
|
|
||||||
//assert results.size()>0;
|
|
||||||
}
|
|
||||||
}
|
|
@ -20,13 +20,13 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class TryTest {
|
public class TestTwoArgs2 {
|
||||||
|
|
||||||
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/insertGenericsJav/";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ggFinder() throws IOException, ClassNotFoundException {
|
public void ggFinder() throws IOException, ClassNotFoundException {
|
||||||
execute(new File(rootDirectory+"TestGGFinder.jav"));
|
execute(new File(rootDirectory+"TestTwoArgs2.jav"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TestResultSet{
|
private static class TestResultSet{
|
||||||
@ -34,25 +34,9 @@ public class TryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
|
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
|
||||||
//filesToTest.add(new File(rootDirectory+"fc.jav"));
|
|
||||||
//filesToTest.add(new File(rootDirectory+"Lambda.jav"));
|
|
||||||
//filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
|
|
||||||
//filesToTest.add(new File(rootDirectory+"Lambda3.jav"));
|
|
||||||
//filesToTest.add(new File(rootDirectory+"Vector.jav"));
|
|
||||||
//filesToTest.add(new File(rootDirectory+"Generics.jav"));
|
|
||||||
//filesToTest.add(new File(rootDirectory+"MethodsEasy.jav"));
|
|
||||||
//filesToTest.add(new File(rootDirectory+"Matrix.jav"));
|
|
||||||
//filesToTest.add(new File(rootDirectory+"Import.jav"));
|
|
||||||
// //filesToTest.add(new File(rootDirectory+"Faculty.jav"));
|
|
||||||
// //filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
|
|
||||||
// //filesToTest.add(new File(rootDirectory+"test.jav"));
|
|
||||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||||
for(File f : compiler.sourceFiles.keySet()){
|
for(File f : compiler.sourceFiles.keySet()){
|
||||||
SourceFile sf = compiler.sourceFiles.get(f);
|
SourceFile sf = compiler.sourceFiles.get(f);
|
||||||
// System.out.println(ASTTypePrinter.print(sf));
|
|
||||||
// System.out.println("---------------------------1");
|
|
||||||
// System.out.println(ASTPrinter.print(sf));
|
|
||||||
// System.out.println("---------------------------2");
|
|
||||||
}
|
}
|
||||||
List<ResultSet> results = compiler.typeInference();
|
List<ResultSet> results = compiler.typeInference();
|
||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results);
|
||||||
@ -60,9 +44,7 @@ public class TryTest {
|
|||||||
for(File f : compiler.sourceFiles.keySet()){
|
for(File f : compiler.sourceFiles.keySet()){
|
||||||
SourceFile sf = compiler.sourceFiles.get(f);
|
SourceFile sf = compiler.sourceFiles.get(f);
|
||||||
System.out.println(ASTTypePrinter.print(sf));
|
System.out.println(ASTTypePrinter.print(sf));
|
||||||
// System.out.println("---------------------------3");
|
|
||||||
System.out.println(ASTPrinter.print(sf));
|
System.out.println(ASTPrinter.print(sf));
|
||||||
// System.out.println("---------------------------4");
|
|
||||||
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
||||||
assert results.size()>0;
|
assert results.size()>0;
|
||||||
Set<String> insertedTypes = new HashSet<>();
|
Set<String> insertedTypes = new HashSet<>();
|
||||||
@ -75,9 +57,7 @@ public class TryTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(String s : insertedTypes){
|
for(String s : insertedTypes){
|
||||||
System.out.println("---------------------------51");
|
|
||||||
System.out.println(s);
|
System.out.println(s);
|
||||||
System.out.println("---------------------------52");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new TestResultSet();
|
return new TestResultSet();
|
22
src/test/resources/insertGenericsJav/TestTwoArgs2.jav
Normal file
22
src/test/resources/insertGenericsJav/TestTwoArgs2.jav
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
class TestTwoArgs {
|
||||||
|
a;
|
||||||
|
|
||||||
|
id(b) {
|
||||||
|
var c = b;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
setA(x) {
|
||||||
|
a = x;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
m(x,y) {
|
||||||
|
x = id(y);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
main(x,y) {
|
||||||
|
return m(id(x),setA(y));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user