Änderungen am TypeInsertSet. Momentan werden keine Generics eingesetzt

This commit is contained in:
JanUlrich 2014-06-19 19:40:13 +02:00
parent 370bb8913b
commit 1f55b81b02
25 changed files with 149 additions and 47 deletions

View File

@ -4,11 +4,11 @@ import java.util.Vector;
import typinferenz.GenericTypeInsertPoint;
import typinferenz.ResultSet;
import typinferenz.TypeInsertPoint;
import typinferenz.TypeInsertSet;
import typinferenz.TypeInsertable;
import typinferenz.exceptions.DebugException;
import typinferenz.exceptions.TypeinferenceException;
import typinferenz.typedeployment.TypeInsertPoint;
import typinferenz.typedeployment.TypeInsertSet;
import mycompiler.myclass.Class;
import mycompiler.myclass.Generic;
import mycompiler.mytype.GenericTypeVar;
@ -86,6 +86,7 @@ public abstract class SyntaxTreeNode{
tip = that.createTypeInsertPoint((TypePlaceholder) t, result);
insertSet.add(tip);//ret.addAll(((TypePlaceholder)t).getTypeInsertPoints(result));
}
/*
//Für den Fall, dass dieser Knoten Generische Variablen halten kann.
if(that instanceof Generic && that.getOffset()>=0){
//Alle unresolvedTPHs ermitteln und GenericTypeVarInsertPoints bilden:
@ -102,6 +103,7 @@ public abstract class SyntaxTreeNode{
}
}
}
*/
}

View File

@ -63,18 +63,19 @@ import org.apache.log4j.Logger;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import typinferenz.ConstraintsSet;
import typinferenz.JavaCodeResult;
import typinferenz.OderConstraint;
import typinferenz.ResultSet;
import typinferenz.TypeInsertPoint;
import typinferenz.Typeable;
import typinferenz.UndConstraint;
import typinferenz.FunN;
import typinferenz.assumptions.ClassAssumption;
import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypeinferenceException;
import typinferenz.typedeployment.TypeInsertPoint;
import typinferenz.*;

View File

