/**
   * This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children that
   * can be created under this object.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generatedNOT
   */
  @Override
  protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) {
    super.collectNewChildDescriptors(newChildDescriptors, object);

    // newChildDescriptors.add(createChildParameter(
    // AnnotationsmodelPackage.Literals.ANNOTATED_EENUM_LITERAL__EENUM_LITERAL_ANNOTATIONS,
    // AnnotationsmodelFactory.eINSTANCE.createEEnumLiteralAnnotation()));

    final AnnotatedEEnumLiteral aEnum = (AnnotatedEEnumLiteral) object;
    for (EClass eClass :
        AnnotationsModelRegistry.getInstance()
            .getSubEClasses(AnnotationsmodelPackage.Literals.EENUM_LITERAL_ANNOTATION)) {
      if (eClass.isAbstract()) {
        continue;
      }
      boolean isUsed = false;
      for (EEnumLiteralAnnotation annotation : aEnum.getEEnumLiteralAnnotations()) {
        if (annotation.eClass() == eClass) {
          isUsed = true;
          break;
        }
      }
      if (!isUsed && !eClass.isAbstract()) {
        newChildDescriptors.add(
            createChildParameter(
                AnnotationsmodelPackage.Literals.ANNOTATED_EENUM_LITERAL__EENUM_LITERAL_ANNOTATIONS,
                EcoreUtil.create(eClass)));
      }
    }
  }
 public static Collection<EClass> getConcreteEClasses(Collection<EClass> eClasses) {
   for (Iterator<EClass> it = eClasses.iterator(); it.hasNext(); ) {
     EClass nextEClass = it.next();
     if (nextEClass != null && (nextEClass.isAbstract() || nextEClass.isInterface())) {
       it.remove();
     }
   }
   return eClasses;
 }
