@Override
    public EOperation define(EcoreEnvironment env) {
      EOperation eOperation = EcoreFactory.eINSTANCE.createEOperation();
      eOperation.setName(fName);
      int pos = 0;
      for (EClassifier cls : fParamTypes) {
        EParameter eParam = EcoreFactory.eINSTANCE.createEParameter();
        String paramName = cls.getName();
        if (fParamNames != null) {
          paramName = fParamNames[pos++];
        }

        eParam.setName(paramName);
        eParam.setEType(cls);
        eOperation.getEParameters().add(eParam);
      }

      eOperation.setEType(fReturnType);

      assert fContextType instanceof EClass;
      ((EClass) fContextType).getEOperations().add(eOperation);

      CallHandlerAdapter.attach(eOperation, fDispatcher);
      return eOperation;
    }
 private String fqn(EClassifier eClassifier) {
   String fqn =
       (eClassifier.getEPackage() != null)
           ? eClassifier.getEPackage().getName() + "." + eClassifier.getName()
           : eClassifier.getName();
   return fqn;
 }
Example #3
0
 /**
  * Sets the instance class on the given classifier.
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 @Override
 protected void fixInstanceClass(EClassifier eClassifier) {
   if (eClassifier.getInstanceClassName() == null) {
     eClassifier.setInstanceClassName("org.yakindu.sct.model.sgraph." + eClassifier.getName());
     setGeneratedClassName(eClassifier);
   }
 }
  private Type getType(EClassifier eClassifier) {
    if (eClassifier == null) {
      return null;
    }
    String fqn = fqn(eClassifier);
    Type type = model.get(fqn);
    if (type != null) {
      return type;
    }

    Kind kind = null;
    if (eClassifier instanceof EClass) {
      kind = ((EClass) eClassifier).isInterface() ? Kind.INTERFACE : Kind.CLASS;
    } else if (eClassifier instanceof EEnum) {
      kind = Kind.ENUM;
    } else {
      kind = Kind.CLASS;
    }
    String name = eClassifier.getName();
    String packageName = "";
    if (eClassifier.getEPackage() != null) {
      packageName = eClassifier.getEPackage().getName();
    }
    type = TypeFactory.create(name, packageName, kind);
    type.displayName = displayName(name, packageName);

    type.setContext(!model.isBasePackage(packageName));

    model.add(type);
    return type;
  }
  @Override
  protected void handleEPackage(EPackage ePackage, Set<EPackage> visitedPackages) {
    if (ePackage != null && visitedPackages.add(ePackage)) {
      if (excludeEcore
          && // Optimize EPackage comparison
          (EcorePackage.eINSTANCE == ePackage
              || EcorePackage.eNS_URI.equals(ePackage.getNsURI()))) {
        return;
      }

      Set<Object> visited = new HashSet<Object>();
      for (EClassifier classifier : ePackage.getEClassifiers()) {
        handleEClassifier(classifier, visitedPackages, visited);
      }

      for (Object object : visited) {
        if (object instanceof EClassifier) {
          EClassifier classifier = (EClassifier) object;
          final EPackage p = classifier.getEPackage();
          if (p != null) {
            if (visitedPackages.add(p)) {
              if (TRACER.isEnabled()) {
                TRACER.trace("Found package " + p.getNsURI()); // $NON-NLS-1$
              }
            }
          } else {
            OM.LOG.warn(
                MessageFormat.format(
                    Messages.getString("CompletePackageClosure.0"),
                    classifier.getName())); // $NON-NLS-1$
          }
        }
      }
    }
  }
 private EClassifier findEClassifier(String typeName, EPackage ePackage) {
   for (EClassifier eClassifier : ePackage.getEClassifiers()) {
     if (typeName.equals(eClassifier.getInstanceTypeName())) {
       return eClassifier;
     }
   }
   return null;
 }
 private static String getFQN(EClassifier c, String separator) {
   EPackage p = c.getEPackage();
   if (p != null) {
     return getEPackageFQN(p, separator) + separator + c.getName();
   } else {
     return c.getName();
   }
 }
 /**
  * Sets the instance class on the given classifier.
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 @Override
 protected void fixInstanceClass(EClassifier eClassifier) {
   if (eClassifier.getInstanceClassName() == null) {
     eClassifier.setInstanceClassName(
         "fumlConfigurationFewSteps.ActionsFewSteps.IntermediateActionsFewSteps."
             + eClassifier.getName());
     setGeneratedClassName(eClassifier);
   }
 }
Example #9
0
    public static int kind(EStructuralFeature eStructuralFeature) {
      int result = 0;

      EClassifier eClassifier = eStructuralFeature.getEType();

      if (eClassifier.getInstanceClass() != null) {
        result |= HAS_INSTANCE_CLASS;
      }

      if (eStructuralFeature.isUnsettable()) {
        result |= IS_UNSETTABLE;
      }

      if (eStructuralFeature instanceof EReference) {
        EReference eReference = (EReference) eStructuralFeature;
        EReference inverseEReference = eReference.getEOpposite();
        if (eReference.isContainment()) {
          result |= IS_CONTAINMENT;
        }

        if (inverseEReference != null) {
          // This forces the feature ids to be assigned.
          //
          inverseEReference.getEContainingClass().getFeatureCount();
          result |= HAS_NAVIGABLE_INVERSE;
          if (inverseEReference.isMany()) {
            result |= HAS_MANY_INVERSE;
          }
          if (inverseEReference.isContainment()) {
            result |= IS_CONTAINER;
          }
        }

        if (eReference.isResolveProxies()) {
          result |= HAS_PROXIES;
        }

        result |= IS_EOBJECT;
      } else // if (eStructuralFeature instanceof EAttribute
      {
        if (eClassifier instanceof EEnum) {
          result |= IS_ENUM;
        } else {
          Class<?> instanceClass = eClassifier.getInstanceClass();
          if (instanceClass != null && instanceClass.isPrimitive()) {
            result |= IS_PRIMITIVE;
          }
        }
      }

      if (eStructuralFeature.isUnique()) {
        result |= IS_UNIQUE;
      }

      return result;
    }
  /**
   * Creates and returns a <em>proxy</em> object. The usage of a proxy object is strongly limited.
   * The only guarantee that can be made is that the following methods are callable and will behave
   * in the expected way:
   *
   * <ul>
   *   <li>{@link CDOObject#cdoID()} will return the {@link CDOID} of the target object
   *   <li>{@link CDOObject#cdoState()} will return {@link CDOState#PROXY PROXY}
   *   <li>{@link InternalEObject#eIsProxy()} will return <code>true</code>
   *   <li>{@link InternalEObject#eProxyURI()} will return the EMF proxy URI of the target object
   * </ul>
   *
   * Calling any other method on the proxy object will result in an {@link
   * UnsupportedOperationException} being thrown at runtime. Note also that the proxy object might
   * even not be cast to the concrete type of the target object. The proxy can only guaranteed to be
   * of <em>any</em> concrete subtype of the declared type of the given feature.
   *
   * <p>TODO {@link InternalEObject#eResolveProxy(InternalEObject)}
   */
  protected InternalEObject createProxy(
      InternalCDOView view, EStructuralFeature feature, CDOID id) {
    EClassifier eType = feature.getEType();
    Class<?> instanceClass = eType.getInstanceClass();

    Class<?>[] interfaces = {instanceClass, InternalEObject.class, LegacyProxy.class};
    ClassLoader classLoader = CDOLegacyWrapper.class.getClassLoader();
    LegacyProxyInvocationHandler handler = new LegacyProxyInvocationHandler(this, id);
    return (InternalEObject) Proxy.newProxyInstance(classLoader, interfaces, handler);
  }
 public void testCreatedErrors_02() {
   maxCallCount = 0;
   ImmutableList<EClassifier> classifiers = ImmutableList.of(createEClass(), createEDataType());
   for (EClassifier classifier : classifiers) {
     classifier.setName("Same");
   }
   expected.addAll(classifiers);
   helper.checkUniqueNames(Scopes.scopedElementsFor(classifiers), this, this);
   assertEquals(classifiers.size(), callCount);
   assertTrue(expected.isEmpty());
 }
 public OclBoolean EnumLiteral_oclIsKindOf(Object o1, OclType type) {
   EClassifier cls = (EClassifier) ((Classifier) type.asJavaObject()).getDelegate();
   OclBoolean res =
       processor
           .getStdLibGenerationAdapter()
           .Boolean("new Boolean(" + o1 + " instanceof " + cls.getInstanceClassName() + ")");
   ((Impl) res)
       .setInitialisation(
           ((Impl) o1).getInitialisation()
               + ((Impl) type).getInitialisation()
               + ((Impl) res).getInitialisation());
   return res;
 }
 public Object EnumLiteral_oclAsType(Object o1, OclType type) {
   EClassifier cls = (EClassifier) ((Classifier) type.asJavaObject()).getDelegate();
   OclAny res =
       processor
           .getStdLibGenerationAdapter()
           .OclAny("((" + cls.getInstanceClassName() + ")" + this + ")");
   ((Impl) res)
       .setInitialisation(
           ((Impl) o1).getInitialisation()
               + ((Impl) type).getInitialisation()
               + ((Impl) res).getInitialisation());
   return res;
 }
 protected void handleEClassifier(
     EClassifier classifier, Set<EPackage> visitedPackages, Set<Object> visited) {
   if (classifier != null && visited.add(classifier)) {
     handleEPackage(classifier.getEPackage(), visitedPackages);
     handleETypeParameters(classifier.getETypeParameters(), visitedPackages, visited);
     if (classifier instanceof EClass) {
       EClass eClass = (EClass) classifier;
       handleEStructuralFeatures(eClass.getEStructuralFeatures(), visitedPackages, visited);
       handleEOperations(eClass.getEOperations(), visitedPackages, visited);
       handleEGenericTypes(eClass.getEGenericSuperTypes(), visitedPackages, visited);
     }
   }
 }
