use of org.eclipse.xtext.scoping.IScope in project xtext-eclipse by eclipse.
the class XbaseProposalProvider method completeXMemberFeatureCall_Feature.
@Override
public void completeXMemberFeatureCall_Feature(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
if (model instanceof XMemberFeatureCall) {
XExpression memberCallTarget = ((XMemberFeatureCall) model).getMemberCallTarget();
IResolvedTypes resolvedTypes = typeResolver.resolveTypes(memberCallTarget);
LightweightTypeReference memberCallTargetType = resolvedTypes.getActualType(memberCallTarget);
Iterable<JvmFeature> featuresToImport = getFavoriteStaticFeatures(model, input -> {
if (input instanceof JvmOperation && input.isStatic()) {
List<JvmFormalParameter> parameters = ((JvmOperation) input).getParameters();
if (parameters.size() > 0) {
JvmFormalParameter firstParam = parameters.get(0);
JvmTypeReference parameterType = firstParam.getParameterType();
if (parameterType != null) {
LightweightTypeReference lightweightTypeReference = memberCallTargetType.getOwner().toLightweightTypeReference(parameterType);
if (lightweightTypeReference != null) {
return memberCallTargetType.isAssignableFrom(lightweightTypeReference);
}
}
}
}
return false;
});
// Create StaticExtensionFeatureDescriptionWithImplicitFirstArgument instead of SimpleIdentifiableElementDescription since we want the Proposal to show parameters
Iterable<IEObjectDescription> scopedFeatures = Iterables.transform(featuresToImport, feature -> {
QualifiedName qualifiedName = QualifiedName.create(feature.getSimpleName());
return new StaticExtensionFeatureDescriptionWithImplicitFirstArgument(qualifiedName, feature, memberCallTarget, memberCallTargetType, 0, true);
});
// Scope for all static features
IScope staticMemberScope = new SimpleScope(IScope.NULLSCOPE, scopedFeatures);
proposeFavoriteStaticFeatures(model, context, acceptor, staticMemberScope);
// Regular proposals
createReceiverProposals(((XMemberFeatureCall) model).getMemberCallTarget(), (CrossReference) assignment.getTerminal(), context, acceptor);
} else if (model instanceof XAssignment) {
createReceiverProposals(((XAssignment) model).getAssignable(), (CrossReference) assignment.getTerminal(), context, acceptor);
}
}
use of org.eclipse.xtext.scoping.IScope in project xtext-eclipse by eclipse.
the class ArithmeticsScopeProvider method getScope.
@Override
public IScope getScope(EObject context, EReference reference) {
if (reference == ArithmeticsPackage.Literals.IMPORT__MODULE) {
return super.getGlobalScope(context.eResource(), reference);
}
Module module = EcoreUtil2.getContainerOfType(context, Module.class);
IScope result = IScope.NULLSCOPE;
for (Import i : module.getImports()) {
if (!i.getModule().eIsProxy()) {
result = getModuleScope(context, reference, i.getModule(), result);
}
}
result = getModuleScope(context, reference, module, result);
return getDefinitionScope(context, reference, result);
}
use of org.eclipse.xtext.scoping.IScope in project xtext-eclipse by eclipse.
the class JavaTypeQuickfixes method addQuickfixes.
@Override
public void addQuickfixes(Issue issue, IssueResolutionAcceptor issueResolutionAcceptor, IXtextDocument xtextDocument, XtextResource resource, EObject referenceOwner, EReference unresolvedReference) throws Exception {
String issueString = xtextDocument.get(issue.getOffset(), issue.getLength());
IScope scope = scopeProvider.getScope(referenceOwner, unresolvedReference);
boolean useJavaSearch = isUseJavaSearch(unresolvedReference, issue);
if (useJavaSearch) {
JvmDeclaredType jvmType = importsConfiguration.getContextJvmDeclaredType(referenceOwner);
IJavaSearchScope javaSearchScope = getJavaSearchScope(referenceOwner);
boolean proposeImports = true;
if (isConstructorReference(unresolvedReference))
proposeImports = !createConstructorProposals(jvmType, issue, issueString, javaSearchScope, issueResolutionAcceptor);
if (proposeImports)
createImportProposals(jvmType, issue, issueString, javaSearchScope, issueResolutionAcceptor);
scope = getImportedTypesScope(referenceOwner, issueString, scope, javaSearchScope);
}
List<IEObjectDescription> discardedDescriptions = Lists.newArrayList();
Set<String> proposedSolutions = Sets.newHashSet();
int addedDescriptions = 0;
int checkedDescriptions = 0;
for (IEObjectDescription referableElement : scope.getAllElements()) {
String solution = qualifiedNameConverter.toString(referableElement.getName());
if (!equal(issueString, solution) && proposedSolutions.add(solution)) {
if (useJavaSearch || similarityMatcher.isSimilar(issueString, solution)) {
addedDescriptions++;
createResolution(issue, issueResolutionAcceptor, issueString, referableElement);
proposedSolutions.add(solution);
} else {
discardedDescriptions.add(referableElement);
}
}
checkedDescriptions++;
if (checkedDescriptions > 100)
break;
}
if (discardedDescriptions.size() + addedDescriptions <= 5) {
for (IEObjectDescription referableElement : discardedDescriptions) {
createResolution(issue, issueResolutionAcceptor, issueString, referableElement);
}
}
}
use of org.eclipse.xtext.scoping.IScope in project xtext-eclipse by eclipse.
the class XbaseHoverDocumentationProvider method getResolvedDeclarator.
protected JvmDeclaredType getResolvedDeclarator(String name) {
JvmDeclaredType jvmDeclaredType = null;
if (Strings.isEmpty(name) || name.trim().length() == 0) {
jvmDeclaredType = getDeclaringType(context);
} else {
HoverReference reference = new HoverReference(TypesPackage.Literals.JVM_TYPE);
IScope scope = scopeProvider.getScope(context, reference);
IEObjectDescription declarator = scope.getSingleElement(qualifiedNameConverter.toQualifiedName(name));
if (declarator != null && EcoreUtil2.isAssignableFrom(TypesPackage.eINSTANCE.getJvmGenericType(), declarator.getEClass())) {
jvmDeclaredType = (JvmDeclaredType) context.eResource().getResourceSet().getEObject(declarator.getEObjectURI(), true);
}
}
return jvmDeclaredType;
}
use of org.eclipse.xtext.scoping.IScope in project n4js by eclipse.
the class IntersectionMemberScope method getCheckedDescription.
@Override
protected IEObjectDescription getCheckedDescription(String name, TMember member) {
IEObjectDescription description = EObjectDescription.create(member.getName(), member);
QualifiedName qn = QualifiedName.create(name);
boolean allDescrWithError = true;
for (IScope currSubScope : subScopes) {
IEObjectDescription subDescription = currSubScope.getSingleElement(qn);
boolean descrWithError = subDescription == null || subDescription instanceof IEObjectDescriptionWithError;
allDescrWithError &= descrWithError;
}
if (allDescrWithError) {
return createComposedMemberDescriptionWithErrors(description);
}
return description;
}
Aggregations