@SuppressWarnings("javadoc")
@Test
public void testGetAllContentsFiltered() {
EPackage root = epack("root",
ecl("A"), ecl("B"), edt("C"), //
epack("notfiltered", ecl("Sub1A"), edt("Sub1C")), //
ecl("D"), //
epack("filteredSub", ecl("Sub2A"), ecl("Sub2B"), edt("Sub2C")),
ecl("E"), edt("F"));
Iterator<EObject> iter = EcoreUtilN4.getAllContentsFiltered(root, new Predicate<EObject>() {
@Override
public boolean apply(EObject input) {
return !((ENamedElement) input).getName().startsWith("filtered");
}
});
assertEqualsByNames("A,B,C,D,E,F,notfiltered,Sub1A,Sub1C", iter);
}
java类org.eclipse.emf.ecore.ENamedElement的实例源码
EcoreUtilN4Test.java 文件源码
项目:n4js
阅读 21
收藏 0
点赞 0
评论 0
EcoreUtilN4Test.java 文件源码
项目:n4js
阅读 22
收藏 0
点赞 0
评论 0
@SuppressWarnings("javadoc")
@Test
public void testGetAllContentsFilteredIgnoreRootPredicate() {
EPackage root = epack("filteredRoot",
ecl("A"), ecl("B"), edt("C"), //
epack("notfiltered", ecl("Sub1A"), edt("Sub1C")), //
ecl("D"), //
epack("filtered", ecl("Sub2A"), ecl("Sub2B"), edt("Sub2C")),
ecl("E"), edt("F"));
Iterator<EObject> iter = EcoreUtilN4.getAllContentsFiltered(root, new Predicate<EObject>() {
@Override
public boolean apply(EObject input) {
return !((ENamedElement) input).getName().startsWith("filtered");
}
});
assertEqualsByNames("A,B,C,D,E,F,notfiltered,Sub1A,Sub1C", iter);
}
EcoreUtilN4Test.java 文件源码
项目:n4js
阅读 25
收藏 0
点赞 0
评论 0
@SuppressWarnings("javadoc")
@Test
public void testGetAllContentsFilteredNoMatch() {
EPackage root = epack("root",
epack("filteredSub1", ecl("Sub1A"), edt("Sub1C")), //
epack("filteredSub2", ecl("Sub2A"), ecl("Sub2B"), edt("Sub2C"))
);
Iterator<EObject> iter = EcoreUtilN4.getAllContentsFiltered(root, new Predicate<EObject>() {
@Override
public boolean apply(EObject input) {
return !((ENamedElement) input).getName().startsWith("filtered");
}
});
assertEqualsByNames("", iter);
}
EcoreResourceDescriptionManagerTest.java 文件源码
项目:xtext-extras
阅读 20
收藏 0
点赞 0
评论 0
@Test public void testPerformance() throws Exception {
GenericResourceDescriptionManager manager = getEmfResourceDescriptionsManager();
Collection<String> uris = ImmutableList.copyOf(EPackage.Registry.INSTANCE.keySet());
for(String uri: uris) {
EPackage pack = EPackage.Registry.INSTANCE.getEPackage(uri);
IResourceDescription description = manager.getResourceDescription(pack.eResource());
assertNotNull(description);
for(int i = 0; i < 10; i++) {
Iterator<EObject> iter = EcoreUtil.getAllProperContents(pack, true);
while(iter.hasNext()) {
EObject next = iter.next();
if (next instanceof ENamedElement) {
String name = ((ENamedElement) next).getName();
// Iterable<IEObjectDescription> objects =
description.getExportedObjects(EcorePackage.Literals.EOBJECT, QualifiedName.create(name), false);
// assertFalse(name + " - " + uri + " - " + next, Iterables.isEmpty(objects));
}
}
}
}
}
XtextValidator.java 文件源码
项目:xtext-core
阅读 15
收藏 0
点赞 0
评论 0
public void createMessageForNameClashes(Multimap<String, ENamedElement> nameToElement) {
for(Entry<String, Collection<ENamedElement>> entry: nameToElement.asMap().entrySet()) {
if (entry.getValue().size() > 1) {
if (!Iterables.isEmpty(Iterables.filter(entry.getValue(), EStructuralFeature.class))
&&!Iterables.isEmpty(Iterables.filter(entry.getValue(), EClassifier.class))) {
String constantName = entry.getKey();
String message = "Name clash in generated code: '" + constantName + "'.";
for(ENamedElement element: entry.getValue()) {
String myMessage = message;
if (element.getName().indexOf('_') >= 0) {
myMessage = myMessage + " Try to avoid underscores in names to prevent conflicts.";
}
createMessageForSource(myMessage, null, Diagnostic.ERROR, element, getMessageAcceptor());
}
}
}
}
}
Formatter2Fragment2.java 文件源码
项目:xtext-core
阅读 18
收藏 0
点赞 0
评论 0
protected String toVarName(final ENamedElement element, final String... reservedNames) {
String _xblockexpression = null;
{
if ((element instanceof EReference)) {
return this.toVarName(((EReference)element).getEReferenceType(), reservedNames);
}
String name = StringExtensions.toFirstLower(element.getName());
boolean _contains = XtendFileAccess.XTEND_KEYWORDS.contains(name);
if (_contains) {
name = ("_" + name);
}
boolean _contains_1 = ((List<String>)Conversions.doWrapArray(reservedNames)).contains(name);
if (_contains_1) {
name = ("_" + name);
}
_xblockexpression = name;
}
return _xblockexpression;
}
NamesAreUniqueValidationHelperTest.java 文件源码
项目:xtext-core
阅读 23
收藏 0
点赞 0
评论 0
@Test public void testCreatedErrors_03() {
maxCallCount = 0;
ImmutableList<ENamedElement> elements = ImmutableList.of(
createEClass(),
createEDataType(),
createEPackage()
);
for(ENamedElement classifier: elements) {
classifier.setName("Same");
}
expected.addAll(elements.subList(0, 2));
helper.checkUniqueNames(
Scopes.scopedElementsFor(elements),
this, this);
assertEquals(elements.size(), callCount);
assertTrue(expected.isEmpty());
}
NamesAreUniqueValidationHelperTest.java 文件源码
项目:xtext-core
阅读 21
收藏 0
点赞 0
评论 0
@Test public void testCreatedErrors_04() {
maxCallCount = 0;
ImmutableList<ENamedElement> elements = ImmutableList.of(
createEClass(),
createEDataType(),
createEPackage(),
createEPackage()
);
for(ENamedElement classifier: elements) {
classifier.setName("Same");
}
expected.addAll(elements);
helper.checkUniqueNames(
Scopes.scopedElementsFor(elements),
this, this);
assertEquals(elements.size(), callCount);
assertTrue(expected.isEmpty());
}
NamesAreUniqueValidationHelperTest.java 文件源码
项目:xtext-core
阅读 20
收藏 0
点赞 0
评论 0
@Test public void testCreatedErrors_05() {
maxCallCount = 0;
ImmutableList<ENamedElement> elements = ImmutableList.of(
createEPackage(),
createEDataType(),
createEPackage()
);
for(ENamedElement classifier: elements) {
classifier.setName("Same");
}
expected.add(elements.get(0));
expected.add(elements.get(2));
helper.checkUniqueNames(
Scopes.scopedElementsFor(elements),
this, this);
assertEquals(elements.size(), callCount);
assertTrue(expected.isEmpty());
}
NamesAreUniqueValidationHelperTest.java 文件源码
项目:xtext-core
阅读 23
收藏 0
点赞 0
评论 0
@Test public void testCreatedErrors_06() {
maxCallCount = 1;
ImmutableList<ENamedElement> elements = ImmutableList.of(
createEPackage(),
createEDataType(),
createEPackage()
);
for(ENamedElement classifier: elements) {
classifier.setName("Same");
}
try {
helper.checkUniqueNames(
Scopes.scopedElementsFor(elements),
this, this);
fail("cancellation expected");
} catch (OperationCanceledError e) {
}
assertEquals(1, callCount);
}
NamesAreUniqueValidationHelperTest.java 文件源码
项目:xtext-core
阅读 21
收藏 0
点赞 0
评论 0
@Test public void testCreatedErrors_07() {
maxCallCount = 0;
ImmutableList<ENamedElement> elements = ImmutableList.of(
createEPackage(),
createEDataType(),
EcoreFactory.eINSTANCE.createEEnumLiteral()
);
for(ENamedElement classifier: elements) {
classifier.setName("Same");
}
expected.add(elements.get(0));
expected.add(elements.get(2));
helper.checkUniqueNames(
Scopes.scopedElementsFor(elements),
this, this);
assertEquals(elements.size(), callCount);
assertTrue(expected.isEmpty());
}
DefaultResourceDescriptionManagerTest.java 文件源码
项目:xtext-core
阅读 22
收藏 0
点赞 0
评论 0
@Before
public void setUp() throws Exception {
EObject copy = EcoreUtil.copy(EcorePackage.eINSTANCE);
resource = new ResourceImpl();
resource.getContents().add(copy);
IQualifiedNameProvider nameProvider = new IQualifiedNameProvider.AbstractImpl() {
@Override
public QualifiedName getFullyQualifiedName(EObject obj) {
if (obj instanceof ENamedElement)
return QualifiedName.create(((ENamedElement) obj).getName());
return null;
}
};
DefaultResourceDescriptionStrategy descriptionStrategy = new DefaultResourceDescriptionStrategy();
descriptionStrategy.setQualifiedNameProvider(nameProvider);
resourceDescription = new DefaultResourceDescription(resource, descriptionStrategy) {
@Override
public Iterable<QualifiedName> getImportedNames() {
return importedNames;
}
};
manager = new DefaultResourceDescriptionManager();
importedNames = Collections.emptySet();
}
ResourceSetBasedResourceDescriptionsTest.java 文件源码
项目:xtext-core
阅读 22
收藏 0
点赞 0
评论 0
@Before
public void setUp() throws Exception {
resourceSet = new ResourceSetImpl();
IQualifiedNameProvider qualifiedNameProvider = new IQualifiedNameProvider.AbstractImpl() {
@Override
public QualifiedName getFullyQualifiedName(EObject obj) {
return QualifiedName.create(((ENamedElement) obj).getName());
}
@Override
public QualifiedName apply(EObject from) {
return QualifiedName.create(((ENamedElement) from).getName());
}
};
resourceDescriptionManager = new DefaultResourceDescriptionManager();
resourceDescriptionManager.setCache(IResourceScopeCache.NullImpl.INSTANCE);
DefaultResourceDescriptionStrategy strategy = new DefaultResourceDescriptionStrategy();
strategy.setQualifiedNameProvider(qualifiedNameProvider);
resourceDescriptionManager.setStrategy(strategy);
resDescs = new ResourceSetBasedResourceDescriptions();
resDescs.setContext(resourceSet);
resDescs.setRegistry(this);
container = new ResourceDescriptionsBasedContainer(resDescs);
}
ResourceSetBasedResourceDescriptionsTest.java 文件源码
项目:xtext-core
阅读 20
收藏 0
点赞 0
评论 0
@Test public void testOneElement_Match() {
QualifiedName qualifiedName = QualifiedName.create("SomeName");
EClass type = EcorePackage.Literals.EPACKAGE;
Resource resource = createResource();
ENamedElement element = createNamedElement(qualifiedName, type, resource);
Iterable<IEObjectDescription> iterable = container.getExportedObjectsByType(EcorePackage.Literals.EPACKAGE);
assertSame(element, Iterables.getOnlyElement(iterable).getEObjectOrProxy());
iterable = container.getExportedObjectsByType(EcorePackage.Literals.EOBJECT);
assertSame(element, Iterables.getOnlyElement(iterable).getEObjectOrProxy());
iterable = container.getExportedObjects(EcorePackage.Literals.EPACKAGE, qualifiedName, false);
assertSame(element, Iterables.getOnlyElement(iterable).getEObjectOrProxy());
iterable = container.getExportedObjects(EcorePackage.Literals.ENAMED_ELEMENT, qualifiedName, false);
assertSame(element, Iterables.getOnlyElement(iterable).getEObjectOrProxy());
iterable = container.getExportedObjects(EcorePackage.Literals.EOBJECT, qualifiedName, false);
assertSame(element, Iterables.getOnlyElement(iterable).getEObjectOrProxy());
}
ResourceSetBasedResourceDescriptionsTest.java 文件源码
项目:xtext-core
阅读 19
收藏 0
点赞 0
评论 0
@Test public void testTwoElements_OneMatch() {
QualifiedName qualifiedName = QualifiedName.create("SomeName");
EClass type = EcorePackage.Literals.EPACKAGE;
Resource resource = createResource();
ENamedElement element = createNamedElement(qualifiedName, type, resource);
ENamedElement other = createNamedElement(null, EcorePackage.Literals.ECLASS, resource);
Iterable<IEObjectDescription> iterable = container.getExportedObjectsByType(EcorePackage.Literals.EPACKAGE);
assertSame(element, Iterables.getOnlyElement(iterable).getEObjectOrProxy());
iterable = container.getExportedObjectsByType(EcorePackage.Literals.ECLASSIFIER);
assertSame(other, Iterables.getOnlyElement(iterable).getEObjectOrProxy());
iterable = container.getExportedObjects(EcorePackage.Literals.EPACKAGE, qualifiedName, false);
assertSame(element, Iterables.getOnlyElement(iterable).getEObjectOrProxy());
iterable = container.getExportedObjects(EcorePackage.Literals.ENAMED_ELEMENT, qualifiedName, false);
assertSame(element, Iterables.getOnlyElement(iterable).getEObjectOrProxy());
iterable = container.getExportedObjects(EcorePackage.Literals.EOBJECT, qualifiedName, false);
assertSame(element, Iterables.getOnlyElement(iterable).getEObjectOrProxy());
}
ResourceSetBasedResourceDescriptionsTest.java 文件源码
项目:xtext-core
阅读 21
收藏 0
点赞 0
评论 0
@Test public void testTwoResources_TwoMatches() {
QualifiedName qualifiedName = QualifiedName.create("SomeName");
EClass type = EcorePackage.Literals.EPACKAGE;
Resource resource = createResource();
ENamedElement first = createNamedElement(qualifiedName, type, resource);
resource = createResource();
ENamedElement second = createNamedElement(qualifiedName, type, resource);
List<ENamedElement> expected = Lists.newArrayList(first, second);
Iterable<IEObjectDescription> iterable = container.getExportedObjectsByType(EcorePackage.Literals.EPACKAGE);
checkFindAllEObjectsResult(expected, iterable);
iterable = container.getExportedObjects(EcorePackage.Literals.EPACKAGE, qualifiedName, false);
checkFindAllEObjectsResult(expected, iterable);
iterable = container.getExportedObjects(EcorePackage.Literals.ENAMED_ELEMENT, qualifiedName, false);
checkFindAllEObjectsResult(expected, iterable);
iterable = container.getExportedObjects(EcorePackage.Literals.EOBJECT, qualifiedName, false);
checkFindAllEObjectsResult(expected, iterable);
}
AbstractLabelingTest.java 文件源码
项目:dsl-devkit
阅读 18
收藏 0
点赞 0
评论 0
/**
* Tests that the expected elements and their labels are exactly identical to all elements of the default test resource.
*/
@Test
public void testLabels() {
if (getExpectedElementLabels() == null) {
return; // TODO: remove this check once all tests have been refactored
}
for (Pair<ENamedElement, String> elementLabel : getExpectedElementLabels()) {
if (elementLabel.getFirst() instanceof EClass) {
// TODO: remove this once all tests have been refactored
assertHasLabel(((EClass) elementLabel.getFirst()).getInstanceClass(), elementLabel.getSecond());
} else {
assertHasLabel(elementLabel.getFirst(), elementLabel.getSecond());
}
}
// assertLabelMapConsistsOf(getExpectedElementLabels()); // TODO : revisit and enable this once all tests have been refactored
}
AbstractEObjectSemanticProvider.java 文件源码
项目:Source
阅读 14
收藏 0
点赞 0
评论 0
/**
* {@inheritDoc}
*
* @see eu.modelwriter.semantic.ISemanticProvider#getRelatedConcepts(java.lang.Object)
*/
public Map<Object, Set<Object>> getRelatedConcepts(Object concept) {
final Map<Object, Set<Object>> res = new LinkedHashMap<Object, Set<Object>>();
if (concept instanceof ENamedElement) {
for (EStructuralFeature feature : ((ENamedElement)concept).eClass().getEAllStructuralFeatures()) {
final Set<Object> values = new LinkedHashSet<Object>();
final Object eValue = ((ENamedElement)concept).eGet(feature);
if (eValue instanceof Collection<?>) {
values.addAll((Collection<?>)eValue);
} else if (eValue != null) {
values.add(eValue);
}
if (!values.isEmpty()) {
res.put(feature, values);
}
}
}
return res;
}
StatemachineElementTypes.java 文件源码
项目:xtext-gef
阅读 17
收藏 0
点赞 0
评论 0
/**
* Returns 'type' of the ecore object associated with the hint.
*
* @generated
*/
public static ENamedElement getElement(IAdaptable hint) {
Object type = hint.getAdapter(IElementType.class);
if (elements == null) {
elements = new IdentityHashMap<IElementType, ENamedElement>();
elements.put(Statemachine_1000,
StatemachinePackage.eINSTANCE.getStatemachine());
elements.put(State_2001, StatemachinePackage.eINSTANCE.getState());
elements.put(Transition_4001,
StatemachinePackage.eINSTANCE.getTransition());
}
return (ENamedElement) elements.get(type);
}
SmcElementTypes.java 文件源码
项目:ROADDesigner
阅读 15
收藏 0
点赞 0
评论 0
/**
* @generated
*/
private static ImageDescriptor getProvidedImageDescriptor(
ENamedElement element) {
if (element instanceof EStructuralFeature) {
EStructuralFeature feature = ((EStructuralFeature) element);
EClass eContainingClass = feature.getEContainingClass();
EClassifier eType = feature.getEType();
if (eContainingClass != null && !eContainingClass.isAbstract()) {
element = eContainingClass;
} else if (eType instanceof EClass
&& !((EClass) eType).isAbstract()) {
element = eType;
}
}
if (element instanceof EClass) {
EClass eClass = (EClass) element;
if (!eClass.isAbstract()) {
return SmcDiagramEditorPlugin.getInstance()
.getItemImageDescriptor(
eClass.getEPackage().getEFactoryInstance()
.create(eClass));
}
}
// TODO : support structural features
return null;
}
LookaheadMatcherTreat.java 文件源码
项目:TreatLookaheadMatcher
阅读 14
收藏 0
点赞 0
评论 0
/**
* Unregisters all listeners from the NavigationHelper
*/
public void unregisterAll()
{
HashSet<EDataType> dtps = new HashSet<EDataType>();
HashSet<EClass> ecls = new HashSet<EClass>();
HashSet<EStructuralFeature> esfs = new HashSet<EStructuralFeature>();
for (Entry<ENamedElement, HashSet<PQuery>> rem : RelativeSet.entrySet())
{
ENamedElement element = rem.getKey();
if (element instanceof EDataType)
dtps.add((EDataType) element);
else if (element instanceof EClass)
ecls.add((EClass) element);
else if (element instanceof EStructuralFeature)
esfs.add((EStructuralFeature) element);
}
navHelp.removeDataTypeListener(dtps, featureListeners.dataTypeListener);
navHelp.removeInstanceListener(ecls, featureListeners.classListener);
navHelp.removeFeatureListener(esfs, featureListeners.featureListener);
}
NECSIS14_DatabaseSchemaElementTypes.java 文件源码
项目:MMINT
阅读 14
收藏 0
点赞 0
评论 0
/**
* Returns 'type' of the ecore object associated with the hint.
*
* @generated
*/
public static ENamedElement getElement(IAdaptable hint) {
Object type = hint.getAdapter(IElementType.class);
if (elements == null) {
elements = new IdentityHashMap<IElementType, ENamedElement>();
elements.put(
DatabaseSchema_1000,
edu.toronto.cs.se.modelepedia.necsis14_databaseschema.NECSIS14_DatabaseSchemaPackage.eINSTANCE
.getDatabaseSchema());
elements.put(
Table_2001,
edu.toronto.cs.se.modelepedia.necsis14_databaseschema.NECSIS14_DatabaseSchemaPackage.eINSTANCE
.getTable());
elements.put(
Column_3001,
edu.toronto.cs.se.modelepedia.necsis14_databaseschema.NECSIS14_DatabaseSchemaPackage.eINSTANCE
.getColumn());
}
return (ENamedElement) elements.get(type);
}
RelationalDatabaseElementTypes.java 文件源码
项目:MMINT
阅读 16
收藏 0
点赞 0
评论 0
/**
* @generated
*/
private static ImageDescriptor getProvidedImageDescriptor(
ENamedElement element) {
if (element instanceof EStructuralFeature) {
EStructuralFeature feature = ((EStructuralFeature) element);
EClass eContainingClass = feature.getEContainingClass();
EClassifier eType = feature.getEType();
if (eContainingClass != null && !eContainingClass.isAbstract()) {
element = eContainingClass;
} else if (eType instanceof EClass
&& !((EClass) eType).isAbstract()) {
element = eType;
}
}
if (element instanceof EClass) {
EClass eClass = (EClass) element;
if (!eClass.isAbstract()) {
return RelationalDatabaseDiagramEditorPlugin.getInstance()
.getItemImageDescriptor(
eClass.getEPackage().getEFactoryInstance()
.create(eClass));
}
}
// TODO : support structural features
return null;
}
IStarElementTypes.java 文件源码
项目:MMINT
阅读 16
收藏 0
点赞 0
评论 0
/**
* @generated
*/
private static ImageDescriptor getProvidedImageDescriptor(
ENamedElement element) {
if (element instanceof EStructuralFeature) {
EStructuralFeature feature = ((EStructuralFeature) element);
EClass eContainingClass = feature.getEContainingClass();
EClassifier eType = feature.getEType();
if (eContainingClass != null && !eContainingClass.isAbstract()) {
element = eContainingClass;
} else if (eType instanceof EClass
&& !((EClass) eType).isAbstract()) {
element = eType;
}
}
if (element instanceof EClass) {
EClass eClass = (EClass) element;
if (!eClass.isAbstract()) {
return IStarDiagramEditorPlugin.getInstance()
.getItemImageDescriptor(
eClass.getEPackage().getEFactoryInstance()
.create(eClass));
}
}
// TODO : support structural features
return null;
}
StateMachineElementTypes.java 文件源码
项目:MMINT
阅读 16
收藏 0
点赞 0
评论 0
/**
* Returns 'type' of the ecore object associated with the hint.
*
* @generated
*/
public static ENamedElement getElement(IAdaptable hint) {
Object type = hint.getAdapter(IElementType.class);
if (elements == null) {
elements = new IdentityHashMap<IElementType, ENamedElement>();
elements.put(StateMachine_1000,
StateMachinePackage.eINSTANCE.getStateMachine());
elements.put(State_2001, StateMachinePackage.eINSTANCE.getState());
elements.put(InitialState_2002,
StateMachinePackage.eINSTANCE.getInitialState());
elements.put(FinalState_2003,
StateMachinePackage.eINSTANCE.getFinalState());
elements.put(StateAction_3001,
StateMachinePackage.eINSTANCE.getStateAction());
elements.put(Transition_4001,
StateMachinePackage.eINSTANCE.getTransition());
}
return (ENamedElement) elements.get(type);
}
DcaseElementTypes.java 文件源码
项目:d-case_editor
阅读 21
收藏 0
点赞 0
评论 0
/**
* @generated
*/
private static ImageDescriptor getProvidedImageDescriptor(
ENamedElement element) {
if (element instanceof EStructuralFeature) {
EStructuralFeature feature = ((EStructuralFeature) element);
EClass eContainingClass = feature.getEContainingClass();
EClassifier eType = feature.getEType();
if (eContainingClass != null && !eContainingClass.isAbstract()) {
element = eContainingClass;
} else if (eType instanceof EClass
&& !((EClass) eType).isAbstract()) {
element = eType;
}
}
if (element instanceof EClass) {
EClass eClass = (EClass) element;
if (!eClass.isAbstract()) {
return DcaseDiagramEditorPlugin.getInstance()
.getItemImageDescriptor(
eClass.getEPackage().getEFactoryInstance()
.create(eClass));
}
}
// TODO : support structural features
return null;
}
GrammarPrettyPrinter.java 文件源码
项目:n4js
阅读 16
收藏 0
点赞 0
评论 0
@Override
protected String getCrossReferenceNameFromScope(EObject semanticObject, CrossReference crossref,
EObject target, IScope scope, Acceptor errors) {
if (target instanceof AbstractRule) {
return ((AbstractRule) target).getName();
}
if (target instanceof ENamedElement) {
return ((ENamedElement) target).getName();
}
return super.getCrossReferenceNameFromScope(semanticObject, crossref, target, scope, errors);
}
OrderedEmfFormatter.java 文件源码
项目:n4js
阅读 16
收藏 0
点赞 0
评论 0
private static void refToStr(EObject obj, EReference ref, String indent, Appendable buf) throws Exception {
Object o = obj.eGet(ref);
if (o instanceof EObject) {
EObject eo = (EObject) o;
if (eo instanceof ENamedElement)
buf.append("'").append(((ENamedElement) eo).getName()).append("' ");
buf.append("ref: ");
getURI(obj, eo, buf);
return;
}
if (o instanceof Collection<?>) {
String innerIndent = indent + INDENT;
buf.append("[");
int counter = 0;
Collection<?> coll = (Collection<?>) o;
for (Iterator<?> i = coll.iterator(); i.hasNext();) {
Object item = i.next();
if (counter == 0)
buf.append('\n');
buf.append(innerIndent);
printInt(counter++, coll.size(), buf);
buf.append(": ");
getURI(obj, (EObject) item, buf);
if (i.hasNext())
buf.append(",\n");
else
buf.append('\n').append(indent);
}
buf.append("]");
return;
}
buf.append("?????");
}
EcoreUtilN4Test.java 文件源码
项目:n4js
阅读 23
收藏 0
点赞 0
评论 0
@SuppressWarnings("javadoc")
@Test
public void testGetAllContentsFilteredEmpty() {
EPackage root = epack("root");
Iterator<EObject> iter = EcoreUtilN4.getAllContentsFiltered(root, new Predicate<EObject>() {
@Override
public boolean apply(EObject input) {
return !((ENamedElement) input).getName().startsWith("filtered");
}
});
assertEqualsByNames("", iter);
}
EcoreUtilN4Test.java 文件源码
项目:n4js
阅读 20
收藏 0
点赞 0
评论 0
private void assertEqualsByNames(String string, Iterator<EObject> iter) {
StringBuilder strb = new StringBuilder();
while (iter.hasNext()) {
strb.append(((ENamedElement) iter.next()).getName());
if (iter.hasNext())
strb.append(",");
}
assertEquals(string, strb.toString());
}