JavaPatternMatching/src/typinferenz/TypeInsertSet.java

70 lines
1.6 KiB
Java

package typinferenz;
import java.util.Vector;
import mycompiler.SyntaxTreeNode;
/**
* Bündelt ein Set von TypeInsertPoints, die alle zu einem TypePlaceholder gehören.
* Diese müssen gemeinsam eingesetzt werden.
* @author janulrich
*
*/
public class TypeInsertSet {
public Vector<TypeInsertPoint> points = new Vector<TypeInsertPoint>();
public TypeInsertSet(TypeInsertPoint p){
points.add(p);
}
public TypeInsertSet() {
}
public void add(TypeInsertPoint typeInsertPoint) {
points.add(typeInsertPoint);
}
/**
* Fügt alle Typen dieses TypeInsertSets in den ü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;
}
/**
*
* @param node
* @return - null, falls kein InsertPoint für node vorhanden.
*/
public TypeInsertPoint getInsertPointFor(TypeInsertable node){
for(TypeInsertPoint point : points){
if(point.getInsertNode().equals(node))return point;
}
return null;
}
@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 öfter als 1x :
if(equals.points.lastIndexOf(point)!=equals.points.indexOf(point))return false;
}
return true;
}
}