Example usage for org.eclipse.jdt.core ITypeRoot isConsistent

List of usage examples for org.eclipse.jdt.core ITypeRoot isConsistent

Introduction

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

Prototype

boolean isConsistent() throws JavaModelException;

Source Link

Document

Returns whether the element is consistent with its underlying resource or buffer.

Usage

From source file:org.jboss.tools.arquillian.ui.internal.utils.ArquillianUIUtil.java

License:Open Source License

public static IType getActiveType() {
    IWorkbenchPage page = getActivePage();
    if (page == null) {
        return null;
    }/*from w  w w  .  j a  v a  2  s.c  om*/
    IEditorPart editor = page.getActiveEditor();
    if (editor instanceof CompilationUnitEditor) {
        CompilationUnitEditor cue = (CompilationUnitEditor) editor;
        IEditorInput editorInput = cue.getEditorInput();
        if (editorInput == null) {
            return null;
        }
        IJavaElement javaElement = (IJavaElement) editorInput.getAdapter(IJavaElement.class);
        if (javaElement != null && !javaElement.exists())
            return null;
        try {
            ITypeRoot rootType = EditorUtility.getEditorInputJavaElement(editor, true);
            if (rootType != null && rootType.isConsistent()) {
                IJavaElement element = SelectionConverter.getElementAtOffset(cue);
                if (element == null) {
                    return null;
                }
                return SelectionConverter.getTypeAtOffset(cue);
            }
        } catch (JavaModelException e) {
            ArquillianUIActivator.log(e);
        }
    }
    return null;
}