summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormclay2009-01-04 14:11:54 (EST)
committer sefftinge2009-01-04 14:11:54 (EST)
commitfa681765c18b3db09bf5a3afac97e7aa8f9e641c (patch)
tree449bbfc7fcc19311940bc754975d6db365ea573b
parent3cf09f953bbb78fc428b66b9d9b230b55e58e8d6 (diff)
downloadorg.eclipse.xtext-fa681765c18b3db09bf5a3afac97e7aa8f9e641c.zip
org.eclipse.xtext-fa681765c18b3db09bf5a3afac97e7aa8f9e641c.tar.gz
org.eclipse.xtext-fa681765c18b3db09bf5a3afac97e7aa8f9e641c.tar.bz2
fix: some bugfixes and tests
-rw-r--r--plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistCalculator.java22
-rw-r--r--plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/OpenDeclarationAction.java12
-rw-r--r--tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessorTest.java7
3 files changed, 37 insertions, 4 deletions
diff --git a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistCalculator.java b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistCalculator.java
index faa1d09..e8b77c4 100644
--- a/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistCalculator.java
+++ b/plugins/org.eclipse.xtext.ui.common/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistCalculator.java
@@ -15,6 +15,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.xtext.AbstractElement;
@@ -121,7 +122,7 @@ public class DefaultContentAssistCalculator extends XtextSwitch<List<AbstractEle
&& includeNext;) {
AbstractElement groupElement = iterator.next();
addWithNullCheck(elementList, doSwitch(groupElement));
- includeNext = GrammarUtil.isOptionalCardinality(groupElement);
+ includeNext = isOptional(groupElement);
}
return elementList;
}
@@ -190,6 +191,25 @@ public class DefaultContentAssistCalculator extends XtextSwitch<List<AbstractEle
return !linkCandidates.isEmpty() && referencedObjects.containsAll(linkCandidates);
}
}
+
+ private boolean isOptional(AbstractElement groupElement) {
+ boolean isOptional = true;
+
+ if ((groupElement instanceof Group || groupElement instanceof Alternatives) && !GrammarUtil.isOptionalCardinality(groupElement)) {
+
+ EList<AbstractElement> abstractTokens = groupElement instanceof Group ? ((Group) groupElement)
+ .getAbstractTokens() : ((Alternatives) groupElement).getGroups();
+
+ for (Iterator<AbstractElement> iterator = abstractTokens.iterator(); isOptional && iterator.hasNext();) {
+ AbstractElement abstractElement = iterator.next();
+ isOptional = isOptional(abstractElement);
+ }
+
+ } else {
+ isOptional = GrammarUtil.isOptionalCardinality(groupElement);
+ }
+ return isOptional;
+ }
}
diff --git a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/OpenDeclarationAction.java b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/OpenDeclarationAction.java
index a105d28..e9e54a2 100644
--- a/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/OpenDeclarationAction.java
+++ b/plugins/org.eclipse.xtext.ui.core/src/org/eclipse/xtext/ui/core/editor/OpenDeclarationAction.java
@@ -11,6 +11,7 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IEditorPart;
@@ -90,9 +91,12 @@ public class OpenDeclarationAction extends Action {
if (!linkedObjects.isEmpty()) {
EObject referenceEObject = linkedObjects.iterator().next();
-
- IFile targetFile = ResourcesPlugin.getWorkspace().getRoot().getFile(
- new Path(referenceEObject.eResource().getURI().toPlatformString(true)));
+
+ IFile targetFile = referenceEObject.eResource().getURI().isPlatformResource() ?
+ ResourcesPlugin.getWorkspace().getRoot().getFile(
+ new Path(referenceEObject.eResource().getURI().toPlatformString(true)))
+ : ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(
+ new Path(referenceEObject.eResource().getURI().toFileString()));
if (targetFile != null) {
@@ -106,6 +110,8 @@ public class OpenDeclarationAction extends Action {
NodeAdapter nodeAdapter = NodeUtil.getNodeAdapter(referenceEObject);
((ITextEditor) openEditor).selectAndReveal(nodeAdapter.getParserNode().getOffset(),
nodeAdapter.getParserNode().getLength());
+ } else if (openEditor instanceof ISelectionProvider) {
+ //TODO: use ISelectionProvider instead of ITextEditor
}
}
catch (PartInitException partInitException) {
diff --git a/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessorTest.java b/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessorTest.java
index 0d93d0b..bc0a386 100644
--- a/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessorTest.java
+++ b/tests/org.eclipse.xtext.ui.common.tests/src/org/eclipse/xtext/ui/common/editor/contentassist/impl/DefaultContentAssistProcessorTest.java
@@ -127,6 +127,13 @@ public class DefaultContentAssistProcessorTest extends AbstractUiTest
);
}
+
+ public void testDefaultRule() throws Exception {
+ contentAssistProcessorTestBuilder.assertText("spielplatz");
+ contentAssistProcessorTestBuilder.set(" spielplatz 1 \"SpielplatzBeschreibung\" { } ")
+ .assertTextAtCursorPosition(1, "spielplatz");;
+ }
+
private ContentAssistProcessorTestBuilder newBuilder(Class<?> standAloneSetup, Class<?> uiConfig) throws Exception {
withUi(standAloneSetup, uiConfig);
return new ContentAssistProcessorTestBuilder(getCurrentServiceScope(), new DefaultContentAssistProcessor());