Package org.evolizer.famix.model.entities

Examples of org.evolizer.famix.model.entities.FamixAttribute


  }
 
  @Test
  public void testUnresolvedAttribute(){
    FamixClass clazz = (FamixClass)fModel.getElement(fFactory.createClass("<undef>.Warrior",null));
    FamixAttribute simpleAttribute = (FamixAttribute) fModel.getElement(fFactory.createAttribute("testPackage.Test.gigs",null));
    assertNotNull(clazz);
    assertNotNull(simpleAttribute);
    assertEquals(simpleAttribute.getDeclaredClass(), clazz);
   
    assertEquals("Type string of " + simpleAttribute.getUniqueName() + " must have modifier PRIVATE",
        simpleAttribute.getModifiers() & Modifier.PRIVATE, Modifier.PRIVATE);
    assertEquals("Type string of " + simpleAttribute.getUniqueName() + " must have modifier STATIC",
        simpleAttribute.getModifiers() & Modifier.STATIC, Modifier.STATIC);
    assertEquals("Type string of " + simpleAttribute.getUniqueName() + " must have modifier FINAL",
        simpleAttribute.getModifiers() & Modifier.FINAL, Modifier.FINAL);
  }
View Full Code Here


 
  @Test
  public void testUnresolvedArrayAttribute(){
    FamixClass clazz = (FamixClass)fModel.getElement(fFactory.createClass(AbstractFamixEntity.ARRAY_TYPE_NAME,null));
    assertNotNull(clazz);
    FamixAttribute simpleAttribute = (FamixAttribute) fModel.getElement(fFactory.createAttribute("testPackage.Test2.paladins",null));
    assertNotNull(simpleAttribute);
    assertEquals(clazz, simpleAttribute.getDeclaredClass());
  }
View Full Code Here

    FamixMethod caller = (FamixMethod) fModel.getElement(fFactory.createMethod("testPackage.UnresolvedCalls.unresolvedAnonymClass()", null));
    FamixMethod oinitAnonym = (FamixMethod) fModel.getElement(fFactory.createMethod("testPackage.UnresolvedCalls$1F.<oinit>()", null));
    FamixMethod initAnonym = (FamixMethod) fModel.getElement(fFactory.createMethod("testPackage.UnresolvedCalls$1F.<init>(int,java.lang.String)", null));
    FamixMethod inUndefAnonym = (FamixMethod) fModel.getElement(fFactory.createMethod("testPackage.UnresolvedCalls$1F.inUndefAnonym(<undef>.String,<undef>.NotDef2)", null));
    FamixMethod inUndefAnonym2 = (FamixMethod) fModel.getElement(fFactory.createMethod("testPackage.UnresolvedCalls$1F.inUndefAnonym(<undef>.String)", null));
    FamixAttribute fieldInAnonym = (FamixAttribute) fModel.getElement(fFactory.createAttribute("testPackage.UnresolvedCalls$1F.fieldInAnonym", null));

    assertNotNull("FamixClass testPackage.UnresolvedCalls must exist", unresolvedCalls);
    assertNotNull("Anonym class testPackage.UnresolvedCalls$1 must exist", undefAnonymClass);
    assertNotNull("FamixMethod testPackage.UnresolvedCalls.unresolvedAnonymClass() must exist", caller);
    assertNotNull("Initializer testPackage.UnresolvedCalls$1F.<oinit>() must exist", oinitAnonym);
    assertNotNull("Constructor testPackage.UnresolvedCalls$1.<init>() must exist", initAnonym);
    assertNotNull("FamixMethod testPackage.UnresolvedCalls$1F.inUndefAnonym(<undef>.String,<undef>.NotDef2) must exist", inUndefAnonym);
    assertNotNull("FamixMethod testPackage.UnresolvedCalls$1F.inUndefAnonym(java.lang.String) must exist", inUndefAnonym2);
    assertNotNull("FamixAttribute testPackage.UnresolvedCalls$1F.fieldInAnonym must exist", fieldInAnonym);
   
    assertTrue("FamixMethod " + caller.getUniqueName() + " must contain anonym class " + undefAnonymClass.getUniqueName(), caller.getAnonymClasses().contains(undefAnonymClass));
    assertTrue("Anonym class " + undefAnonymClass.getUniqueName() + " must contain initializer " + oinitAnonym.getUniqueName(), undefAnonymClass.getMethods().contains(oinitAnonym));
    assertTrue("Anonym class " + undefAnonymClass.getUniqueName() + " must contain initializer " + initAnonym.getUniqueName(), undefAnonymClass.getMethods().contains(initAnonym));
    assertTrue("Anonym class " + undefAnonymClass.getUniqueName() + " must contain method " + inUndefAnonym.getUniqueName(), undefAnonymClass.getMethods().contains(inUndefAnonym));
    assertTrue("Anonym class " + undefAnonymClass.getUniqueName() + " must contain method " + inUndefAnonym2.getUniqueName(), undefAnonymClass.getMethods().contains(inUndefAnonym2));
    assertTrue("Anonym class " + undefAnonymClass.getUniqueName() + " must contain attribute " + fieldInAnonym.getUniqueName(), undefAnonymClass.getAttributes().contains(fieldInAnonym));
   
    Set<FamixAssociation> lRelations = fModel.getAssociations(caller);
    int nrContainsInvocation = TestHelper.containsRelationTo(initAnonym, lRelations);
    assertEquals("FamixInvocation relationships from " + caller.getUniqueName() + " to " + initAnonym.getUniqueName(), 1, nrContainsInvocation);
   
    Set<FamixAssociation> lAccessRelations = fModel.getAssociations(oinitAnonym);
    int nrContainsAccess = TestHelper.containsRelationTo(fieldInAnonym, lAccessRelations);
    assertEquals("FamixAccess relationships from " + oinitAnonym.getUniqueName() + " to " + fieldInAnonym.getUniqueName(), 1, nrContainsAccess);
  }
