ResultSet um resolveType erweitern

This commit is contained in:
JanUlrich 2017-09-07 17:02:49 +02:00
parent 7c3181c3f0
commit b6f62b48eb
22 changed files with 410 additions and 87 deletions

View File

@ -100,7 +100,7 @@ var activeTableTab = "activeTableTab";
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>de.dhbwstuttgart.typeinference.ResultSet</li>
<li>de.dhbwstuttgart.typeinference.result.ResultSet</li>
</ul>
</li>
</ul>

View File

@ -3,7 +3,7 @@
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_05) on Tue May 12 19:56:24 CEST 2015 -->
<title>Uses of Class de.dhbwstuttgart.typeinference.ResultSet</title>
<title>Uses of Class de.dhbwstuttgart.typeinference.result.ResultSet</title>
<meta name="date" content="2015-05-12">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../script.js"></script>
@ -70,7 +70,7 @@
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<div class="header">
<h2 title="Uses of Class de.dhbwstuttgart.typeinference.ResultSet" class="title">Uses of Class<br>de.dhbwstuttgart.typeinference.ResultSet</h2>
<h2 title="Uses of Class de.dhbwstuttgart.typeinference.result.ResultSet" class="title">Uses of Class<br>de.dhbwstuttgart.typeinference.ResultSet</h2>
</div>
<div class="classUseContainer">
<ul class="blockList">

View File

@ -1,25 +1,18 @@
package de.dhbwstuttgart.core;
import de.dhbwstuttgart.exceptions.DebugException;
import de.dhbwstuttgart.parser.JavaTXParser;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typedeployment.TypeInsertPoint;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
import java.io.File;
import java.io.IOException;
@ -52,7 +45,7 @@ public class JavaTXCompiler {
System.out.println("RESULT: " + result);
results.addAll(result);
}
return new ResultSet(UnifyTypeFactory.convert(results, generateTPHMap(cons)));
return new ResultSet(UnifyTypeFactory.convert(results.iterator().next(), generateTPHMap(cons)));
//return new ResultSet(new HashSet<>(Arrays.asList(UnifyTypeFactory.convert(results, generateTPHMap(cons)).iterator().next())));
}

View File

