Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Belle2019-03-10 09:57:24 -0400
committerJan Belle2019-05-15 11:03:05 -0400
commit357f6435baeebb3c650e94ad4d1728984088f74b (patch)
tree1657952d854d66164e8813b0141135e96116deaf /plugins
parent7881487a6e88e6ffe9c56a4cdcd12f6ca00d2b22 (diff)
downloadorg.eclipse.etrice-357f6435baeebb3c650e94ad4d1728984088f74b.tar.gz
org.eclipse.etrice-357f6435baeebb3c650e94ad4d1728984088f74b.tar.xz
org.eclipse.etrice-357f6435baeebb3c650e94ad4d1728984088f74b.zip
[common.ui] Modify content assist to always propose unqualified names
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/contentassist/BaseProposalProvider.java26
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/contentassist/IProposalFilter.java23
-rw-r--r--plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/contentassist/RoomProposalProvider.java104
3 files changed, 55 insertions, 98 deletions
diff --git a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/contentassist/BaseProposalProvider.java b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/contentassist/BaseProposalProvider.java
index fb48276ba..fc1860849 100644
--- a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/contentassist/BaseProposalProvider.java
+++ b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/contentassist/BaseProposalProvider.java
@@ -17,10 +17,15 @@ package org.eclipse.etrice.core.common.ui.contentassist;
import org.eclipse.emf.ecore.EObject;
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.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;
+
/**
* see http://www.eclipse.org/Xtext/documentation.html#contentAssist on how to
* customize content assistant
@@ -50,4 +55,25 @@ public class BaseProposalProvider extends org.eclipse.etrice.core.common.ui.cont
super.complete_TIME(model, ruleCall, context, acceptor);
}
+ @Override
+ protected Function<IEObjectDescription, ICompletionProposal> getProposalFactory(String ruleName,
+ ContentAssistContext contentAssistContext) {
+ // Proposal creator that always proposes unqualified names
+ return new DefaultProposalCreator(contentAssistContext, ruleName, new IQualifiedNameConverter() {
+ @Override
+ public String toString(QualifiedName name) {
+ // The converted string contains only the last segment of the qualified name
+ if(!name.isEmpty()) {
+ return name.getLastSegment();
+ }
+ return "";
+ }
+
+ @Override
+ public QualifiedName toQualifiedName(String qualifiedNameAsText) {
+ return getQualifiedNameConverter().toQualifiedName(qualifiedNameAsText);
+ }
+ });
+ }
+
}
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/contentassist/IProposalFilter.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/contentassist/IProposalFilter.java
deleted file mode 100644
index ff4a71570..000000000
--- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/contentassist/IProposalFilter.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * CONTRIBUTORS:
- * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.core.ui.contentassist;
-
-import org.eclipse.xtext.resource.IEObjectDescription;
-import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
-
-public interface IProposalFilter {
-
- boolean accept(ContentAssistContext context, IEObjectDescription candidate);
-}
diff --git a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/contentassist/RoomProposalProvider.java b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/contentassist/RoomProposalProvider.java
index da94e11cf..8ef81fe69 100644
--- a/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/contentassist/RoomProposalProvider.java
+++ b/plugins/org.eclipse.etrice.core.room.ui/src/org/eclipse/etrice/core/ui/contentassist/RoomProposalProvider.java
@@ -33,7 +33,6 @@ 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;
@@ -41,16 +40,15 @@ import org.eclipse.etrice.core.ui.util.UIExpressionUtil;
import org.eclipse.etrice.expressions.detailcode.IDetailExpressionProvider;
import org.eclipse.etrice.expressions.ui.contentassist.RoomExpressionProposalProvider;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.viewers.StyledString;
-import org.eclipse.swt.graphics.Image;
import org.eclipse.xtext.Assignment;
import org.eclipse.xtext.Keyword;
+import org.eclipse.xtext.CrossReference;
import org.eclipse.xtext.RuleCall;
import org.eclipse.xtext.resource.IEObjectDescription;
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.common.base.Predicate;
import com.google.common.collect.Lists;
import com.google.inject.Inject;
@@ -58,70 +56,6 @@ import com.google.inject.Inject;
* see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#contentAssist on how to customize content assistant
*/
public class RoomProposalProvider extends AbstractRoomProposalProvider {
-
- protected class FilteredProposalCreator implements Function<IEObjectDescription, ICompletionProposal> {
- private IProposalFilter filter;
- private final ContentAssistContext contentAssistContext;
- private final String ruleName;
-
- protected FilteredProposalCreator(IProposalFilter filter, ContentAssistContext contentAssistContext, String ruleName) {
- this.filter = filter;
- this.contentAssistContext = contentAssistContext;
- this.ruleName = ruleName;
- }
-
- public ICompletionProposal apply(IEObjectDescription candidate) {
- if (candidate == null)
- return null;
- ICompletionProposal result = null;
- String proposal = candidate.getName().toString();
- if (ruleName != null)
- proposal = getValueConverter().toString(proposal, ruleName);
- EObject objectOrProxy = candidate.getEObjectOrProxy();
-
- // three new lines in code taken from org.eclipse.xtext.ui.editor.contentassist.AbstractJavaBasedContentProposalProvider.DefaultProposalCreator
- if (!objectOrProxy.eIsProxy() && filter!=null)
- if (!filter.accept(contentAssistContext, candidate))
- return null;
-
- StyledString displayString = getStyledDisplayString(objectOrProxy, candidate.getQualifiedName().toString(), candidate.getName().toString());
- Image image = getImage(objectOrProxy);
- result = createCompletionProposal(proposal, displayString, image, contentAssistContext);
- getPriorityHelper().adjustCrossReferencePriority(result, contentAssistContext.getPrefix());
- return result;
- }
-
- }
-
- protected class ActorRefFilter implements IProposalFilter {
-
- @Override
- public boolean accept(ContentAssistContext context, IEObjectDescription candidate) {
- if (!(context.getCurrentModel() instanceof ActorRef))
- // unexpected call??
- return false;
-
- ActorRef ar = (ActorRef) context.getCurrentModel();
- if (!(ar.eContainer() instanceof ActorClass))
- // can not filter due to lack of information
- return true;
-
- ActorClass ac = (ActorClass) ar.eContainer();
-
- EObject objectOrProxy = candidate.getEObjectOrProxy();
-
- if (objectOrProxy instanceof ActorClass) {
- ActorClass referenced = (ActorClass) objectOrProxy;
- return !roomHelpers.isReferencing(referenced, ac);
- }
-
- return false;
- }
-
- }
-
- @Inject
- protected RoomGrammarAccess grammar;
@Inject
protected RoomHelpers roomHelpers;
@@ -129,13 +63,8 @@ public class RoomProposalProvider extends AbstractRoomProposalProvider {
@Inject
protected RoomNameProvider roomNameProvider;
- protected Function<IEObjectDescription, ICompletionProposal> getProposalFactory(String ruleName, ContentAssistContext contentAssistContext) {
- if (contentAssistContext!=null && contentAssistContext.getCurrentModel().eClass()==RoomPackage.eINSTANCE.getActorRef())
- return new FilteredProposalCreator(new ActorRefFilter(), contentAssistContext, ruleName);
-
- // delegate to default
- return super.getProposalFactory(ruleName, contentAssistContext);
- }
+ @Inject
+ protected RoomGrammarAccess grammar;
@Override
public void completeKeyword(Keyword keyword, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
@@ -148,6 +77,31 @@ public class RoomProposalProvider extends AbstractRoomProposalProvider {
}
@Override
+ public void completeActorRef_Type(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
+ lookupCrossReference(((CrossReference)assignment.getTerminal()), context, acceptor, new Predicate<IEObjectDescription>() {
+ @Override
+ public boolean apply(IEObjectDescription candidate) {
+ ActorRef ar = (ActorRef) model;
+ if (!(ar.eContainer() instanceof ActorClass)) {
+ // can not filter due to lack of information
+ return true;
+ }
+
+ ActorClass ac = (ActorClass) ar.eContainer();
+
+ EObject objectOrProxy = candidate.getEObjectOrProxy();
+
+ if (objectOrProxy instanceof ActorClass) {
+ ActorClass referenced = (ActorClass) objectOrProxy;
+ return !roomHelpers.isReferencing(referenced, ac);
+ }
+
+ return false;
+ }
+ });
+ }
+
+ @Override
public void completeImport_ImportURI(EObject model, Assignment assignment,
final ContentAssistContext context,
final ICompletionProposalAcceptor acceptor) {

Back to the top