Example usage for org.eclipse.jdt.core.search IJavaSearchScope encloses

List of usage examples for org.eclipse.jdt.core.search IJavaSearchScope encloses

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.search IJavaSearchScope encloses.

Prototype

public boolean encloses(IJavaElement element);

Source Link

Document

Checks whether this scope encloses the given element.

Usage

From source file:com.aliyun.odps.eclipse.launch.configuration.udf.UDFSearchEngine.java

License:Apache License

/**
 * Adds subtypes and enclosed types to the listing of 'found' types
 * //from ww  w . j  a  v a 2  s  . c o m
 * @param types the list of found types thus far
 * @param monitor progress monitor
 * @param scope the scope of elements
 * @return as set of all types to consider
 */
private Set addSubtypes(List types, IProgressMonitor monitor, IJavaSearchScope scope) {
    Iterator iterator = types.iterator();
    Set result = new HashSet(types.size());
    IType type = null;
    ITypeHierarchy hierarchy = null;
    IType[] subtypes = null;
    while (iterator.hasNext()) {
        type = (IType) iterator.next();
        if (result.add(type)) {
            try {
                hierarchy = type.newTypeHierarchy(monitor);
                subtypes = hierarchy.getAllSubtypes(type);
                for (int i = 0; i < subtypes.length; i++) {
                    if (scope.encloses(subtypes[i])) {
                        result.add(subtypes[i]);
                    }
                }
            } catch (JavaModelException e) {
                JDIDebugUIPlugin.log(e);
            }
        }
        monitor.worked(1);
    }
    return result;
}

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 {/*from  w  w  w. ja  v a 2  s  .  com*/
            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 {/*from   www .  j a v a2  s.co  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.acceleo.internal.ide.ui.launching.AcceleoMainMethodSearchEngine.java

License:Open Source License

/**
 * Adds sub-types and enclosed types to the listing of 'found' types.
 * //from w  w  w. ja  va  2s  . c  o  m
 * @param types
 *            the list of found types thus far
 * @param monitor
 *            progress monitor
 * @param scope
 *            the scope of elements
 * @return as set of all types to consider
 */
private Set<IType> addSubtypes(List<IType> types, IProgressMonitor monitor, IJavaSearchScope scope) {
    Iterator<IType> iterator = types.iterator();
    Set<IType> result = new CompactHashSet<IType>(types.size());
    IType type = null;
    ITypeHierarchy hierarchy = null;
    IType[] subtypes = null;
    while (iterator.hasNext()) {
        type = iterator.next();
        if (result.add(type)) {
            try {
                hierarchy = type.newTypeHierarchy(monitor);
                subtypes = hierarchy.getAllSubtypes(type);
                for (int i = 0; i < subtypes.length; i++) {
                    if (scope.encloses(subtypes[i])) {
                        result.add(subtypes[i]);
                    }
                }
            } catch (JavaModelException e) {
                AcceleoUIActivator.getDefault().getLog().log(e.getStatus());
            }
        }
        monitor.worked(1);
    }
    return result;
}

From source file:org.eclipse.ajdt.internal.launching.AJMainMethodSearchEngine.java

License:Open Source License

private Set<IType> getAllAspectsWithMain(IJavaSearchScope scope, Collection<IFile> includedFiles)
        throws JavaModelException {
    Set<IType> mainTypes = new HashSet<IType>();
    for (IFile file : includedFiles) {
        if (file.getFileExtension().equals("java")) {
            ICompilationUnit unit = (ICompilationUnit) AspectJCore.create(file);
            if (unit != null && unit.exists() && scope.encloses(unit)) {
                IType[] types = unit.getAllTypes();
                for (int i = 0; i < types.length; i++) {
                    IType type = types[i];
                    IMethod[] methods = type.getMethods();
                    for (int j = 0; j < methods.length; j++) {
                        if (methods[j].isMainMethod()) {
                            mainTypes.add(type);
                            break;
                        }/*from   w w w  .jav  a2s. c o m*/
                    }
                }
            }
        }
    }
    return mainTypes;
}

From source file:org.eclipse.xtext.common.types.xtext.ui.IntersectingJavaSearchScope.java

License:Open Source License

@Override
public boolean encloses(String resourcePath) {
    boolean result = false;
    for (int i = 0; i < scopes.length; i++) {
        if (!dontAsk[i]) {
            IJavaSearchScope scope = scopes[i];
            try {
                if (!scope.encloses(resourcePath))
                    return false;
                result = true;/*from  www.  j av  a2 s.c  o m*/
            } catch (Exception e) {
                dontAsk[i] = true;
                log.info("Exception in JDT code", e);
            }
        }
    }
    return result;
}

From source file:org.eclipse.xtext.common.types.xtext.ui.IntersectingJavaSearchScope.java

License:Open Source License

@Override
public boolean encloses(IJavaElement element) {
    boolean result = false;
    for (int i = 0; i < scopes.length; i++) {
        if (!dontAsk[i]) {
            IJavaSearchScope scope = scopes[i];
            try {
                if (!scope.encloses(element))
                    return false;
                result = true;//  w w  w .  jav a  2s  .c o m
            } catch (Exception e) {
                dontAsk[i] = true;
                log.info("Exception in JDT code", e);
            }
        }
    }
    return result;
}

From source file:org.grails.ide.eclipse.search.AbstractGrailsSearch.java

License:Open Source License

private boolean encloses(IJavaSearchScope scope, IFile gspFile) {
    if (scope != null) {
        return scope.encloses(gspFile.getFullPath().toString());
    } else {//from w w w .j  av a2  s . co m
        return true;
    }
}

From source file:org.grails.ide.eclipse.search.AbstractGrailsSearch.java

License:Open Source License

private boolean encloses(IJavaSearchScope scope, IType controllerClass) {
    if (scope != null) {
        return scope.encloses(controllerClass);
    }//from w  w w . j  a va 2 s.co m
    return true;
}

From source file:org.hawkinssoftware.rns.analysis.compile.util.CompoundHierarchiesScope.java

License:Open Source License

@Override
public boolean encloses(String resourcePath) {
    for (IJavaSearchScope scope : hierarchyScopes) {
        if (scope.encloses(resourcePath)) {
            return true;
        }//from  w ww .j a v  a  2s. c o  m
    }
    return false;
}