2014-03-09 10:44:12 +00:00
|
|
|
|
package typinferenz;
|
|
|
|
|
|
|
|
|
|
import java.util.Vector;
|
|
|
|
|
|
2014-03-17 16:55:55 +00:00
|
|
|
|
import mycompiler.SyntaxTreeNode;
|
|
|
|
|
|
2014-03-09 10:44:12 +00:00
|
|
|
|
/**
|
|
|
|
|
* B<EFBFBD>ndelt ein Set von TypeInsertPoints, die alle zu einem TypePlaceholder geh<EFBFBD>ren.
|
|
|
|
|
* Diese m<EFBFBD>ssen gemeinsam eingesetzt werden.
|
|
|
|
|
* @author janulrich
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public class TypeInsertSet {
|
|
|
|
|
|
2014-03-09 13:12:48 +00:00
|
|
|
|
public Vector<TypeInsertPoint> points = new Vector<TypeInsertPoint>();
|
2014-03-09 10:44:12 +00:00
|
|
|
|
|
|
|
|
|
public TypeInsertSet(TypeInsertPoint p){
|
|
|
|
|
points.add(p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TypeInsertSet() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void add(TypeInsertPoint typeInsertPoint) {
|
|
|
|
|
points.add(typeInsertPoint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* F<EFBFBD>gt alle Typen dieses TypeInsertSets in den <EFBFBD>bergebenen Quellcode ein
|
|
|
|
|
* @param fileContent
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public String insertAllTypes(String fileContent) {
|
|
|
|
|
int additionalOffset = 0;
|
|
|
|
|
String ret = fileContent;
|
|
|
|
|
for(TypeInsertPoint p : points){
|
|
|
|
|
ret = p.insertType(ret, additionalOffset);
|
|
|
|
|
additionalOffset += p.getInsertLength();
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-17 16:55:55 +00:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param node
|
|
|
|
|
* @return - null, falls kein InsertPoint f<EFBFBD>r node vorhanden.
|
|
|
|
|
*/
|
|
|
|
|
public TypeInsertPoint getInsertPointFor(TypeInsertable node){
|
|
|
|
|
for(TypeInsertPoint point : points){
|
|
|
|
|
if(point.getInsertNode().equals(node))return point;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-18 12:38:47 +00:00
|
|
|
|
@Override
|
|
|
|
|
public boolean equals(Object obj){
|
|
|
|
|
if(! (obj instanceof TypeInsertSet))return false;
|
|
|
|
|
TypeInsertSet equals = (TypeInsertSet) obj;
|
|
|
|
|
for(TypeInsertPoint point : points){
|
|
|
|
|
//Jeder TypeInsertPoint muss auch in equals vorkommen:
|
|
|
|
|
if(!equals.points.contains(point))return false;
|
|
|
|
|
//... aber nicht <20>fter als 1x :
|
|
|
|
|
if(equals.points.lastIndexOf(point)!=equals.points.indexOf(point))return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-09 10:44:12 +00:00
|
|
|
|
}
|