Example #3
0
 private static void includeClass(
     EClassifier classifier,
     boolean includeInterfaces,
     boolean includeAbstracts,
     Set<EClass> result) {
   if (classifier instanceof EClass) {
     EClass eClass = (EClass) classifier;
     if (eClass.isInterface() && !includeInterfaces) return;
     if (eClass.isAbstract() && !includeAbstracts) return;
     result.add(eClass);
   }
 }
 /** @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 ComponentsDiagramEditorPlugin.getInstance()
           .getItemImageDescriptor(eClass.getEPackage().getEFactoryInstance().create(eClass));
     }
   }
   // TODO : support structural features
   return null;
 }
 /**
  * Returns the names of the types that can be created as the root object.
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 protected Collection<String> getInitialObjectNames() {
   if (initialObjectNames == null) {
     initialObjectNames = new ArrayList<String>();
     for (EClassifier eClassifier : webpagePackage.getEClassifiers()) {
       if (eClassifier instanceof EClass) {
         EClass eClass = (EClass) eClassifier;
         if (!eClass.isAbstract()) {
           initialObjectNames.add(eClass.getName());
         }
       }
     }
     Collections.sort(initialObjectNames, CommonPlugin.INSTANCE.getComparator());
   }
   return initialObjectNames;
 }
  @Override
  public Object visit(
      VariableDeclarationExpression variableDeclarationExpression,
      TypeResolutionContext context,
      EolVisitorController<TypeResolutionContext, Object> controller) {

    // visit contents first
    controller.visitContents(variableDeclarationExpression, context);

    // if create is not null
    if (variableDeclarationExpression.getCreate() != null) {

      // get the value of the create
      boolean newExpression = variableDeclarationExpression.getCreate().isVal();

      // if it is a new variable
      if (newExpression) {

        // get resolved type
        Type rawType = variableDeclarationExpression.getResolvedType();

        // we are interested in the model element types
        if (rawType instanceof ModelElementType) {

          // get the type
          ModelElementType modelElementType = (ModelElementType) rawType;

          // if the model element type is a EClass in the meta model
          if (modelElementType.getEcoreType() instanceof EClass) {

            // get the EClass
            EClass eClass = (EClass) modelElementType.getEcoreType();

            // check if the class is an interface or abstract
            if (eClass.isAbstract() || eClass.isInterface()) {

              context
                  .getLogBook()
                  .addError(
                      modelElementType, "Model element type is not instantiable"); // throw error
            }
          }
        }
      }
    }
    return null;
  }
  @Override
  public Object caseEClass(EClass object) {
    Type type = getType(object);

    if (object.isInterface()) {
    } else { // class
      Class clazz = (Class) type;
      clazz.setAbstract(object.isAbstract());
    }

    Set<Type> assocAndGen = new HashSet<>();
    Set<Type> dependencies = new HashSet<>();

    for (EClass eSuperType : object.getESuperTypes()) {
      Type superType = getType(eSuperType);
      assocAndGen.add(superType);

      if (eSuperType.isInterface()) {
        type.addInterface((Interface) superType);
      } else {
        type.addSuperClass((Class) superType);
      }
    }

    for (EStructuralFeature eFeature : object.getEStructuralFeatures()) {
      Attribute attr = (Attribute) doSwitch(eFeature);
      type.addAttribute(attr);

      assocAndGen.add(attr.type);
    }
    for (EOperation eOperation : object.getEOperations()) {
      Operation op = (Operation) doSwitch(eOperation);
      type.addOperation(op);

      dependencies.add(op.type);
      for (TypedElement fpar : op.formalParameters()) {
        dependencies.add(fpar.type);
      }
    }
    dependencies.removeAll(assocAndGen);
    for (Type dep : dependencies) {
      type.addDependency(dep);
    }

    return type;
  }
  public static List<EClass> getSubClasses(EClass parentClass) {

    List<EClass> classList = new ArrayList<EClass>();
    EList<EClassifier> classifiers = Bpmn2Package.eINSTANCE.getEClassifiers();

    for (EClassifier classifier : classifiers) {
      if (classifier instanceof EClass) {
        EClass clazz = (EClass) classifier;

        clazz.getEAllSuperTypes().contains(parentClass);
        if (parentClass.isSuperTypeOf(clazz) && !clazz.isAbstract()) {
          classList.add(clazz);
        }
      }
    }
    return classList;
  }
 /**
  * Returns the names of the types that can be created as the root object.
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 protected Collection getInitialObjectNames() {
   if (initialObjectNames == null) {
     initialObjectNames = new ArrayList();
     for (Iterator classifiers = workaroundPackage.getEClassifiers().iterator();
         classifiers.hasNext(); ) {
       EClassifier eClassifier = (EClassifier) classifiers.next();
       if (eClassifier instanceof EClass) {
         EClass eClass = (EClass) eClassifier;
         if (!eClass.isAbstract()) {
           initialObjectNames.add(eClass.getName());
         }
       }
     }
     Collections.sort(initialObjectNames, java.text.Collator.getInstance());
   }
   return initialObjectNames;
 }
Example #10
0
  @Override
  protected void saveEObjectSingle(EObject o, EStructuralFeature f) {
    StringBuffer buffer = new StringBuffer();

    EObject value = (EObject) helper.getValue(o, f);
    if (value != null) {
      String id = helper.getHREF(value);
      if (id != null) {
        id = convertURI(id);
        buffer.setLength(0);
        // if (!id.startsWith("#"))
        // {
        if (!o.eClass().getEPackage().getNsURI().equals(f.getEType().getEPackage().getNsURI())) {

          EClass eClass = value.eClass();
          EClass expectedType = (EClass) f.getEType();
          if (saveTypeInfo
              ? xmlTypeInfo.shouldSaveType(eClass, expectedType, f)
              : eClass != expectedType
                  && (expectedType.isAbstract()
                      || f.getEGenericType().getETypeParameter() != null)) {
            buffer.append(helper.getQName(eClass));
            buffer.append(' ');
          }
        }
        // }
        buffer.append(id);
        if (!toDOM) {
          String name = helper.getQName(f);
          doc.startAttribute(name);
          doc.addAttributeContent(buffer.toString());
          doc.endAttribute();
        } else {
          helper.populateNameInfo(nameInfo, f);
          Attr attr =
              document.createAttributeNS(nameInfo.getNamespaceURI(), nameInfo.getQualifiedName());
          attr.setNodeValue(buffer.toString());
          ((Element) currentNode).setAttributeNodeNS(attr);
          handler.recordValues(attr, o, f, value);
        }
      }
    }
  }
Example #11
0
  private EClass findEClass(
      EClass eReferenceType, JsonNode node, JsonNode root, Resource resource) {
    if (eReferenceType.isAbstract() || node.get(EJS_TYPE_KEYWORD) != null) {

      if (node.has(EJS_REF_KEYWORD)) {

        URI refURI = getEObjectURI(node.get(EJS_REF_KEYWORD), resource.getURI(), nsMap);
        EObject eObject = resourceSet.getEObject(refURI, false);
        if (eObject != null) {
          return resourceSet.getEObject(refURI, false).eClass();
        }

        if (node.has(EJS_TYPE_KEYWORD)) {
          refURI = URI.createURI(node.get(EJS_TYPE_KEYWORD).asText());
          eObject = resourceSet.getEObject(refURI, false);
          if (eObject != null) {
            return (EClass) eObject;
          }
        }

        JsonNode refNode = findNode(refURI, eReferenceType, rootNode);
        if (refNode != null) {
          return findEClass(eReferenceType, refNode, root, resource);
        }

      } else if (node.has(EJS_TYPE_KEYWORD)) {
        final URI typeURI =
            getEObjectURI(node.get(EJS_TYPE_KEYWORD), eReferenceType.eResource().getURI(), nsMap);

        if (typeURI.fragment().equals(eReferenceType.getName())) {
          return eReferenceType;
        } else {
          try {
            return (EClass) this.resourceSet.getEObject(typeURI, false);
          } catch (ClassCastException e) {
            e.printStackTrace();
            return null;
          }
        }
      }
    }
    return eReferenceType;
  }
Example #12
0
  public static synchronized List<EclDocCommand> getAllPublicCommands() {
    if (commands != null) return commands;

    commands = new ArrayList<EclDocCommand>();
    commandsByName = new HashMap<String, EclDocCommand>();

    for (Object o : EPackage.Registry.INSTANCE.values().toArray()) {
      try {
        if (o instanceof EPackage.Descriptor) o = ((EPackage.Descriptor) o).getEPackage();

        if (!(o instanceof EPackage)) continue;

        EPackage p = (EPackage) o;
        for (EClassifier classifier : p.getEClassifiers()) {
          if (!(classifier instanceof EClass)) continue;

          EClass class_ = (EClass) classifier;
          if (class_.isAbstract() || !class_.getEAllSuperTypes().contains(COMMAND)) continue;

          EclDocCommand command = new EclDocCommand(class_);
          if (command.isInternal() || command.isExcluded()) continue;

          if (commandsByName.containsKey(command.getName())) continue;

          commands.add(command);
          commandsByName.put(command.getName(), command);
        }
      } catch (Exception e) {
        EclDocPlugin.err("Failed to load documentation from: " + o, e);
      }
    }

    Collections.sort(
        commands,
        new Comparator<EclDocCommand>() {
          public int compare(EclDocCommand a, EclDocCommand b) {
            return a.getName().compareTo(b.getName());
          }
        });

    return commands;
  }
  public static Collection<EClass> filterByFeatureSeqInitializer(
      Collection<EClass> eClasses, FeatureSeqInitializer featureSeqInitializer) {
    if (featureSeqInitializer.getCreatingInitializer() != null) {
      EStructuralFeature feature = featureSeqInitializer.getCreatingInitializer().getFeature();
      if (feature != null && feature.getEType() instanceof EClass) {
        for (Iterator<EClass> it = eClasses.iterator(); it.hasNext(); ) {
          EClass nextEClass = it.next();
          EClass typeEClass = (EClass) feature.getEType();
          if (nextEClass == null
              || nextEClass.isAbstract()
              || nextEClass.isInterface()
              || !typeEClass.isSuperTypeOf(nextEClass)) {
            it.remove();
          }
        }
      }
    } else if (featureSeqInitializer.getElementClass() != null) {
      return Collections.singleton(featureSeqInitializer.getElementClass());
    }

    return eClasses;
  }
Example #14
0
  public EObject getStaticInstance() {
    if (null == staticObj) {
      EClass eClass = eClass();
      if (eClass.isAbstract()) {
        throw new IllegalArgumentException(
            "Cannot create an instance of the abstract type: " + eClass.getName());
      }
      staticObj = eClass.getEPackage().getEFactoryInstance().create(eClass);

      //            System.out.println("New static instance: " + staticObj.hashCode() + " of type "
      // + eClass.getName());

      // Copy over all property values
      EPropertiesHolder props = eProperties();
      if (props.getEClass() != null && props.hasSettings()) {
        List features = eClass.getEAllStructuralFeatures();
        for (Iterator itr = features.iterator(); itr.hasNext(); ) {
          EStructuralFeature feature = (EStructuralFeature) itr.next();

          staticObj.eSet(feature, eGet(feature));
          //                    System.out.println("    F: " + feature.getName());
        }
      }

      // Update all external references
      for (Iterator itr = actions.iterator(); itr.hasNext(); ) {
        Action action = (Action) itr.next();
        action.doIt(staticObj);
      }

      // Update containing resource
      //            List contents = eResource().getContents();
      //            contents.remove(this);
      //            contents.add(staticObj);
    }

    return staticObj;
  }
Example #15
0
  private void mapClasses(Connection connection, boolean unmap, EClass... eClasses) {
    for (EClass eClass : eClasses) {
      if (!(eClass.isInterface() || eClass.isAbstract())) {
        String mappingAnnotation = DBAnnotation.TABLE_MAPPING.getValue(eClass);

        // TODO Maybe we should explicitly report unknown values of the annotation
        if (mappingAnnotation != null
            && mappingAnnotation.equalsIgnoreCase(DBAnnotation.TABLE_MAPPING_NONE)) {
          continue;
        }

        if (!unmap) {
          // TODO Bugzilla 296087: Before we go ahead with creation, we should check if it's already
          // there
          IClassMapping mapping = createClassMapping(eClass);
          getStore().getDBAdapter().createTables(mapping.getDBTables(), connection);
        } else {
          IClassMapping mapping = removeClassMapping(eClass);
          getStore().getDBAdapter().dropTables(mapping.getDBTables(), connection);
        }
      }
    }
  }
  /**
   * Adds to the specified list of {@link IChildCreationSpecification} with the specified
   * information.
   *
   * <p>Also adds any sub-classes of child type.
   *
   * @param specs the list of specifications to add to
   * @param parent the parent object
   * @param ref the reference
   * @param childType the child type
   * @param index TODO
   */
  public static void addToChildCreationSpecification(
      final List<IChildCreationSpecification> specs,
      EObject parent,
      EReference ref,
      final EClass childType,
      int index) {
    /*
     * Allow the user to prevent the addition
     */
    final IBindingDataType dt = IBindingDataType.Factory.create(parent, ref);

    if (!childType.isAbstract()
        && !childType.isInterface()
        && dt.getArgument(Constants.ARG_NEW_ALLOWED, null, Boolean.class, Boolean.TRUE)) {
      specs.add(new ChildCreationSpecification(parent, ref, childType, index));
    }

    final Collection<EClass> subClasses = EcoreExtendedUtils.getSubClasses(childType);
    if (subClasses == null) return;

    for (final EClass c : subClasses) {
      addToChildCreationSpecification(specs, parent, ref, c, index);
    }
  }
 /**
  * Returns whether <code>eClass</code> can be instantiated or not. An EClass can be instantiated,
  * if it is neither an interface nor abstract.
  *
  * @param eClass the EClass in question
  * @return whether <code>eClass</code> can be instantiated or not.
  */
 public static boolean canHaveInstance(EClass eClass) {
   return !eClass.isInterface() && !eClass.isAbstract();
 }
 public boolean isConcrete(org.eclipse.emf.ecore.EClass eClass) {
   return !eClass.isAbstract() && !eClass.isInterface();
 }