コード例 #1
0
 public EObject resolve(
     ParseTreeNode parseTreeNode,
     Object actual,
     Object value,
     IModelCreatingContext context,
     ReferenceBinding binding)
     throws ModelCreatingException, UnresolveableReferenceErrorException {
   String id = parseTreeNode.getNodeText();
   EObject resolution = null;
   if (actual instanceof PropertyBinding) {
     EClass correspondingMetaClass =
         SyntaxHelper.findCorrespondingElementBinding(
             getContainingRule((EObject) actual),
             (Syntax) context.getResource().getContents().get(0),
             new HashSet<Rule>());
     if (correspondingMetaClass == null) {
       new UnresolvableReferenceError(
               "Cannot resolve the meta-class for the given property", parseTreeNode)
           .throwIt();
       return null;
     }
     for (EStructuralFeature feature : correspondingMetaClass.getEAllStructuralFeatures()) {
       if (feature.getName().equals(id)) {
         resolution = feature;
       }
     }
     if (resolution == null) {
       new UnresolvableReferenceError(
               "Class "
                   + correspondingMetaClass.getName()
                   + " does not contain a structural feature with the given name",
               parseTreeNode)
           .throwIt();
       return null;
     }
   } else {
     try {
       resolution =
           resolve(
               DefaultIdentificationScheme.INSTANCE,
               id,
               null,
               binding.getProperty().getEType(),
               context.getAdapter(IEcoreModel.class).getAllContents());
     } catch (AmbiguousReferenceException ex) {
       context.addError(new Error(parseTreeNode.getPosition(), "Reference is ambiguous"));
     }
   }
   if (resolution != null) {
     return resolution;
   } else {
     new UnresolvableReferenceError("Could not resolve " + id + ".", parseTreeNode).throwIt();
     return null;
   }
 }
コード例 #2
0
 /** Is bound to the platform URI for the referenced meta-model. */
 public void addValue(
     ParseTreeNode parseTreeNode,
     Object actual,
     Object value,
     IModelCreatingContext context,
     CompositeBinding binding)
     throws ModelCreatingException {
   try {
     ((IEcoreModel) context.getAdapter(IEcoreModel.class)).loadModel((String) value);
     ((Syntax) actual).setMetaModelPlatformURI((String) value);
   } catch (Exception ex) {
     context.addError(
         new Error(
             parseTreeNode.getPosition(), "Cannot load ecore file: " + ex.getLocalizedMessage()));
   }
 }