@Test public void testContainsFields() throws Exception { JvmTypeReference reference = typeRefs.typeReference(SubClass.class.getName()).create(); Iterable<JvmFeature> iterable = service.getAllJvmFeatures(reference); HashSet<JvmFeature> set = Sets.newHashSet(iterable); assertTrue(set.contains(findOperation(SubClass.class.getName(), "privateField"))); assertTrue(set.contains(findOperation(SubClass.class.getName(), "protectedField"))); assertTrue(set.contains(findOperation(SubClass.class.getName(), "publicField"))); // #privateField is public and static in the super class assertTrue(set.contains(findOperation(SuperClass.class.getName(), "privateField"))); assertFalse(set.contains(findOperation(SuperClass.class.getName(), "protectedField"))); assertFalse(set.contains(findOperation(SuperClass.class.getName(), "publicField"))); assertTrue(set.contains(findOperation(SubClass.class.getName(), "publicMethod()"))); assertFalse(set.contains(findOperation(SuperClass.class.getName(), "publicMethod()"))); assertFalse(set.contains(findOperation(SubClass.class.getName(), "protectedMethod()"))); assertTrue(set.contains(findOperation(SuperClass.class.getName(), "protectedMethod()"))); assertFalse( set.contains(findOperation(SuperClass.class.getName(), "privateMethod(java.lang.Object)"))); assertFalse( set.contains(findOperation(SuperClass.class.getName(), "privateMethod(java.lang.String)"))); assertTrue( set.contains(findOperation(SubClass.class.getName(), "privateMethod(java.lang.Object)"))); assertTrue( set.contains(findOperation(SubClass.class.getName(), "privateMethod(java.lang.String)"))); }
@Test public void testSimple() throws Exception { JvmTypeReference reference = typeRefs .typeReference(Concrete.class.getName()) .wildCardExtends("java.lang.CharSequence") .create(); Iterable<JvmFeature> iterable = service.getAllJvmFeatures(reference); HashSet<JvmFeature> set = Sets.newHashSet(iterable); assertFalse( set.contains( findOperation( "org.eclipse.xtext.common.types.testSetups.Interface", "overriddenByAll(T)"))); assertFalse( set.contains( findOperation( "org.eclipse.xtext.common.types.testSetups.Abstract", "overriddenByAll(T)"))); assertTrue( set.contains( findOperation( "org.eclipse.xtext.common.types.testSetups.Concrete", "overriddenByAll(T)"))); assertFalse( set.contains( findOperation("org.eclipse.xtext.common.types.testSetups.Interface", "inherited()"))); assertTrue( set.contains( findOperation("org.eclipse.xtext.common.types.testSetups.Abstract", "inherited()"))); }
@Test public void testPrivateFieldShadowsInheritedPublicField() throws Exception { JvmTypeReference reference = typeRefs.typeReference(SubClass.class.getName()).create(); Iterable<JvmFeature> iterable = service.getAllJvmFeatures(reference); HashSet<JvmFeature> set = Sets.newHashSet(iterable); assertTrue(set.contains(findOperation(SubClass.class.getName(), "shadowedByPrivateField"))); assertFalse(set.contains(findOperation(SuperClass.class.getName(), "shadowedByPrivateField"))); }
@Test public void testGenerics_01() throws Exception { JvmTypeReference reference = typeRefs .typeReference(SubOfGenericClass.class.getName()) .arg(Object.class.getName()) .create(); Iterable<JvmFeature> iterable = service.getAllJvmFeatures(reference); HashSet<JvmFeature> set = Sets.newHashSet(iterable); assertTrue( set.contains( findOperation(SubOfGenericClass.class.getName(), "myMethod(java.lang.String)"))); assertFalse( set.contains( findOperation(GenericSuperClass.class.getName(), "myMethod(java.lang.String)"))); assertTrue(set.contains(findOperation(GenericSuperClass.class.getName(), "myMethod(T)"))); }