TypeInsert ausbessern

This commit is contained in:
JanUlrich 2017-08-25 02:59:16 +02:00
parent 77c59de0f0
commit 397ac3cd58
3 changed files with 19 additions and 48 deletions

View File

@ -15,13 +15,9 @@ public class GenericTypeName extends JavaClassName {
this.methodName = genericContext.parentMethod;
}
public String toString(){
public String getUniqueIdentifier() {
return parentClass.toString()
+ DELIMITER + methodName
+ DELIMITER + super.toString();
}
public String getShortName() {
return super.toString();
}
}

View File

@ -1,15 +1,12 @@
package de.dhbwstuttgart.typedeployment;
import de.dhbwstuttgart.exceptions.DebugException;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import org.antlr.v4.runtime.Token;
import java.lang.reflect.Type;
import java.util.*;
/**
@ -59,9 +56,13 @@ public class TypeInsertFactory {
}
}
}
if(insertPoint == null){ //Dann muss es ein TPH sein, welcher nicht im Result auftaucht
insertPoint = new TypeInsertPoint(offset, ((TypePlaceholder) type).getName());
additionalInserts.add(((TypePlaceholder) type));
if(insertPoint == null ){ //Dann muss es ein TPH sein, welcher nicht im Result auftaucht
if(type instanceof TypePlaceholder){
insertPoint = new TypeInsertPoint(offset, ((TypePlaceholder) type).getName());
additionalInserts.add(((TypePlaceholder) type));
}else if(type instanceof GenericRefType){
insertPoint = new TypeInsertPoint(offset, ((GenericRefType) type).getName().toString());
}else throw new NotImplementedException();
}
//Alle Bounds finden:

View File

@ -27,37 +27,11 @@ public class TypeInsertPlacer extends AbstractASTWalker{
TypeInsertPlacerClass cl = new TypeInsertPlacerClass(classOrInterface, withResults);
this.inserts.addAll(cl.inserts);
}
/*
List<TypeInsert> ret = new ArrayList<>();
for(ClassOrInterface cl : forSourcefile.getClasses()){
//Felder:
for(Field field : cl.getFieldDecl()){
}
for(Method m : cl.getMethods()){
if(m.getReturnType() instanceof TypePlaceholder)for(Set<Pair> pairs : withResults.results) {
ret.add(createInsertPoints(
m.getReturnType(), m.getReturnType().getOffset(), cl, m, pairs));
}
for(FormalParameter param : m.getParameterList().getFormalparalist()){
if(param.getType() instanceof TypePlaceholder)for(Set<Pair> pairs : withResults.results)
ret.add(createInsertPoints(
param.getType(), param.getType().getOffset(), cl, m, pairs));
}
}
}
return ret;
*/
}
class TypeInsertPlacerClass extends AbstractASTWalker{
private final ResultSet results;
private final ClassOrInterface cl;
protected final ResultSet results;
protected final ClassOrInterface cl;
public final Set<TypeInsert> inserts = new HashSet<>();
TypeInsertPlacerClass(ClassOrInterface forClass, ResultSet withResults){
@ -68,7 +42,9 @@ class TypeInsertPlacerClass extends AbstractASTWalker{
@Override
public void visit(Method method) {
TypeInsertPlacerMethod mWalker = new TypeInsertPlacerMethod(method);
for(Set<Pair> pairs : results.results)
inserts.add(TypeInsertFactory.createInsertPoints(
method.getReturnType(), method.getReturnType().getOffset(), cl, null, pairs));
super.visit(method);
}
@ -81,15 +57,14 @@ class TypeInsertPlacerClass extends AbstractASTWalker{
}
super.visit(field);
}
}
class TypeInsertPlacerMethod extends AbstractASTWalker{
TypeInsertPlacerMethod(Method forMethod){
forMethod.accept(this);
}
@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));
}
super.visit(params);
}
@ -97,5 +72,4 @@ class TypeInsertPlacerMethod extends AbstractASTWalker{
public void visit(LambdaExpression lambdaExpression) {
//Lambda-Ausdrücke brauchen keine Typeinsetzungen
}
}
}