Package org.evolizer.famix.model.entities

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


    @Test
    public void testSourceAnchorInnerClass() throws Exception {
        FamixClass classHelperClass = (FamixClass) aModel.getElement(aFactory.createClass("testPackage.InnerAnonym$HelperClass", null));
       
        SourceAnchor anchor = classHelperClass.getSourceAnchor();
        assertNotNull("Source anchor file of class " + classHelperClass.getUniqueName() + " must not be null", anchor);
        assertEquals("Source anchor file of class " + classHelperClass.getUniqueName() + " must be", "/TestProject1/src/testPackage/InnerAnonym.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 classSumDecl = fileContent.substring(anchor.getStartPos(), anchor.getEndPos());
        assertTrue("Declaration of class must start with 'public class HelperClass'", classSumDecl.startsWith("public class HelperClass"));
        assertEquals("Declaration in source file must equal the source attribute ", classSumDecl, classHelperClass.getSource());
    }
View Full Code Here


    protected FamixMethod addObjectInitMethod(FamixClass pClass) {
        String lMethodID = pClass.getUniqueName() + AbstractFamixEntity.NAME_DELIMITER + AbstractFamixEntity.OBJECT_INIT_METHOD;
        FamixMethod lObjectInitMethod = getFactory().createMethod(lMethodID, null);
        lObjectInitMethod = (FamixMethod) getModel().addElement(lObjectInitMethod);
        lObjectInitMethod.setModifiers(AbstractFamixEntity.UNKOWN_OR_NO_MODIFIERS);
        lObjectInitMethod.setSourceAnchor(new SourceAnchor(pClass.getSourceAnchor().getFile(), pClass.getSourceAnchor()
                .getStartPos(), pClass.getSourceAnchor().getEndPos()));
        lObjectInitMethod.setParent(pClass);
        pClass.getMethods().add(lObjectInitMethod);

        // initialize unresolved method hash of the oinit FamixMethod
View Full Code Here

  }
 
  @Test
  public void testFamixAssociationAndSourceAnchorConnection() throws EvolizerException{
    FamixAssociation association = new FamixAssociation();
    SourceAnchor anchor = new SourceAnchor("someFile", new Integer(1),new Integer(2));
    association.setSourceAnchor(anchor);
    fEvolizerSession.startTransaction();
    fEvolizerSession.saveObject(anchor);
    fEvolizerSession.saveObject(association);
    fEvolizerSession.endTransaction();
    fEvolizerSession.close();
   
    fEvolizerSession = fSessionHandler.getCurrentSession(fDBUrl);
   
    List<FamixAssociation> associationResults = fEvolizerSession.query("from FamixAssociation", FamixAssociation.class);
    assertEquals(1,associationResults.size());
    FamixAssociation associationResult = associationResults.get(0);
    SourceAnchor anchorresult = associationResult.getSourceAnchor();
    assertEquals("someFile", anchorresult.getFile());
    assertEquals(2, anchorresult.getEndPos().intValue());
    assertEquals(1, anchorresult.getStartPos().intValue());
  }
View Full Code Here

  @Test
  public void testMethodLocalVariableContainsSimple() {
    FamixMethod simpleMethod = (FamixMethod) aModel.getElement(aFactory.createMethod("testPackage.Test3.gather()",null));
    assertNotNull(simpleMethod);
    FamixLocalVariable simpleLocalVariableWithoutAnchor = aFactory.createLocalVariable("testPackage.Test3.gather().a",simpleMethod);
    simpleLocalVariableWithoutAnchor.setSourceAnchor(new SourceAnchor("/TestProject/src/testPackage/Test3.java",new Integer(203),new Integer(204)));
    FamixLocalVariable simpleLocal = (FamixLocalVariable) aModel.getElement(simpleLocalVariableWithoutAnchor);
    assertNotNull(simpleLocal);
   
    assertTrue("FamixMethod must contain local variable", simpleMethod.getLocalVariables().size() > 0);
    boolean containsLocal = containsLocalVariable(simpleMethod, simpleLocal);
View Full Code Here

  public void testMethodLocalVariableContainsMulti() {
    FamixMethod simpleMethod = (FamixMethod) aModel.getElement(aFactory.createMethod("testPackage.Test3.gather()",null));
    assertNotNull(simpleMethod);
   
    FamixLocalVariable multiLocal1WithoutAnchor = aFactory.createLocalVariable("testPackage.Test3.gather().gigs1",simpleMethod);
    multiLocal1WithoutAnchor.setSourceAnchor(new SourceAnchor("/TestProject/src/testPackage/Test3.java",249,254));
    FamixLocalVariable multiLocal1 = (FamixLocalVariable) aModel.getElement(multiLocal1WithoutAnchor);
    FamixLocalVariable multiLocal2WithoutAnchor = aFactory.createLocalVariable("testPackage.Test3.gather().gigs2",simpleMethod);
    multiLocal2WithoutAnchor.setSourceAnchor(new SourceAnchor("/TestProject/src/testPackage/Test3.java",257,262));
    FamixLocalVariable multiLocal2 = (FamixLocalVariable) aModel.getElement(multiLocal2WithoutAnchor);
   
    assertNotNull(multiLocal1);
    assertNotNull(multiLocal2);
   
View Full Code Here

  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);
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);
View Full Code Here

        }

        int startPosition = astNode.getStartPosition();
        int length = astNode.getLength();

        return new SourceAnchor(file, startPosition, startPosition + length);

    }
View Full Code Here

    @Test
    public void testSourceAnchorMethod() throws Exception {
        FamixMethod returnRef = (FamixMethod) aModel.getElement(aFactory.createMethod("testPackage.ae.Test.getRefSum()", null));

        SourceAnchor anchor = returnRef.getSourceAnchor();
        assertNotNull("Source anchor file of method " + returnRef.getUniqueName() + " must not be null", anchor);
        assertEquals("Source anchor file of method " + returnRef.getUniqueName() + " must be", "/TestProject1/src/testPackage/ae/Test.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 returnRefDecl = fileContent.substring(anchor.getStartPos(), anchor.getEndPos());
        assertTrue("Declaration of method must start with 'public Sum getRefSum()'", returnRefDecl.startsWith("public Sum getRefSum()"));
        assertEquals("Declaration in source file must equal the source attribute ", returnRefDecl, returnRef.getSource());
    }
View Full Code Here

    @Test
    public void testSourceAnchorAttribute() throws Exception {
        FamixAttribute fMulti3 = (FamixAttribute) aModel.getElement(aFactory.createAttribute("testPackage.Variables.fMulti3", null));

        SourceAnchor anchor = fMulti3.getSourceAnchor();
        assertNotNull("Source anchor file of attribute " + fMulti3.getUniqueName() + " must not be null", anchor);
        assertEquals("Source anchor file of attribute " + fMulti3.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 returnRefDecl = fileContent.substring(anchor.getStartPos(), anchor.getEndPos());
        assertEquals("Declaration of attribute must be 'fMulti3'", "fMulti3", returnRefDecl);
        assertEquals("Declaration in source file must equal the source attribute ", returnRefDecl, fMulti3.getSource());
    }
View Full Code Here

TOP

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

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.