Пример #1
0
 private String fqn(EClassifier eClassifier) {
   String fqn =
       (eClassifier.getEPackage() != null)
           ? eClassifier.getEPackage().getName() + "." + eClassifier.getName()
           : eClassifier.getName();
   return fqn;
 }
 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();
   }
 }
    @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;
    }
Пример #4
0
 @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();
 }
Пример #5
0
  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;
  }
Пример #6
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);
   }
 }
  @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$
          }
        }
      }
    }
  }
Пример #8
0
  private EClassifier eClassifierForCustomClass(
      Type type, TypeReference typeReference, EPackage startEPackage) {
    Set<EPackage> allEPackages = new LinkedHashSet<EPackage>();
    collectAllEPackages(startEPackage, allEPackages);

    for (EPackage ePackage : allEPackages) {
      if (type instanceof ConcreteClassifier) {
        if (((ConcreteClassifier) type).getName().equals("EList")) {
          QualifiedTypeArgument typeArgument =
              (QualifiedTypeArgument)
                  ((NamespaceClassifierReference) typeReference)
                      .getClassifierReferences()
                      .get(0)
                      .getTypeArguments()
                      .get(0);
          type = typeArgument.getTypeReference().getTarget();
        }
        String className = eClassNameForCustomClassName(((ConcreteClassifier) type).getName());
        for (EClassifier eClassifier : ePackage.getEClassifiers()) {
          if (eClassifier.getName().equals(className)) {
            return eClassifier;
          }
        }
        if (className.equals("Class")) {
          className = "JavaClass"; // TODO type parameters
        }
        for (EClassifier typeFromEcore : EcorePackage.eINSTANCE.getEClassifiers()) {
          // so that not only String is mapped to EString but also EObject to EObject
          if (typeFromEcore.getName().equals(className)
              || typeFromEcore.getName().equals("E" + className)) {
            return typeFromEcore;
          }
        }
      } else if (type instanceof PrimitiveType) {
        String primitiveTypeName = "E" + type.eClass().getName();
        for (EClassifier typeFromEcore : EcorePackage.eINSTANCE.getEClassifiers()) {
          if (typeFromEcore.getName().equals(primitiveTypeName)) {
            return typeFromEcore;
          }
        }
      }
    }

    return null;
  }
 /**
  * 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);
   }
 }
 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 "?";
         }
       }
     }
   }
 }
Пример #11
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();
  }
Пример #12
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();
  }
Пример #13
0
 private boolean checkClassifier(
     String identifier,
     boolean resolveFuzzy,
     final IMecoreReferenceResolveResult<MType> result,
     EClassifier eClassifier,
     String prefix) {
   String name = prefix + eClassifier.getName();
   if (identifier.equals(name) || resolveFuzzy) {
     if (eClassifier instanceof EDataType) {
       result.addMapping(name, getMDataType((EDataType) eClassifier));
     } else if (eClassifier instanceof EClassifier) {
       result.addMapping(name, createMEcoreType((EClassifier) eClassifier));
     }
     if (!resolveFuzzy) {
       return true;
     }
   }
   return false;
 }
  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);
      }
    }
  }
    public EOperation define(EcoreEnvironment env) {
      List<Variable<EClassifier, EParameter>> argList =
          new ArrayList<Variable<EClassifier, EParameter>>();
      int pos = 0;
      for (EClassifier cls : fParamTypes) {
        Variable<EClassifier, EParameter> stringVariable =
            ExpressionsFactory.eINSTANCE.createVariable();

        String paramName = cls.getName();
        if (fParamNames != null) {
          paramName = fParamNames[pos++];
        }
        stringVariable.setName(paramName);
        stringVariable.setType(cls);
        argList.add(stringVariable);
      }

      EOperation result =
          env.defineOperation(
              fContextType,
              fName,
              fReturnType,
              argList,
              org.eclipse.ocl.ecore.EcoreFactory.eINSTANCE.createConstraint());

      CallHandlerAdapter.attach(result, fDispatcher);

      if (fIsDeprecated) {
        if (fDeprecatedBy != null) {
          QvtOperationalParserUtil.markAsDeprecated(result, fDeprecatedBy);
        } else {
          QvtOperationalParserUtil.markAsDeprecated(result);
        }
      }
      return result;
    }
 /**
  * Obtains the operations declared on the specified type.
  *
  * @param type The type which operation are sought.
  * @return The operations it declares. <code>null</code> if none.
  */
 public EList<EOperation> getExistingOperations(EClassifier type) {
   return getExistingOperations(type.getName());
 }
 protected boolean isMatchingClassifier(
     final EClassifier classifier, final String classifierQuery) {
   return matches(classifier.getName(), classifierQuery, true);
 }
  public void resolve(
      String lexem,
      org.eclipse.emf.ecore.EStructuralFeature feature,
      org.emftext.term.propositional.expression.resource.expression.IExpressionTokenResolveResult
          result,
      String suffix,
      String prefix,
      String escapeCharacter) {
    // Step 1: unescape keywords if required
    if (escapeKeywords && lexem.startsWith("_")) {
      for (String keyword :
          org.emftext.term.propositional.expression.resource.expression.grammar
              .ExpressionGrammarInformationProvider.INSTANCE.getKeywords()) {
        if (lexem.endsWith(keyword)) {
          String keywordPrefix = lexem.substring(0, lexem.length() - keyword.length());
          if (keywordPrefix.matches("_+")) {
            lexem = lexem.substring(1);
            break;
          }
        }
      }
    }

    // Step 2: remove prefix, suffix and unescape escaped suffixes
    // Step 2a: remove prefix
    if (prefix != null) {
      int count = prefix.length();
      lexem = lexem.substring(count);
    }
    // Step 2b: remove suffix
    if (suffix != null) {
      int count = suffix.length();
      lexem = lexem.substring(0, lexem.length() - count);
      // take care of the escape character (may be null)
      // Step 2c: replaced escaped suffixes and escaped escape sequences
      if (escapeCharacter != null) {
        lexem = lexem.replace(escapeCharacter + suffix, suffix);
        lexem = lexem.replace(escapeCharacter + escapeCharacter, escapeCharacter);
      }
    }

    // Step 3: convert text to Java object
    if (feature instanceof org.eclipse.emf.ecore.EAttribute) {
      org.eclipse.emf.ecore.EClassifier featureType = feature.getEType();
      if (featureType instanceof org.eclipse.emf.ecore.EEnum) {
        org.eclipse.emf.ecore.EEnumLiteral literal =
            ((org.eclipse.emf.ecore.EEnum) featureType).getEEnumLiteralByLiteral(lexem);
        if (literal != null) {
          result.setResolvedToken(literal.getInstance());
          return;
        } else {
          result.setErrorMessage(
              "Could not map lexem '" + lexem + "' to enum '" + featureType.getName() + "'.");
          return;
        }
      } else if (featureType instanceof org.eclipse.emf.ecore.EDataType) {
        try {
          result.setResolvedToken(
              org.eclipse.emf.ecore.util.EcoreUtil.createFromString(
                  (org.eclipse.emf.ecore.EDataType) featureType, lexem));
        } catch (Exception e) {
          result.setErrorMessage(
              "Could not convert '" + lexem + "' to '" + featureType.getName() + "'.");
        }
        String typeName = featureType.getInstanceClassName();
        if (typeName.equals("boolean") || java.lang.Boolean.class.getName().equals(typeName)) {
          String featureName = feature.getName();
          boolean featureNameMatchesLexem = featureName.equals(lexem);
          if (featureNameMatchesLexem) {
            result.setResolvedToken(true);
            return;
          }
          if (featureName.length() > 2 && featureName.startsWith("is")) {
            if ((featureName.substring(2, 3).toLowerCase() + featureName.substring(3))
                .equals(lexem)) {
              result.setResolvedToken(true);
              return;
            }
          }
          if (Boolean.parseBoolean(lexem)) {
            result.setResolvedToken(true);
            return;
          }
        }
      } else {
        assert false;
      }
    } else {
      result.setResolvedToken(lexem);
      return;
    }
  }
