Skip to content

Package: ConstructorByReferenceState

ConstructorByReferenceState

nameinstructionbranchcomplexitylinemethod
ConstructorByReferenceState(Constructor, Type)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
accept(ConstructorReferenceStateVisitor)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
accept(ConstructorReferenceStateVisitorException)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
accept(ConstructorReferenceStateVisitorReturn)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
accept(ConstructorReferenceStateVisitorReturnException)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
create(Constructor, Type)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
equals(Object)
M: 54 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
getTarget()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getType()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
hashCode()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
toString()
M: 42 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package de.fhdw.wtf.common.ast;
2:
3: import java.util.Collection;
4: import java.util.Iterator;
5:
6: import de.fhdw.wtf.common.ast.type.ProductElementType;
7: import de.fhdw.wtf.common.ast.type.ProductType;
8: import de.fhdw.wtf.common.ast.type.Type;
9: import de.fhdw.wtf.common.ast.visitor.ConstructorReferenceStateVisitor;
10: import de.fhdw.wtf.common.ast.visitor.ConstructorReferenceStateVisitorException;
11: import de.fhdw.wtf.common.ast.visitor.ConstructorReferenceStateVisitorReturn;
12: import de.fhdw.wtf.common.ast.visitor.ConstructorReferenceStateVisitorReturnException;
13: import de.fhdw.wtf.common.constants.parser.AstDescriptionConstants;
14:
15: /**
16: * This class represents a state of a {@link ConstructorReference}, which already has been successfully referenced by
17: * the Referencer.
18: */
19: public final class ConstructorByReferenceState implements ConstructorReferenceState {
20:         
21:         /**
22:          * The target-Constructor.
23:          */
24:         private final Constructor target;
25:         
26:         /**
27:          * The type of the target.
28:          */
29:         private final Type targetType;
30:         
31:         /**
32:          * Constructor of {@link ConstructorByReferenceState}.
33:          *
34:          * @param constructor
35:          * the target-Constructor
36:          * @param targetType
37:          * the type of the target.
38:          */
39:         private ConstructorByReferenceState(final Constructor constructor, final Type targetType) {
40:                 this.target = constructor;
41:                 this.targetType = targetType;
42:         }
43:         
44:         /**
45:          * Factory Method for {@link ConstructorByReferenceState}.
46:          *
47:          * @param constructor
48:          * constructor
49:          * @param targetType
50:          * targetType
51:          * @return {@link ConstructorByReferenceState}
52:          */
53:         public static ConstructorByReferenceState create(final Constructor constructor, final Type targetType) {
54:                 return new ConstructorByReferenceState(constructor, targetType);
55:         }
56:         
57:         /**
58:          * Returns the constructor that is the target of this.
59:          *
60:          * @return the constructor that is the target of this.
61:          */
62:         public Constructor getTarget() {
63:                 return this.target;
64:         }
65:         
66:         /**
67:          * Returns the type that the referenced constructor (target) belongs to.
68:          *
69:          * @return the type that the referenced constructor (target) belongs to.
70:          */
71:         public Type getType() {
72:                 return this.targetType;
73:         }
74:         
75:         @Override
76:         public boolean equals(final Object o) {
77:•                if (o instanceof ConstructorByReferenceState) {
78:                         final ConstructorByReferenceState other = (ConstructorByReferenceState) o;
79:                         final Constructor myTarget = this.getTarget();
80:                         final Constructor otherTarget = other.getTarget();
81:                         final ProductType myProductType = myTarget.getParameters();
82:                         final ProductType otherProductType = otherTarget.getParameters();
83:                         final Collection<ConstructorReference> myReferences = myTarget.getSuperConstructors();
84:                         final Collection<ConstructorReference> otherReferences = otherTarget.getSuperConstructors();
85:                         final Type myType = this.getType();
86:                         final Type otherType = other.getType();
87:•                        return myType.getTypeString().equals(otherType.getTypeString()) && myProductType.equals(otherProductType)
88:•                                        && myReferences.containsAll(otherReferences) && otherReferences.containsAll(myReferences);
89:                 }
90:                 return false;
91:         }
92:         
93:         @Override
94:         public int hashCode() {
95:                 return this.getTarget().hashCode() ^ this.getType().getTypeString().hashCode();
96:         }
97:         
98:         @Override
99:         public String toString() {
100:                 final StringBuilder result = new StringBuilder();
101:                 result.append(AstDescriptionConstants.BRACKET_OPEN_TOKEN);
102:                 final Iterator<ProductElementType> iterator = this.getTarget().getParameters().getElements().iterator();
103:•                while (iterator.hasNext()) {
104:                         final ProductElementType current = iterator.next();
105:                         result.append(current.getType().getTypeString());
106:•                        if (iterator.hasNext()) {
107:                                 result.append(AstDescriptionConstants.COMMA_TOKEN);
108:                         }
109:                 }
110:                 result.append(AstDescriptionConstants.BRACKET_CLOSE_TOKEN);
111:                 return result.toString();
112:         }
113:         
114:         @Override
115:         public void accept(final ConstructorReferenceStateVisitor v) {
116:                 v.handle(this);
117:         }
118:         
119:         @Override
120:         public <X> X accept(final ConstructorReferenceStateVisitorReturn<X> v) {
121:                 return v.handle(this);
122:         }
123:         
124:         @Override
125:         public <Y extends Exception> void accept(final ConstructorReferenceStateVisitorException<Y> v) throws Y {
126:                 v.handle(this);
127:         }
128:         
129:         @Override
130:         public <X, Y extends Exception> X accept(final ConstructorReferenceStateVisitorReturnException<X, Y> v) throws Y {
131:                 return v.handle(this);
132:         }
133: }