mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 00:38:56 +00:00
removed dependency to oaw (replaced by M2T/Xpand)
This commit is contained in:
parent
69c9125d66
commit
004cb13416
12 changed files with 263 additions and 375 deletions
|
@ -15,7 +15,6 @@ Export-Package: org.eclipse.xtext,
|
|||
org.eclipse.xtext.crossref,
|
||||
org.eclipse.xtext.crossref.impl,
|
||||
org.eclipse.xtext.crossref.internal,
|
||||
org.eclipse.xtext.junit,
|
||||
org.eclipse.xtext.parser,
|
||||
org.eclipse.xtext.parser.antlr,
|
||||
org.eclipse.xtext.parser.impl,
|
||||
|
@ -33,9 +32,8 @@ Export-Package: org.eclipse.xtext,
|
|||
Require-Bundle: org.eclipse.xtext.log4j;bundle-version="1.2.15",
|
||||
org.eclipse.emf.ecore;visibility:=reexport,
|
||||
org.antlr;visibility:=reexport,
|
||||
org.openarchitectureware.util.stdlib,
|
||||
org.eclipse.emf.ecore.xmi;bundle-version="2.3.2";visibility:=reexport,
|
||||
org.eclipse.xtext.service;bundle-version="1.0.0";visibility:=reexport,
|
||||
org.eclipse.xtext.util;bundle-version="1.0.0",
|
||||
org.junit;resolution:=optional,
|
||||
org.openarchitectureware.dependencies;bundle-version="4.3.0";resolution:=optional
|
||||
org.eclipse.xtend.util.stdlib;bundle-version="0.7.0"
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
import ecore;
|
||||
import xtext;
|
||||
|
||||
extension org::openarchitectureware::util::stdlib::io;
|
||||
extension org::eclipse::xtext::GrammarUtil reexport;
|
||||
|
||||
// ***********************************************************************************
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
extension org::openarchitectureware::util::stdlib::io;
|
||||
// *************************
|
||||
// generic utilities
|
||||
|
||||
subList(List this, Object start, Object end) :
|
||||
let s = (contains(start) ? indexOf(start) : 0) :
|
||||
let e = (contains(end) ? indexOf(end) : this.size) :
|
||||
select(x|let ix = indexOf(x) : info(ix)>=info(s) && ix<=info(e));
|
||||
select(x|let ix = indexOf(x) : ix>=s && ix<=e);
|
|
@ -36,9 +36,6 @@ context GeneratedMetamodel ERROR "Only one generated metamodel can have default
|
|||
context GeneratedMetamodel ERROR "Duplicate aliases are only allowed for referenced metamodels" :
|
||||
grammar().metamodelDeclarations.typeSelect(GeneratedMetamodel).select(gmm|gmm.alias == alias).size == 1;
|
||||
|
||||
context Group ERROR "Group cannot contain more than one action" :
|
||||
eAllContents.typeSelect(Action).size <= 1;
|
||||
|
||||
context AbstractRule ERROR "Name must be unique" :
|
||||
grammar().rules.select(p | p.name == name).size==1;
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import ecore;
|
|||
import xtext;
|
||||
import xtextutil;
|
||||
|
||||
extension org::openarchitectureware::util::stdlib::io;
|
||||
extension org::eclipse::xtend::util::stdlib::io;
|
||||
extension org::eclipse::xtext::Extensions;
|
||||
|
||||
cached List[MetaModel] getAllMetaModels(Grammar this) :
|
||||
|
|
|
@ -1,105 +0,0 @@
|
|||
package org.eclipse.xtext.junit;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
||||
import org.eclipse.m2t.type.emf.EmfRegistryMetaModel;
|
||||
import org.eclipse.xtext.parser.IParseResult;
|
||||
import org.eclipse.xtext.parser.IParser;
|
||||
import org.eclipse.xtext.service.IServiceScope;
|
||||
import org.eclipse.xtext.service.Inject;
|
||||
import org.eclipse.xtext.service.ServiceRegistry;
|
||||
import org.eclipse.xtext.util.StringInputStream;
|
||||
import org.openarchitectureware.expression.ExecutionContextImpl;
|
||||
import org.openarchitectureware.xtend.XtendFacade;
|
||||
|
||||
public abstract class AbstractXtextTests extends TestCase {
|
||||
|
||||
public AbstractXtextTests() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AbstractXtextTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Inject
|
||||
private IParser parser;
|
||||
public IParser getParser() {
|
||||
return parser;
|
||||
}
|
||||
|
||||
protected void setCurrentLanguage(IServiceScope desc) {
|
||||
ServiceRegistry.injectServices(desc, this);
|
||||
}
|
||||
|
||||
public EObject loadModel(URI uri, String model) throws Exception {
|
||||
ResourceSet rs = new ResourceSetImpl();
|
||||
Resource resource = rs.createResource(uri);
|
||||
resource.load(new StringInputStream(model), null);
|
||||
if (resource.getContents().isEmpty())
|
||||
return null;
|
||||
return resource.getContents().iterator().next();
|
||||
}
|
||||
|
||||
public IParseResult parse(InputStream model) throws Exception {
|
||||
return getParser().parse(model);
|
||||
}
|
||||
|
||||
public IParseResult parse(String model) throws Exception {
|
||||
return getParser().parse(new StringInputStream(model));
|
||||
}
|
||||
|
||||
// Xtend helper methods
|
||||
|
||||
protected void assertWithXtend(String left, String right, Object _this) {
|
||||
assertWithXtend(left + " != " + right, left, right, _this);
|
||||
}
|
||||
|
||||
protected Object invokeWithXtend(String expression, Object _this) {
|
||||
XtendFacade f = getXtendFacade();
|
||||
f = f.cloneWithExtensions(getImportDeclarations()+"invoke(Object this) : " + expression + ";");
|
||||
return f.call("invoke", _this);
|
||||
}
|
||||
|
||||
protected String[] importedExtensions() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
protected void assertWithXtend(String message, String left, String right, Object _this) {
|
||||
XtendFacade f = getXtendFacade();
|
||||
StringBuffer code = getImportDeclarations();
|
||||
code.append("__compare(Object this) : __left(this) == __right(this);__left(Object this) : " + left
|
||||
+ "; __right(Object this) :" + right + ";");
|
||||
f = f.cloneWithExtensions(code.toString());
|
||||
Boolean result = (Boolean) f.call("__compare", _this);
|
||||
if (!result) {
|
||||
Object leftResult = f.call("__left", _this);
|
||||
Object rightResult = f.call("__right", _this);
|
||||
fail(message + " was : " + leftResult + "("
|
||||
+ (leftResult != null ? leftResult.getClass().getSimpleName() : "") + ") != " + rightResult + "("
|
||||
+ (leftResult != null ? leftResult.getClass().getSimpleName() : "") + ")");
|
||||
}
|
||||
}
|
||||
|
||||
private StringBuffer getImportDeclarations() {
|
||||
StringBuffer code = new StringBuffer();
|
||||
for (String _import : importedExtensions()) {
|
||||
code.append("extension ").append(_import).append(";");
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
protected XtendFacade getXtendFacade() {
|
||||
ExecutionContextImpl ctx = new ExecutionContextImpl();
|
||||
ctx.registerMetaModel(new EmfRegistryMetaModel());
|
||||
return XtendFacade.create(ctx);
|
||||
}
|
||||
|
||||
}
|
|
@ -11,7 +11,6 @@ package org.eclipse.xtext.parsetree;
|
|||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.util.EcoreUtil;
|
||||
import org.eclipse.xtext.AbstractElement;
|
||||
|
@ -34,287 +33,292 @@ import org.eclipse.xtext.RuleCall;
|
|||
*/
|
||||
public final class ParseTreeUtil {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param abstractNode
|
||||
* the node to inspect
|
||||
* @param grammarElementClass
|
||||
* to match
|
||||
* @return a set of abstractNode associated with a grammarelement class
|
||||
* matching the given class
|
||||
*/
|
||||
public static Set<AbstractNode> getNodesByGrammarElement(AbstractNode abstractNode, Class<?> grammarElementClass) {
|
||||
/**
|
||||
*
|
||||
* @param abstractNode
|
||||
* the node to inspect
|
||||
* @param grammarElementClass
|
||||
* to match
|
||||
* @return a set of abstractNode associated with a grammarelement class
|
||||
* matching the given class
|
||||
*/
|
||||
public static Set<AbstractNode> getNodesByGrammarElement(AbstractNode abstractNode, Class<?> grammarElementClass) {
|
||||
|
||||
assertParameterNotNull(abstractNode, "abstractNode");
|
||||
assertParameterNotNull(grammarElementClass, "grammarElementClass");
|
||||
assertParameterNotNull(abstractNode, "abstractNode");
|
||||
assertParameterNotNull(grammarElementClass, "grammarElementClass");
|
||||
|
||||
Set<AbstractNode> abstractNodeSet = new LinkedHashSet<AbstractNode>();
|
||||
Set<AbstractNode> abstractNodeSet = new LinkedHashSet<AbstractNode>();
|
||||
|
||||
if (abstractNode.getGrammarElement() != null
|
||||
&& grammarElementClass.isAssignableFrom(abstractNode.getGrammarElement().getClass())) {
|
||||
abstractNodeSet.add(abstractNode);
|
||||
}
|
||||
if (abstractNode.getGrammarElement() != null
|
||||
&& grammarElementClass.isAssignableFrom(abstractNode.getGrammarElement().getClass())) {
|
||||
abstractNodeSet.add(abstractNode);
|
||||
}
|
||||
|
||||
for (AbstractNode leafNode : abstractNode.getLeafNodes()) {
|
||||
abstractNodeSet.addAll(getNodesByGrammarElement(leafNode, grammarElementClass));
|
||||
}
|
||||
for (AbstractNode leafNode : abstractNode.getLeafNodes()) {
|
||||
abstractNodeSet.addAll(getNodesByGrammarElement(leafNode, grammarElementClass));
|
||||
}
|
||||
|
||||
return abstractNodeSet;
|
||||
}
|
||||
return abstractNodeSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump the composite structure (parsetree) of the given node.
|
||||
*
|
||||
* @param abstractNode
|
||||
* the node to dump
|
||||
*/
|
||||
public static final void dumpNode(AbstractNode abstractNode) {
|
||||
assertParameterNotNull(abstractNode, "abstractNode");
|
||||
System.out.println("dump parsetree with root node '" + EcoreUtil.getIdentification(abstractNode) + "'");
|
||||
doDumpNode(abstractNode, "\t");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param contextNode
|
||||
* the node representing the 'scope' of the current lookup
|
||||
* @param offsetPosition
|
||||
* the text position within the the current sentence
|
||||
* @return the last 'complete' (an associated grammar element is available) node element contained within the given contextNode at
|
||||
* the provided position
|
||||
*/
|
||||
public static final AbstractNode getLastCompleteNodeByOffset(AbstractNode contextNode, int offsetPosition) {
|
||||
/**
|
||||
* Dump the composite structure (parsetree) of the given node.
|
||||
*
|
||||
* @param abstractNode
|
||||
* the node to dump
|
||||
*/
|
||||
public static final void dumpNode(AbstractNode abstractNode) {
|
||||
assertParameterNotNull(abstractNode, "abstractNode");
|
||||
System.out.println("dump parsetree with root node '" + EcoreUtil.getIdentification(abstractNode) + "'");
|
||||
doDumpNode(abstractNode, "\t");
|
||||
}
|
||||
|
||||
assertParameterNotNull(contextNode, "contextNode");
|
||||
/**
|
||||
* @param contextNode
|
||||
* the node representing the 'scope' of the current lookup
|
||||
* @param offsetPosition
|
||||
* the text position within the the current sentence
|
||||
* @return the last 'complete' (an associated grammar element is available)
|
||||
* node element contained within the given contextNode at the
|
||||
* provided position
|
||||
*/
|
||||
public static final AbstractNode getLastCompleteNodeByOffset(AbstractNode contextNode, int offsetPosition) {
|
||||
|
||||
AbstractNode abstractNode = null;
|
||||
assertParameterNotNull(contextNode, "contextNode");
|
||||
|
||||
if (contextNode.getOffset() < offsetPosition ||
|
||||
(0==offsetPosition && offsetPosition==contextNode.getOffset())) {
|
||||
AbstractNode abstractNode = null;
|
||||
|
||||
if (contextNode.getGrammarElement() instanceof AbstractElement
|
||||
|| contextNode.getGrammarElement() instanceof ParserRule) {
|
||||
if (contextNode.getOffset() < offsetPosition
|
||||
|| (0 == offsetPosition && offsetPosition == contextNode.getOffset())) {
|
||||
|
||||
abstractNode = contextNode;
|
||||
}
|
||||
for (AbstractNode childNode : contextNode.getLeafNodes()) {
|
||||
if (contextNode.getGrammarElement() instanceof AbstractElement
|
||||
|| contextNode.getGrammarElement() instanceof ParserRule) {
|
||||
|
||||
AbstractNode lastElementByOffset = getLastCompleteNodeByOffset(childNode, offsetPosition);
|
||||
abstractNode = contextNode;
|
||||
}
|
||||
for (AbstractNode childNode : contextNode.getLeafNodes()) {
|
||||
|
||||
if (lastElementByOffset != null) {
|
||||
abstractNode = lastElementByOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
AbstractNode lastElementByOffset = getLastCompleteNodeByOffset(childNode, offsetPosition);
|
||||
|
||||
return abstractNode;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param contextNode
|
||||
* the node representing the 'scope' of the current lookup
|
||||
* @param offsetPosition
|
||||
* the text position within the the current sentence
|
||||
|
||||
* @return the last node element at the provided position
|
||||
*/
|
||||
public static final LeafNode getCurrentNodeByOffset(AbstractNode contextNode, int offsetPosition) {
|
||||
if (lastElementByOffset != null) {
|
||||
abstractNode = lastElementByOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertParameterNotNull(contextNode, "contextNode");
|
||||
return abstractNode;
|
||||
}
|
||||
|
||||
LeafNode leafNode = null;
|
||||
/**
|
||||
*
|
||||
* @param contextNode
|
||||
* the node representing the 'scope' of the current lookup
|
||||
* @param offsetPosition
|
||||
* the text position within the the current sentence
|
||||
*
|
||||
* @return the last node element at the provided position
|
||||
*/
|
||||
public static final LeafNode getCurrentNodeByOffset(AbstractNode contextNode, int offsetPosition) {
|
||||
|
||||
for (AbstractNode childNode : contextNode.getLeafNodes()) {
|
||||
assertParameterNotNull(contextNode, "contextNode");
|
||||
|
||||
if (childNode.getOffset() + childNode.getLength() <= offsetPosition) {
|
||||
leafNode = (LeafNode) childNode;
|
||||
}
|
||||
}
|
||||
LeafNode leafNode = null;
|
||||
|
||||
return leafNode;
|
||||
}
|
||||
for (AbstractNode childNode : contextNode.getLeafNodes()) {
|
||||
|
||||
/**
|
||||
*
|
||||
* This method returns the parent grammar of the given eObject by recursive
|
||||
* 'upwards' invocations, passing the eContainer property as parameter until
|
||||
* some Grammar level object is reached.
|
||||
*
|
||||
* @param eObject
|
||||
* an object contained or referenced within some 'root' grammar
|
||||
* @return the {@link org.eclipse.xtext.Grammar} of the given object.
|
||||
*/
|
||||
public static final Grammar getGrammar(EObject eObject) {
|
||||
assertParameterNotNull(eObject, "eObject");
|
||||
if (childNode.getOffset() + childNode.getLength() <= offsetPosition) {
|
||||
leafNode = (LeafNode) childNode;
|
||||
}
|
||||
}
|
||||
|
||||
if (eObject instanceof Grammar) {
|
||||
return (Grammar) eObject;
|
||||
}
|
||||
else {
|
||||
return getGrammar(eObject.eContainer());
|
||||
}
|
||||
return leafNode;
|
||||
}
|
||||
|
||||
}
|
||||
//
|
||||
// /**
|
||||
// *
|
||||
// * Returns a list of all assignment to the given rule.
|
||||
// *
|
||||
// * @param parserRule
|
||||
// * the rule of the assignments (ruleCall) to match
|
||||
// * @return a list containing all {@see org.eclipse.xtext.Assignment} to the
|
||||
// * given rule.
|
||||
// */
|
||||
// public static final List<AbstractElement> getParserRuleAssignments(ParserRule parserRule) {
|
||||
// assertParameterNotNull(parserRule, "parserRule");
|
||||
// List<AbstractElement> list = new ArrayList<AbstractElement>();
|
||||
// Grammar grammar = (Grammar) parserRule.eContainer();
|
||||
// // filter and search
|
||||
// for (ParserRule rule : GrammarUtil.allParserRules(grammar)) {
|
||||
// // excluded?
|
||||
// if (!parserRule.equals(rule)) {
|
||||
// Assignment ruleAssignment = getParserRuleAssignment(rule.getAlternatives(), parserRule);
|
||||
// if (ruleAssignment != null) {
|
||||
// list.add(ruleAssignment);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return list;
|
||||
// }
|
||||
/**
|
||||
*
|
||||
* This method returns the parent grammar of the given eObject by recursive
|
||||
* 'upwards' invocations, passing the eContainer property as parameter until
|
||||
* some Grammar level object is reached.
|
||||
*
|
||||
* @param eObject
|
||||
* an object contained or referenced within some 'root' grammar
|
||||
* @return the {@link org.eclipse.xtext.Grammar} of the given object.
|
||||
*/
|
||||
public static final Grammar getGrammar(EObject eObject) {
|
||||
assertParameterNotNull(eObject, "eObject");
|
||||
|
||||
/**
|
||||
* asserts if the given parameter object isnt null
|
||||
*
|
||||
* @param parameter
|
||||
* reference to assert
|
||||
* @param parameterName
|
||||
* the name of the parameter
|
||||
*/
|
||||
public static final void assertParameterNotNull(Object parameter, String parameterName) {
|
||||
Assert.isLegal(parameter != null, "parameter '" + parameterName + "' must not be null.");
|
||||
}
|
||||
if (eObject instanceof Grammar) {
|
||||
return (Grammar) eObject;
|
||||
} else {
|
||||
return getGrammar(eObject.eContainer());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param abstractNode
|
||||
* the node of the asociated grammar element
|
||||
*
|
||||
* @return the grammar element of the given node or null if its neither a
|
||||
* abstractElement or a parserRule
|
||||
*/
|
||||
public static final AbstractElement getGrammarElementFromNode(AbstractNode abstractNode) {
|
||||
}
|
||||
|
||||
assertParameterNotNull(abstractNode, "abstractNode");
|
||||
//
|
||||
// /**
|
||||
// *
|
||||
// * Returns a list of all assignment to the given rule.
|
||||
// *
|
||||
// * @param parserRule
|
||||
// * the rule of the assignments (ruleCall) to match
|
||||
// * @return a list containing all {@see org.eclipse.xtext.Assignment} to
|
||||
// the
|
||||
// * given rule.
|
||||
// */
|
||||
// public static final List<AbstractElement>
|
||||
// getParserRuleAssignments(ParserRule parserRule) {
|
||||
// assertParameterNotNull(parserRule, "parserRule");
|
||||
// List<AbstractElement> list = new ArrayList<AbstractElement>();
|
||||
// Grammar grammar = (Grammar) parserRule.eContainer();
|
||||
// // filter and search
|
||||
// for (ParserRule rule : GrammarUtil.allParserRules(grammar)) {
|
||||
// // excluded?
|
||||
// if (!parserRule.equals(rule)) {
|
||||
// Assignment ruleAssignment =
|
||||
// getParserRuleAssignment(rule.getAlternatives(), parserRule);
|
||||
// if (ruleAssignment != null) {
|
||||
// list.add(ruleAssignment);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return list;
|
||||
// }
|
||||
|
||||
AbstractElement abstractElement = null;
|
||||
/**
|
||||
* asserts if the given parameter object isnt null
|
||||
*
|
||||
* @param parameter
|
||||
* reference to assert
|
||||
* @param parameterName
|
||||
* the name of the parameter
|
||||
*/
|
||||
public static final void assertParameterNotNull(Object parameter, String parameterName) {
|
||||
if (parameter == null)
|
||||
throw new IllegalArgumentException("parameter '" + parameterName + "' must not be null.");
|
||||
}
|
||||
|
||||
if (abstractNode.getGrammarElement() instanceof AbstractElement) {
|
||||
abstractElement = (AbstractElement) abstractNode.getGrammarElement();
|
||||
}
|
||||
else if (abstractNode.getGrammarElement() instanceof ParserRule) {
|
||||
abstractElement = ((ParserRule) abstractNode.getGrammarElement()).getAlternatives();
|
||||
/**
|
||||
*
|
||||
* @param abstractNode
|
||||
* the node of the asociated grammar element
|
||||
*
|
||||
* @return the grammar element of the given node or null if its neither a
|
||||
* abstractElement or a parserRule
|
||||
*/
|
||||
public static final AbstractElement getGrammarElementFromNode(AbstractNode abstractNode) {
|
||||
|
||||
}
|
||||
return abstractElement;
|
||||
}
|
||||
assertParameterNotNull(abstractNode, "abstractNode");
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @param contextElement
|
||||
// * element searched for assignments to the given rule
|
||||
// * @param parserRule
|
||||
// * the rule of the assignments to search for
|
||||
// * @return an assignment object containing a rulecall to the given
|
||||
// * parserRule or null if not found.
|
||||
// */
|
||||
// private static final Assignment getParserRuleAssignment(AbstractElement contextElement, ParserRule parserRule) {
|
||||
//
|
||||
// assertParameterNotNull(contextElement, "contextElement");
|
||||
// assertParameterNotNull(parserRule, "parserRule");
|
||||
//
|
||||
// Assignment assignment = null;
|
||||
// if (contextElement instanceof Group) {
|
||||
// Group group = (Group) contextElement;
|
||||
// for (AbstractElement groupElement : group.getAbstractTokens()) {
|
||||
// assignment = getParserRuleAssignment(groupElement, parserRule);
|
||||
// if (null != assignment) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else if (contextElement instanceof Alternatives) {
|
||||
// Alternatives alternatives = (Alternatives) contextElement;
|
||||
// for (AbstractElement groupElement : alternatives.getGroups()) {
|
||||
// assignment = getParserRuleAssignment(groupElement, parserRule);
|
||||
// if (null != assignment) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else if (contextElement instanceof Assignment) {
|
||||
// Assignment assignmentToMatch = (Assignment) contextElement;
|
||||
// if (assignmentToMatch.getTerminal() instanceof RuleCall
|
||||
// && ((RuleCall) assignmentToMatch.getTerminal()).getName().equalsIgnoreCase(parserRule.getName())) {
|
||||
// assignment = assignmentToMatch;
|
||||
// }
|
||||
// }
|
||||
// return assignment;
|
||||
// }
|
||||
AbstractElement abstractElement = null;
|
||||
|
||||
/**
|
||||
* @param abstractNode
|
||||
* @param indentString
|
||||
*/
|
||||
private static final void doDumpNode(AbstractNode abstractNode, String indentString) {
|
||||
if (abstractNode.getGrammarElement() instanceof AbstractElement) {
|
||||
abstractElement = (AbstractElement) abstractNode.getGrammarElement();
|
||||
} else if (abstractNode.getGrammarElement() instanceof ParserRule) {
|
||||
abstractElement = ((ParserRule) abstractNode.getGrammarElement()).getAlternatives();
|
||||
|
||||
if (abstractNode instanceof CompositeNode) {
|
||||
}
|
||||
return abstractElement;
|
||||
}
|
||||
|
||||
// CompositeNode compositeNode = (CompositeNode) abstractNode;
|
||||
// /**
|
||||
// *
|
||||
// * @param contextElement
|
||||
// * element searched for assignments to the given rule
|
||||
// * @param parserRule
|
||||
// * the rule of the assignments to search for
|
||||
// * @return an assignment object containing a rulecall to the given
|
||||
// * parserRule or null if not found.
|
||||
// */
|
||||
// private static final Assignment getParserRuleAssignment(AbstractElement
|
||||
// contextElement, ParserRule parserRule) {
|
||||
//
|
||||
// assertParameterNotNull(contextElement, "contextElement");
|
||||
// assertParameterNotNull(parserRule, "parserRule");
|
||||
//
|
||||
// Assignment assignment = null;
|
||||
// if (contextElement instanceof Group) {
|
||||
// Group group = (Group) contextElement;
|
||||
// for (AbstractElement groupElement : group.getAbstractTokens()) {
|
||||
// assignment = getParserRuleAssignment(groupElement, parserRule);
|
||||
// if (null != assignment) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else if (contextElement instanceof Alternatives) {
|
||||
// Alternatives alternatives = (Alternatives) contextElement;
|
||||
// for (AbstractElement groupElement : alternatives.getGroups()) {
|
||||
// assignment = getParserRuleAssignment(groupElement, parserRule);
|
||||
// if (null != assignment) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else if (contextElement instanceof Assignment) {
|
||||
// Assignment assignmentToMatch = (Assignment) contextElement;
|
||||
// if (assignmentToMatch.getTerminal() instanceof RuleCall
|
||||
// && ((RuleCall)
|
||||
// assignmentToMatch.getTerminal()).getName().equalsIgnoreCase
|
||||
// (parserRule.getName())) {
|
||||
// assignment = assignmentToMatch;
|
||||
// }
|
||||
// }
|
||||
// return assignment;
|
||||
// }
|
||||
|
||||
System.out.println(indentString + "line '" + abstractNode.getLine() + "' offset '" + abstractNode.getOffset()
|
||||
+ "' length '" + abstractNode.getLength() + "' grammar-hierarchy ("
|
||||
+ dumpParentHierarchy(abstractNode) + ")");
|
||||
/**
|
||||
* @param abstractNode
|
||||
* @param indentString
|
||||
*/
|
||||
private static final void doDumpNode(AbstractNode abstractNode, String indentString) {
|
||||
|
||||
}
|
||||
else if (abstractNode instanceof LeafNode) {
|
||||
if (abstractNode instanceof CompositeNode) {
|
||||
|
||||
LeafNode leafNode = (LeafNode) abstractNode;
|
||||
// ommit hidden channel
|
||||
if (!leafNode.isHidden()) {
|
||||
// CompositeNode compositeNode = (CompositeNode) abstractNode;
|
||||
|
||||
System.out.println(indentString + "'" + "line '" + leafNode.getLine() + "' offset '" + leafNode.getOffset()
|
||||
+ " length '" + leafNode.getLength() + "' "
|
||||
+ (leafNode.getFeature() != null ? leafNode.getFeature() + " = " : "") + " text '"
|
||||
+ leafNode.getText() + "' grammar-hierarchy (" + dumpParentHierarchy(leafNode) + ")");
|
||||
System.out.println(indentString + "line '" + abstractNode.getLine() + "' offset '"
|
||||
+ abstractNode.getOffset() + "' length '" + abstractNode.getLength() + "' grammar-hierarchy ("
|
||||
+ dumpParentHierarchy(abstractNode) + ")");
|
||||
|
||||
}
|
||||
} else if (abstractNode instanceof LeafNode) {
|
||||
|
||||
}
|
||||
LeafNode leafNode = (LeafNode) abstractNode;
|
||||
// ommit hidden channel
|
||||
if (!leafNode.isHidden()) {
|
||||
|
||||
for (AbstractNode childNode : abstractNode.getLeafNodes()) {
|
||||
doDumpNode(childNode, indentString + indentString);
|
||||
}
|
||||
System.out.println(indentString + "'" + "line '" + leafNode.getLine() + "' offset '"
|
||||
+ leafNode.getOffset() + " length '" + leafNode.getLength() + "' "
|
||||
+ (leafNode.getFeature() != null ? leafNode.getFeature() + " = " : "") + " text '"
|
||||
+ leafNode.getText() + "' grammar-hierarchy (" + dumpParentHierarchy(leafNode) + ")");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static final String dumpParentHierarchy(AbstractNode abstractNode) {
|
||||
}
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
while (null != abstractNode) {
|
||||
stringBuilder.append(abstractNode.getGrammarElement().getClass().getSimpleName());
|
||||
if (abstractNode.getGrammarElement() instanceof ParserRule) {
|
||||
stringBuilder.append("[" + ((ParserRule) abstractNode.getGrammarElement()).getName() + "]");
|
||||
}
|
||||
else if (abstractNode.getGrammarElement() instanceof RuleCall) {
|
||||
stringBuilder.append("[" + ((RuleCall) abstractNode.getGrammarElement()).getName() + "]");
|
||||
for (AbstractNode childNode : abstractNode.getLeafNodes()) {
|
||||
doDumpNode(childNode, indentString + indentString);
|
||||
}
|
||||
|
||||
}
|
||||
abstractNode = abstractNode.getParent();
|
||||
if (null != abstractNode) {
|
||||
stringBuilder.append("->");
|
||||
}
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private static final String dumpParentHierarchy(AbstractNode abstractNode) {
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
while (null != abstractNode) {
|
||||
stringBuilder.append(abstractNode.getGrammarElement().getClass().getSimpleName());
|
||||
if (abstractNode.getGrammarElement() instanceof ParserRule) {
|
||||
stringBuilder.append("[" + ((ParserRule) abstractNode.getGrammarElement()).getName() + "]");
|
||||
} else if (abstractNode.getGrammarElement() instanceof RuleCall) {
|
||||
stringBuilder.append("[" + ((RuleCall) abstractNode.getGrammarElement()).getName() + "]");
|
||||
|
||||
}
|
||||
abstractNode = abstractNode.getParent();
|
||||
if (null != abstractNode) {
|
||||
stringBuilder.append("->");
|
||||
}
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -16,8 +16,6 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.eclipse.emf.common.util.TreeIterator;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
|
@ -60,8 +58,6 @@ public class XtextResource extends ResourceImpl {
|
|||
@Inject
|
||||
private IValueConverterService valueConverterService;
|
||||
|
||||
private Log log = LogFactory.getLog(getClass());
|
||||
|
||||
private IParseResult parseResult;
|
||||
|
||||
public XtextResource(URI uri) {
|
||||
|
@ -136,8 +132,8 @@ public class XtextResource extends ResourceImpl {
|
|||
if (fragment != null) {
|
||||
if (map.put(fragment, object) != null) {
|
||||
map.remove(fragment);
|
||||
log.info("The id " + fragment
|
||||
+ " is not unique within the resource. Will use relative pathes instead.");
|
||||
// log.info("The id " + fragment
|
||||
// + " is not unique within the resource. Will use relative pathes instead.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,12 +8,12 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
|||
Require-Bundle: org.antlr;bundle-version="3.0.0",
|
||||
org.eclipse.xtext;bundle-version="1.0.0",
|
||||
org.eclipse.xtext.generator;bundle-version="1.0.0",
|
||||
org.openarchitectureware.xtext.core;bundle-version="4.3.0",
|
||||
org.openarchitectureware.xtext.core.base;bundle-version="4.3.0",
|
||||
org.openarchitectureware.xtext.generator;bundle-version="4.3.0",
|
||||
org.junit,
|
||||
org.openarchitectureware.dependencies;bundle-version="4.3.0",
|
||||
org.eclipse.emf.compare,
|
||||
org.eclipse.emf.compare.diff,
|
||||
org.eclipse.emf.compare.match
|
||||
org.eclipse.emf.compare.match,
|
||||
org.eclipse.xtext.log4j;bundle-version="1.2.15",
|
||||
org.eclipse.xtend;bundle-version="0.7.0",
|
||||
org.eclipse.xtend.typesystem.emf;bundle-version="0.7.0",
|
||||
org.eclipse.xtend.util.stdlib;bundle-version="0.7.0"
|
||||
Export-Package: org.eclipse.xtext
|
||||
|
|
|
@ -19,7 +19,9 @@ import org.eclipse.emf.ecore.EObject;
|
|||
import org.eclipse.emf.ecore.EPackage;
|
||||
import org.eclipse.emf.ecore.EcorePackage;
|
||||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
import org.eclipse.m2t.type.emf.EmfRegistryMetaModel;
|
||||
import org.eclipse.xtend.XtendFacade;
|
||||
import org.eclipse.xtend.expression.ExecutionContextImpl;
|
||||
import org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel;
|
||||
import org.eclipse.xtext.GenerateAllTestGrammars;
|
||||
import org.eclipse.xtext.XtextStandaloneSetup;
|
||||
import org.eclipse.xtext.conversion.IValueConverterService;
|
||||
|
@ -33,8 +35,6 @@ import org.eclipse.xtext.resource.XtextResourceSet;
|
|||
import org.eclipse.xtext.service.IServiceScope;
|
||||
import org.eclipse.xtext.service.ServiceRegistry;
|
||||
import org.eclipse.xtext.util.StringInputStream;
|
||||
import org.openarchitectureware.expression.ExecutionContextImpl;
|
||||
import org.openarchitectureware.xtend.XtendFacade;
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
|
|
|
@ -2,14 +2,14 @@ package org.eclipse.xtext.typeresolution;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.m2t.type.emf.EmfRegistryMetaModel;
|
||||
import org.eclipse.xtend.XtendFacade;
|
||||
import org.eclipse.xtend.expression.ExecutionContextImpl;
|
||||
import org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel;
|
||||
import org.eclipse.xtext.Grammar;
|
||||
import org.eclipse.xtext.XtextStandaloneSetup;
|
||||
import org.eclipse.xtext.tests.AbstractGeneratorTest;
|
||||
import org.eclipse.xtext.xtextutil.MetaModel;
|
||||
import org.eclipse.xtext.xtextutil.XtextutilPackage;
|
||||
import org.openarchitectureware.expression.ExecutionContextImpl;
|
||||
import org.openarchitectureware.xtend.XtendFacade;
|
||||
|
||||
public class XtextUtilConstructionTest extends AbstractGeneratorTest {
|
||||
|
||||
|
|
|
@ -13,7 +13,9 @@ package org.eclipse.xtext.xtext2ecore;
|
|||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.m2t.type.emf.EmfRegistryMetaModel;
|
||||
import org.eclipse.xtend.XtendFacade;
|
||||
import org.eclipse.xtend.expression.ExecutionContextImpl;
|
||||
import org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel;
|
||||
import org.eclipse.xtext.Grammar;
|
||||
import org.eclipse.xtext.XtextStandaloneSetup;
|
||||
import org.eclipse.xtext.tests.AbstractGeneratorTest;
|
||||
|
@ -22,8 +24,6 @@ import org.eclipse.xtext.xtextutil.ComplexType;
|
|||
import org.eclipse.xtext.xtextutil.Feature;
|
||||
import org.eclipse.xtext.xtextutil.MetaModel;
|
||||
import org.eclipse.xtext.xtextutil.XtextutilPackage;
|
||||
import org.openarchitectureware.expression.ExecutionContextImpl;
|
||||
import org.openarchitectureware.xtend.XtendFacade;
|
||||
|
||||
/**
|
||||
* @author Jan Köhnlein
|
||||
|
|
Loading…
Reference in a new issue