View Full Code Here

        double value = 0d;
        SnapshotAnalyzer snapshotAnalyzer = new SnapshotAnalyzer(getCurrentSession());
        List<AbstractFamixEntity> entities = snapshotAnalyzer.getDescendants(getCurrentEntity());
        for (AbstractFamixEntity famixEntity : entities) {
            if (famixEntity instanceof FamixAttribute) {
                FamixAttribute method = (FamixAttribute) famixEntity;
                if ((method.getModifiers() & AbstractFamixEntity.MODIFIER_STATIC) == AbstractFamixEntity.MODIFIER_STATIC) {
                    value += 1d;
                }
            }
        }
View Full Code Here

            setCurrMethod(classInit);
        }
    }

    private void createAttributes() {
        FamixAttribute lField = null;

        int lModifiers = getASTNode().getModifiers();
        for (VariableDeclaration fragment : getFragments()) {
            String lFieldID = null;
            String lSimpleName = fragment.getName().getFullyQualifiedName();
            if (lSimpleName != null) {
                lFieldID = getCurrType().getUniqueName() + AbstractFamixEntity.NAME_DELIMITER + lSimpleName;
                lField = getFactory().createAttribute(lFieldID, null);
                lField = (FamixAttribute) getModel().addElement(lField);
                lField.setModifiers(lModifiers);
                lField.setSourceAnchor(getSourceAnchor(fragment));
                lField.setParent(getCurrType());
                getCurrType().getAttributes().add(lField);
                lField.setDeclaredClass(getDataType());

                // If there is any initialization to this field then we write them as an access by <init> or <clinit>
                Expression lInit = fragment.getInitializer();
                if (lInit != null) {
                    FamixAssociation access = getFactory().createAccess(getCurrMethod(), lField);
View Full Code Here

  }
 
  @Test
  public void testUnresolvedAttribute(){
    FamixClass clazz = (FamixClass)aModel.getElement(aFactory.createClass("<undef>.Warrior",null));
    FamixAttribute simpleAttribute = (FamixAttribute) aModel.getElement(aFactory.createAttribute("testPackage.Test.gigs",null));
    assertNotNull(clazz);
    assertNotNull(simpleAttribute);
    assertEquals(simpleAttribute.getDeclaredClass(), clazz);
   
    assertEquals("Type string of " + simpleAttribute.getUniqueName() + " must have modifier PRIVATE",
        simpleAttribute.getModifiers() & Modifier.PRIVATE, Modifier.PRIVATE);
    assertEquals("Type string of " + simpleAttribute.getUniqueName() + " must have modifier STATIC",
        simpleAttribute.getModifiers() & Modifier.STATIC, Modifier.STATIC);
    assertEquals("Type string of " + simpleAttribute.getUniqueName() + " must have modifier FINAL",
        simpleAttribute.getModifiers() & Modifier.FINAL, Modifier.FINAL);
  }
View Full Code Here

 
  @Test
  public void testUnresolvedArrayAttribute(){
    FamixClass clazz = (FamixClass)aModel.getElement(aFactory.createClass(AbstractFamixEntity.ARRAY_TYPE_NAME,null));
    assertNotNull(clazz);
    FamixAttribute simpleAttribute = (FamixAttribute) aModel.getElement(aFactory.createAttribute("testPackage.Test2.paladins",null));
    assertNotNull(simpleAttribute);
    assertEquals(clazz, simpleAttribute.getDeclaredClass());
  }
View Full Code Here

    class2.setParent(clazz);
    innerClasses.add(class1);
    innerClasses.add(class2);
    clazz.setInnerClasses(innerClasses);
   
    FamixAttribute a1 = new FamixAttribute("attribute1");
    FamixAttribute a2 = new FamixAttribute("attribute2");
    a1.setParent(clazz);
    a2.setParent(clazz);
    clazz.getAttributes().add(a1);
    clazz.getAttributes().add(a2);
   
    FamixMethod m1 = new FamixMethod("method1");
    FamixMethod m2 = new FamixMethod("method2");
    m1.setParent(clazz);
    m2.setParent(clazz);
    clazz.getMethods().add(m1);
    clazz.getMethods().add(m2);
       
    fEvolizerSession.startTransaction();
    fEvolizerSession.saveObject(class1);
    fEvolizerSession.saveObject(class2);
    fEvolizerSession.saveObject(clazz);
    fEvolizerSession.saveObject(a1);
    fEvolizerSession.saveObject(a2);
    fEvolizerSession.saveObject(m1);
    fEvolizerSession.saveObject(m2);
    fEvolizerSession.endTransaction();
    fEvolizerSession.close();
   
    fEvolizerSession = fSessionHandler.getCurrentSession(fDBUrl);
   
    List<FamixClass> results = fEvolizerSession.query("from FamixClass as c where c.uniqueName = 'Foo'", FamixClass.class);
    assertEquals(1, results.size());
   
    FamixClass returnedClass = results.get(0);
    assertEquals("Foo", returnedClass.getUniqueName());
   
    Set<FamixClass> returnedInnerClasses = returnedClass.getInnerClasses();
    assertEquals(2, returnedInnerClasses.size());
    for(Iterator<FamixClass> iter = returnedInnerClasses.iterator();iter.hasNext();){
      FamixClass cl = iter.next();
      assertTrue((cl.getUniqueName().equals("innerClass1") || cl.getUniqueName().equals("innerClass2")));
      assertTrue(cl.getParent()==returnedClass);
    }
   
    Set<FamixAttribute> returnedFamixAttributes = returnedClass.getAttributes();
    assertEquals(2, returnedFamixAttributes.size());
    for(Iterator<FamixAttribute> iter = returnedFamixAttributes.iterator();iter.hasNext();){
      FamixAttribute at = iter.next();
      assertTrue((at.getUniqueName().equals("attribute1") || at.getUniqueName().equals("attribute2")));
      assertTrue(at.getParent()==returnedClass);
    }
   
    Set<FamixMethod> returnedFamixMethods = returnedClass.getMethods();
    assertEquals(2, returnedFamixMethods.size());
    for(Iterator<FamixMethod> iter = returnedFamixMethods.iterator();iter.hasNext();){
View Full Code Here

    }

    @Test
    public void testAnonymousClassAttributeContainer() {
        FamixClass anonymClass = (FamixClass) aModel.getElement(aFactory.createClass("testPackage.ae.Test$1", null));
        FamixAttribute anonymAttribute = (FamixAttribute) aModel.getElement(aFactory.createAttribute("testPackage.ae.Test$1.anonymAttribute", null));

        assertNotNull("FamixModel must contain anonymous class testPackage.ae.Test$1", anonymClass);
        assertNotNull("FamixModel must contain ananymous class attribute testPackage.ae.Test$1.anonymAttribute", anonymAttribute);

        assertTrue("Anonymous class must contain attribute " + anonymAttribute.getUniqueName(), anonymClass.getAttributes().contains(anonymAttribute));
        assertEquals("No or wrong parent class for attribute " + anonymAttribute.getUniqueName(),
                anonymClass, anonymAttribute.getParent());
    }
View Full Code Here

    public void testAnonymousClassInitializer() {
        FamixClass anonymClass = (FamixClass) aModel.getElement(aFactory.createClass("testPackage.ae.Test$1", null));
        FamixMethod oinitTest = (FamixMethod) aModel.getElement(aFactory.createMethod("testPackage.ae.Test.<oinit>()", null));
        FamixMethod oinitAnonym = (FamixMethod) aModel.getElement(aFactory.createMethod("testPackage.ae.Test$1.<oinit>()", null));
        FamixMethod initAnonym = (FamixMethod) aModel.getElement(aFactory.createMethod("testPackage.ae.Test$1.<init>()", null));
        FamixAttribute anonymAttribute = (FamixAttribute) aModel.getElement(aFactory.createAttribute("testPackage.ae.Test$1.anonymAttribute", null));

        assertNotNull("FamixModel must contain anonymous class testPackage.ae.Test$1", anonymClass);
        assertNotNull("FamixModel must contain initializer testPackage.ae.Test.<oinit>()", oinitTest);
        assertNotNull("FamixModel must contain anonymous class initializer testPackage.ae.Test$1.<oinit>()", oinitAnonym);
        assertNotNull("FamixModel must contain anonymous class initializer testPackage.ae.Test$1.<init>()", initAnonym);
        assertNotNull("FamixModel must contain ananymous class attribute testPackage.ae.Test$1.anonymAttribute", anonymAttribute);
        assertNotNull(oinitAnonym);

        assertTrue("Anonymous class must contain initializer " + oinitAnonym.getUniqueName(), anonymClass.getMethods().contains(oinitAnonym));
        assertEquals("No or wrong parent class for initializer " + oinitAnonym.getUniqueName(),
                anonymClass, oinitAnonym.getParent());
        assertTrue("Anonymous class must contain initializer " + initAnonym.getUniqueName(), anonymClass.getMethods().contains(initAnonym));
        assertEquals("No or wrong parent class for initializer " + initAnonym.getUniqueName(),
                anonymClass, initAnonym.getParent());

        // FamixInvocation Test.<oinit> -> Test$1.<init>
        Set<FamixAssociation> lRelations = aModel.getAssociations(oinitTest);
        assertTrue("FamixMethod " + oinitTest.getUniqueName() + " must contain relationships", lRelations.size() > 0);
        int containsInvocationTo = TestHelper.containsRelationTo(initAnonym, lRelations);
        assertEquals("Missing invocation relationship from " + oinitTest.getUniqueName() + " to " + initAnonym.getUniqueName(), 1, containsInvocationTo);

        lRelations = aModel.getAssociations(oinitAnonym);
        int containsAccessTo = TestHelper.containsRelationTo(anonymAttribute, lRelations);
        assertEquals("Missing access relationship from " + oinitAnonym.getUniqueName() + " to " + anonymAttribute.getUniqueName(), 1, containsAccessTo);
    }
View Full Code Here

TOP

Related Classes of org.evolizer.famix.model.entities.FamixAttribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.