Example #15
0
 @Override
 public boolean isStereotype(
     @NonNull EnvironmentFactoryInternal environmentFactory, @NonNull EClass eClass) {
   for (EStructuralFeature eFeature : eClass.getEAllStructuralFeatures()) {
     EClassifier eType = eFeature.getEType();
     if (eType != null) {
       assert !eType.eIsProxy() : "Unresolved proxy: '" + EcoreUtil.getURI(eType) + "'";
       EPackage ePackage = eType.getEPackage();
       assert !"http://www.eclipse.org/uml2/5.0.0/UML".equals(ePackage.getNsURI());
     }
   }
   return false;
 }
Example #16
0
  protected List<EClass> getAllEClasses() {
    final List<EClass> eClasses = new ArrayList<EClass>();
    for (final EPackage ePackage : ePackages) {
      for (final EClassifier eClassifier : ePackage.getEClassifiers()) {
        if (eClassifier instanceof EClass) {
          eClasses.add((EClass) eClassifier);

          eClassifier.setInstanceClass(null);
        }
      }
    }
    return eClasses;
  }
 @Override
 public String toString() {
   StringBuilder s = new StringBuilder();
   s.append(reference.getName());
   s.append(" : "); // $NON-NLS-1$
   //		s.append(reference.getEType().getName());
   if (requiredType != null) {
     s.append(requiredType.getName());
   }
   if (isQualifier) {
     s.append(" (qualifier)");
   }
   s.append(" \""); // $NON-NLS-1$
   if (name != null) {
     s.append(name);
   }
   s.append("\" {"); // $NON-NLS-1$
   String prefix = ""; // $NON-NLS-1$
   for (String contentName : contentsByName.keySet()) {
     s.append(prefix);
     s.append(contentName);
     Object content = contentsByName.get(contentName);
     if (content instanceof List<?>) {
       s.append("*");
       s.append(((List<?>) content).size());
     }
     prefix = ","; // $NON-NLS-1$
   }
   s.append("}"); // $NON-NLS-1$
   return s.toString();
 }
  /**
   * Returns the new Id for the section
   *
   * @param selectionClass the selected class
   * @param selectionSize size of the selection
   * @return the new Id for the section
   */
  protected String getNewFragmentId(
      EClassifier selectionClass, Stereotype stereotype, int selectionSize) {
    for (int i = 0;
        i < 100;
        i++) { // no need to go to more than 100, because 100 is already a very big number of
               // fragments
      boolean found = false; // indicates if the id has been found in already fragments or not

      StringBuffer buffer = new StringBuffer();
      buffer.append("fragment_");
      if (selectionSize == 1) {
        buffer.append("single");
      } else if (selectionSize < 0) {
        buffer.append("multi");
      } else {
        buffer.append(selectionSize);
      }
      buffer.append("_");

      if (selectionClass != null && selectionClass.getInstanceClass() != null) {
        buffer.append(selectionClass.getInstanceClass().getSimpleName());
      } else if (stereotype != null && stereotype.getName() != null) {
        buffer.append(stereotype.getName());
      } else {
        buffer.append("NoName");
      }
      if (i > 0) {
        buffer.append(i);
      }
      String name = buffer.toString();

      Iterator<IFragmentDescriptorState> it =
          sectionDescriptorState.getFragmentDescriptorStates().iterator();
      while (it.hasNext()) {
        IFragmentDescriptorState fragmentDescriptorState = it.next();
        String id = fragmentDescriptorState.getDescriptor().getId();
        if (name.equalsIgnoreCase(id)) {
          found = true;
        }
      }

      if (!found) {
        return name;
      }
    }
    return "";
  }
  public static boolean isIntermediateClass(EClassifier class_) {
    if (class_ == null) {
      return false;
    }

    EPackage ePackage = class_.getEPackage();
    return ePackage != null && isIntermediatePackage(ePackage);
  }
