Example usage for org.eclipse.jdt.core.dom SimpleName getLength

List of usage examples for org.eclipse.jdt.core.dom SimpleName getLength

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom SimpleName getLength.

Prototype

public final int getLength() 

Source Link

Document

Returns the length in characters of the original source file indicating where the source fragment corresponding to this node ends.

Usage

From source file:br.uff.ic.gems.resources.ast.Visitor.java

@Override
public boolean visit(FieldDeclaration node) {

    List<VariableDeclarationFragment> fragments = node.fragments();

    for (VariableDeclarationFragment fragment : fragments) {
        int beginLine = cu.getLineNumber(fragment.getStartPosition());
        int endLine = cu.getLineNumber(fragment.getStartPosition() + fragment.getLength());
        int beginColumn = beginColunm(node);
        int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength());

        SimpleName name = fragment.getName();

        if (name != null) {
            endLine = cu.getLineNumber(name.getStartPosition() + name.getLength());
            endColumn = cu.getColumnNumber(name.getStartPosition() + name.getLength());
        }// w  w w .  ja v a2  s. co m

        languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine,
                beginColumn, endColumn, fragment.getName().getIdentifier()));

    }

    return true;
}

From source file:br.uff.ic.gems.resources.ast.Visitor.java

@Override
public boolean visit(SingleVariableDeclaration node) {
    int beginLine = cu.getLineNumber(node.getStartPosition());
    int endLine = cu.getLineNumber(node.getStartPosition() + node.getLength());
    int beginColumn = cu.getColumnNumber(node.getStartPosition());
    int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength());

    SimpleName name = node.getName();

    if (name != null) {
        endLine = cu.getLineNumber(name.getStartPosition() + name.getLength());
        endColumn = cu.getColumnNumber(name.getStartPosition() + name.getLength());
    }//from   ww w . j  a v a  2s. c  o  m

    languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine,
            beginColumn, endColumn, node.getName().getIdentifier()));

    return true;
}

From source file:br.uff.ic.gems.resources.ast.Visitor.java

@Override
public boolean visit(VariableDeclarationExpression node) {

    List<VariableDeclarationFragment> fragments = node.fragments();
    for (VariableDeclarationFragment fragment : fragments) {
        int beginLine = cu.getLineNumber(fragment.getStartPosition());
        int endLine = cu.getLineNumber(fragment.getStartPosition() + fragment.getLength());
        int beginColumn = cu.getColumnNumber(node.getStartPosition());
        int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength());

        SimpleName name = fragment.getName();

        if (name != null) {
            endLine = cu.getLineNumber(name.getStartPosition() + name.getLength());
            endColumn = cu.getColumnNumber(name.getStartPosition() + name.getLength());
        }//from   ww w  . ja  va  2  s.com

        languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine,
                beginColumn, endColumn, fragment.getName().getIdentifier()));
    }

    return true;
}

From source file:br.uff.ic.gems.resources.ast.Visitor.java

@Override
public boolean visit(VariableDeclarationStatement node) {

    List<VariableDeclarationFragment> fragments = node.fragments();

    for (VariableDeclarationFragment fragment : fragments) {
        String identifier = fragment.getName().getIdentifier();
        int beginLine = cu.getLineNumber(fragment.getStartPosition());
        int endLine = cu.getLineNumber(fragment.getStartPosition() + fragment.getLength());
        int beginColumn = cu.getColumnNumber(node.getStartPosition());
        int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength());

        SimpleName name = fragment.getName();

        if (name != null) {
            endLine = cu.getLineNumber(name.getStartPosition() + name.getLength());
            endColumn = cu.getColumnNumber(name.getStartPosition() + name.getLength());
        }/*from  w ww  . j ava2 s  . c o m*/

        languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine,
                beginColumn, endColumn, identifier));

    }

    return true;
}

From source file:br.uff.ic.gems.resources.ast.Visitor.java

@Override
public boolean visit(SimpleName node) {
    int beginLine = cu.getLineNumber(node.getStartPosition());
    int endLine = cu.getLineNumber(node.getStartPosition() + node.getLength());
    int beginColumn = cu.getColumnNumber(node.getStartPosition());
    int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength());

    String typeByIdentifier = getTypeByIdentifier(node.getIdentifier());

    if (typeByIdentifier != null) {
        languageConstructs.add(new LanguageConstruct(typeByIdentifier, beginLine, endLine, beginColumn,
                endColumn, node.getIdentifier()));
    }/*from   ww w.jav  a2 s.c  o m*/

    return true;
}