@ -13,10 +13,10 @@ import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent;
import typinferenz.ConstraintsSet;
import typinferenz.JavaCodeResult;
import typinferenz.ResultSet;
import typinferenz.TypeInsertPoint;
import typinferenz.Typeable;
import typinferenz.TypeInsertable;
import typinferenz.assumptions.TypeAssumptions;
import typinferenz.typedeployment.TypeInsertPoint;
public abstract class Field extends SyntaxTreeNode implements TypeInsertable, Typeable, Generic{

View File

@ -28,14 +28,15 @@ import org.apache.log4j.Logger;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import typinferenz.JavaCodeResult;
import typinferenz.ResultSet;
import typinferenz.TypeInsertPoint;
import typinferenz.TypeInsertSet;
import typinferenz.Typeable;
import typinferenz.TypeInsertable;
import typinferenz.exceptions.TypeinferenceException;
import typinferenz.typedeployment.TypeInsertPoint;
import typinferenz.typedeployment.TypeInsertSet;
// ino.class.FormalParameter.23391.declaration
public class FormalParameter extends SyntaxTreeNode implements ITypeReplacementListener, Typeable, TypeInsertable

View File

@ -36,12 +36,12 @@ import typinferenz.JavaCodeResult;
import typinferenz.SingleConstraint;
import typinferenz.ConstraintsSet;
import typinferenz.ResultSet;
import typinferenz.TypeInsertPoint;
import typinferenz.TypeInsertable;
import typinferenz.assumptions.MethodAssumption;
import typinferenz.assumptions.ParameterAssumption;
import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypeinferenceException;
import typinferenz.typedeployment.TypeInsertPoint;

View File

@ -1,7 +1,7 @@
package mycompiler.mystatement;
import typinferenz.ResultSet;
import typinferenz.TypeInsertPoint;
import typinferenz.typedeployment.TypeInsertPoint;
import mycompiler.myclass.DeclId;
import mycompiler.myclass.FormalParameter;
import mycompiler.mytype.Type;

View File

@ -41,15 +41,16 @@ import org.apache.log4j.Logger;
import typinferenz.ConstraintsSet;
import typinferenz.FreshTypeVariable;
import typinferenz.JavaCodeResult;
import typinferenz.ResultSet;
import typinferenz.TypeInsertPoint;
import typinferenz.TypeInsertable;
import typinferenz.assumptions.LocalVarAssumption;
import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypeinferenceException;
import typinferenz.typedeployment.TypeInsertPoint;

View File

@ -17,15 +17,16 @@ import java.util.Vector;
import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent;
import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener;
import typinferenz.ConstraintsSet;
import typinferenz.JavaCodeResult;
import typinferenz.ResultSet;
import typinferenz.SingleConstraint;
import typinferenz.TypeInsertPoint;
import typinferenz.TypeInsertable;
import typinferenz.assumptions.TypeAssumptions;
import typinferenz.typedeployment.TypeInsertPoint;
// ino.class.GenericTypeVar.26505.description type=javadoc

View File

@ -10,9 +10,9 @@ import java.util.logging.Logger;
import typinferenz.JavaCodeResult;
import typinferenz.ResultSet;
import typinferenz.TypeInsertPoint;
import typinferenz.TypeInsertSet;
import typinferenz.TypeInsertable;
import typinferenz.typedeployment.TypeInsertPoint;
import typinferenz.typedeployment.TypeInsertSet;
import mycompiler.MyCompiler;
import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent;
import mycompiler.mytypereconstruction.replacementlistener.IReplaceTypeEventProvider;

View File

@ -9,10 +9,10 @@ import java.util.Vector;
import typinferenz.ConstraintsSet;
import typinferenz.ResultSet;
import typinferenz.TypeInsertPoint;
import typinferenz.TypeInsertSet;
import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypeinferenceException;
import typinferenz.typedeployment.TypeInsertPoint;
import typinferenz.typedeployment.TypeInsertSet;
import mycompiler.mytype.GenericTypeVar;
import mycompiler.mytype.Pair;
import mycompiler.mytype.RefType;
@ -73,7 +73,6 @@ public class TypeinferenceResultSet
public Vector<Pair> getConstraints() {
return this.constraints;
}
/**
* @author Andreas Stadelmeier, a10023
@ -114,7 +113,7 @@ public class TypeinferenceResultSet
* @return
*/
public TypeInsertSet getTypeInsertionPoints(){
TypeInsertSet ret = new TypeInsertSet();
TypeInsertSet ret = new TypeInsertSet(this.unifiedConstraints);
this.ownerOfResultSet.addTypeInsertPoints(ret,this.unifiedConstraints);

View File

@ -2,6 +2,7 @@ package typinferenz;
import java.util.Vector;
import typinferenz.typedeployment.TypeInsertPoint;
import mycompiler.mytype.*;
import mycompiler.myclass.*;
import mycompiler.mytype.TypePlaceholder;

View File

@ -4,6 +4,7 @@ import java.util.Iterator;
import java.util.Vector;
import typinferenz.exceptions.DebugException;
import typinferenz.typedeployment.TypeInsertPoint;
import mycompiler.IItemWithOffset;
import mycompiler.SyntaxTreeNode;
import mycompiler.mytype.GenericTypeVar;
@ -19,6 +20,7 @@ import mycompiler.mytype.TypePlaceholder;
*/
public class GenericTypeInsertPoint extends TypeInsertPoint {
private Vector<Pair> genericPairs = new Vector<Pair>();
public GenericTypeInsertPoint(TypeInsertPoint p) {
@ -100,9 +102,10 @@ public class GenericTypeInsertPoint extends TypeInsertPoint {
}
@Override
public IItemWithOffset getInsertNode(){
public TypeInsertable getInsertNode(){
return super.getGenericTypeVarInsertNode();
}
/**
* Versucht den GenericTypeInsertPoint mit dem <FC>bergebenenen p2 zusam
* basierend auf ihren insertPoints.
@ -121,4 +124,17 @@ public class GenericTypeInsertPoint extends TypeInsertPoint {
return ret;
}
@Override
public JavaCodeResult insertType(String fileContent, int additionalOffset) {
//TODO: Es kann sein, dass eine Methode bereits Generische Variablen hat, diese müssen dann an diese Liste angefügt werden.
return super.insertType(fileContent, additionalOffset);
}
public boolean associatedWith(TypeInsertPoint tip, ResultSet resultSet) {
if(!(tip.point instanceof TypePlaceholder))return false;
Vector<TypePlaceholder> tphs = new Vector<>();
tphs.add((TypePlaceholder)tip.point);
resultSet.getConstraintsFor(tphs);
return false;
}
}

View File

@ -1,5 +1,6 @@
package typinferenz;
import typinferenz.typedeployment.TypeInsertPoint;
import mycompiler.IItemWithOffset;
import mycompiler.mytype.TypePlaceholder;
import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener;

View File

@ -1,7 +1,10 @@
package typinferenz;
package typinferenz.typedeployment;
import java.util.Vector;
import typinferenz.JavaCodeResult;
import typinferenz.ResultSet;
import typinferenz.TypeInsertable;
import typinferenz.exceptions.DebugException;
import mycompiler.myclass.*;
import mycompiler.myclass.Class;
@ -18,9 +21,9 @@ import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListe
*/
public class TypeInsertPoint implements Comparable<TypeInsertPoint>{
protected IItemWithOffset point;
protected Type type;
protected ResultSet resultSet;
public TypeInsertable point;
public Type type;
public ResultSet resultSet;
/**
* Dieser Konstruktor erstellt einen TypInsertPoint
@ -29,7 +32,7 @@ public class TypeInsertPoint implements Comparable<TypeInsertPoint>{
* @param resultSet
* @param generics - die generischen Parameter des einzusetzenden Typs
*/
public TypeInsertPoint(IItemWithOffset insertPoint, Type insertType, ResultSet resultSet){
public TypeInsertPoint(TypeInsertable insertPoint, Type insertType, ResultSet resultSet){
this.point = insertPoint;
this.type = insertType;
this.resultSet = resultSet;
@ -106,10 +109,7 @@ public class TypeInsertPoint implements Comparable<TypeInsertPoint>{
return resultSet;
}
public IItemWithOffset getGenericTypeVarInsertNode() {
if(! (this.point instanceof SyntaxTreeNode)){
throw new DebugException("Ein IItemWithOffset muss immer auch ein SyntaxTreeNode sein");
}
public TypeInsertable getGenericTypeVarInsertNode() {
SyntaxTreeNode ret = (SyntaxTreeNode)this.point;
while(!(ret instanceof Field || ret instanceof Class)){
ret = ret.getParent();
@ -117,7 +117,7 @@ public class TypeInsertPoint implements Comparable<TypeInsertPoint>{
throw new DebugException(this.getInsertNode().toString()+" hat kein Feld oder Klasse als Elternelement");
}
}
return (IItemWithOffset)ret;
return (TypeInsertable) ret;
}
}

View File

@ -1,10 +1,14 @@
package typinferenz;
package typinferenz.typedeployment;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;
import typinferenz.GenericTypeInsertPoint;
import typinferenz.JavaCodeResult;
import typinferenz.ResultSet;
import typinferenz.TypeInsertable;
import mycompiler.IItemWithOffset;
import mycompiler.SyntaxTreeNode;
import mycompiler.mytype.GenericTypeVar;
@ -26,8 +30,10 @@ public class TypeInsertSet {
public Vector<TypeInsertPoint> points = new Vector<TypeInsertPoint>();
private Vector<GenericTypeInsertPoint> genericTypeInsertPoints = new Vector<GenericTypeInsertPoint>();
private ResultSet resultSet;
public TypeInsertSet() {
public TypeInsertSet(ResultSet resultSet) {
this.resultSet = resultSet;
}
/**
@ -53,26 +59,56 @@ public class TypeInsertSet {
* @return
*/
public String insertType(TypeInsertPoint tip, String fileContent){
TypeInsertSet tis = new TypeInsertSet();
TypePatchJob tpj = new TypePatchJob();
int additionalOffset = 0;
String ret = fileContent;
JavaCodeResult unresolvedTPHs = tip.insertType(ret, additionalOffset);
for(TypePlaceholder tph : unresolvedTPHs.getUnresolvedTPH()){
GenericTypeInsertPoint genericTIP = new GenericTypeInsertPoint((TypeInsertable)tip.getGenericTypeVarInsertNode(),tph,tip.getResultSet());
tis.add(genericTIP);
GenericTypeInsertPoint genericTIP = new GenericTypeInsertPoint(tip.getGenericTypeVarInsertNode(),tph,tip.getResultSet());
tpj.add(genericTIP);
}
tis.add(tip);
tpj.add(tip);
return tis.insertAllTypes(fileContent);
return tpj.run(fileContent);
}
/**
* Fügt einen einzelnen TypeInsertPoint einem TypePatchJob hinzu
* @param tip
* @param tpj
*/
public void insertType(TypeInsertPoint tip, TypePatchJob tpj){
for(GenericTypeInsertPoint gip : this.genericTypeInsertPoints){
if(gip.associatedWith(tip, this.resultSet)){
tpj.add(gip);
}
}
tpj.add(tip);
}
/*
* Der Plan:
* SyntaxTreeNode generiert die TypeInsertPoints.
* Beim Einsetzen eines TIP werden die ebenfalls von den SyntaxTreeNodes berechneten GenericInsertPoints durchsucht nach den Punkten
* die mit dem einzusetzenden TIP zusammenhängen.
* Das funktioniert mithilfe des ResultSets. Denn es müssen alle Constraints mit einbezogen werden, da der Unify
* Algorithmus als Ergebnis nur die zu einem RefType aufgelösten TPHs ausgibt.
*
*/
/**
* Fügt alle Typen dieses TypeInsertSets in den übergebenen Quellcode ein
* @param fileContent
* @return
*/
public String insertAllTypes(String fileContent) {
//TODO: Das hier kann nicht funktionieren. Nach jedem einsetzen eines TIP muss momentan neu geparst werden
TypePatchJob tpj = new TypePatchJob();
for(TypeInsertPoint tip : this.points){
this.insertType(tip, tpj);
}
return tpj.run(fileContent);
/*
int additionalOffset = 0;
String ret = fileContent;
@ -105,6 +141,7 @@ public class TypeInsertSet {
additionalOffset += p.getInsertLength();
}
return ret;
*/
}
/**
@ -166,3 +203,26 @@ public class TypeInsertSet {
}
}
/**
* Stellt eine Reihe von TypeInsertions dar
*/
class TypePatchJob{
private Vector<TypeInsertPoint> points = new Vector<>();
void add(TypeInsertPoint tip){
points.add(tip);
}
String run(String fileContent){
//sortieren (nach dem Offset der InsertPoints):
Collections.sort(points);
int additionalOffset = 0;
for(TypeInsertPoint p : points){
//Zuerst den Typ einsetzen
JavaCodeResult insertCode = p.insertType(fileContent, additionalOffset);
fileContent = insertCode.toString();
//Dann Additional Offset korrigieren:
additionalOffset += p.getInsertLength();
}
return fileContent;
}
}

View File

@ -15,8 +15,8 @@ import mycompiler.MyCompiler;
import mycompiler.MyCompilerAPI;
import mycompiler.myparser.JavaParser.yyException;
import mycompiler.mytypereconstruction.TypeinferenceResultSet;
import typinferenz.TypeInsertPoint;
import typinferenz.TypeInsertSet;
import typinferenz.typedeployment.TypeInsertPoint;
import typinferenz.typedeployment.TypeInsertSet;
public class InsertSingleTypeTest {
private static final String testFile = "SingleTypeInsertTest.jav";

View File

@ -13,7 +13,7 @@ import mycompiler.MyCompiler;
import mycompiler.MyCompilerAPI;
import mycompiler.myparser.JavaParser.yyException;
import mycompiler.mytypereconstruction.TypeinferenceResultSet;
import typinferenz.TypeInsertSet;
import typinferenz.typedeployment.TypeInsertSet;
public class Tester extends TypeInsertTester{

View File

@ -21,9 +21,9 @@ import mycompiler.mytype.TypePlaceholder;
import mycompiler.mytypereconstruction.TypeinferenceResultSet;
import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent;
import typinferenz.ResultSet;
import typinferenz.TypeInsertPoint;
import typinferenz.TypeInsertSet;
import typinferenz.TypeInsertable;
import typinferenz.typedeployment.TypeInsertPoint;
import typinferenz.typedeployment.TypeInsertSet;
public class TRMEqualTest {
Vector<TypeInsertSet> replaceSet = new Vector<TypeInsertSet>();
@ -56,7 +56,7 @@ public class TRMEqualTest {
resultContent.add(pair);
ResultSet resultSet = new ResultSet(resultContent);
Vector<TypeInsertPoint> tphs = tph.getTypeInsertPoints(resultSet);
TypeInsertSet toAdd = new TypeInsertSet();
TypeInsertSet toAdd = new TypeInsertSet(resultSet);
for(TypeInsertPoint tip : tphs){
toAdd.add(tip);
}

View File

@ -12,7 +12,7 @@ import mycompiler.mytypereconstruction.TypeinferenceResultSet;
import org.junit.Test;
import typinferenz.TypeInsertSet;
import typinferenz.typedeployment.TypeInsertSet;
public class TypeInsertSetEqualTest {

View File

@ -17,8 +17,8 @@ import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.SimpleLayout;
import typinferenz.TypeInsertPoint;
import typinferenz.TypeInsertSet;
import typinferenz.typedeployment.TypeInsertPoint;
import typinferenz.typedeployment.TypeInsertSet;
import junit.framework.TestCase;
import mycompiler.MyCompiler;
import mycompiler.MyCompilerAPI;

View File

@ -10,7 +10,7 @@ public class BoundedGenericsTest {
@Test
public void run(){
Vector<String> mustContain = new Vector<String>();
mustContain.add("var");
mustContain.add("java.lang.String var");
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
}
}

View File

@ -0,0 +1,3 @@
class GenericParaListInsertTest{
methode(a){return a;}
}

View File

@ -0,0 +1,16 @@
package plugindevelopment.TypeInsertTests;
import java.util.Vector;
import org.junit.Test;
public class GenericParaListInsertTest {
private static final String TEST_FILE = "GenericParaListInsertTest.jav";
@Test
public void run(){
Vector<String> mustContain = new Vector<String>();
mustContain.add("<"); //Es muss eine Parameterliste generiert werden.
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
}
}

View File

@ -10,7 +10,7 @@ import mycompiler.MyCompiler;
import mycompiler.MyCompilerAPI;
import mycompiler.myparser.JavaParser.yyException;
import mycompiler.mytypereconstruction.TypeinferenceResultSet;
import typinferenz.TypeInsertSet;
import typinferenz.typedeployment.TypeInsertSet;
public class MultipleTypesInsertTester extends TypeInsertTester{

View File

@ -12,7 +12,7 @@ import mycompiler.mytypereconstruction.TypeinferenceResultSet;
import org.junit.Test;
import typinferenz.TypeInsertSet;
import typinferenz.typedeployment.TypeInsertSet;
public class OverloadingInsertTest {
private static final String TEST_FILE = "OverloadingInsertTest.jav";