示例#1
0
 public static RuleNames tryGetRuleNames(AbstractRule rule) {
   Adapter adapter = (Adapter) EcoreUtil.getAdapter(rule.eAdapters(), RuleNames.class);
   if (adapter == null) {
     return null;
   }
   return adapter.getRuleNames();
 }
示例#2
0
 private void installAdapterIfMissing(Adapter adapter, EObject context) {
   if (EcoreUtil.getAdapter(context.eAdapters(), RuleNames.class) == null) {
     context.eAdapters().add(adapter);
   } else {
     throw new IllegalStateException("Duplicate adapter");
   }
 }
示例#3
0
 public static RuleNames getRuleNames(AbstractRule rule) {
   Adapter adapter = (Adapter) EcoreUtil.getAdapter(rule.eAdapters(), RuleNames.class);
   if (adapter == null) {
     throw new IllegalStateException("Cannot find adapter");
   }
   return adapter.getRuleNames();
 }
 @Override
 public List<EObject> getLinkedObjects(EObject context, EReference ref, INode node)
     throws IllegalNodeException {
   try {
     depth++;
     String text = getText(node);
     boolean traceLookup = BaseScopeProvider.LOOKUP.isActive();
     if ((text == null) || "".equals(text)) { // Avoid IQualifiedNameConverter IAE
       if (traceLookup) {
         BaseScopeProvider.LOOKUP.println("" + depth + " Lookup null");
       }
       return Collections.emptyList();
     }
     IScope scope = getScope(context, ref);
     if (traceLookup) {
       //				EObject target = ((ScopeView)scope).getTarget();
       //				String inString = target instanceof ElementCS ? ((ElementCS)target).getSignature() :
       // target.toString();
       //				BaseScopeProvider.LOOKUP.println("" + depth + " Lookup " + text + " in " + inString);
       BaseScopeProvider.LOOKUP.println("" + depth + " Lookup " + text);
     }
     if (scope == null) {
       return Collections.emptyList();
     }
     QualifiedName qualifiedName = QualifiedName.create(text);
     List<EObject> linkedObjects = lookUp(scope, qualifiedName);
     if ((linkedObjects.size() <= 0) && text.startsWith("_")) { // Deprecated compatibility
       linkedObjects = lookUp(scope, QualifiedName.create(text.substring(1)));
     }
     if (traceLookup) {
       BaseScopeProvider.LOOKUP.println("" + depth + " Lookup " + text + " failed");
     }
     List<Adapter> eAdapters = context.eAdapters();
     Adapter adapter = EcoreUtil.getAdapter(eAdapters, ExceptionAdapter.class);
     if (adapter != null) {
       eAdapters.remove(adapter);
     }
     if (linkedObjects.size() > 1) {
       if (DEBUG_RETRY.isActive()) {
         scope.getElements(qualifiedName);
       }
       AmbiguitiesAdapter.setAmbiguities(context, linkedObjects);
       return Collections.emptyList();
     }
     if (linkedObjects.size() <= 0) {
       if (DEBUG_RETRY.isActive()) {
         scope.getElements(qualifiedName);
       }
     }
     return linkedObjects;
   } catch (IllegalLibraryException e) {
     context.eAdapters().add(new ExceptionAdapter(e));
     return Collections.emptyList();
   } finally {
     depth--;
   }
 }
 public static void markFeatureAsStatic(EStructuralFeature eFeature) {
   IntermediateStaticFieldAdapter adapter =
       (IntermediateStaticFieldAdapter)
           EcoreUtil.getAdapter(eFeature.eAdapters(), IntermediateStaticFieldAdapter.class);
   if (adapter == null) {
     adapter = new IntermediateStaticFieldAdapter();
     eFeature.eAdapters().add(adapter);
   }
 }
示例#6
0
 public static RuleNames getRuleNames(Grammar grammar, boolean cache) {
   if (cache) {
     Adapter adapter = (Adapter) EcoreUtil.getAdapter(grammar.eAdapters(), RuleNames.class);
     if (adapter == null) {
       return new RuleNames(grammar, true);
     }
     return adapter.getRuleNames();
   }
   return new RuleNames(grammar, false);
 }
示例#7
0
  /**
   * This allows to get the {@link ECPContainer} from a {@link Notifier} using the EcoreUtil. This
   * first gets the {@link ECPModelContextAdapter} and from it it gets the {@link ECPContainer}.
   *
   * @param notifier the {@link Notifier} to get the {@link ECPContainer} from
   * @return the {@link ECPContainer} registered as an Adapter on this {@link Notifier} or null
   */
  protected final ECPContainer getModelContextFromAdapter(Notifier notifier) {
    final ECPModelContextAdapter adapter =
        (ECPModelContextAdapter)
            EcoreUtil.getAdapter(notifier.eAdapters(), ECPModelContextAdapter.class);
    if (adapter != null) {
      return adapter.getContext();
    }

    return null;
  }
 @Override
 public String getDocumentation(EObject o) {
   if (o == null) return null;
   if (o instanceof JvmIdentifiableElement) {
     DocumentationAdapter adapter =
         (DocumentationAdapter) EcoreUtil.getAdapter(o.eAdapters(), DocumentationAdapter.class);
     if (adapter != null) return adapter.getDocumentation();
   }
   return super.getDocumentation(o);
 }
 /**
  * getParentType - return the Class which corresponds to our parent JavaClass we're going to do
  * this a lot, so cache it.
  */
 protected Class getParentType() {
   if (parentType == null) {
     Field targetField = (Field) getTarget();
     JavaClass parentJavaClass = targetField.getJavaClass();
     JavaClassJDKAdaptor pa =
         (JavaClassJDKAdaptor)
             EcoreUtil.getAdapter(parentJavaClass.eAdapters(), ReadAdaptor.TYPE_KEY);
     if (pa != null) parentType = pa.getSourceType();
   }
   return parentType;
 }
