@Test public void testParams() { ProducedType type = new TypeParser(MockLoader.instance, mockUnit).decodeType("t2<b,c>", null); Assert.assertNotNull(type); TypeDeclaration declaration = type.getDeclaration(); Assert.assertNotNull(declaration); Assert.assertTrue(declaration instanceof Class); Assert.assertEquals("t2", declaration.getName()); Assert.assertEquals(2, type.getTypeArgumentList().size()); Assert.assertEquals("b", type.getTypeArgumentList().get(0).getDeclaration().getName()); Assert.assertTrue(type.getTypeArgumentList().get(0).getDeclaration() instanceof Class); Assert.assertEquals("c", type.getTypeArgumentList().get(1).getDeclaration().getName()); Assert.assertTrue(type.getTypeArgumentList().get(1).getDeclaration() instanceof Class); }
private void addLocalType( Declaration dec, ProducedType type, List<TypeDeclaration> localTypes, List<ProducedType> visited) { if (visited.contains(type)) { return; } else { visited.add(type); } TypeDeclaration td = type.getDeclaration(); if (td.getContainer() == dec) { boolean found = false; for (TypeDeclaration typeDeclaration : localTypes) { if (typeDeclaration == td) { found = true; break; } } if (!found) { localTypes.add(td); } } for (ProducedType pt : td.getSatisfiedTypes()) { addLocalType(dec, pt, localTypes, visited); } for (ProducedType pt : type.getTypeArgumentList()) { addLocalType(dec, pt, localTypes, visited); } }
public ProducedType getElementType(ProducedType pt) { ProducedType st = getNonemptySequenceType(pt); if (st != null && st.getTypeArguments().size() == 1) { return st.getTypeArgumentList().get(0); } else { return null; } }
public ProducedType getIteratedType(ProducedType type) { ProducedType st = type.getSupertype(getIterableDeclaration()); if (st != null && st.getTypeArguments().size() == 1) { return st.getTypeArgumentList().get(0); } else { return null; } }
public ProducedType getValueType(ProducedType type) { ProducedType st = type.getSupertype(getEntryDeclaration()); if (st != null && st.getTypeArguments().size() == 2) { return st.getTypeArgumentList().get(1); } else { return null; } }
@Test public void testQualifiedAndParameterised() { ProducedType type = new TypeParser(MockLoader.instance, mockUnit).decodeType("t2<a,b>.t2<c,d>", null); Assert.assertNotNull(type); TypeDeclaration declaration = type.getDeclaration(); Assert.assertNotNull(declaration); Assert.assertTrue(declaration instanceof Class); Assert.assertEquals("t2.t2", declaration.getName()); Assert.assertEquals(2, type.getTypeArgumentList().size()); // c ProducedType c = type.getTypeArgumentList().get(0); Assert.assertEquals("c", c.getDeclaration().getName()); Assert.assertTrue(c.getDeclaration() instanceof Class); // d ProducedType d = type.getTypeArgumentList().get(1); Assert.assertEquals("d", d.getDeclaration().getName()); Assert.assertTrue(d.getDeclaration() instanceof Class); ProducedType qualifyingType = type.getQualifyingType(); Assert.assertNotNull(qualifyingType); TypeDeclaration qualifyingDeclaration = qualifyingType.getDeclaration(); Assert.assertNotNull(qualifyingDeclaration); Assert.assertTrue(qualifyingDeclaration instanceof Class); Assert.assertEquals("t2", qualifyingDeclaration.getName()); Assert.assertEquals(2, qualifyingType.getTypeArgumentList().size()); // a ProducedType a = qualifyingType.getTypeArgumentList().get(0); Assert.assertEquals("a", a.getDeclaration().getName()); Assert.assertTrue(a.getDeclaration() instanceof Class); // b ProducedType b = qualifyingType.getTypeArgumentList().get(1); Assert.assertEquals("b", b.getDeclaration().getName()); Assert.assertTrue(b.getDeclaration() instanceof Class); }
@Test public void testUnionParams() { ProducedType type = new TypeParser(MockLoader.instance, mockUnit).decodeType("a|t2<b|c,t2<d,e|f>>", null); Assert.assertNotNull(type); TypeDeclaration declaration = type.getDeclaration(); Assert.assertNotNull(declaration); Assert.assertTrue(declaration instanceof UnionType); UnionType union = (UnionType) declaration; List<ProducedType> caseTypes = union.getCaseTypes(); Assert.assertEquals(2, caseTypes.size()); // a Assert.assertEquals("a", caseTypes.get(0).getDeclaration().getName()); Assert.assertTrue(caseTypes.get(0).getDeclaration() instanceof Class); // first t2 ProducedType firstT2 = caseTypes.get(1); TypeDeclaration firstT2Declaration = firstT2.getDeclaration(); Assert.assertNotNull(firstT2Declaration); Assert.assertTrue(firstT2Declaration instanceof Class); Assert.assertEquals("t2", firstT2Declaration.getName()); Assert.assertEquals(2, firstT2.getTypeArgumentList().size()); // b|c ProducedType bc = firstT2.getTypeArgumentList().get(0); Assert.assertTrue(bc.getDeclaration() instanceof UnionType); Assert.assertEquals(2, bc.getDeclaration().getCaseTypes().size()); // b ProducedType b = bc.getDeclaration().getCaseTypes().get(0); Assert.assertEquals("b", b.getDeclaration().getName()); Assert.assertTrue(b.getDeclaration() instanceof Class); // c ProducedType c = bc.getDeclaration().getCaseTypes().get(1); Assert.assertEquals("c", c.getDeclaration().getName()); Assert.assertTrue(c.getDeclaration() instanceof Class); // second t2 ProducedType secondT2 = firstT2.getTypeArgumentList().get(1); TypeDeclaration secondT2Declaration = firstT2.getDeclaration(); Assert.assertNotNull(secondT2Declaration); Assert.assertTrue(secondT2Declaration instanceof Class); Assert.assertEquals("t2", secondT2Declaration.getName()); Assert.assertEquals(2, secondT2.getTypeArgumentList().size()); // d ProducedType d = secondT2.getTypeArgumentList().get(0); Assert.assertEquals("d", d.getDeclaration().getName()); Assert.assertTrue(d.getDeclaration() instanceof Class); // e|f ProducedType ef = secondT2.getTypeArgumentList().get(1); Assert.assertTrue(ef.getDeclaration() instanceof UnionType); Assert.assertEquals(2, ef.getDeclaration().getCaseTypes().size()); // e ProducedType e = ef.getDeclaration().getCaseTypes().get(0); Assert.assertEquals("e", e.getDeclaration().getName()); Assert.assertTrue(e.getDeclaration() instanceof Class); // f ProducedType f = ef.getDeclaration().getCaseTypes().get(1); Assert.assertEquals("f", f.getDeclaration().getName()); Assert.assertTrue(f.getDeclaration() instanceof Class); }