Example usage for org.eclipse.jdt.internal.core CompilationUnit getTypes

List of usage examples for org.eclipse.jdt.internal.core CompilationUnit getTypes

Introduction

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

Prototype

@Override
public IType[] getTypes() throws JavaModelException 

Source Link

Usage

From source file:com.aliyun.odps.eclipse.launch.shortcut.udf.UDFLaunchShortcuts2.java

License:Apache License

/**
 * Returns the smallest enclosing <code>IType</code> if the specified object is a main method, or
 * <code>null</code>//  w w w.  j  a v a2s.co  m
 * 
 * @param o the object to inspect
 * @return the smallest enclosing <code>IType</code> of the specified object if it is a main
 *         method or <code>null</code> if it is not
 */
private IType isUDF(Object o) {
    if (o instanceof IAdaptable) {
        IAdaptable adapt = (IAdaptable) o;
        IJavaElement element = (IJavaElement) adapt.getAdapter(IJavaElement.class);
        if (element instanceof CompilationUnit) {
            CompilationUnit unit = (CompilationUnit) element;
            IClassFile i;
            try {
                IType[] types = unit.getTypes();
                for (IType iType : types) {
                    String superClassName = iType.getSuperclassName();
                    if (superClassName.equals("UDF") || superClassName.equals("UDTF")
                            || superClassName.equals("Aggregator")) {
                        return iType;
                    }

                }
            } catch (JavaModelException e) {
            }
        }
    }
    return null;
}

From source file:de.gebit.integrity.ui.contentassist.DSLProposalProvider.java

License:Open Source License

private IType resolveJDTTypeForJvmType(JvmType aType) throws JavaModelException {
    IJavaElement tempSourceMethod = (IJavaElement) elementFinder.findElementFor(aType);

    if (tempSourceMethod.getParent() instanceof CompilationUnit) {
        CompilationUnit tempCompilationUnit = (CompilationUnit) tempSourceMethod.getParent();
        return tempCompilationUnit.getTypes()[0];
    } else if (tempSourceMethod.getParent() instanceof ClassFile) {
        ClassFile tempClassFile = (ClassFile) tempSourceMethod.getParent();
        tempClassFile.open(null);//from   w  ww . j  a  va2  s  .  c  o m
        return tempClassFile.getType();
    }

    return null;
}

From source file:org.eclipse.objectteams.otdt.internal.ui.packageview.PackageExplorerAdaptor.ContentProvider.java

License:Open Source License

void findTeamCU(Object element) {
        if (element instanceof CompilationUnit) {
            // when refreshing in logical view, rofi-CUs are not visible, replace element by the enclosing Team CU
            CompilationUnit cu = (CompilationUnit) element;
            try {
                IType[] types = cu.getTypes();
                if (types != null && types.length > 0) {
                    IOTType ottype = OTModelManager.getOTElement(types[0]);
                    if (ottype instanceof IRoleFileType) {
                        // search outermost team:
                        while (ottype.isRole())
                            ottype = ((IRoleType) ottype).getTeam();
                        element = ottype.getCompilationUnit();
                    }//from w  w  w. ja  va  2  s .  c o  m
                }
            } catch (JavaModelException jme) {
                // nop, just keep element unchanged
            }
        }
        base.findTeamCU(element);
    }