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;
}
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
}
}
Aggregations