Package org.evolizer.famix.model.entities

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


  @Test
  public void testMethodLocalVariableContainsWithinFor() {
    FamixMethod simpleMethod = (FamixMethod) aModel.getElement(aFactory.createMethod("testPackage.Test4.iterate()",null));
    assertNotNull(simpleMethod);
   
    FamixLocalVariable withinForWithoutAnchor = aFactory.createLocalVariable("testPackage.Test4.iterate().iter",simpleMethod);
    withinForWithoutAnchor.setSourceAnchor(new SourceAnchor("/TestProject/src/testPackage/Test4.java",152,173));
    FamixLocalVariable withinFor = (FamixLocalVariable) aModel.getElement(withinForWithoutAnchor);

    assertNotNull(withinFor);
   
    assertTrue("FamixMethod must contain local variable", simpleMethod.getLocalVariables().size() > 0);

    boolean containsLocal = containsLocalVariable(simpleMethod, withinFor);
    assertTrue("FamixMethod must contain local variable nrs within for loop", containsLocal);
    assertEquals("No or wrong parent method for local variable nrs within for loop", simpleMethod, withinFor.getParent());
   
    FamixClass clazz = (FamixClass) aModel.getElement(aFactory.createClass("<undef>",null));
    assertNotNull(clazz);
   
    assertEquals(clazz, withinFor.getDeclaredClass());
   
  }
View Full Code Here


 
  @Test
  public void testArrayLocalVariable(){
    FamixMethod simpleMethod = (FamixMethod) aModel.getElement(aFactory.createMethod("testPackage.Test3.gather()",null));
    assertNotNull(simpleMethod);
    FamixLocalVariable lVarWithout = aFactory.createLocalVariable("testPackage.Test3.gather().items", simpleMethod);
    lVarWithout.setSourceAnchor(new SourceAnchor("/TestProject/src/testPackage/Test3.java",216,235));
    FamixLocalVariable lVar = (FamixLocalVariable)aModel.getElement(lVarWithout);

    assertNotNull(lVar);
    FamixClass declClass = (FamixClass) aModel.getElement(aFactory.createClass(AbstractFamixEntity.ARRAY_TYPE_NAME, null));
    assertNotNull(declClass);
   
    assertEquals(declClass, lVar.getDeclaredClass());
  }
View Full Code Here

    FamixMethod method = new FamixMethod("foo");
   
    FamixClass declaredReturnedClass = new FamixClass("someClass");
    method.setDeclaredReturnClass(declaredReturnedClass);
   
    FamixLocalVariable lVar1 = new FamixLocalVariable("counter");
    FamixLocalVariable lVar2 = new FamixLocalVariable("metricValue");
    Set<FamixLocalVariable> lVars = new HashSet<FamixLocalVariable>();
    lVars.add(lVar1);
    lVars.add(lVar2);
    method.setLocalVariables(lVars);
    lVar1.setParent(method);
    lVar2.setParent(method);
   
    FamixClass anonymClass1 = new FamixClass("anonymClass1");
    FamixClass anonymClass2 = new FamixClass("anonymClass2");
    Set<FamixClass> anonyClasses = new HashSet<FamixClass>();
    anonyClasses.add(anonymClass1);
    anonyClasses.add(anonymClass2);
    method.setAnonymClasses(anonyClasses);
    anonymClass1.setParent(method);
    anonymClass2.setParent(method);
   
    FamixParameter fPar1 = new FamixParameter("parameter1");
    FamixParameter fPar2 = new FamixParameter("parameter2");
    List<FamixParameter> fPars = new ArrayList<FamixParameter>();
    fPars.add(fPar1);
    fPars.add(fPar2);
    method.setParameters(fPars);
    fPar1.setParent(method);
    fPar2.setParent(method);
   
   
    fEvolizerSession.startTransaction();
    fEvolizerSession.saveObject(lVar1);
    fEvolizerSession.saveObject(lVar2);
    fEvolizerSession.saveObject(anonymClass1);
    fEvolizerSession.saveObject(anonymClass2);
    fEvolizerSession.saveObject(declaredReturnedClass);
    fEvolizerSession.saveObject(fPar1);
    fEvolizerSession.saveObject(fPar2);
    fEvolizerSession.saveObject(method);
    fEvolizerSession.endTransaction();
    fEvolizerSession.close();
   
   
    fEvolizerSession = fSessionHandler.getCurrentSession(fDBUrl);
   
    List<FamixMethod> result = fEvolizerSession.query("from FamixMethod", FamixMethod.class);
    assertEquals(1, result.size());
    FamixMethod returnedFamixMethod = result.get(0);
    assertEquals("foo", returnedFamixMethod.getUniqueName());
   
    Set<FamixLocalVariable> returnedLVars = returnedFamixMethod.getLocalVariables();
    assertEquals(2, returnedLVars.size());
    for(Iterator<FamixLocalVariable> iter = returnedLVars.iterator();iter.hasNext();){
      FamixLocalVariable var = iter.next();
      assertTrue((var.getUniqueName().equals("counter") || var.getUniqueName().equals("metricValue")));
      assertEquals("foo", var.getParent().getUniqueName());
      assertTrue(returnedFamixMethod==var.getParent());
    }

    List<FamixParameter> returnedFormalPars = returnedFamixMethod.getParameters();
    assertEquals(2, returnedFormalPars.size());
    for(Iterator<FamixParameter> iter = returnedFamixMethod.getParameters().iterator();iter.hasNext();){
View Full Code Here

        String lLocalVariableID = null;
        String lSimpleName = getASTNode().getName().getFullyQualifiedName();
        if (lSimpleName != null) {
            lLocalVariableID = getCurrMethod().getUniqueName() + AbstractFamixEntity.NAME_DELIMITER + lSimpleName;

            FamixLocalVariable lLocalVariable = getFactory().createLocalVariable(lLocalVariableID, null);
            lLocalVariable.setSourceAnchor(getSourceAnchor());

            if (getModel().contains(lLocalVariable)) {
                sLogger.warn("Duplicated entry " + lLocalVariable.getUniqueName());
            }
            lLocalVariable = (FamixLocalVariable) getModel().addElement(lLocalVariable);
            int modifier =
                (lLocalVariable != null ? lLocalVariable.getModifiers() : AbstractFamixEntity.UNKOWN_OR_NO_MODIFIERS);
            lLocalVariable.setModifiers(modifier);
            lLocalVariable.setParent(getCurrMethod());
            getCurrMethod().getLocalVariables().add(lLocalVariable);
            if (getDataType() != null) {
                lLocalVariable.setDeclaredClass(getDataType());
            }

            // remember the scope of the local variabel for later variable resolution
            getCrawler().getLocalVariableScope().put(lLocalVariable, getCrawler().getCurrStatementBlock());
        } else {
View Full Code Here

     * @param uniqueName Unique name of local variable (full method name + local variable name).
     * @param parent FamixMethod declaring the local variable (optional).
     * @return FamixLocalVariable.
     */
    public FamixLocalVariable createLocalVariable(String uniqueName, FamixMethod parent) {
        return new FamixLocalVariable(uniqueName, parent);
    }
View Full Code Here

TOP

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

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.