Example usage for org.eclipse.jdt.core.dom VariableDeclaration getStartPosition

List of usage examples for org.eclipse.jdt.core.dom VariableDeclaration getStartPosition

Introduction

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

Prototype

public final int getStartPosition() 

Source Link

Document

Returns the character index into the original source file indicating where the source fragment corresponding to this node begins.

Usage

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

public boolean visit(VariableDeclaration 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());

    languageConstructs.add(/* www  . j a  v  a 2s.co m*/
            new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine, beginColumn, endColumn));

    return true;
}

From source file:org.eclipse.wb.internal.core.model.variable.LocalVariableSupport.java

License:Open Source License

/**
 * Ensures that variable has name (existing or re-generated) such that it does not conflict with
 * other variables related with given position (visible or can be shadowed).
 * /*  w w  w.  j av  a2  s.  com*/
 * @param newPosition
 *          the position where this variable will be declared.
 * @param statementsToMove
 *          the {@link Statement}'s that will be moved.
 */
void ensureUniqueVariableDuringMove(int newPosition, Statement[] statementsToMove) throws Exception {
    // prepare potentially conflicting declarations 
    List<VariableDeclaration> existingDeclarations;
    {
        existingDeclarations = Lists.newArrayList();
        // prepare state
        AstEditor editor = m_javaInfo.getEditor();
        CompilationUnit unit = editor.getAstUnit();
        VariableDeclaration declaration = m_declaration;
        // in any case add visible variables
        existingDeclarations.addAll(AstNodeUtils.getVariableDeclarationsVisibleAt(unit, newPosition));
        // in any case add shadow variables in *old* position
        existingDeclarations
                .addAll(AstNodeUtils.getVariableDeclarationsAfter(unit, declaration.getStartPosition()));
        // if moved declaration is not in Block, then it can shadow variables below
        {
            boolean isInBlock = false;
            for (Statement statement : statementsToMove) {
                isInBlock |= statement instanceof Block && AstNodeUtils.contains(statement, declaration);
            }
            if (!isInBlock) {
                existingDeclarations.addAll(AstNodeUtils.getVariableDeclarationsAfter(unit, newPosition));
            }
        }
        // exclude this variable
        existingDeclarations.remove(declaration);
    }
    // do generate unique name
    {
        String oldName = getName();
        String newName = AstEditor.getUniqueVariableName(existingDeclarations, oldName);
        if (!oldName.equals(newName)) {
            setName(newName);
        }
    }
}

From source file:org.jboss.tools.ws.jaxrs.core.jdt.SourceType.java

License:Open Source License

/**
 * Factory method for the {@link SourceType}
 * @param declaration the {@link VariableDeclaration} 
 * @return the {@link SourceType}/*from  w  w w .  j av  a 2  s.  c  o  m*/
 */
public static SourceType from(final VariableDeclaration declaration) {
    final IVariableBinding paramBinding = declaration.resolveBinding();
    if (paramBinding != null) {
        final String erasureName = paramBinding.getType().getErasure().getQualifiedName();
        final IType erasureType = (IType) paramBinding.getType().getErasure().getJavaElement();
        final List<IType> typeArguments = new ArrayList<IType>();
        final ISourceRange nameRange = new SourceRange(declaration.getStartPosition(), declaration.getLength());
        for (ITypeBinding typeArgumentBinding : paramBinding.getType().getTypeArguments()) {
            typeArguments.add((IType) typeArgumentBinding.getJavaElement());
        }
        return new SourceType(erasureName, erasureType, typeArguments, paramBinding.getType().isPrimitive(),
                nameRange);
    }
    return null;
}