Package ch.uzh.ifi.seal.changedistiller.treedifferencing

Examples of ch.uzh.ifi.seal.changedistiller.treedifferencing.Node


        return sInjector.getInstance(DistillerFactory.class).create(structureEntity);
    }

    public Node convertMethodBody(String methodName, JavaCompilation compilation) {
        AbstractMethodDeclaration method = CompilationUtils.findMethod(compilation.getCompilationUnit(), methodName);
        Node root = new Node(JavaEntityType.METHOD, methodName);
        root.setEntity(new SourceCodeEntity(methodName, JavaEntityType.METHOD, new SourceRange(
                method.declarationSourceStart,
                method.declarationSourceEnd)));
        List<Comment> comments = CompilationUtils.extractComments(compilation);
        sMethodBodyConverter.initialize(root, method, comments, compilation.getScanner());
        method.traverse(sMethodBodyConverter, (ClassScope) null);
View Full Code Here


        return root;
    }

    public Node convertMethodDeclaration(String methodName, JavaCompilation compilation) {
        AbstractMethodDeclaration method = CompilationUtils.findMethod(compilation.getCompilationUnit(), methodName);
        Node root = new Node(JavaEntityType.METHOD, methodName);
        root.setEntity(new SourceCodeEntity(methodName, JavaEntityType.METHOD, new SourceRange(
                method.declarationSourceStart,
                method.declarationSourceEnd)));
        sDeclarationConverter.initialize(root, compilation.getScanner());
        method.traverse(sDeclarationConverter, (ClassScope) null);
        return root;
View Full Code Here

        return root;
    }

    public Node convertFieldDeclaration(String fieldName, JavaCompilation compilation) {
      FieldDeclaration field = CompilationUtils.findField(compilation.getCompilationUnit(), fieldName);
      Node root = new Node(JavaEntityType.FIELD, fieldName);
      root.setEntity(new SourceCodeEntity(fieldName, JavaEntityType.FIELD, new SourceRange(
          field.declarationSourceStart,
          field.declarationSourceEnd)));
      sDeclarationConverter.initialize(root, compilation.getScanner());
      field.traverse(sDeclarationConverter, (MethodScope) null);
      return root;
View Full Code Here

              structureEntityVersion = refactoringHelper.createStructureEntityVersionWithID(rightDrn, fVersion);
            } else {
              structureEntityVersion = refactoringHelper.createStructureEntityVersion(rightDrn);
            }

            Node rightRoot = fRightASTHelper.createDeclarationTree(rightDrn);
            // use the new qualified name for the method; otherwise TreeDifferencer detects a return type change
            Node leftRoot = fLeftASTHelper.createDeclarationTree(leftDrn, rightRoot.getValue());
            if (isRenaming(leftDrn, rightDrn, refactoringHelper)) {
              if (fVersion != null) {
                structureEntityVersion =
                        refactoringHelper.createStructureEntityVersionWithID(leftDrn, rightDrn.getFullyQualifiedName(), fVersion);
              } else {
                structureEntityVersion =
                        refactoringHelper.createStructureEntityVersion(leftDrn, rightDrn.getFullyQualifiedName());
              }
                Update upd =
                        new Update(
                                structureEntityVersion,
                                fLeftASTHelper.createSourceCodeEntity(leftDrn),
                                fRightASTHelper.createSourceCodeEntity(rightDrn),
                                leftRoot.getEntity());
                structureEntityVersion.addAllSourceCodeChanges(fChangeClassifier.classifySourceCodeChanges(Arrays
                        .asList(upd)));
            }
            extractChanges(leftRoot, rightRoot, structureEntityVersion);
            leftRoot = fLeftASTHelper.createMethodBodyTree(leftDrn);
View Full Code Here

    private final static String TEST_DATA = "src_change/";

    @Test
    public void unchangedMethodBodyShouldNotHaveAnyChanges() throws Exception {
        JavaCompilation compilation = CompilationUtils.compileFile(TEST_DATA + "TestLeft.java");
        Node rootLeft = convertMethodBody("foo", compilation);
        Node rootRight = convertMethodBody("foo", compilation);
        StructureEntityVersion structureEntity = new StructureEntityVersion(JavaEntityType.METHOD, "foo", 0);
        Distiller distiller = getDistiller(structureEntity);
        distiller.extractClassifiedSourceCodeChanges(rootLeft, rootRight);
        assertThat(structureEntity.getSourceCodeChanges().isEmpty(), is(true));
    }
