forked from JavaTX/JavaCompilerCore
createTypeInsertPoint-Methode eingeführt
This commit is contained in:
parent
c738e5c0de
commit
0e19e996c1
@ -1371,7 +1371,7 @@ formalparameter : type variabledeclaratorid
|
||||
{
|
||||
FormalParameter FP = new FormalParameter($2);
|
||||
FP.setType($1);
|
||||
//FP.set_DeclId($2);
|
||||
//FP.set_DeclId($2); //auskommentiert von Andreas Stadelmeier. DeclId wird nun dem Konstruktor von FormalParameter übergeben.
|
||||
$$=FP;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
package mycompiler.mybytecode;
|
||||
// ino.end
|
||||
// ino.module.CONSTANT_Float_info.8536.import
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
// ino.end
|
||||
import java.io.OutputStream;
|
||||
|
@ -6,10 +6,12 @@ import mycompiler.SyntaxTreeNode;
|
||||
import mycompiler.mybytecode.ClassFile;
|
||||
import mycompiler.myexception.JVMCodeException;
|
||||
import mycompiler.mytype.Type;
|
||||
import mycompiler.mytype.TypePlaceholder;
|
||||
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;
|
||||
@ -95,4 +97,11 @@ public abstract class Field extends SyntaxTreeNode implements TypeInsertable, Ty
|
||||
public String getDescription(){
|
||||
return this.getIdentifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph,
|
||||
ResultSet resultSet) {
|
||||
return new TypeInsertPoint(tph, this, resultSet.getTypeEqualTo(tph), resultSet);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,9 +23,12 @@ import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
import typinferenz.JavaCodeResult;
|
||||
import typinferenz.ResultSet;
|
||||
import typinferenz.TypeInsertPoint;
|
||||
import typinferenz.Typeable;
|
||||
import typinferenz.TypeInsertable;
|
||||
import typinferenz.exceptions.TypinferenzException;
|
||||
@ -240,5 +243,13 @@ public class FormalParameter extends SyntaxTreeNode implements ITypeReplacementL
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph,
|
||||
ResultSet resultSet) {
|
||||
if(this.getOffset()<=0)return null;
|
||||
return new TypeInsertPoint(tph, this, resultSet.getTypeEqualTo(tph), resultSet);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -36,6 +36,7 @@ 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;
|
||||
@ -710,6 +711,8 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
if(!this.parameterlist.equals(equals.parameterlist))return false;
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -1962,7 +1962,7 @@ case 149:
|
||||
{
|
||||
FormalParameter FP = new FormalParameter(((DeclId)yyVals[0+yyTop]));
|
||||
FP.setType(((Type)yyVals[-1+yyTop]));
|
||||
/*FP.set_DeclId($2);*/
|
||||
/*FP.set_DeclId($2); //auskommentiert von Andreas Stadelmeier. DeclId wird nun dem Konstruktor von FormalParameter übergeben.*/
|
||||
yyVal=FP;
|
||||
}
|
||||
break;
|
||||
|
@ -1371,7 +1371,7 @@ formalparameter : type variabledeclaratorid
|
||||
{
|
||||
FormalParameter FP = new FormalParameter($2);
|
||||
FP.setType($1);
|
||||
//FP.set_DeclId($2);
|
||||
//FP.set_DeclId($2); //auskommentiert von Andreas Stadelmeier. DeclId wird nun dem Konstruktor von FormalParameter übergeben.
|
||||
$$=FP;
|
||||
}
|
||||
|
||||
|
@ -527,7 +527,9 @@ public class TypePlaceholder extends Type implements IReplaceTypeEventProvider
|
||||
TypeInsertSet ret = new TypeInsertSet();
|
||||
for(ITypeReplacementListener ti : this.m_ReplacementListeners){
|
||||
if(ti instanceof TypeInsertable){
|
||||
ret.add(new TypeInsertPoint(this, (TypeInsertable)ti, result.getTypeEqualTo(this), result));
|
||||
TypeInsertPoint toAdd = ((TypeInsertable) ti).createTypeInsertPoint(this, result);
|
||||
if(toAdd != null)ret.add(toAdd);
|
||||
//ret.add(new TypeInsertPoint(this, (TypeInsertable)ti, result.getTypeEqualTo(this), result));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -6,7 +6,6 @@ import mycompiler.myclass.*;
|
||||
import mycompiler.mytype.TypePlaceholder;
|
||||
|
||||
public class FunNMethod extends Method{
|
||||
|
||||
/**
|
||||
*
|
||||
* @param N - Anzahl der Parameter (Beispiel: Fun2<R, T1, T2>)
|
||||
@ -14,6 +13,7 @@ public class FunNMethod extends Method{
|
||||
public FunNMethod(int N){
|
||||
super(0); //Hat keinen Offset, da nur theoretisch gedachte Methode
|
||||
this.setType(TypePlaceholder.fresh(this));
|
||||
this.set_DeclId(new DeclId("Fun"+N));
|
||||
ParameterList pl = new ParameterList();
|
||||
Vector<FormalParameter> fpList = new Vector<FormalParameter>();
|
||||
for(int i = 0;i<N;i++){
|
||||
@ -27,4 +27,10 @@ public class FunNMethod extends Method{
|
||||
this.parameterlist = pl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph,
|
||||
ResultSet resultSet) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import mycompiler.mytype.*;
|
||||
import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener;
|
||||
|
||||
|
||||
public class TypeInsertPoint {
|
||||
public class TypeInsertPoint implements Comparable<TypeInsertPoint>{
|
||||
|
||||
private TypePlaceholder tph;
|
||||
private TypeInsertable point;
|
||||
@ -70,4 +70,9 @@ public class TypeInsertPoint {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(TypeInsertPoint arg0) {
|
||||
return new Integer(this.getOffset()).compareTo(new Integer(arg0.getOffset()));
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package typinferenz;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Vector;
|
||||
|
||||
import mycompiler.SyntaxTreeNode;
|
||||
@ -33,6 +34,7 @@ public class TypeInsertSet {
|
||||
public String insertAllTypes(String fileContent) {
|
||||
int additionalOffset = 0;
|
||||
String ret = fileContent;
|
||||
Collections.sort(points);
|
||||
for(TypeInsertPoint p : points){
|
||||
ret = p.insertType(ret, additionalOffset);
|
||||
additionalOffset += p.getInsertLength();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package typinferenz;
|
||||
|
||||
import mycompiler.mytype.TypePlaceholder;
|
||||
import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener;
|
||||
|
||||
public interface TypeInsertable extends ITypeReplacementListener, Typeable {
|
||||
@ -8,4 +9,13 @@ public interface TypeInsertable extends ITypeReplacementListener, Typeable {
|
||||
public void setOffset(int offset);
|
||||
public String getIdentifier();
|
||||
|
||||
/**
|
||||
* Errechnet den TypeInsertPoint für das TypeInsertable.
|
||||
* TypeInsertPoints sollten nur über diese Funktion erstellt werden.
|
||||
* @param tph
|
||||
* @param resultSet
|
||||
* @return - kann auch null zurückgeben.
|
||||
*/
|
||||
public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph, ResultSet resultSet);
|
||||
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -21,6 +21,7 @@ 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;
|
||||
|
||||
@ -43,7 +44,7 @@ public class TRMEqualTest {
|
||||
addTestNode("Typ1");
|
||||
assertTrue("Nach dem Anfügen eines Type muss das Set 1 Element enthalten",replaceSet.size()==1);
|
||||
addTestNode("Typ2");
|
||||
assertTrue("Nach dem Anfügen eines weiteren Typs muss das Set 2 Elemente enthalten",replaceSet.size()==2);
|
||||
assertTrue("Nach dem Anfügen eines weiteren Typs muss das Set 2 Elemente enthalten und nicht "+replaceSet.size(),replaceSet.size()==2);
|
||||
addTestNode("Typ1");
|
||||
assertTrue("Nach dem Anfügen des selben Typs wie zuvor muss das Set immer noch 2 Element enthalten. Und nicht "+replaceSet.size(),replaceSet.size()==2);
|
||||
}
|
||||
@ -103,6 +104,12 @@ class TestNode implements TypeInsertable{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph,
|
||||
ResultSet resultSet) {
|
||||
return new TypeInsertPoint(tph, this, resultSet.getTypeEqualTo(tph), resultSet);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import org.junit.Test;
|
||||
public class MutlitpleTestCases {
|
||||
|
||||
private static final String TEST_FILE = "Test1.jav";
|
||||
private static final String TEST_FILE2 = "Test2.jav";
|
||||
|
||||
@Test
|
||||
public void test1(){
|
||||
@ -15,4 +16,10 @@ public class MutlitpleTestCases {
|
||||
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2(){
|
||||
Vector<String> mustContain = new Vector<String>();
|
||||
MultipleTypesInsertTester.test(this.TEST_FILE2, mustContain);
|
||||
}
|
||||
|
||||
}
|
||||
|
4
test/plugindevelopment/TypeInsertTests/Test2.jav
Normal file
4
test/plugindevelopment/TypeInsertTests/Test2.jav
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
public class Matrix{
|
||||
op = (m) -> (f) -> f.apply(this, m);
|
||||
}
|
Loading…
Reference in New Issue
Block a user