@ -467,7 +467,7 @@ public class StatementGenerator {
private Statement convert(Java8Parser.ReturnStatementContext stmt){
if(stmt.expression() != null){
return new Return( convert(stmt.expression()),stmt.getStart());
return new Return( convert(stmt.expression()),stmt.getStart() );
}else{
return new ReturnVoid(stmt.getStart());
}

View File

@ -11,6 +11,9 @@ import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.typecheck.JavaClassName;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefType;
import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH;
import de.dhbwstuttgart.typeinference.result.ResultPair;
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.FunNType;
@ -133,18 +136,20 @@ public class UnifyTypeFactory {
* Convert from
* UnifyType -> ASTType
*/
public static Set<Set<Pair>> convert(Set<Set<UnifyPair>> unifyPairSet, Map<String,TypePlaceholder> tphs) {
public static Set<ResultPair> convert(Set<UnifyPair> unifyPairSet, Map<String,TypePlaceholder> tphs) {
return unifyPairSet.stream().map(
set -> set.stream().map(
unifyPair -> convert(unifyPair, tphs))
.collect(Collectors.toSet()))
.collect(Collectors.toSet());
unifyPair -> convert(unifyPair, tphs))
.collect(Collectors.toSet());
}
public static Pair convert(UnifyPair mp, Map<String,TypePlaceholder> tphs) {
public static ResultPair convert(UnifyPair mp, Map<String,TypePlaceholder> tphs) {
RefTypeOrTPHOrWildcardOrGeneric tl = UnifyTypeFactory.convert(mp.getLhsType(), tphs);
RefTypeOrTPHOrWildcardOrGeneric tr = UnifyTypeFactory.convert(mp.getRhsType(), tphs);
return new Pair(tl, tr, mp.getPairOp());
if(tl instanceof TypePlaceholder){
if(tr instanceof TypePlaceholder) return new PairTPHsmallerTPH((TypePlaceholder)tl, (TypePlaceholder)tr);
if(tr instanceof RefType)return new PairTPHequalRefType((TypePlaceholder)tl, (RefType)tr);
throw new NotImplementedException();
}else throw new NotImplementedException();
}
public static RefTypeOrTPHOrWildcardOrGeneric convert(ReferenceType t, Map<String,TypePlaceholder> tphs) {

View File

@ -2,6 +2,7 @@ package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
import org.antlr.v4.runtime.Token;
/**
@ -38,4 +39,9 @@ public class ExtendsWildcardType extends WildcardType{
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
@Override
public void accept(ResultSetVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -3,6 +3,7 @@ package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import de.dhbwstuttgart.typecheck.GenericTypeName;
import de.dhbwstuttgart.typecheck.JavaClassName;
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
import org.antlr.v4.runtime.Token;
public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
@ -26,5 +27,10 @@ public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
@Override
public void accept(ResultSetVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -2,6 +2,7 @@ package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import de.dhbwstuttgart.typecheck.JavaClassName;
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
import org.antlr.v4.runtime.Token;
import java.util.ArrayList;
@ -105,5 +106,10 @@ public class RefType extends RefTypeOrTPHOrWildcardOrGeneric
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
@Override
public void accept(ResultSetVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -2,6 +2,7 @@ package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
import org.antlr.v4.runtime.Token;
public abstract class RefTypeOrTPHOrWildcardOrGeneric extends SyntaxTreeNode{
@ -11,4 +12,6 @@ public abstract class RefTypeOrTPHOrWildcardOrGeneric extends SyntaxTreeNode{
@Override
public abstract void accept(ASTVisitor visitor);
public abstract void accept(ResultSetVisitor visitor);
}

View File

@ -2,6 +2,7 @@ package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
import org.antlr.v4.runtime.Token;
/**
@ -48,4 +49,9 @@ public class SuperWildcardType extends WildcardType{
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
@Override
public void accept(ResultSetVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -4,6 +4,7 @@ import java.util.Hashtable;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
import org.antlr.v4.runtime.Token;
/**
@ -71,4 +72,9 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
@Override
public void accept(ResultSetVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -3,8 +3,9 @@ package de.dhbwstuttgart.typedeployment;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
import de.dhbwstuttgart.typeinference.result.ResolvedType;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import org.antlr.v4.runtime.Token;
import java.util.*;
@ -30,10 +31,16 @@ public class TypeInsertFactory {
}
public static TypeInsert createInsertPoints(RefTypeOrTPHOrWildcardOrGeneric type, Token offset, ClassOrInterface cl, Method m,
Set<Pair> pairs) {
ResultSet resultSet) {
Set<TypeInsertPoint> ret = new HashSet<>();
TypeInsertPoint insertPoint = null;
Set<TypePlaceholder> additionalInserts = new HashSet<>();
ResolvedType resolvedType = resultSet.resolveType(type);
if(resolvedType.resolvedType instanceof RefType){
insertPoint = new TypeInsertPoint(offset,
createInsertString((RefType) resolvedType.resolvedType));
}
return new TypeInsert(insertPoint, new HashSet<>(Arrays.asList(createGenericInsert(resolvedType.additionalGenerics, cl, m))));
/*
for (Pair pair : pairs) {
RefTypeOrTPHOrWildcardOrGeneric relatedType = null;
if (pair.TA1.equals(type)) {
@ -97,10 +104,10 @@ public class TypeInsertFactory {
ret.add(createGenericInsert(newGenerics, cl, m));
//return ret;
return new TypeInsert(insertPoint, ret);
*/
}
private static String createInsertString(RefType resolved, Set<TypePlaceholder> additionalInserts) {
private static String createInsertString(RefType resolved) {
String insert = resolved.getName().toString();
if(resolved.getParaList().size() > 0){
insert += "<";
@ -109,13 +116,12 @@ public class TypeInsertFactory {
RefTypeOrTPHOrWildcardOrGeneric typeParam = iterator.next();
if(typeParam instanceof TypePlaceholder){
insert += ((TypePlaceholder) typeParam).getName();
additionalInserts.add((TypePlaceholder) typeParam);
}else if(typeParam instanceof RefType) {
insert += createInsertString((RefType) typeParam, additionalInserts);
insert += createInsertString((RefType) typeParam);
}else if(typeParam instanceof SuperWildcardType){
insert += "? super " + createInsertString(((SuperWildcardType) typeParam).getInnerType(), additionalInserts);
insert += "? super " + createInsertString(((SuperWildcardType) typeParam).getInnerType());
}else if(typeParam instanceof ExtendsWildcardType){
insert += "? extends " + createInsertString(((ExtendsWildcardType) typeParam).getInnerType(), additionalInserts);
insert += "? extends " + createInsertString(((ExtendsWildcardType) typeParam).getInnerType());
}else throw new NotImplementedException();
if(iterator.hasNext())insert += ", ";
}

View File

@ -1,16 +1,13 @@
package de.dhbwstuttgart.typedeployment;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.statement.AssignLeftSide;
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.ResultPair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class TypeInsertPlacer extends AbstractASTWalker{
@ -43,18 +40,16 @@ class TypeInsertPlacerClass extends AbstractASTWalker{
@Override
public void visit(Method method) {
for(Set<Pair> pairs : results.results)
inserts.add(TypeInsertFactory.createInsertPoints(
method.getReturnType(), method.getReturnType().getOffset(), cl, null, pairs));
method.getReturnType(), method.getReturnType().getOffset(), cl, null, results));
super.visit(method);
}
@Override
public void visit(Field field) {
if(field.getType() instanceof TypePlaceholder){
for(Set<Pair> pairs : results.results)
inserts.add(TypeInsertFactory.createInsertPoints(
field.getType(), field.getType().getOffset(), cl, null, pairs));
field.getType(), field.getType().getOffset(), cl, null, results));
}
super.visit(field);
}
@ -62,9 +57,8 @@ class TypeInsertPlacerClass extends AbstractASTWalker{
@Override
public void visit(ParameterList params) {
for(FormalParameter param : params){
for(Set<Pair> pairs : results.results)
inserts.add(TypeInsertFactory.createInsertPoints(
param.getType(), param.getType().getOffset(), cl, null, pairs));
param.getType(), param.getType().getOffset(), cl, null, results));
}
super.visit(params);
}

View File

@ -1,36 +0,0 @@
package de.dhbwstuttgart.typeinference;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class ResultSet {
public final Set<Set<Pair>> results;
public ResultSet(Set<Set<Pair>> results){
this.results = results;
}
public List<Pair> resolveType(RefTypeOrTPHOrWildcardOrGeneric type) {
/*//Probleme:
* Es müssen teilweise mehrere TPH eingesetzt werden
* Es werden alle eingesetzt, welch in der Kette stehen!
* TPHs müssen zu eindeutigen Namen aufgelöst werden
*/
final List<Pair> ret = new ArrayList<>();
for(Set<Pair> pairs : results)for(Pair pair : pairs){
//if(pair.OperatorEqual()){ //type ist vom Typ TypePlaceholder
if(pair.TA1.equals(type) || pair.TA2.equals(type)){
ret.add(pair);
}
//}
}
return ret;
}
}

View File

@ -1,4 +1,4 @@
package de.dhbwstuttgart.typedeployment;
package de.dhbwstuttgart.typeinference.result;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;

View File

@ -0,0 +1,23 @@
package de.dhbwstuttgart.typeinference.result;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
/**
* Steht für A =. RefType
*/
public class PairTPHequalRefType extends ResultPair{
public final TypePlaceholder left;
public final RefType right;
public PairTPHequalRefType(TypePlaceholder left, RefType right){
super(left, right);
this.left = left;
this.right = right;
}
@Override
public void accept(ResultSetVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -0,0 +1,23 @@
package de.dhbwstuttgart.typeinference.result;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
/**
* Steht für: A <. B
*/
public class PairTPHsmallerTPH extends ResultPair{
public final TypePlaceholder left;
public final TypePlaceholder right;
public PairTPHsmallerTPH(TypePlaceholder left, TypePlaceholder right){
super(left, right);
this.left = left;
this.right = right;
}
@Override
public void accept(ResultSetVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -0,0 +1,17 @@
package de.dhbwstuttgart.typeinference.result;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import java.util.Set;
public class ResolvedType{
public final RefTypeOrTPHOrWildcardOrGeneric resolvedType;
public final Set<GenericInsertPair> additionalGenerics;
public ResolvedType(RefTypeOrTPHOrWildcardOrGeneric resolvedType, Set<GenericInsertPair> additionalGenerics){
this.resolvedType = resolvedType;
this.additionalGenerics = additionalGenerics;
}
}

View File

@ -0,0 +1,26 @@
package de.dhbwstuttgart.typeinference.result;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
/**
* Paare, welche das Unifikationsergebnis darstellen
*/
public abstract class ResultPair {
private final RefTypeOrTPHOrWildcardOrGeneric left;
private final RefTypeOrTPHOrWildcardOrGeneric right;
public abstract void accept(ResultSetVisitor visitor);
public ResultPair(RefTypeOrTPHOrWildcardOrGeneric left, RefTypeOrTPHOrWildcardOrGeneric right){
this.left = left;
this.right = right;
}
public RefTypeOrTPHOrWildcardOrGeneric getLeft() {
return left;
}
public RefTypeOrTPHOrWildcardOrGeneric getRight() {
return right;
}
}

View File

@ -0,0 +1,230 @@
package de.dhbwstuttgart.typeinference.result;
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import javax.xml.transform.Result;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ResultSet {
public final Set<ResultPair> results;
public ResultSet(Set<ResultPair> results){
this.results = results;
}
public ResolvedType resolveType(RefTypeOrTPHOrWildcardOrGeneric type) {
if(type instanceof TypePlaceholder)
return new Resolver(this).resolve((TypePlaceholder)type);
if(type instanceof RefType){
RelatedTypeWalker related = new RelatedTypeWalker(null, this);
type.accept(related);
return new ResolvedType(type, related.relatedTPHs);
}else{
return new ResolvedType(type,new HashSet<>());
}
}
//TODO Beim Einsetzen eines Generics, müssen die new und Methodenaufrufe verändert werden
}
class Resolver implements ResultSetVisitor {
private final ResultSet result;
private TypePlaceholder toResolve;
private RefType resolved;
private final Set<GenericInsertPair> additionalTPHs = new HashSet<>();
public Resolver(ResultSet resultPairs){
this.result = resultPairs;
}
public ResolvedType resolve(TypePlaceholder tph){
toResolve = tph;
resolved = null;
for(ResultPair resultPair : result.results){
resultPair.accept(this);
}
if(resolved==null){//TPH kommt nicht im Result vor:
}
return new ResolvedType(resolved, additionalTPHs);//resolved;
}
@Override
public void visit(PairTPHsmallerTPH p) {
if(p.left.equals(toResolve)){
additionalTPHs.add(new GenericInsertPair(p.left, p.right));
additionalTPHs.addAll(new RelatedTypeWalker(p.right, result).relatedTPHs);
}
if(p.right.equals(toResolve))
additionalTPHs.addAll(new RelatedTypeWalker(p.left, result).relatedTPHs);
}
@Override
public void visit(PairTPHequalRefType p) {
if(p.left.equals(toResolve)){
resolved = p.right;
RelatedTypeWalker related = new RelatedTypeWalker(null, result);
related.visit(p.right);
additionalTPHs.addAll(related.relatedTPHs);
}
}
@Override
public void visit(RefType refType) {
}
@Override
public void visit(GenericRefType genericRefType) {
}
@Override
public void visit(SuperWildcardType superWildcardType) {
}
@Override
public void visit(TypePlaceholder typePlaceholder) {
}
@Override
public void visit(ExtendsWildcardType extendsWildcardType) {
}
}
/**
* Sucht aus dem Result Set den Sub/supertyp für einen TPH
*/
class TPHResolver implements ResultSetVisitor {
private final TypePlaceholder tph;
Set<GenericInsertPair> resolved = new HashSet<>();
TPHResolver(TypePlaceholder tph, ResultSet resultSet){
this.tph = tph;
for(ResultPair p : resultSet.results){
p.accept(this);
}
if(resolved.size() == 0){
resolved.add(new GenericInsertPair(tph, null));
}
}
@Override
public void visit(PairTPHsmallerTPH p) {
if(p.left.equals(tph) || p.right.equals(tph)){
resolved.add(new GenericInsertPair(p.left, p.right));
}
}
@Override
public void visit(PairTPHequalRefType p) {
}
@Override
public void visit(RefType refType) {
}
@Override
public void visit(GenericRefType genericRefType) {
}
@Override
public void visit(SuperWildcardType superWildcardType) {
}
@Override
public void visit(TypePlaceholder typePlaceholder) {
}
@Override
public void visit(ExtendsWildcardType extendsWildcardType) {
}
}
class RelatedTypeWalker implements ResultSetVisitor {
final Set<GenericInsertPair> relatedTPHs = new HashSet<>();
private final TypePlaceholder toResolve;
private final ResultSet resultSet;
/**
* Läuft über das resultSet und speichert alle TPHs, welche mit start in Verbindung stehen
* @param start
* @param resultSet
*/
RelatedTypeWalker(TypePlaceholder start, ResultSet resultSet){
this.toResolve = start;
this.resultSet = resultSet;
for(ResultPair p : resultSet.results){
p.accept(this);
p.accept(this);
}
}
@Override
public void visit(PairTPHsmallerTPH p) {
if(p.getRight().equals(toResolve)){
relatedTPHs.addAll(new TPHResolver(p.right, resultSet).resolved);
relatedTPHs.addAll(new RelatedTypeWalker(p.right, resultSet).relatedTPHs);
}
if(p.getLeft().equals(toResolve)){
relatedTPHs.addAll(new TPHResolver(p.left, resultSet).resolved);
relatedTPHs.addAll(new RelatedTypeWalker(p.left, resultSet).relatedTPHs);
}
}
@Override
public void visit(PairTPHequalRefType p) {
if(p.getLeft().equals(toResolve)){
p.getRight().accept(this);
}
}
/*
Die folgenden Funktionen fügen alle TPHs an die relatedTPHs an, denen sie begegnen:
*/
@Override
public void visit(RefType refType) {
for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){
param.accept(this);
}
}
@Override
public void visit(SuperWildcardType superWildcardType) {
superWildcardType.getInnerType().accept(this);
}
@Override
public void visit(TypePlaceholder typePlaceholder) {
relatedTPHs.addAll(new TPHResolver(typePlaceholder, resultSet).resolved);
}
@Override
public void visit(ExtendsWildcardType extendsWildcardType) {
extendsWildcardType.getInnerType().accept(this);
}
@Override
public void visit(GenericRefType genericRefType) {
}
}

View File

@ -0,0 +1,18 @@
package de.dhbwstuttgart.typeinference.result;
import de.dhbwstuttgart.syntaxtree.type.*;
public interface ResultSetVisitor {
void visit(PairTPHsmallerTPH p);
void visit(PairTPHequalRefType p);
void visit(RefType refType);
void visit(GenericRefType genericRefType);
void visit(SuperWildcardType superWildcardType);
void visit(TypePlaceholder typePlaceholder);
void visit(ExtendsWildcardType extendsWildcardType);
}

View File

@ -1,17 +1,10 @@
package typeinference;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.exceptions.DebugException;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.syntaxtree.visual.OutputGenerator;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typedeployment.TypeInsertPoint;
import de.dhbwstuttgart.typeinference.ResultSet;
import org.junit.Test;
import java.io.File;
@ -24,8 +17,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import static org.junit.Assert.*;
public class JavaTXCompilerTest extends JavaTXCompiler {
private static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/";