Example usage for org.eclipse.jdt.core ISourceRange ISourceRange

List of usage examples for org.eclipse.jdt.core ISourceRange ISourceRange

Introduction

In this page you can find the example usage for org.eclipse.jdt.core ISourceRange ISourceRange.

Prototype

ISourceRange

Source Link

Usage

From source file:com.architexa.diagrams.relo.jdt.ParseUtilities.java

License:Open Source License

/**
 * @param method//from w  w  w  .j  a v  a 2  s .c o  m
 * @return SourceRange
 * @throws JavaModelException
 */
public static ISourceRange getBodyRange(IMethod method) throws JavaModelException {
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(method.getCompilationUnit());
    CompilationUnit cu = (CompilationUnit) parser.createAST(null);
    TypeDeclaration td = findTypeDeclaration(cu, method);
    MethodDeclaration md = findMethodDeclaration(td, method);
    Block body = md.getBody();
    final int startPos;
    final int length;
    List<?> bodyStatements = body.statements();
    int stmnts = bodyStatements.size();
    if (stmnts > 0) {
        startPos = ((Statement) bodyStatements.get(0)).getStartPosition();
        Statement lastStmnt = (Statement) bodyStatements.get(stmnts - 1);
        length = lastStmnt.getStartPosition() + lastStmnt.getLength() - startPos;
    } else {
        startPos = body.getStartPosition();
        length = body.getLength();
    }
    return new ISourceRange() {
        public int getLength() {
            return length;
        }

        public int getOffset() {
            return startPos;
        }
    };
}

From source file:com.architexa.diagrams.relo.jdt.ParseUtilities.java

License:Open Source License

/**
 * @param method/*from ww w . j av  a  2 s.  c om*/
 * @return SourceRange
 * @throws JavaModelException
 */
public static ISourceRange getMethodRange(IMethod method) throws JavaModelException {
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(method.getCompilationUnit());
    CompilationUnit cu = (CompilationUnit) parser.createAST(null);
    TypeDeclaration td = findTypeDeclaration(cu, method);
    final MethodDeclaration md = findMethodDeclaration(td, method);
    return new ISourceRange() {
        public int getLength() {
            return md.getLength();
        }

        public int getOffset() {
            return md.getStartPosition();
        }
    };
}

From source file:de.fu_berlin.inf.jtourbus.BusStopJavaElement.java

License:Open Source License

@Override
public ISourceRange getSourceRange() {
    return new ISourceRange() {

        public int getLength() {
            return length;
        }/*  w w  w .  jav  a2  s  . c  o m*/

        public int getOffset() {
            return offset;
        }
    };
}

From source file:org.ucdetector.util.NonJavaIMember.java

License:Open Source License

public ISourceRange getNameRange() throws JavaModelException {
    return new ISourceRange() {

        public int getOffset() {
            return offset;
        }//  ww  w.  j  a  v a 2s.  c o m

        public int getLength() {
            return length;
        }
    };
}

From source file:org.ucdetector.util.NonJavaIMember.java

License:Open Source License

public ISourceRange getSourceRange() throws JavaModelException {
    return new ISourceRange() {

        public int getOffset() {
            return offset;
        }//from w  ww  . jav a  2s.c  o  m

        public int getLength() {
            return length;
        }
    };
}