remove raw types and add java doc

This commit is contained in:
Till Schnell 2021-04-08 18:52:33 +02:00
parent 5f7829191c
commit 11b63e0a5d

View File

@ -15,6 +15,12 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator; import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
/**
* Utilities to generate the constraints for the infer wildcards algorithm.
*
* @author Till Schnell
* @version 1.0
*/
public final class ConstraintsGenerationUtils public final class ConstraintsGenerationUtils
{ {
@ -22,23 +28,37 @@ public final class ConstraintsGenerationUtils
throw new AssertionError("No ConstraintsGenerationUtils instance for you"); throw new AssertionError("No ConstraintsGenerationUtils instance for you");
} }
@SuppressWarnings("rawtypes") /**
public static ConstraintSet generateConstraints (Map<TypePlaceholder, RefType> tphMap) { * Generate the constraints for a map of type placeholder and RefType.
ConstraintSet constraintSet = new ConstraintSet<>(); *
* @param tphMap {@link Map} of {@link TypePlaceholder} and {@link RefType}
* @return {@link ConstraintSet} of {@link Pair} containing the constraints to
* infer the matching wildcard type.
*/
public static ConstraintSet<Pair> generateConstraints (Map<TypePlaceholder, RefType> tphMap) {
ConstraintSet<Pair> constraintSet = new ConstraintSet<>();
tphMap.forEach( (tph, refType) -> { tphMap.forEach( (tph, refType) -> {
ConstraintSet constraintSet2 = generateConstraints(refType, tph); ConstraintSet<Pair> constraintSet2 = generateConstraints(refType, tph);
constraintSet.addAll(constraintSet2); constraintSet.addAll(constraintSet2);
}); });
return constraintSet; return constraintSet;
} }
@SuppressWarnings({ "unchecked", "rawtypes" }) /**
public static ConstraintSet generateConstraints (RefType refType, TypePlaceholder tph) { * Generate the constraints for a single RefType type placeholder pair to infer
ConstraintSet constraintSet = new ConstraintSet<>(); * the wildcards for the generic parameter type.
Set<Constraint<?>> oderConstraints = new HashSet<>(); *
* @param refType {@link RefType}
* @param tph {@link TypePlaceholder}
* @return {@link ConstraintSet} of {@link Pair} generated containing the
* constraints.
*/
public static ConstraintSet<Pair> generateConstraints (RefType refType, TypePlaceholder tph) {
ConstraintSet<Pair> constraintSet = new ConstraintSet<>();
Set<Constraint<Pair>> oderConstraints = new HashSet<>();
constraintSet.addOderConstraint(oderConstraints); constraintSet.addOderConstraint(oderConstraints);
Constraint<?> c = new Constraint<>(); Constraint<Pair> c = new Constraint<>();
oderConstraints.add(c); oderConstraints.add(c);
// single type // single type
@ -55,8 +75,15 @@ public final class ConstraintsGenerationUtils
return constraintSet; return constraintSet;
} }
@SuppressWarnings({ "unchecked", "rawtypes" }) /**
private static void addToConstraint (Constraint c, TypePlaceholder tph, RefTypeOrTPHOrWildcardOrGeneric type) { * Generate a pair and adds it to a constraint.
*
* @param c {@link Constraint} of {@link Pair}
* @param tph {@link TypePlaceholder}
* @param type {@link RefTypeOrTPHOrWildcardOrGeneric}
*/
private static void addToConstraint (Constraint<Pair> c, TypePlaceholder tph,
RefTypeOrTPHOrWildcardOrGeneric type) {
Pair pair = new Pair(tph, type, PairOperator.EQUALSDOT); Pair pair = new Pair(tph, type, PairOperator.EQUALSDOT);
c.add(pair); c.add(pair);
} }