Java 类org.eclipse.emf.ecore.ENamedElement 实例源码

项目:n4js    文件:EcoreUtilN4Test.java   
@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);
}
项目:n4js    文件:EcoreUtilN4Test.java   
@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);
}
项目:n4js    文件:EcoreUtilN4Test.java   
@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);
}
项目:xtext-extras    文件:EcoreResourceDescriptionManagerTest.java   
@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));
                    }
                }
            }
        }
    }
项目:xtext-core    文件:XtextValidator.java   
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());
                }
            }
        }
    }
}
项目:xtext-core    文件:Formatter2Fragment2.java   
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;
}
项目:xtext-core    文件:NamesAreUniqueValidationHelperTest.java   
@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());
}
项目:xtext-core    文件:NamesAreUniqueValidationHelperTest.java   
@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());
}
项目:xtext-core    文件:NamesAreUniqueValidationHelperTest.java   
@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());
}
项目:xtext-core    文件:NamesAreUniqueValidationHelperTest.java   
@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);
}
项目:xtext-core    文件:NamesAreUniqueValidationHelperTest.java   
@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());
}
项目:xtext-core    文件:DefaultResourceDescriptionManagerTest.java   
@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();
}
项目:xtext-core    文件:ResourceSetBasedResourceDescriptionsTest.java   
@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);
}
项目:xtext-core    文件:ResourceSetBasedResourceDescriptionsTest.java   
@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());
}
项目:xtext-core    文件:ResourceSetBasedResourceDescriptionsTest.java   
@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());
}
项目:xtext-core    文件:ResourceSetBasedResourceDescriptionsTest.java   
@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);
}
项目:dsl-devkit    文件:AbstractLabelingTest.java   
/**
 * 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
}
项目:Source    文件:AbstractEObjectSemanticProvider.java   
/**
 * {@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;
}
项目:xtext-gef    文件:StatemachineElementTypes.java   
/**
 * 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);
}
项目:ROADDesigner    文件:SmcElementTypes.java   
/**
 * @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;
}
项目:TreatLookaheadMatcher    文件:LookaheadMatcherTreat.java   
/**
 * 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);
}
项目:MMINT    文件:NECSIS14_DatabaseSchemaElementTypes.java   
/**
 * 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);
}
项目:MMINT    文件:RelationalDatabaseElementTypes.java   
/**
 * @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;
}
项目:MMINT    文件:IStarElementTypes.java   
/**
 * @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;
}
项目:MMINT    文件:StateMachineElementTypes.java   
/**
 * 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);
}
项目:d-case_editor    文件:DcaseElementTypes.java   
/**
 * @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;
}
项目:n4js    文件:GrammarPrettyPrinter.java   
@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);
}
项目:n4js    文件:OrderedEmfFormatter.java   
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("?????");
}
项目:n4js    文件:EcoreUtilN4Test.java   
@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);
}
项目:n4js    文件:EcoreUtilN4Test.java   
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());
}
项目:gemoc-studio-modeldebugging    文件:ENamedElementQualifiedNameLabelProvider.java   
@Override
public String getText(Object element) {
    if(element instanceof ENamedElement){
        StringBuilder sb = new StringBuilder();
        if(((ENamedElement)element).eContainer() != null){
            sb.append(getText(((ENamedElement)element).eContainer()));
            sb.append("::");
        }
        sb.append(((ENamedElement)element).getName());
        return sb.toString();
    }
    else return super.getText(element);
}
项目:Tarski    文件:MarkHandler.java   
private void createMarker() {
  editor =
      PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
  file = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
      .getActiveEditor().getEditorInput().getAdapter(IFile.class);
  selection =
      PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();

  final IMarker beAdded = getMarker();
  @SuppressWarnings("unused")
  String text = "";
  if (selection instanceof ITextSelection) {
    if (beAdded != null && beAdded.exists()) {
      text = ((ITextSelection) selection).getText();
      AnnotationFactory.addAnnotation(beAdded, AnnotationFactory.ANNOTATION_MARKING);
    }
  } else if (selection instanceof ITreeSelection) {
    if (editor instanceof EcoreEditor) {
      final ITreeSelection treeSelection = (ITreeSelection) selection;
      if (beAdded != null && beAdded.exists()) {
        if (treeSelection.getFirstElement() instanceof EModelElement) {
          text = ((ENamedElement) treeSelection.getFirstElement()).getName();
        } else {
          text = MarkUtilities.getText(beAdded);
        }
      }
    }
  }

  addToAlloyXML(beAdded);

  // MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Mark Information",
  // null,
  // "\"" + text + "\" has been selected to be marked", MessageDialog.INFORMATION,
  // new String[] {"OK"}, 0);
  // dialog.open();
}
项目:Tarski    文件:MarkerFactory.java   
/**
 * @param selections
 * @return
 */