Пример #19
0
  /** See test description here: {@link InternalRefTest}. */
  @Test
  public void testInternalRef() {
    // get creators
    final ISymbolicReferenceCreator symrefCreator =
        ExtensionManager.getAllSymbolicReferenceCreators().get("Condition-based");
    final IModelDescriptorCreator descriptorCreator =
        ExtensionManager.getAllModelDescriptorCreators().get("Default");
    final String info =
        "symrefCreator: "
            + symrefCreator.getLabel()
            + ", descriptorCreator: "
            + descriptorCreator.getLabel();

    // create mpatch
    final MPatchModel mpatch =
        CompareTestHelper.getMPatchFromUris(
            TestConstants.INTERNAL_REF_URI2,
            TestConstants.INTERNAL_REF_URI1,
            symrefCreator,
            descriptorCreator);

    doTransformations(mpatch);
    modifyDiff(mpatch);

    // resolve references to other model
    final EPackage applyModel =
        (EPackage)
            CompareTestHelper.loadModel(TestConstants.INTERNAL_REF_URI3, new ResourceSetImpl())
                .get(0);
    final ResolvedSymbolicReferences resolvedReferences =
        CompareTestHelper.resolveReferences(mpatch, applyModel, info);

    // apply differences
    final Map<Integer, Boolean> options = new HashMap<Integer, Boolean>();
    options.put(IMPatchApplication.OPTION_STORE_BINDING, true);
    final MPatchApplicationResult result =
        TestConstants.DIFF_APPLIER.applyMPatch(resolvedReferences, options);

    // check application status
    assertTrue("Some changes failed to apply: " + result.failed, result.failed.isEmpty());
    assertTrue(
        "Cross reference restoring failed for: " + result.crossReferences,
        result.crossReferences.isEmpty());
    assertEquals(
        "Application result was not successful!",
        MPatchApplicationResult.ApplicationStatus.SUCCESSFUL,
        result.status);

    // check model!
    assertEquals(
        "Different number of elements in root package than expected: "
            + applyModel.getEClassifiers(),
        3,
        applyModel.getEClassifiers().size());
    assertEquals(
        "Different number of elements in sub package than expected: "
            + applyModel.getESubpackages().get(0).getEClassifiers(),
        1,
        applyModel.getESubpackages().get(0).getEClassifiers().size());
    for (EClassifier classifier : applyModel.getEClassifiers()) {
      if (!classifier.getName().equals("C")) {
        final EClass aClass = (EClass) classifier;
        assertEquals(
            "Cross references (eSuperType) does not refer to the two new classes 'C', but: "
                + aClass.getESuperTypes(),
            2,
            aClass.getESuperTypes().size());
      }
    }
  }