View Full Code Here

    @Test
    public void changedMethodBodyShouldHaveChanges() throws Exception {
        JavaCompilation compilationLeft = CompilationUtils.compileFile(TEST_DATA + "TestLeft.java");
        JavaCompilation compilationRight = CompilationUtils.compileFile(TEST_DATA + "TestRight.java");
        Node rootLeft = convertMethodBody("foo", compilationLeft);
        Node rootRight = convertMethodBody("foo", compilationRight);
        StructureEntityVersion structureEntity = new StructureEntityVersion(JavaEntityType.METHOD, "foo", 0);
        Distiller distiller = getDistiller(structureEntity);
        distiller.extractClassifiedSourceCodeChanges(rootLeft, rootRight);
        assertThat(structureEntity.getSourceCodeChanges().size(), is(11));
    }
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    private void matchNodes(Node left, Node right) {
        for (Enumeration<Node> leftNodes = left.postorderEnumeration(); leftNodes.hasMoreElements();) {
            Node x = leftNodes.nextElement();
            if (!x.isMatched() && (!x.isLeaf() || x.isRoot())) {
                for (Enumeration<Node> rightNodes = right.postorderEnumeration(); rightNodes.hasMoreElements()
                        && !x.isMatched();) {
                    Node y = rightNodes.nextElement();
                    if ((!y.isMatched() && (!y.isLeaf() || y.isRoot())) && equal(x, y)) {
                        fMatch.add(new NodePair(x, y));
                        x.enableMatched();
                        y.enableMatched();
                    }
                }
            }
        }
    }
View Full Code Here

        }
    }

    private void markMatchedLeaves(List<LeafPair> matchedLeafs) {
        for (LeafPair pair : matchedLeafs) {
            Node x = pair.getLeft();
            Node y = pair.getRight();
            if (!(x.isMatched() || y.isMatched())) {
                fMatch.add(pair);
                x.enableMatched();
                y.enableMatched();
            }
        }
    }
View Full Code Here

    @SuppressWarnings("unchecked")
    private List<LeafPair> matchLeaves(Node left, Node right) {
        List<LeafPair> matchedLeafs = new ArrayList<LeafPair>();
        for (Enumeration<Node> leftNodes = left.postorderEnumeration(); leftNodes.hasMoreElements();) {
            Node x = leftNodes.nextElement();
            if (x.isLeaf()) {
                for (Enumeration<Node> rightNodes = right.postorderEnumeration(); rightNodes.hasMoreElements();) {
                    Node y = rightNodes.nextElement();
                    if (y.isLeaf() && haveSameLabel(x, y)) {
                        double similarity = 0;

                        if (x.getLabel().isComment()) {
                            similarity =
                                    fLeafCommentStringSimilarityCalculator.calculateSimilarity(
                                            x.getValue(),
                                            y.getValue());

                            // Important! Otherwhise nodes that match poorly will make it into final matching set,
                            // if no better matches are found!
                            if (similarity >= LEAF_COMMENT_STRING_SIMILARITY_THRESHOLD) {
                                matchedLeafs.add(new LeafPair(x, y, similarity));
                            }

                        } else { // ...other statements.
                            similarity =
                                    fLeafGenericStringSimilarityCalculator.calculateSimilarity(
                                            x.getValue(),
                                            y.getValue());

                            // Important! Otherwise nodes that match poorly will make it into final matching set,
                            // if no better matches are found!
                            if (similarity >= fLeafGenericStringSimilarityThreshold) {
                                matchedLeafs.add(new LeafPair(x, y, similarity));
View Full Code Here

    public double calculateSimilarity(Node left, Node right) {
        int common = 0;
        // common(x, y) = {(w, z) in M | x contains w, and y contains z}
        // |common|
        for (NodePair p : fLeafMatchSet) {
            Node l = p.getLeft();
            Node r = p.getRight();
            if (left.isLeafDescendant(l) && !isComment(l) && right.isLeafDescendant(r) && !isComment(r)) {
                common++;
            }
        }
        int max = maxLeafStatements(left, right);
View Full Code Here

TOP

Related Classes of ch.uzh.ifi.seal.changedistiller.treedifferencing.Node

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.