Package org.evolizer.famix.model.entities

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


  public void testMethodParameters(){
    FamixMethod method = (FamixMethod)fModel.getElement(fFactory.createMethod("testPackage.Test.myMethod(int,double,<undef>.Warlock)",null));
    assertNotNull(method);
    assertEquals(3, method.getParameters().size());
   
    FamixParameter param = (FamixParameter) fModel.getElement(fFactory.createFormalParameter("testPackage.Test.myMethod(int,double,<undef>.Warlock).i",null,0));
    assertNotNull(param);
    assertEquals(new Integer(0), param.getParamIndex());
   
    FamixClass clazz = (FamixClass) fModel.getElement(fFactory.createClass("int",null));
    assertEquals(clazz, param.getDeclaredClass());
    assertTrue(method.getParameters().contains(param));
    assertEquals(method, param.getParent());
   
    param = (FamixParameter) fModel.getElement(fFactory.createFormalParameter("testPackage.Test.myMethod(int,double,<undef>.Warlock).d",null,1));
    clazz = (FamixClass) fModel.getElement(fFactory.createClass("double",null));
    assertEquals(clazz, param.getDeclaredClass());
    assertNotNull(param);
    assertTrue(method.getParameters().contains(param));
    assertEquals(method, param.getParent());
    assertEquals(new Integer(1), param.getParamIndex());
   
    param = (FamixParameter) fModel.getElement(fFactory.createFormalParameter("testPackage.Test.myMethod(int,double,<undef>.Warlock).zorf",null,2));
    clazz = (FamixClass) fModel.getElement(fFactory.createClass("<undef>.Warlock",null));
    assertEquals(clazz, param.getDeclaredClass());
    assertNotNull(param);
    assertTrue(method.getParameters().contains(param));
    assertEquals(method, param.getParent());
    assertEquals(new Integer(2), param.getParamIndex());
  }
View Full Code Here


  @Test
  public void testUnresolvedArrayParameter(){
    FamixMethod method = (FamixMethod)fModel.getElement(fFactory.createMethod("testPackage.Test.myMethod(<undef>.Hunter[])",null));
    assertNotNull(method);
   
    FamixParameter param = (FamixParameter) fModel.getElement(fFactory.createFormalParameter("testPackage.Test.myMethod(<undef>.Hunter[]).h",null,0));
    assertNotNull(param);
    assertEquals(new Integer(0), param.getParamIndex());
    FamixClass clazz = (FamixClass)fModel.getElement(fFactory.createClass(AbstractFamixEntity.ARRAY_TYPE_NAME,null));
    assertEquals(clazz, param.getDeclaredClass());
    assertTrue(method.getParameters().contains(param));
    assertEquals(method, param.getParent());
  }
View Full Code Here

    }

    @Test
    public void testMethodParameterConainer() {
        FamixMethod simpleMethod = (FamixMethod) aModel.getElement(aFactory.createMethod("testPackage.Variables.m(int,int[])", null));
        FamixParameter simpleParam = (FamixParameter) aModel.getElement(aFactory.createFormalParameter("testPackage.Variables.m(int,int[]).param", null, 0));

        assertTrue("FamixMethod must contain formal parameters", simpleMethod.getParameters().size() > 0);
        assertNotNull("FamixMethod must contain formal parameter testPackage.Variables.m(int,int[]).param", simpleParam);

        boolean containsParam = false;
        for (FamixParameter lParam : simpleMethod.getParameters()) {
            if (lParam.getUniqueName().equals(simpleParam.getUniqueName())) {
                containsParam = true;
                break;
            }
        }
        assertTrue("FamixMethod must contain formal parameter param", containsParam);
        assertEquals("No or wrong parent method for formal parameter param", simpleMethod, simpleParam.getParent());
    }
