Search in sources :

Example 1 with IJdtTypeProvider

use of org.eclipse.xtext.common.types.access.jdt.IJdtTypeProvider in project dsl-devkit by dsldevkit.

the class JdtFallbackTypeProviderFactory method createBundleAwareDelegate.

/**
 * Creates a new bundle aware JdtFallbackTypeProvider.
 * <p>
 * <em>Note</em>: Uses a custom bundle class finder to locate and load classes.
 * </p>
 *
 * @param typeProvider
 *          the {@link IJdtTypeProvider}, may be {@code null}
 * @param resourceSet
 *          the {@link ResourceSet}, must not be {@code null}
 * @return the {@link IJdtTypeProvider}, never {@code null}
 */
protected IJdtTypeProvider createBundleAwareDelegate(final IJdtTypeProvider typeProvider, final ResourceSet resourceSet) {
    IJdtTypeProvider firstProvider = typeProvider instanceof NullJdtTypeProvider ? null : typeProvider;
    BundleAwareTypeProvider bundleAwareTypeProvider = new BundleAwareTypeProvider(classLoader, resourceSet, indexedJvmTypeAccess, typeResourceServices);
    JdtFallbackTypeProvider result = new JdtFallbackTypeProvider(firstProvider, bundleAwareTypeProvider);
    resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(URIHelperConstants.PROTOCOL, result);
    return result;
}
Also used : NullJdtTypeProvider(org.eclipse.xtext.common.types.access.jdt.NullJdtTypeProvider) BundleAwareTypeProvider(com.avaloq.tools.ddk.xtext.common.types.access.jdt.BundleAwareTypeProvider) IJdtTypeProvider(org.eclipse.xtext.common.types.access.jdt.IJdtTypeProvider)

Example 2 with IJdtTypeProvider

use of org.eclipse.xtext.common.types.access.jdt.IJdtTypeProvider in project xtext-eclipse by eclipse.

the class JdtTypesProposalProvider method createSubTypeProposals.

@Override
public void createSubTypeProposals(final JvmType superType, ICompletionProposalFactory proposalFactory, ContentAssistContext context, EReference typeReference, final Filter filter, IValueConverter<String> valueConverter, ICompletionProposalAcceptor acceptor) {
    if (superType == null || superType.eIsProxy())
        return;
    if (superType.eResource() == null || superType.eResource().getResourceSet() == null)
        return;
    IJavaProject project = getProjectProvider().getJavaProject(superType.eResource().getResourceSet());
    if (project == null)
        return;
    final String superTypeIdentifier = superType.getIdentifier();
    // java.lang.Object - no need to create hierarchy scope
    if (Object.class.getName().equals(superTypeIdentifier)) {
        createTypeProposals(project, proposalFactory, context, typeReference, filter, valueConverter, acceptor);
        return;
    }
    try {
        final Set<String> superTypeNames = Sets.newHashSet();
        final IJdtTypeProvider provider = jdtTypeProviderFactory.createTypeProvider(superType.eResource().getResourceSet());
        IJavaSearchScope scope = createSearchScope(project, superType, superTypeNames);
        searchAndCreateProposals(scope, proposalFactory, context, typeReference, TypeMatchFilters.and(filter, new ITypesProposalProvider.Filter() {

            @Override
            public boolean accept(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) {
                if (path == null || path.endsWith(".class") || path.endsWith(".java")) {
                    // Java index match
                    String identifier = getIdentifier(packageName, simpleTypeName, enclosingTypeNames);
                    if (!superTypeNames.contains(identifier)) {
                        return true;
                    }
                    return false;
                } else {
                    // accept match from dirty state
                    String identifier = getIdentifier(packageName, simpleTypeName, enclosingTypeNames);
                    if (identifier.equals(superTypeIdentifier)) {
                        return true;
                    }
                    JvmType candidate = provider.findTypeByName(identifier, true);
                    if (superTypeCollector.collect(candidate).contains(superType)) {
                        return true;
                    }
                    return false;
                }
            }

            @Override
            public int getSearchFor() {
                return filter.getSearchFor();
            }
        }), valueConverter, acceptor);
    } catch (JavaModelException ex) {
    // ignore
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) IJdtTypeProvider(org.eclipse.xtext.common.types.access.jdt.IJdtTypeProvider) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) EObject(org.eclipse.emf.ecore.EObject) StyledString(org.eclipse.jface.viewers.StyledString) JvmType(org.eclipse.xtext.common.types.JvmType)

Aggregations

IJdtTypeProvider (org.eclipse.xtext.common.types.access.jdt.IJdtTypeProvider)2 BundleAwareTypeProvider (com.avaloq.tools.ddk.xtext.common.types.access.jdt.BundleAwareTypeProvider)1 EObject (org.eclipse.emf.ecore.EObject)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 IJavaSearchScope (org.eclipse.jdt.core.search.IJavaSearchScope)1 StyledString (org.eclipse.jface.viewers.StyledString)1 JvmType (org.eclipse.xtext.common.types.JvmType)1 NullJdtTypeProvider (org.eclipse.xtext.common.types.access.jdt.NullJdtTypeProvider)1