java类org.eclipse.emf.ecore.ENamedElement的实例源码

ENamedElementQualifiedNameLabelProvider.java 文件源码 项目:gemoc-studio-modeldebugging 阅读 20 收藏 0 点赞 0 评论 0
@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);
}
MarkHandler.java 文件源码 项目:Tarski 阅读 23 收藏 0 点赞 0 评论 0
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();
}
MarkerFactory.java 文件源码 项目:Tarski 阅读 30 收藏 0 点赞 0 评论 0
/**
 * @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;
}
XtextValidator.java 文件源码 项目:xtext-core 阅读 18 收藏 0 点赞 0 评论 0
@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);
}
SerializationExtensions.java 文件源码 项目:xtext-core 阅读 16 收藏 0 点赞 0 评论 0
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);
}
EmfFormatter.java 文件源码 项目:xtext-core 阅读 15 收藏 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("?????");
}
SimpleAttributeResolver.java 文件源码 项目:xtext-core 阅读 20 收藏 0 点赞 0 评论 0
@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);
            }
        }

    }
}
ResourceSetBasedResourceDescriptionsTest.java 文件源码 项目:xtext-core 阅读 23 收藏 0 点赞 0 评论 0
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);
}
ResourceSetBasedResourceDescriptionsTest.java 文件源码 项目:xtext-core 阅读 23 收藏 0 点赞 0 评论 0
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;
}
DefaultResourceDescriptionTest.java 文件源码 项目:xtext-core 阅读 19 收藏 0 点赞 0 评论 0
@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);

}


问题


面经


文章

微信
公众号

扫码关注公众号