示例#10
0
    @Override
    public void eSet(EStructuralFeature feature, Object newValue) {
      IntermediateStaticFieldAdapter adapter =
          (IntermediateStaticFieldAdapter)
              EcoreUtil.getAdapter(feature.eAdapters(), IntermediateStaticFieldAdapter.class);
      if (adapter != null) {
        adapter.eSet(feature, newValue);
      }

      super.eSet(feature, newValue);
    }
示例#11
0
    @Override
    public Object eGet(EStructuralFeature feature, boolean resolve, boolean coreType) {
      IntermediateStaticFieldAdapter adapter =
          (IntermediateStaticFieldAdapter)
              EcoreUtil.getAdapter(feature.eAdapters(), IntermediateStaticFieldAdapter.class);
      if (adapter != null) {
        return adapter.eGet(feature);
      }

      return super.eGet(feature, resolve, coreType);
    }
 private static boolean isConstructorCS(CSTNode syntaxElement) {
   if (false == syntaxElement.eContainer() instanceof InstantiationExpCS) {
     return false;
   }
   InstantiationExpCS constructorCS = (InstantiationExpCS) syntaxElement.eContainer();
   if (false == constructorCS.getAst() instanceof InstantiationExp) {
     return false;
   }
   InstantiationExp instExp = (InstantiationExp) constructorCS.getAst();
   Adapter adapter = EcoreUtil.getAdapter(instExp.eAdapters(), ConstructorOperationAdapter.class);
   return adapter != null
       && ((ConstructorOperationAdapter) adapter).getReferredConstructor() != null;
 }
示例#13
0
 public static <T> T getAdapter(Class<T> adapterClass, List<Adapter> eAdapters) {
   Adapter adapter = EcoreUtil.getAdapter(eAdapters, adapterClass);
   if (adapter == null) {
     return null;
   }
   if (!adapterClass.isAssignableFrom(adapter.getClass())) {
     throw new ClassCastException(
         adapter.getClass().getName() + " is not assignable to " + adapterClass.getName());
   }
   @SuppressWarnings("unchecked")
   T castAdapter = (T) adapter;
   return castAdapter;
 }
示例#14
0
  public void doInstancePropertyInit(Object instance, QvtOperationalEvaluationVisitor evalVisitor) {
    if (false == instance instanceof EObject) {
      return;
    }
    EObject eInstance = (EObject) instance;

    EClass intermediateClass = eInstance.eClass();

    Map<EStructuralFeature, OCLExpression<EClassifier>> clsFeatures =
        myClassifierInitializations.get(intermediateClass);
    if (clsFeatures == null) {
      return;
    }
    for (EStructuralFeature eFeature : intermediateClass.getEAllStructuralFeatures()) {
      IntermediateStaticFieldAdapter adapter =
          (IntermediateStaticFieldAdapter)
              EcoreUtil.getAdapter(eFeature.eAdapters(), IntermediateStaticFieldAdapter.class);
      if (adapter != null && adapter.isInitialized()) {
        continue;
      }

      OCLExpression<EClassifier> expression = clsFeatures.get(eFeature);

      Object evalResult = expression != null ? evalVisitor.visitExpression(expression) : null;

      if (evalResult == null) {
        // no init expression specified for a single-valued feature, or init expression evaluated to
        // null
        EClassifier featureType =
            evalVisitor.getEnvironment().getUMLReflection().getOCLType(eFeature);
        evalResult =
            EvaluationUtil.createInitialValue(
                featureType,
                evalVisitor.getEnvironment().getOCLStandardLibrary(),
                evalVisitor.getEvaluationEnvironment());
      }

      // temporary switch off read-only property
      boolean isChangeable = eFeature.isChangeable();
      eFeature.setChangeable(true);

      boolean isUndefined =
          QvtOperationalUtil.isUndefined(evalResult, evalVisitor.getEvaluationEnvironment());
      evalVisitor
          .getOperationalEvaluationEnv()
          .callSetter(eInstance, eFeature, evalResult, isUndefined, true);

      eFeature.setChangeable(isChangeable);
    }
  }
 private static void addResourceTrackingModificationAdapter(
     TransactionalEditingDomain editingDomain) {
   EList<Adapter> adapters = editingDomain.getResourceSet().eAdapters();
   Adapter adapter = EcoreUtil.getAdapter(adapters, SetTrackModificationAdapter.class);
   if (adapter == null) {
     final NotificationFilter diagramResourceModifiedFilter =
         NotificationFilter.createNotifierFilter(editingDomain.getResourceSet())
             .and(NotificationFilter.createEventTypeFilter(Notification.ADD))
             .and(
                 NotificationFilter.createFeatureFilter(
                     ResourceSet.class, ResourceSet.RESOURCE_SET__RESOURCES));
     adapters.add(new SetTrackModificationAdapter(diagramResourceModifiedFilter));
   }
 }
示例#16
0
 public static boolean isFeatureStatic(EStructuralFeature eFeature) {
   return EcoreUtil.getAdapter(eFeature.eAdapters(), IntermediateStaticFieldAdapter.class) != null;
 }
示例#17
0
文件: FSMUtil.java 项目: merks/cdo
 private static CDOLegacyAdapter getLegacyAdapter(EList<Adapter> adapters) {
   return (CDOLegacyAdapter) EcoreUtil.getAdapter(adapters, CDOLegacyAdapter.class);
 }