Example #20
0
  /** @return the qualified name of the given metaclass */
  public static String getMetaclassQualifiedName(final EClassifier eClass) {
    final ArrayList<String> qualifiedNameParts = new ArrayList<String>();
    final StringBuilder builder = new StringBuilder();

    EPackage ePackage = eClass.getEPackage();
    while (ePackage != null) {
      qualifiedNameParts.add(ePackage.getName());
      ePackage = ePackage.getESuperPackage();
    }

    for (int i = qualifiedNameParts.size() - 1; i >= 0; i--) {
      builder.append(qualifiedNameParts.get(i) + "."); // $NON-NLS-1$
    }

    builder.append(eClass.getName());

    return builder.toString();
  }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((fE == null) ? 0 : fE.hashCode());
   result = prime * result + ((fAttr == null) ? 0 : fAttr.hashCode());
   result = prime * result + ((fType == null) ? 0 : fType.hashCode());
   return result;
 }
Example #22
0
  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);

    /**
     * **************************************************************************** Copyright (C)
     * 2009-2016 BIMserver.org
     *
     * <p>This program is free software: you can redistribute it and/or modify it under the terms of
     * the GNU Affero General Public License as published by the Free Software Foundation, either
     * version 3 of the License, or (at your option) any later version.
     *
     * <p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
     * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
     * the GNU Affero General Public License for more details.
     *
     * <p>You should have received a copy of the GNU Affero General Public License along with this
     * program. If not, see <http://www.gnu.org/licenses/>.
     * ***************************************************************************
     */
    stringBuffer.append(TEXT_2);
    stringBuffer.append(TEXT_3);
    stringBuffer.append(Licenser.getCommentedLicenseText(new File("license.txt")));
    stringBuffer.append(TEXT_4);

    @SuppressWarnings("unchecked")
    Set<EPackage> ePackages = (Set<EPackage>) argument;

    stringBuffer.append(TEXT_5);

    for (EPackage ePackage : ePackages) {
      for (EClassifier eClassifier : ePackage.getEClassifiers()) {
        if (eClassifier instanceof EClass || eClassifier instanceof EEnum) {

          stringBuffer.append(TEXT_6);
          stringBuffer.append(eClassifier.getName());
          stringBuffer.append(TEXT_7);
        }
      }
    }

    stringBuffer.append(TEXT_8);
    return stringBuffer.toString();
  }
 /**
  * {@inheritDoc}
  *
  * @see
  *     org.eclipse.acceleo.common.utils.IAcceleoCrossReferenceProvider#getInverseReferences(org.eclipse.emf.ecore.EObject,
  *     org.eclipse.emf.ecore.EClassifier)
  */
 public Set<EObject> getInverseReferences(EObject eObject, EClassifier filter) {
   final Set<EObject> result = Sets.newLinkedHashSet();
   for (EStructuralFeature.Setting setting : crossReferencer.getInverseReferences(eObject)) {
     final EObject eObj = setting.getEObject();
     if (filter == null || filter.isInstance(eObj)) {
       result.add(eObj);
     }
   }
   return result;
 }
 /**
  * Test if a possibleSub eclass is a sub eclass
  *
  * @param aclass, cannot be null
  * @param possibleSubClasse, cannot be null
  * @return true if possible eclass is a subtype of a eclass or false
  */
 public boolean isSubClass(EClassifier aclass, EClass possibleSubClasse) {
   if (aclass.equals(possibleSubClasse)) {
     return true;
   }
   EList<EClass> superTypeList = possibleSubClasse.getEAllSuperTypes();
   if (superTypeList.contains(aclass)) {
     return true;
   }
   return false;
 }
 static String getText(EGenericType eGenericType) {
   ETypeParameter eTypeParameter = eGenericType.getETypeParameter();
   if (eTypeParameter != null) {
     String name = eTypeParameter.getName();
     return name == null ? "null" : name;
   } else {
     EClassifier eClassifier = eGenericType.getEClassifier();
     if (eClassifier != null) {
       List<EGenericType> eTypeArguments = eGenericType.getETypeArguments();
       if (eTypeArguments.isEmpty()) {
         String name = eClassifier.getName();
         return name == null ? "null" : name;
       } else {
         StringBuilder result = new StringBuilder();
         result.append(eClassifier.getName());
         result.append('<');
         for (Iterator<EGenericType> i = eTypeArguments.iterator(); ; ) {
           result.append(getText(i.next()));
           if (i.hasNext()) {
             result.append(", ");
           } else {
             break;
           }
         }
         result.append('>');
         return result.toString();
       }
     } else {
       EGenericType eUpperBound = eGenericType.getEUpperBound();
       if (eUpperBound != null) {
         return "? extends " + getText(eUpperBound);
       } else {
         EGenericType eLowerBound = eGenericType.getELowerBound();
         if (eLowerBound != null) {
           return "? super " + getText(eLowerBound);
         } else {
           return "?";
         }
       }
     }
   }
 }
