use of org.eclipse.xtext.naming.QualifiedName in project xtext-xtend by eclipse.
the class XtendProposalProvider method completeMember_Name.
@Override
public void completeMember_Name(final EObject model, Assignment assignment, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
if (announceProcessing(Lists.newArrayList("completeMember_Name", model, assignment.getFeature()))) {
EObject previousModel = context.getPreviousModel();
if (previousModel instanceof XExpression) {
if (!(previousModel instanceof XBlockExpression)) {
return;
}
}
if (model instanceof XtendField) {
// TODO go up type hierarchy and collect all local fields
final List<XtendField> siblings = EcoreUtil2.getSiblingsOfType(model, XtendField.class);
Set<String> alreadyTaken = Sets.newHashSet();
for (XtendField sibling : siblings) {
alreadyTaken.add(sibling.getName());
}
alreadyTaken.addAll(getAllKeywords());
completions.getVariableProposals(model, XtendPackage.Literals.XTEND_FIELD__TYPE, VariableType.INSTANCE_FIELD, alreadyTaken, new JdtVariableCompletions.CompletionDataAcceptor() {
@Override
public void accept(String replaceText, StyledString label, Image img) {
acceptor.accept(createCompletionProposal(replaceText, label, img, context));
}
});
} else if (model instanceof XtendFunction) {
for (QualifiedName operator : operatorMapping.getOperators()) {
StyledString displayString = new StyledString(operator.getFirstSegment());
displayString.append(" " + operatorMapping.getMethodName(operator), StyledString.DECORATIONS_STYLER);
acceptor.accept(createCompletionProposal(operator.getFirstSegment(), displayString, getImage(model), context));
}
super.completeMember_Name(model, assignment, context, acceptor);
} else {
super.completeMember_Name(model, assignment, context, acceptor);
}
}
}
use of org.eclipse.xtext.naming.QualifiedName in project xtext-xtend by eclipse.
the class CreateMemberQuickfixes method getOperatorMethodName.
/* @Nullable */
protected String getOperatorMethodName(XAbstractFeatureCall call) {
for (INode node : NodeModelUtils.findNodesForFeature(call, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE)) {
for (ILeafNode leafNode : node.getLeafNodes()) {
if (!leafNode.isHidden()) {
String symbol = leafNode.getText();
QualifiedName methodName = operatorMapping.getMethodName(QualifiedName.create(symbol));
if (methodName != null)
return methodName.getFirstSegment();
}
}
}
return null;
}
use of org.eclipse.xtext.naming.QualifiedName in project xtext-xtend by eclipse.
the class CreateXtendTypeQuickfixes method isTypeMissing.
protected boolean isTypeMissing(EObject referenceOwner, String typeName, String explicitPackage) {
QualifiedName typeQName = (!isEmpty(explicitPackage)) ? converter.toQualifiedName(explicitPackage).append(typeName) : converter.toQualifiedName(typeName);
final IScope typeScope = scopeProvider.getScope(referenceOwner, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
return typeScope.getSingleElement(typeQName) == null;
}
use of org.eclipse.xtext.naming.QualifiedName in project xtext-xtend by eclipse.
the class ImportedNamesTest method testNestedTypesIncluded.
@Test
public void testNestedTypesIncluded() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.newLine();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("val foo = types.StaticOuterClass.StaticMiddleClass.StaticInnerClass.CONSTANT");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.file(_builder.toString());
final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(file.eResource());
final Iterable<QualifiedName> importedNames = description.getImportedNames();
final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> {
String _string = it.toString();
String _lowerCase = "types.StaticOuterClass$StaticMiddleClass$StaticInnerClass".toLowerCase();
return Boolean.valueOf(Objects.equal(_string, _lowerCase));
};
Assert.assertTrue(("" + importedNames), IterableExtensions.<QualifiedName>exists(importedNames, _function));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.naming.QualifiedName in project xtext-xtend by eclipse.
the class ImportedNamesTest method testAnonymousClass.
@Test
public void testAnonymousClass() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.newLine();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("val foo = new Runnable() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("override run() {}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.file(_builder.toString());
final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(file.eResource());
final Iterable<QualifiedName> importedNames = description.getImportedNames();
final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> {
return Boolean.valueOf(it.getLastSegment().equals("runnable"));
};
Assert.assertTrue(("" + importedNames), IterableExtensions.<QualifiedName>exists(importedNames, _function));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations