Example usage for org.eclipse.jdt.internal.core BinaryType getTypeRoot

List of usage examples for org.eclipse.jdt.internal.core BinaryType getTypeRoot

Introduction

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

Prototype

ITypeRoot getTypeRoot();

Source Link

Document

Returns the Java type root in which this member is declared.

Usage

From source file:de.instantouch.model.search.SnakeClassInfo.java

License:Open Source License

public void createFrom(BinaryType binaryType) throws SnakeWrongTypeException {
    String className = binaryType.getFullyQualifiedName();
    findByName("className").set(className);

    ITypeRoot typeRoot = binaryType.getTypeRoot();

    IPackageFragment packageFragment = binaryType.getPackageFragment();
    IJavaElement parent = packageFragment.getParent();
    if (parent instanceof ExternalPackageFragmentRoot) {

        ExternalPackageFragmentRoot root = (ExternalPackageFragmentRoot) parent;
        String path = root.getPath().toString();

        int end = path.lastIndexOf("/");
        int start = path.lastIndexOf("/", end - 1);

        String bundleName = path.substring(++start, end);
        findByName("bundleName").set(bundleName);
    } else if (parent instanceof JarPackageFragmentRoot) {

        JarPackageFragmentRoot root = (JarPackageFragmentRoot) parent;
        String path = root.getPath().toString();

        int start = path.lastIndexOf("plugins/");
        String bundle = path.substring(start + "plugins/".length());
        int end = bundle.indexOf("_");

        String bundleName = bundle.substring(0, end);
        findByName("bundleName").set(bundleName);
    }//  w  ww  .j  av  a 2  s  . c  o m
}