Commit 1180d909 authored by Jan Belle's avatar Jan Belle
Browse files

[ui] Add content assist for namespace of import statements

Bug 564396

Change-Id: I41daad65c7a2b7a1311009dcf6fa10dfb6d1e345
parent bdb72890
......@@ -14,17 +14,24 @@
*******************************************************************************/
package org.eclipse.etrice.core.common.ui.contentassist;
import java.util.Arrays;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.etrice.core.common.base.util.ImportHelpers;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.xtext.RuleCall;
import org.eclipse.xtext.naming.IQualifiedNameConverter;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal;
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor;
import com.google.common.base.Function;
import com.google.inject.Inject;
/**
* see http://www.eclipse.org/Xtext/documentation.html#contentAssist on how to
......@@ -32,6 +39,8 @@ import com.google.common.base.Function;
*/
public class BaseProposalProvider extends org.eclipse.etrice.core.common.ui.contentassist.AbstractBaseProposalProvider {
@Inject protected ImportHelpers importHelpers;
@Override
public void complete_TIME(EObject model, RuleCall ruleCall, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
......@@ -55,6 +64,21 @@ public class BaseProposalProvider extends org.eclipse.etrice.core.common.ui.cont
super.complete_TIME(model, ruleCall, context, acceptor);
}
/**
* Creates content assist proposals for imported namespaces that match the given type and filter.
*/
protected void lookupImportedNamespace(EObject model, ContentAssistContext context, ICompletionProposalAcceptor acceptor,
EClass... types) {
IScope scope = importHelpers.getVisibleScope(model.eResource(), EcorePackage.eINSTANCE.getEObject(),
eod -> Arrays.stream(types).anyMatch(t -> t.isSuperTypeOf(eod.getEClass())));
DefaultProposalCreator proposalCreator = new DefaultProposalCreator(context, null, getQualifiedNameConverter());
for (IEObjectDescription candidate : scope.getAllElements()) {
if (!acceptor.canAcceptMoreProposals())
return;
acceptor.accept(proposalCreator.apply(candidate));
}
}
@Override
protected Function<IEObjectDescription, ICompletionProposal> getProposalFactory(String ruleName,
ContentAssistContext contentAssistContext) {
......
......@@ -84,17 +84,23 @@ public class ImportHelpers {
* Returns current visible/imported scope of given resource.
*/
public IScope getVisibleScope(Resource context) {
return getVisibleScope(context, null);
return getVisibleScope(context, EOBJECT);
}
/**
* Returns current visible/imported scope of given resource.
*/
public IScope getVisibleScope(Resource context, EClass type) {
return getVisibleScope(context, type, Predicates.alwaysTrue());
}
/**
* Returns current imported scope of given resource.
*/
public IScope getVisibleScope(Resource context, EClass type, Predicate<IEObjectDescription> filter) {
EReference reference = EcoreFactory.eINSTANCE.createEReference();
reference.setEType((type != null) ? type : EOBJECT);
return globalScope.getScope(context, reference, Predicates.alwaysTrue());
reference.setEType((type != null) ? type : EOBJECT);
return globalScope.getScope(context, reference, filter);
}
/**
......
......@@ -35,6 +35,7 @@ import org.eclipse.etrice.core.room.DataType;
import org.eclipse.etrice.core.room.EnumLiteral;
import org.eclipse.etrice.core.room.EnumerationType;
import org.eclipse.etrice.core.room.PrimitiveType;
import org.eclipse.etrice.core.room.RoomPackage;
import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.xtext.Assignment;
import org.eclipse.xtext.Keyword;
......@@ -57,13 +58,19 @@ public class ConfigProposalProvider extends AbstractConfigProposalProvider {
@Inject
private ConfigUtil configUtil;
@Override
public void completeImport_ImportedNamespace(EObject model, Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
lookupImportedNamespace(model, context, acceptor, RoomPackage.eINSTANCE.getRoomClass());
}
@Override
public void completeImport_ImportURI(EObject model, Assignment assignment,
final ContentAssistContext context,
final ICompletionProposalAcceptor acceptor) {
ImportModelAssist.addPaths(this, context, acceptor, ".room");
}
@Override
public void completeActorInstanceConfig_Path(EObject model,
Assignment assignment, ContentAssistContext context,
......
......@@ -16,6 +16,8 @@ package org.eclipse.etrice.core.etmap.ui.contentassist;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.common.ui.contentassist.ImportModelAssist;
import org.eclipse.etrice.core.etphys.eTPhys.ETPhysPackage;
import org.eclipse.etrice.core.room.RoomPackage;
import org.eclipse.xtext.Assignment;
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor;
......@@ -25,6 +27,12 @@ import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor;
*/
public class ETMapProposalProvider extends AbstractETMapProposalProvider {
@Override
public void completeImport_ImportedNamespace(EObject model, Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
lookupImportedNamespace(model, context, acceptor, RoomPackage.eINSTANCE.getLogicalSystem(), ETPhysPackage.eINSTANCE.getPhysicalSystem());
}
@Override
public void completeImport_ImportURI(EObject model, Assignment assignment,
final ContentAssistContext context,
......@@ -32,5 +40,5 @@ public class ETMapProposalProvider extends AbstractETMapProposalProvider {
ImportModelAssist.addPaths(this, context, acceptor, ".room");
ImportModelAssist.addPaths(this, context, acceptor, ".etphys");
}
}
......@@ -14,6 +14,7 @@ package org.eclipse.etrice.core.etphys.ui.contentassist;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.common.ui.contentassist.ImportModelAssist;
import org.eclipse.etrice.core.etphys.eTPhys.ETPhysPackage;
import org.eclipse.xtext.Assignment;
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor;
......@@ -22,6 +23,12 @@ import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor;
* see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#contentAssist on how to customize content assistant
*/
public class ETPhysProposalProvider extends AbstractETPhysProposalProvider {
@Override
public void completeImport_ImportedNamespace(EObject model, Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
lookupImportedNamespace(model, context, acceptor, ETPhysPackage.eINSTANCE.getNodeClass(), ETPhysPackage.eINSTANCE.getRuntimeClass());
}
@Override
public void completeImport_ImportURI(EObject model, Assignment assignment,
......@@ -29,5 +36,5 @@ public class ETPhysProposalProvider extends AbstractETPhysProposalProvider {
final ICompletionProposalAcceptor acceptor) {
ImportModelAssist.addPaths(this, context, acceptor, ".etphys");
}
}
......@@ -23,6 +23,7 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.etrice.core.common.base.AnnotationType;
import org.eclipse.etrice.core.common.base.BasePackage;
import org.eclipse.etrice.core.common.ui.contentassist.ImportModelAssist;
import org.eclipse.etrice.core.fsm.fSM.DetailCode;
import org.eclipse.etrice.core.naming.RoomNameProvider;
......@@ -35,6 +36,7 @@ import org.eclipse.etrice.core.room.DataClass;
import org.eclipse.etrice.core.room.Operation;
import org.eclipse.etrice.core.room.RefPath;
import org.eclipse.etrice.core.room.RoomAnnotationTargetEnum;
import org.eclipse.etrice.core.room.RoomPackage;
import org.eclipse.etrice.core.room.StandardOperation;
import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.core.services.RoomGrammarAccess;
......@@ -130,13 +132,19 @@ public class RoomProposalProvider extends AbstractRoomProposalProvider {
});
}
@Override
public void completeImport_ImportedNamespace(EObject model, Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
lookupImportedNamespace(model, context, acceptor, RoomPackage.eINSTANCE.getRoomClass(), BasePackage.eINSTANCE.getAnnotationType());
}
@Override
public void completeImport_ImportURI(EObject model, Assignment assignment,
final ContentAssistContext context,
final ICompletionProposalAcceptor acceptor) {
ImportModelAssist.addPaths(this, context, acceptor, ".room");
}
@Override
public void completeActorInstanceMapping_Path(EObject model,
Assignment assignment, ContentAssistContext context,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment