From 11b63e0a5d3e0598eaf520adec9f72981d4f5114 Mon Sep 17 00:00:00 2001 From: Till Schnell Date: Thu, 8 Apr 2021 18:52:33 +0200 Subject: [PATCH] remove raw types and add java doc --- .../ConstraintsGenerationUtils.java | 49 ++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/inferWildcards/ConstraintsGenerationUtils.java b/src/main/java/de/dhbwstuttgart/inferWildcards/ConstraintsGenerationUtils.java index b1c35c15..8c792f60 100644 --- a/src/main/java/de/dhbwstuttgart/inferWildcards/ConstraintsGenerationUtils.java +++ b/src/main/java/de/dhbwstuttgart/inferWildcards/ConstraintsGenerationUtils.java @@ -15,6 +15,12 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.constraints.Pair; 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 { @@ -22,23 +28,37 @@ public final class ConstraintsGenerationUtils throw new AssertionError("No ConstraintsGenerationUtils instance for you"); } - @SuppressWarnings("rawtypes") - public static ConstraintSet generateConstraints (Map tphMap) { - ConstraintSet constraintSet = new ConstraintSet<>(); + /** + * Generate the constraints for a map of type placeholder and RefType. + * + * @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 generateConstraints (Map tphMap) { + ConstraintSet constraintSet = new ConstraintSet<>(); tphMap.forEach( (tph, refType) -> { - ConstraintSet constraintSet2 = generateConstraints(refType, tph); + ConstraintSet constraintSet2 = generateConstraints(refType, tph); constraintSet.addAll(constraintSet2); }); return constraintSet; } - @SuppressWarnings({ "unchecked", "rawtypes" }) - public static ConstraintSet generateConstraints (RefType refType, TypePlaceholder tph) { - ConstraintSet constraintSet = new ConstraintSet<>(); - Set> oderConstraints = new HashSet<>(); + /** + * Generate the constraints for a single RefType type placeholder pair to infer + * the wildcards for the generic parameter type. + * + * @param refType {@link RefType} + * @param tph {@link TypePlaceholder} + * @return {@link ConstraintSet} of {@link Pair} generated containing the + * constraints. + */ + public static ConstraintSet generateConstraints (RefType refType, TypePlaceholder tph) { + ConstraintSet constraintSet = new ConstraintSet<>(); + Set> oderConstraints = new HashSet<>(); constraintSet.addOderConstraint(oderConstraints); - Constraint c = new Constraint<>(); + Constraint c = new Constraint<>(); oderConstraints.add(c); // single type @@ -55,8 +75,15 @@ public final class ConstraintsGenerationUtils 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 c, TypePlaceholder tph, + RefTypeOrTPHOrWildcardOrGeneric type) { Pair pair = new Pair(tph, type, PairOperator.EQUALSDOT); c.add(pair); }