From 645d1565bd38b9d217fc7774a2395f65ab54f877 Mon Sep 17 00:00:00 2001 From: dhubner Date: Wed, 2 Jul 2008 07:30:52 +0000 Subject: [PATCH] patch by michael clay BUG #239192 and other stuff --- .../src/org/eclipse/xtext/GrammarUtil.java | 43 +++++++++++-------- .../eclipse/xtext/resource/XtextResource.java | 1 + 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/plugins/org.eclipse.xtext/src/org/eclipse/xtext/GrammarUtil.java b/plugins/org.eclipse.xtext/src/org/eclipse/xtext/GrammarUtil.java index a2a1a555e..c13b64abc 100644 --- a/plugins/org.eclipse.xtext/src/org/eclipse/xtext/GrammarUtil.java +++ b/plugins/org.eclipse.xtext/src/org/eclipse/xtext/GrammarUtil.java @@ -43,9 +43,9 @@ public class GrammarUtil { } public static String getNamespace(Grammar g) { - return Strings.concat(".", g.getIdElements(), 1); + return Strings.concat(".", g.getIdElements(), 1); } - + public static Grammar getGrammar(EObject grammarElement) { EObject root = getRootContainer(grammarElement); if (root instanceof Grammar) { @@ -85,7 +85,8 @@ public class GrammarUtil { for (AbstractElement ae : g.getAbstractTokens()) { if (ae == _this || eAllContentsAsList(ae).contains(_this)) { return result; - } else { + } + else { result.add(ae); } } @@ -120,30 +121,30 @@ public class GrammarUtil { } public static Grammar getSuperGrammar(Grammar _this) { - if(IXtextBuiltin.ID.equals(getLanguageId(_this))) { - return null; - } + if (IXtextBuiltin.ID.equals(getLanguageId(_this))) { + return null; + } String id = getSuperGrammarId(_this); if (id == null) { id = IXtextBuiltin.ID; } ILanguageDescriptor descriptor = LanguageDescriptorFactory.get(id); if (descriptor == null) - throw new IllegalStateException("Language '"+id+"' has not been set up properly"); + throw new IllegalStateException("Language '" + id + "' has not been set up properly"); IGrammarAccess service = ServiceRegistry.getService(descriptor, IGrammarAccess.class); if (service == null) - throw new IllegalStateException("Language '"+id+"' has not been set up properly"); + throw new IllegalStateException("Language '" + id + "' has not been set up properly"); Grammar superGrammar = service.getGrammar(); return superGrammar == _this ? null : superGrammar; } - + public static String getSuperGrammarId(Grammar _this) { if (_this.getSuperGrammarIdElements().isEmpty()) return null; StringBuffer buff = new StringBuffer(); - for (int i = 0, x = _this.getSuperGrammarIdElements().size(); i kws = new HashSet(); List rules = allParserRules(g); for (ParserRule parserRule : rules) { - List list = typeSelect(eAllContentsAsList(parserRule),Keyword.class); + List list = typeSelect(eAllContentsAsList(parserRule), Keyword.class); for (Keyword keyword : list) { kws.add(keyword.getValue()); } } return kws; } - + public static boolean isOptionalCardinality(AbstractElement e) { - return e.getCardinality()!=null && (e.getCardinality().equals("?") || e.getCardinality().equals("*")); + return e.getCardinality() != null && (e.getCardinality().equals("?") || e.getCardinality().equals("*")); } - + public static boolean isMultipleCardinality(AbstractElement e) { - return e.getCardinality()!=null && (e.getCardinality().equals("+") || e.getCardinality().equals("*")); + return isOneOrMoreCardinality(e) || isAnyCardinality(e); + } + + public static boolean isOneOrMoreCardinality(AbstractElement e) { + return e.getCardinality() != null && (e.getCardinality().equals("+")); + } + + public static boolean isAnyCardinality(AbstractElement e) { + return e.getCardinality() != null && (e.getCardinality().equals("*")); } - - } diff --git a/plugins/org.eclipse.xtext/src/org/eclipse/xtext/resource/XtextResource.java b/plugins/org.eclipse.xtext/src/org/eclipse/xtext/resource/XtextResource.java index 1bc6b6a25..72398398d 100644 --- a/plugins/org.eclipse.xtext/src/org/eclipse/xtext/resource/XtextResource.java +++ b/plugins/org.eclipse.xtext/src/org/eclipse/xtext/resource/XtextResource.java @@ -53,6 +53,7 @@ public class XtextResource extends ResourceImpl { } public void update(int offset, int length, String change) { + parser.reparse(parse.getRootNode(), offset, length, change); }