View Full Code Here

        }
    }

    @Test
    public void testParameterPosition() {
        FamixParameter simpleParam = (FamixParameter) aModel.getElement(aFactory.createFormalParameter("testPackage.Variables.m(int,int[]).param", null, 0));
        FamixParameter arrayParam = (FamixParameter) aModel.getElement(aFactory.createFormalParameter("testPackage.Variables.m(int,int[]).arrayParam", null, 1));

        assertNotNull("FamixMethod must contain formal parameter testPackage.Variables.m(int,int[]).param", simpleParam);
        assertNotNull("FamixMethod must contain formal parameter testPackage.Variables.m(int,int[]).arrayParam", arrayParam);

        assertTrue("Position of " + simpleParam.getUniqueName() + " must be 0", simpleParam.getParamIndex() == 0);       
        assertTrue("Position of " + arrayParam.getUniqueName() + " must be 1", arrayParam.getParamIndex() == 1);
    }
View Full Code Here

    }

    @Test
    public void testSimpleParameterType() {
        FamixClass classInt = (FamixClass) aModel.getElement(aFactory.createClass("int", null));
        FamixParameter simpleParam = (FamixParameter) aModel.getElement(aFactory.createFormalParameter("testPackage.Variables.m(int,int[]).param", null, 0));

        assertNotNull("FamixMethod must contain formal parameter testPackage.Variables.m(int,int[]).param", simpleParam);
        assertEquals("Declared class of " + simpleParam.getUniqueName() + " must be " + classInt.getUniqueName(),
                simpleParam.getDeclaredClass(), classInt);
    }
View Full Code Here

    }

    @Test
    public void testArrayParameterType() {
        FamixClass classArray = (FamixClass) aModel.getElement(aFactory.createClass("<Array>", null));
        FamixParameter arrayParam = (FamixParameter) aModel.getElement(aFactory.createFormalParameter("testPackage.Variables.m(int,int[]).arrayParam", null, 1));

        assertNotNull("FamixMethod must contain formal parameter testPackage.Variables.m(int,int[]).arrayParam", arrayParam);
        assertEquals("Declared class of " + arrayParam.getUniqueName() + " must be <Array>",
                arrayParam.getDeclaredClass(), classArray);
    }
View Full Code Here

        assertEquals("Declaration in source file must equal the source attribute ", classDecl, anonymClass.getSource());
    }

    @Test
    public void testSourceAnchorFormalParameter() throws Exception {
        FamixParameter simpleParam = (FamixParameter) aModel.getElement(aFactory.createFormalParameter("testPackage.Variables.m(int,int[]).param", null, 0));
        FamixParameter arrayParam = (FamixParameter) aModel.getElement(aFactory.createFormalParameter("testPackage.Variables.m(int,int[]).arrayParam", null, 1));

        SourceAnchor anchor = simpleParam.getSourceAnchor();
        assertNotNull("Source anchor file of parameter " + simpleParam.getUniqueName() + " must not be null", anchor);
        assertEquals("Source anchor file of parameter " + simpleParam.getUniqueName() + " must be", "/TestProject1/src/testPackage/Variables.java", anchor.getFile());
        assertTrue("The start must be before the end position", anchor.getStartPos() <= anchor.getEndPos());
        InputStream fileStream = ResourcesPlugin.getWorkspace().getRoot().getFile(Path.fromPortableString(anchor.getFile())).getContents();
        String fileContent = TestHelper.getFileContent(fileStream);
        String simpleParamDecl = fileContent.substring(anchor.getStartPos(), anchor.getEndPos());
        assertEquals("Declaration of parameter must be 'param'", "int param", simpleParamDecl);
        assertEquals("Declaration in source file must equal the source attribute ", simpleParamDecl, simpleParam.getSource());

        anchor = arrayParam.getSourceAnchor();
        assertNotNull("Source anchor file of parameter " + arrayParam.getUniqueName() + " must not be null", anchor);
        assertEquals("Source anchor file of parameter " + arrayParam.getUniqueName() + " must be", "/TestProject1/src/testPackage/Variables.java", anchor.getFile());
        assertTrue("The start must be before the end position", anchor.getStartPos() <= anchor.getEndPos());
        String arrayParamDecl = fileContent.substring(anchor.getStartPos(), anchor.getEndPos());
        assertEquals("Declaration of parameter must be 'arrayParam'", "int[] arrayParam", arrayParamDecl);
        assertEquals("Declaration in source file must equal the source attribute ", arrayParamDecl, arrayParam.getSource());
    }