Example #26
0
  protected boolean hasEClass(IStructuredSelection selection, String eClassQName) {
    if (!selection.isEmpty()) {
      // Resolve the EClass in the context of the first element. If we can't resolve it
      // in this context, then that element necessarily isn't an instance of that EClass,
      // so not all of the selection is an instance of that class. Thus, it doesn't
      // matter that we choose the first element to resolve the EClass
      EClassifier eClassifier =
          resolveEClass(EMFHelper.getEObject(selection.getFirstElement()), eClassQName);

      if (eClassifier != null) {
        boolean result = true;
        for (Iterator<?> iter = selection.iterator(); result && iter.hasNext(); ) {
          EObject next = EMFHelper.getEObject(iter.next());
          result = (next != null) && eClassifier.isInstance(next);
        }

        return result;
      }
    }
    return false;
  }
  protected CellEditor createCellEditor(Object element, String property) {
    Composite parent = tableViewer.getTable();
    if (cellEditor == null && feature != null) {
      EClassifier ec = feature.getEType();
      Class ic = ec.getInstanceClass();

      if (boolean.class.equals(ic)) {
        cellEditor = new CustomCheckboxCellEditor(parent);
      } else if (ec instanceof EEnum) {
        cellEditor = new CustomComboBoxCellEditor(parent, (EObject) element, feature);
      } else if (ModelUtil.isMultiChoice((EObject) element, feature)) {
        cellEditor = new CustomComboBoxCellEditor(parent, (EObject) element, feature);
      } else if (ec instanceof EDataType) {
        cellEditor = new EDataTypeCellEditor((EDataType) ec, parent);
      } else if (ic == EObject.class) {
        cellEditor = new StringWrapperCellEditor(parent);
      }
      setCellEditor(cellEditor);
    }
    return cellEditor;
  }