From source file:br.uff.ic.mergeguider.javaparser.DepVisitor.java

public void treatingSimpleName(SimpleName node) {
    IBinding simpleNameBinding = node.resolveBinding();

    if (simpleNameBinding == null) {
        return;/*from   w  w  w . j  a  v  a 2  s  . c o  m*/
    }

    //Treating Variable or Attribute
    if (simpleNameBinding instanceof IVariableBinding || simpleNameBinding instanceof ITypeBinding) {

        //Treating Attribute
        for (MyAttributeDeclaration attribute : classLanguageConstructsList
                .get(classLanguageConstructsList.size() - 1).getAttributes()) {

            IVariableBinding attributeBinding = attribute.getFieldDeclaration().resolveBinding();
            if (attributeBinding == null) {
                continue;
            }

            if (simpleNameBinding.equals(attributeBinding)) {

                int elementLineBegin = cu.getLineNumber(node.getStartPosition());
                int elementLineEnd = cu.getLineNumber(node.getStartPosition() + node.getLength());
                int elementColumnBegin = cu.getColumnNumber(node.getStartPosition());
                int elementColumnEnd = cu.getColumnNumber(node.getStartPosition() + node.getLength());

                Location location = new Location(elementLineBegin, elementLineEnd, elementColumnBegin,
                        elementColumnEnd);

                if (!attribute.getLocation().contains(location)) {

                    MyAttributeCall myAttributeCall = new MyAttributeCall(node, location);

                    if (!classLanguageConstructsList.isEmpty()) {
                        classLanguageConstructsList.get(classLanguageConstructsList.size() - 1)
                                .getAttributeCalls().add(myAttributeCall);
                    }
                }
            }

        }

        //Treating variables
        for (MyVariableDeclaration variableDeclaration : classLanguageConstructsList
                .get(classLanguageConstructsList.size() - 1).getVariableDeclarations()) {

            IVariableBinding attributeBinding = variableDeclaration.resolveBinding();
            if (attributeBinding == null) {
                continue;
            }

            if (simpleNameBinding.equals(attributeBinding)) {

                int elementLineBegin = cu.getLineNumber(node.getStartPosition());
                int elementLineEnd = cu.getLineNumber(node.getStartPosition() + node.getLength());
                int elementColumnBegin = cu.getColumnNumber(node.getStartPosition());
                int elementColumnEnd = cu.getColumnNumber(node.getStartPosition() + node.getLength());

                Location location = new Location(elementLineBegin, elementLineEnd, elementColumnBegin,
                        elementColumnEnd);

                if (!variableDeclaration.getLocation().contains(location)) {

                    MyVariableCall myVariableCall = new MyVariableCall(node, location);

                    classLanguageConstructsList.get(classLanguageConstructsList.size() - 1).getVariableCalls()
                            .add(myVariableCall);
                }
            }

        }
    }
}

From source file:ch.uzh.ifi.seal.changedistiller.treedifferencing.Node.java

License:Apache License

/**
 * @param aNewName//  w w w .ja va2s .c o  m
 * @param aOldName
 * @param aSrc
 */
public void setNewValue_localValDecl(SimpleName aNewName, SimpleName aOldName, String aSrc) {
    String oldName = aOldName.getFullyQualifiedName();
    String newName = aNewName.getFullyQualifiedName();
    int bgn14 = aOldName.getStartPosition();
    int end14 = bgn14 + aOldName.getLength();
    String value = getValue();
    int bgn17 = getEntity().getStartPosition();
    int end17 = getEntity().getEndPosition();

    if (bgn17 < bgn14 && end14 < end17 && value.contains(oldName)) {
        String newSrcFirstPart = aSrc.substring(bgn17, bgn14);
        String newSrcLastPart = aSrc.substring(end14, end17 + 1);
        String newValue = newSrcFirstPart + newName + newSrcLastPart;
        mNewValue = newValue;
    }
}