View Full Code Here

        int position = 0;
        for (Object lParamDeclaration : getASTNode().parameters()) {
            String lParamID =
                    getCurrMethod().getUniqueName() + AbstractFamixEntity.NAME_DELIMITER
                            + ((SingleVariableDeclaration) lParamDeclaration).getName();
            FamixParameter lParameter = getFactory().createFormalParameter(lParamID, getCurrMethod(), position);
            if (getModel().contains(lParameter)) {
                sLogger.error("Formal parameter " + lParamID + " already exists - skip it");
            } else {
                lParameter = (FamixParameter) getModel().addElement(lParameter);
                lParameter.setModifiers(((SingleVariableDeclaration) lParamDeclaration).getModifiers());
                lParameter.setSourceAnchor(getSourceAnchor((SingleVariableDeclaration) lParamDeclaration));
                getCurrMethod().getParameters().add(lParameter);

                // set data type
                ITypeBinding pBinding = ((SingleVariableDeclaration) lParamDeclaration).getType().resolveBinding();
                FamixClass lDataType = getClass(pBinding, ((SingleVariableDeclaration) lParamDeclaration).getType(), false);
                lDataType = (FamixClass) getModel().addElement(lDataType);
                lParameter.setDeclaredClass(lDataType);

                position++;
            }
        }
    }
View Full Code Here

    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();){
      FamixParameter par = iter.next();
      assertTrue((par.getUniqueName().equals("parameter1") || par.getUniqueName().equals("parameter2")));
      assertEquals("foo", par.getParent().getUniqueName());
      assertTrue(returnedFamixMethod==par.getParent());
    }
   
    Set<FamixClass> returnedAnonyClass = returnedFamixMethod.getAnonymClasses();
    assertEquals(2, returnedAnonyClass.size());
    for(Iterator<FamixClass> iter = returnedFamixMethod.getAnonymClasses().iterator();iter.hasNext();){
View Full Code Here

  public void testMethodParameters(){
    FamixMethod method = (FamixMethod)aModel.getElement(aFactory.createMethod("testPackage.Test.myMethod(int,double,<undef>.Warlock)",null));
    assertNotNull(method);
    assertEquals(3, method.getParameters().size());
   
    FamixParameter param = (FamixParameter) aModel.getElement(aFactory.createFormalParameter("testPackage.Test.myMethod(int,double,<undef>.Warlock).i",null,0));
    assertNotNull(param);
    assertEquals(new Integer(0), param.getParamIndex());
   
    FamixClass clazz = (FamixClass) aModel.getElement(aFactory.createClass("int",null));
    assertEquals(clazz, param.getDeclaredClass());
    assertTrue(method.getParameters().contains(param));
    assertEquals(method, param.getParent());
   
    param = (FamixParameter) aModel.getElement(aFactory.createFormalParameter("testPackage.Test.myMethod(int,double,<undef>.Warlock).d",null,1));
    clazz = (FamixClass) aModel.getElement(aFactory.createClass("double",null));
    assertEquals(clazz, param.getDeclaredClass());
    assertNotNull(param);
    assertTrue(method.getParameters().contains(param));
    assertEquals(method, param.getParent());
    assertEquals(new Integer(1), param.getParamIndex());
   
    param = (FamixParameter) aModel.getElement(aFactory.createFormalParameter("testPackage.Test.myMethod(int,double,<undef>.Warlock).zorf",null,2));
    clazz = (FamixClass) aModel.getElement(aFactory.createClass("<undef>.Warlock",null));
    assertEquals(clazz, param.getDeclaredClass());
    assertNotNull(param);
    assertTrue(method.getParameters().contains(param));
    assertEquals(method, param.getParent());
    assertEquals(new Integer(2), param.getParamIndex());
  }
View Full Code Here

TOP

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

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.