public static String getQualifiedName(final ITreeSelection selections) {
  final TreePath[] paths = selections.getPaths();

  // Consider only not empty and single selection
  if (selections.isEmpty() || selections.size() > 1) {
    return null;
  }

  final TreePath path = paths[0];
  IElementComparer comparer = null;
  if (selections instanceof TreeSelection) {
    comparer = ((TreeSelection) selections).getElementComparer();
  }
  System.out.println(path.hashCode(comparer));
  for (int i = 1; i < path.getSegmentCount(); i++) {
    if (path.getSegment(i) instanceof ResourceFactoryImpl) {
      final EcoreResourceFactoryImpl eResourceFactory =
          (EcoreResourceFactoryImpl) path.getSegment(i);
      System.out
          .println(eResourceFactory.getClass().getName() + ": " + eResourceFactory.toString());
    } else if (path.getSegment(i) instanceof ENamedElement) {
      final ENamedElement namedElement = (ENamedElement) path.getSegment(i);
      System.out.println(namedElement.getClass().getName() + ": " + namedElement.getName());
    } else {
      System.out.println("?");
    }
  }
  return null;
}
项目:xtext-core    文件:XtextValidator.java   
@Check
public void checkGeneratedPackageForNameClashes(GeneratedMetamodel metamodel) {
    EPackage pack = metamodel.getEPackage();
    Multimap<String, ENamedElement> constantNameToElement = HashMultimap.create();
    Multimap<String, ENamedElement> accessorNameToElement = HashMultimap.create();
    if (pack != null) {
        for(EClassifier classifier: pack.getEClassifiers()) {
            String accessorName = classifier.getName();
            if ("Class".equals(accessorName) || "Name".equals(accessorName))
                accessorName += "_";
            accessorNameToElement.put("get" + accessorName, classifier);
            String classifierConstantName = CodeGenUtil2.format(classifier.getName(), '_', null, true, true).toUpperCase();
            constantNameToElement.put(classifierConstantName, classifier);
            if (classifier instanceof EClass) {
                for(EStructuralFeature feature: ((EClass) classifier).getEAllStructuralFeatures()) {
                    String featureConstantPart = CodeGenUtil2.format(feature.getName(), '_', null, false, false).toUpperCase();
                    String featureConstantName = classifierConstantName + "__" + featureConstantPart;
                    constantNameToElement.put(featureConstantName, feature);
                    String featureAccessorName = "get" + classifier.getName() + "_" + Strings.toFirstUpper(feature.getName());
                    accessorNameToElement.put(featureAccessorName, feature);
                }
            }
        }
    }
    createMessageForNameClashes(constantNameToElement);
    createMessageForNameClashes(accessorNameToElement);
}
项目:xtext-core    文件:SerializationExtensions.java   
public static <T extends ENamedElement> T readEcoreElement(final ObjectInput in) throws IOException {
  final URI uri = SerializationExtensions.readURI(in);
  final EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(uri.trimFragment().toString());
  Resource _eResource = null;
  if (ePackage!=null) {
    _eResource=ePackage.eResource();
  }
  EObject _eObject = null;
  if (_eResource!=null) {
    _eObject=_eResource.getEObject(uri.fragment());
  }
  return ((T) _eObject);
}
项目:xtext-core    文件:EmfFormatter.java   
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("?????");
}
项目:xtext-core    文件:SimpleAttributeResolver.java   
@Override
public void notifyChanged(final Notification notification) {
    if (!notification.isTouch() && Notification.SET == notification.getEventType()) {
        final Object feature = notification.getFeature();
        if (feature != null) {
            if (resolver.attributeName.equals(((ENamedElement) feature).getName())) {
                resolver.valueCache.discard((EObject) notification.getNotifier());
                ((EObject) notification.getNotifier()).eAdapters().remove(this);
            }
        }

    }
}
项目:xtext-core    文件:ResourceSetBasedResourceDescriptionsTest.java   
private void checkFindAllEObjectsResult(List<ENamedElement> expected, Iterable<IEObjectDescription> iterable) {
    Iterable<EObject> transformed = Iterables.transform(iterable, this);
    Set<EObject> transformedSet = Sets.newHashSet(transformed);
    Set<ENamedElement> expectedSet = Sets.newHashSet(expected);
    assertEquals(expected.size(), expectedSet.size());
    assertEquals(expectedSet, transformedSet);
}
项目:xtext-core    文件:ResourceSetBasedResourceDescriptionsTest.java   
private ENamedElement createNamedElement(QualifiedName qualifiedName, EClass type, Resource resource) {
    ENamedElement result = (ENamedElement) EcoreUtil.create(type);
    if (qualifiedName != null)
        result.setName(qualifiedName.getFirstSegment());
    else
        result.setName("" + nameCount++);
    if (resource != null)
        resource.getContents().add(result);
    return result;
}
项目:xtext-core    文件:DefaultResourceDescriptionTest.java   
@Before
public void setUp() throws Exception {
    resource = new XMLResourceImpl();
    resource.setURI(URI.createURI("foo:/test"));
    nameProvider = new IQualifiedNameProvider.AbstractImpl() {
        @Override
        public QualifiedName getFullyQualifiedName(EObject obj) {
            if (obj instanceof ENamedElement)
                return QualifiedName.create(((ENamedElement) obj).getName());
            return null;
        }
    };
    strategy = new DefaultResourceDescriptionStrategy();
    strategy.setQualifiedNameProvider(nameProvider);
    description = new DefaultResourceDescription(resource, strategy);
    EcoreFactory f = EcoreFactory.eINSTANCE;
    pack = f.createEPackage();
    pack.setName("MyPackage");
    eClass = f.createEClass();
    eClass.setName("MyEClass");
    dtype = f.createEDataType();
    dtype.setName("MyDatatype");
    pack.getEClassifiers().add(eClass);
    pack.getEClassifiers().add(dtype);
    resource.getContents().add(pack);

}