From source file:ch.uzh.ifi.seal.changedistiller.treedifferencing.Node.java

License:Apache License

/**
 * Sets the new value./*from   w ww  . j  a  va 2  s .co m*/
 * 
 * @param aNewName
 *            the a new name
 * @param aOldName
 *            the a old name
 * @param aSrc
 *            the a src
 */
@SuppressWarnings("unused")
public void setNewValue(SimpleName aNewName, SimpleName aOldName, String aSrc) {
    String oldName = aOldName.getFullyQualifiedName();
    String newName = aNewName.getFullyQualifiedName();
    int bgn14 = aOldName.getStartPosition();
    int end14 = bgn14 + aOldName.getLength();
    String value = getValue();
    int bgn17 = getEntity().getStartPosition();
    int end17 = getEntity().getEndPosition();
    // if (bgn17 <= bgn14 && end14 <= end17 && oldName.equals(value)) {
    // System.out.print("");
    // }
    if (bgn17 <= bgn14 && end14 <= end17) {
        String newSrcFirstPart = aSrc.substring(bgn17, bgn14);
        String newSrcLastPart = aSrc.substring(end14, end17 + 1);
        String newValue = newSrcFirstPart + newName + newSrcLastPart;
        mNewValue = newValue;
    }
}

From source file:ch.uzh.ifi.seal.changedistiller.treedifferencing.Node.java

License:Apache License

/**
 * @param aNewName//from   w ww  . j  a  v  a2s  .  c  om
 * @param aOldName
 * @param aSrc
 */
@SuppressWarnings("unused")
public void setNewValueForEachStmt(SimpleName aNewName, SimpleName aOldName, String aSrc) {
    String oldName = aOldName.getFullyQualifiedName();
    String newName = aNewName.getFullyQualifiedName();
    int bgn14 = aOldName.getStartPosition();
    int end14 = bgn14 + aOldName.getLength();

    String value = getValue();
    int bgn17 = getEntity().getStartPosition();
    int end17 = getEntity().getEndPosition();

    int bgnPar17 = aSrc.indexOf("(", bgn17) + 1;
    int bgnBlock17 = aSrc.indexOf("{", bgn17);
    int endPar17 = aSrc.lastIndexOf(")", bgnBlock17);

    if (bgnPar17 <= bgn14 && end14 <= endPar17) {
        String forEachValue = aSrc.substring(bgnPar17, endPar17);
        String firstPart = aSrc.substring(bgnPar17, bgn14);
        String lastPart = aSrc.substring(end14, endPar17);
        String newValue = firstPart + newName + lastPart;
        mNewValue = newValue;
    }
}

From source file:ch.uzh.ifi.seal.changedistiller.treedifferencing.Node.java

License:Apache License

/**
 * @param aNewName//from  www .  j a  va 2  s  .co  m
 * @param aOldName
 * @param aSrc
 */
@SuppressWarnings("unused")
public void setNewValueForStmt(SimpleName aNewName, SimpleName aOldName, String aSrc) {
    String oldName = aOldName.getFullyQualifiedName();
    String newName = aNewName.getFullyQualifiedName();
    int bgn14 = aOldName.getStartPosition();
    int end14 = bgn14 + aOldName.getLength();

    String value = getValue();
    int bgn17 = getEntity().getStartPosition();
    int end17 = getEntity().getEndPosition();

    int bgnPar17 = aSrc.indexOf("(", bgn17) + 1;
    int bgnBlock17 = aSrc.indexOf("{", bgn17);
    int endPar17 = aSrc.lastIndexOf(")", bgnBlock17);

    int bgnSemicolon17 = aSrc.indexOf(";", bgnPar17) + 1;
    int endSemicolon17 = aSrc.lastIndexOf(";", endPar17);

    if (bgnSemicolon17 <= bgn14 && end14 <= endSemicolon17) {
        String forConditon = aSrc.substring(bgnSemicolon17, endSemicolon17);
        String firstPart = aSrc.substring(bgnSemicolon17, bgn14);
        String lastPart = aSrc.substring(end14, endSemicolon17);
        String newValue = "(" + firstPart + newName + lastPart + ")";
        String newValueNoSpace = newValue.replaceAll("\\s", "");
        mNewValue = newValueNoSpace;
    }
}