Example #28
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @param eClassifier the {@link EClassifier}
  * @return the class implementing a specific {@link EClass}.
  * @generated
  */
 @Override
 public Class<?> getEClassifierClass(EClassifier eClassifier) {
   switch (eClassifier.getClassifierID()) {
     case INCLUDE1_CLASSIFIER_ID:
       return Include1.class;
     case INCLUDE2_CLASSIFIER_ID:
       return Include2.class;
     default:
       throw new IllegalArgumentException(
           "The EClassifier '" + eClassifier + "' is not defined in this EPackage");
   }
 }
Example #29
0
 public static Type findTypeOf(MetaModelManager metaModelManager, EClassifier eClass) {
   Resource resource = eClass.eResource();
   if (resource != null) {
     Ecore2Pivot adapter = Ecore2Pivot.findAdapter(resource, metaModelManager);
     if (adapter != null) {
       Type type = adapter.getCreated(Type.class, eClass);
       if (type != null) {
         return type;
       }
     }
   }
   return null;
 }
  public void resolve(
      String identifier,
      org.emftext.language.petrinets.Setting container,
      org.eclipse.emf.ecore.EReference reference,
      int position,
      boolean resolveFuzzy,
      final org.emftext.language.petrinets.resource.petrinets.IPetrinetsReferenceResolveResult<
              org.eclipse.emf.ecore.EStructuralFeature>
          result) {
    EClassifier type;
    if (container.eContainer() instanceof ProducingArc) {
      ProducingArc arc = (ProducingArc) container.eContainer();
      type = FunctionCallAnalysisHelper.getInstance().getType(arc.getOutput());
    } else {
      ConstructorCall cc = (ConstructorCall) container.eContainer();
      type = cc.getType();
    }

    List<EStructuralFeature> candidates = new ArrayList<EStructuralFeature>();
    if (type != null && type instanceof EClass) {
      EClass c = (EClass) type;
      candidates.addAll(c.getEAllStructuralFeatures());
    } else if (type instanceof EDataType) {
      EAttribute dummy = EcoreFactory.eINSTANCE.createEAttribute();
      dummy.setName(type.getName());
      dummy.setEType(type);
      dummy.setUpperBound(1);
      dummy.setLowerBound(1);
      candidates.add(dummy);
    }
    for (EStructuralFeature eStructuralFeature : candidates) {
      if (resolveFuzzy) {
        result.addMapping(eStructuralFeature.getName(), eStructuralFeature);
      } else if (identifier.equals(eStructuralFeature.getName())) {
        result.addMapping(eStructuralFeature.getName(), eStructuralFeature);
      }
    }
  }