Example usage for org.eclipse.jdt.internal.core.search BasicSearchEngine createStrictHierarchyScope

List of usage examples for org.eclipse.jdt.internal.core.search BasicSearchEngine createStrictHierarchyScope

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core.search BasicSearchEngine createStrictHierarchyScope.

Prototype

public static IJavaSearchScope createStrictHierarchyScope(IJavaProject project, IType type,
        boolean onlySubtypes, boolean includeFocusType, WorkingCopyOwner owner) throws JavaModelException 

Source Link

Usage

From source file:com.liferay.ide.portlet.core.operation.NewPortletClassDataModelProvider.java

License:Open Source License

@Override
public DataModelPropertyDescriptor[] getValidPropertyDescriptors(String propertyName) {
    if (SUPERCLASS.equals(propertyName)) {
        String defaults = QUALIFIED_MVC_PORTLET + StringPool.COMMA + QUALIFIED_LIFERAY_PORTLET
                + StringPool.COMMA + QUALIFIED_GENERIC_PORTLET;

        String[] defaultVals = defaults.split(StringPool.COMMA);

        try {//  w  w w.  jav  a2 s .  co  m
            IJavaProject javaProject = JavaCore.create(getProject());

            Preferences preferences = PortletCore.getPreferences();
            String superclasses = preferences.get(PortletCore.PREF_KEY_PORTLET_SUPERCLASSES_USED, null);

            if (superclasses != null) {
                String[] customVals = superclasses.split(StringPool.COMMA);

                List<String> list = new ArrayList<String>();
                list.addAll(Arrays.asList(defaultVals));

                final IType portletType = JavaModelUtil.findType(javaProject, "javax.portlet.Portlet"); //$NON-NLS-1$

                final IJavaSearchScope scope = BasicSearchEngine.createStrictHierarchyScope(javaProject,
                        portletType, true, true, null);

                for (int i = 0; i < customVals.length; i++) {
                    IType type = JavaModelUtil.findType(javaProject, customVals[i]);

                    if (type != null && scope.encloses(type)) {
                        list.add(customVals[i]);
                    }
                }

                return DataModelPropertyDescriptor.createDescriptors(list.toArray(),
                        list.toArray(new String[0]));
            }
        } catch (JavaModelException e) {
        }

        return DataModelPropertyDescriptor.createDescriptors(defaultVals, defaultVals);
    } else if (CATEGORY.equals(propertyName)) {
        Properties categories = getCategories();

        if (categories != null && categories.size() > 0) {
            return DataModelPropertyDescriptor.createDescriptors(categories.keySet().toArray(new Object[0]),
                    categories.values().toArray(new String[0]));
        }
    } else if (ENTRY_CATEGORY.equals(propertyName)) {
        Properties entryCategories = getEntryCategories();

        if (entryCategories != null && entryCategories.size() > 0) {
            Object[] keys = entryCategories.keySet().toArray();
            Arrays.sort(keys);

            String[] values = new String[keys.length];

            for (int i = 0; i < keys.length; i++) {
                values[i] = entryCategories.getProperty(keys[i].toString());
            }

            return DataModelPropertyDescriptor.createDescriptors(keys, values);
        }
    }

    return super.getValidPropertyDescriptors(propertyName);
}

From source file:com.liferay.ide.portlet.core.operation.NewPortletClassDataModelProvider.java

License:Open Source License

public boolean isValidPortletClass(String qualifiedClassName) {
    try {//w w  w .ja v  a 2  s.  c  o m
        IJavaProject javaProject = JavaCore.create(getProject());

        if (javaProject != null) {
            final IType portletType = JavaModelUtil.findType(javaProject, "javax.portlet.Portlet"); //$NON-NLS-1$

            if (portletType != null) {
                final IJavaSearchScope scope = BasicSearchEngine.createStrictHierarchyScope(javaProject,
                        portletType, true, true, null);

                final IType classType = JavaModelUtil.findType(javaProject, qualifiedClassName);

                if (classType != null && scope.encloses(classType)) {
                    return true;
                }
            }
        }
    } catch (JavaModelException e) {
        PortletCore.logError(e);
    }

    return false;
}

From source file:org.eclipse.jdt.core.search.SearchEngine.java

License:Open Source License

/**
 * Returns a Java search scope limited to the hierarchy of the given type and to a given project.
 * The Java elements resulting from a search with this scope will be types in this hierarchy.
 * <p>//from  ww w  . j a v  a  2  s .com
 * Unlike the <code>createHierarchyScope</code> methods, this method creates <em>strict</em>
 * scopes that only contain types that actually span the hierarchy of the focus
 * type, but do not include additional enclosing or member types.
 * </p>
 * <p>
 * By default, hierarchy scopes include all direct and indirect supertypes and subtypes of the
 * focus type. This method, however, allows to restrict the hierarchy to true subtypes,
 * and exclude supertypes. Also, inclusion of the focus type itself is controlled by a parameter. 
 * </p>
 * 
 * @param project the project to which to constrain the search, or <code>null</code> if
 *        search should consider all types in the workspace 
 * @param type the focus of the hierarchy scope
 * @param onlySubtypes if <code>true</code> only subtypes of <code>type</code> are considered
 * @param includeFocusType if true the focus type <code>type</code> is included in the resulting scope, 
 *         otherwise it is excluded
 * @param owner the owner of working copies that take precedence over original compilation units, 
 *        or <code>null</code> if the primary working copy owner should be used
 * @return a new hierarchy scope
 * @exception JavaModelException if the hierarchy could not be computed on the given type
 * @since 3.6
 */
public static IJavaSearchScope createStrictHierarchyScope(IJavaProject project, IType type,
        boolean onlySubtypes, boolean includeFocusType, WorkingCopyOwner owner) throws JavaModelException {
    return BasicSearchEngine.createStrictHierarchyScope(project, type, onlySubtypes, includeFocusType, owner);
}