Example usage for org.eclipse.jdt.internal.core SourceType getMethods

List of usage examples for org.eclipse.jdt.internal.core SourceType getMethods

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core SourceType getMethods.

Prototype

@Override
public IMethod[] getMethods() throws JavaModelException 

Source Link

Usage

From source file:costabs.utils.SourceUtils.java

License:Open Source License

public static IMethod[] getMethodsFromJavaFile(IJavaElement element) throws Exception {
    try {//from  ww  w  .  j  a v a 2s  .  c o m
        ICompilationUnit unit = (ICompilationUnit) element;
        IJavaElement elements[] = unit.getChildren();
        for (int i = 0; i < elements.length; i++) {
            //LogUtils.debug(elements[i].getClass());
            if (elements[i] instanceof org.eclipse.jdt.internal.core.SourceType) {
                SourceType source = (SourceType) elements[i];

                return source.getMethods();
            }
        }
        throw new Exception("No methods found in file ");

    } catch (Exception e) {
        throw new Exception("Cannot find the methods from Java file");
    }

}