コード例 #1
0
 public boolean wEquals(IEntity entity) {
   if (this == entity) return true;
   if (!wGetEntityDescriptor().equals(entity.wGetEntityDescriptor())) return false;
   try {
     return getName().wEquals(entity.wGet(TestsFeatureDescriptorEnum.name));
   } catch (Exception e) {
     return false;
   }
 }
コード例 #2
0
 private static IEntity createPattern(IEntity child) {
   IEntity pattern = EntityUtils.clone(child);
   EntityDescriptor<?> ed = pattern.wGetEntityDescriptor();
   for (FeatureDescriptor fd : ed.getEntityFeatureDescriptors()) {
     if (!name.equals(fd))
       pattern.wSet(
           fd, CommonsEntityAdapterFactory.createVariable(fd.getEntityDescriptor(), fd.getName()));
   }
   return pattern;
 }
コード例 #3
0
 public boolean isEmbedded(IEntity entity) {
   IEntity parent = entity.wGetParent();
   switch (parent.wGetEntityKind()) {
     case SIMPLE:
       return parent.wGetEntityDescriptor(entity).getEntityKind().isData();
     case COMPOSITE:
       return embedChildren(parent);
     default:
       return false;
   }
 }
コード例 #4
0
 public void wSet(int index, IEntity value) {
   switch (index) {
     case 0:
       setMetadata(value.wGetAdapter(ArtifactsEntityDescriptorEnum.Metadata));
       break;
     case 1:
       setProjects(value.wGetAdapter(ArtifactsEntityDescriptorEnum.Projects));
       break;
     default:
       throw new IllegalArgumentException();
   }
 }
コード例 #5
0
 public void wSet(int index, IEntity value) {
   switch (index) {
     case 0:
       setLabel(value.wGetAdapter(WorkflowsEntityDescriptorEnum.Label));
       break;
     case 1:
       setEventHandlers(value.wGetAdapter(WorkflowsEntityDescriptorEnum.EventHandlers));
       break;
     default:
       throw new IllegalArgumentException();
   }
 }
コード例 #6
0
 public void wSet(int index, IEntity value) {
   switch (index) {
     case 0:
       setException(value.wGetAdapter(JavaEntityDescriptorEnum.SingleVariableDeclaration));
       break;
     case 1:
       setBody(value.wGetAdapter(JavaEntityDescriptorEnum.Block));
       break;
     default:
       throw new IllegalArgumentException();
   }
 }
コード例 #7
0
 public void wSet(int index, IEntity value) {
   switch (index) {
     case 0:
       setLabel(value.wGetAdapter(FlowchartEntityDescriptorEnum.Text));
       break;
     case 1:
       setSource(value.wGetAdapter(FlowchartEntityDescriptorEnum.Node));
       break;
     case 2:
       setTarget(value.wGetAdapter(FlowchartEntityDescriptorEnum.Node));
       break;
     default:
       throw new IllegalArgumentException();
   }
 }
コード例 #8
0
  @Override
  public void visit(IsAssignableTo entity) {
    Name edName = entity.getDescriptorName();
    if (isLearning() && EntityUtils.isResolver(edName)) {
      IEntity subject = getBindings().wGet("evaluatedSubject");
      EntityDescriptor<?> ed =
          EntityUtils.hasParent(subject)
              ? subject.wGetParent().wGetEntityDescriptor(subject)
              : subject.wGetEntityDescriptor();
      Name learntEdName = TestsEntityFactory.instance.createName(ed.getName());

      putLearntEntity(edName, learntEdName);
      setResultVisitor(GenericTraversalFactory.instance.identity());
    } else super.visit(entity);
  }
コード例 #9
0
 public void wSet(int index, IEntity value) {
   switch (index) {
     case 0:
       setDescription(value.wGetAdapter(TestsEntityDescriptorEnum.Description));
       break;
     case 1:
       setName(value.wGetAdapter(TestsEntityDescriptorEnum.Name));
       break;
     case 2:
       setBody(value.wGetAdapter(TestsEntityDescriptorEnum.Statement));
       break;
     default:
       throw new IllegalArgumentException();
   }
 }
コード例 #10
0
ファイル: CommentImpl.java プロジェクト: wholeplatform/whole
 public void wSet(int index, IEntity value) {
   switch (index) {
     case 0:
       setComment(value.wGetAdapter(ChangesEntityDescriptorEnum.Text));
       break;
     case 1:
       setContent(value.wGetAdapter(ChangesEntityDescriptorEnum.Content));
       break;
     case 2:
       setRevisions(value.wGetAdapter(ChangesEntityDescriptorEnum.ChangeRevisions));
       break;
     default:
       throw new IllegalArgumentException();
   }
 }
コード例 #11
0
 public void visit(IEntity entity) {
   switch (entity.wGetEntityOrd()) {
     case SyntaxTreesEntityDescriptorEnum.Rule_ord:
       visit((Rule) entity);
       break;
     case SyntaxTreesEntityDescriptorEnum.Nodes_ord:
       visit((Nodes) entity);
       break;
     case SyntaxTreesEntityDescriptorEnum.Terminal_ord:
       visit((Terminal) entity);
       break;
     case SyntaxTreesEntityDescriptorEnum.Literal_ord:
       visit((Literal) entity);
       break;
     case SyntaxTreesEntityDescriptorEnum.Data_ord:
       visit((Data) entity);
       break;
     case SyntaxTreesEntityDescriptorEnum.Error_ord:
       visit((Error) entity);
       break;
     case SyntaxTreesEntityDescriptorEnum.Text_ord:
       visit((Text) entity);
       break;
     case SyntaxTreesEntityDescriptorEnum.Name_ord:
       visit((Name) entity);
       break;
   }
 }
コード例 #12
0
 public static String getPersistenceKitId(IEntity artifact) {
   IEntity metaData = artifact.wGet(metadata);
   if (!EntityUtils.isNotResolver(metaData)) return null;
   PersistenceKitId persistenceKitId = ((Metadata) metaData).getPersistenceKitId();
   return DataTypeUtils.getDataKind(persistenceKitId).isString()
       ? persistenceKitId.getValue()
       : null;
 }
コード例 #13
0
 public void wSet(int index, IEntity value) {
   switch (index) {
     case 0:
       setNamespaces(value.wGetAdapter(XsdEntityDescriptorEnum.NamespaceDecls));
       break;
     case 1:
       setId(value.wGetAdapter(XsdEntityDescriptorEnum.StringData));
       break;
     case 2:
       setAttributes(value.wGetAdapter(XsdEntityDescriptorEnum.Attributes));
       break;
     case 3:
       setName(value.wGetAdapter(XsdEntityDescriptorEnum.Name));
       break;
     case 4:
       setPublic(value.wGetAdapter(XsdEntityDescriptorEnum.StringData));
       break;
     case 5:
       setSystem(value.wGetAdapter(XsdEntityDescriptorEnum.AnyURI));
       break;
     case 6:
       setAnnotation(value.wGetAdapter(XsdEntityDescriptorEnum.Annotation));
       break;
     default:
       throw new IllegalArgumentException();
   }
 }
コード例 #14
0
 public void wSet(int index, IEntity value) {
   switch (index) {
     case 0:
       setJavadoc(value.wGetAdapter(JavaEntityDescriptorEnum.Javadoc));
       break;
     case 1:
       setModifiers(value.wGetAdapter(JavaEntityDescriptorEnum.ExtendedModifiers));
       break;
     case 2:
       setName(value.wGetAdapter(JavaEntityDescriptorEnum.SimpleName));
       break;
     case 3:
       setTypeParameters(value.wGetAdapter(JavaEntityDescriptorEnum.TypeParameters));
       break;
     case 4:
       setSuperclassType(value.wGetAdapter(JavaEntityDescriptorEnum.Type));
       break;
     case 5:
       setSuperInterfaceTypes(value.wGetAdapter(JavaEntityDescriptorEnum.Types));
       break;
     case 6:
       setBodyDeclarations(value.wGetAdapter(JavaEntityDescriptorEnum.BodyDeclarations));
       break;
     default:
       throw new IllegalArgumentException();
   }
 }
コード例 #15
0
ファイル: IncludeImpl.java プロジェクト: wholeplatform/whole
 public void wSet(int index, IEntity value) {
   switch (index) {
     case 0:
       setSource(value.wGetAdapter(ReusablesEntityDescriptorEnum.Source));
       break;
     default:
       throw new IllegalArgumentException();
   }
 }
コード例 #16
0
ファイル: CommentImpl.java プロジェクト: wholeplatform/whole
 public void wSet(int index, IEntity value) {
   switch (index) {
     case 0:
       setText(value.wGetAdapter(XmlEntityDescriptorEnum.CommentText));
       break;
     default:
       throw new IllegalArgumentException();
   }
 }
コード例 #17
0
 public void wSet(int index, IEntity value) {
   switch (index) {
     case 0:
       setExpression(value.wGetAdapter(MiniJavaEntityDescriptorEnum.Expression));
       break;
     default:
       throw new IllegalArgumentException();
   }
 }
コード例 #18
0
 public void visit(IEntity entity) {
   boolean fail = true;
   for (int i = startIndex(entity); i < endIndex(entity); i++)
     try {
       wGetVisitor1().visit(entity.wGet(i));
       fail = false;
     } catch (VisitException e) {
     }
   if (fail) throw new VisitException();
 }
コード例 #19
0
ファイル: UpdateImpl.java プロジェクト: wholeplatform/whole
 public void wSet(int index, IEntity value) {
   switch (index) {
     case 0:
       setTableName(value.wGetAdapter(SQLEntityDescriptorEnum.TableName));
       break;
     case 1:
       setSetClauses(value.wGetAdapter(SQLEntityDescriptorEnum.SetClauses));
       break;
     case 2:
       setFromClauses(value.wGetAdapter(SQLEntityDescriptorEnum.FromClauses));
       break;
     case 3:
       setWhereExpr(value.wGetAdapter(SQLEntityDescriptorEnum.SQLExpression));
       break;
     case 4:
       setLimit(value.wGetAdapter(SQLEntityDescriptorEnum.IntValue));
       break;
     default:
       throw new IllegalArgumentException();
   }
 }
コード例 #20
0
  public static IEntity cloneArtifact(IEntity artifact, IEntity appendChild) {
    IEntityFactory ef = GenericEntityFactory.instance(RegistryConfigurations.RESOLVER);
    EntityDescriptor<?> ed = artifact.wGetEntityDescriptor();

    IEntity newArtifact = ef.create(ed);
    for (FeatureDescriptor fd : ed.getEntityFeatureDescriptors()) {
      if (artifacts.equals(fd) || projects.equals(fd)) {
        IEntity composite = newArtifact.wGet(fd);
        if (appendChild != null) composite.wAdd(appendChild);
        else composite.wResolveWith(fd.getEntityDescriptor());
      } else newArtifact.wSet(fd, EntityUtils.clone(artifact.wGet(fd)));
    }
    return newArtifact;
  }
コード例 #21
0
  protected void addMissingVariables(IEntity contextModel, MissingVariableException e) {
    String[] varNames = e.getVariableNames();
    EnvironmentEntityFactory ef = EnvironmentEntityFactory.instance;

    for (String varName : varNames) {
      Name var = ef.createName(varName);
      IEntity find = Matcher.find(var, contextModel, false);
      if (find == null)
        contextModel.wAdd(
            ef.createBinding(
                var,
                CommonsEntityAdapterFactory.createResolver(EnvironmentEntityDescriptorEnum.Value)));
    }
  }
コード例 #22
0
 public static String getName(IEntity artifact) {
   switch (artifact.wGetEntityOrd()) {
     case ArtifactsEntityDescriptorEnum.FileArtifact_ord:
       FileName filename = ((FileArtifact) artifact).getName();
       if (DataTypeUtils.getDataKind(filename).isString()) return filename.wStringValue();
       else {
         NameWithExtension nameWithExtension = (NameWithExtension) filename;
         return nameWithExtension.getName().wStringValue()
             + FILE_NAME_SEPARATOR
             + nameWithExtension.getExtension().wStringValue();
       }
     case ArtifactsEntityDescriptorEnum.FolderArtifact_ord:
       return ((FolderArtifact) artifact).getName().wStringValue();
     case ArtifactsEntityDescriptorEnum.Project_ord:
       return ((Project) artifact).getName().wStringValue();
     case ArtifactsEntityDescriptorEnum.PackageArtifact_ord:
       return ((PackageArtifact) artifact).getName().wStringValue();
     case ArtifactsEntityDescriptorEnum.Workspace_ord:
       return WORKSPACEROOT_NAME;
     default:
       throw new IllegalArgumentException(
           "No name feature in \"" + artifact.toString() + "\" entity.");
   }
 }
コード例 #23
0
  public static void moveArtifactsIntoWorkspace(IEntity artifacts, IBindingManager bm) {
    switch (artifacts.wGetEntityDescriptor().getOrdinal()) {
      case ArtifactsEntityDescriptorEnum.Workspace_ord:
        Projects projectsPoint = (Projects) bm.wGet("projectsPoint");
        if (projectsPoint == null) throw new IllegalArgumentException("projectsPoint is undefined");

        IEntityIterator<Project> projectIterator = IteratorFactory.childIterator();
        projectIterator.reset(((Workspace) artifacts).getProjects());
        for (Project project : projectIterator) {
          projectIterator.remove();
          projectsPoint.add(project);
        }
        break;
      case ArtifactsEntityDescriptorEnum.Artifacts_ord:
        Artifacts packagesPoint = (Artifacts) bm.wGet("packagesPoint");
        if (packagesPoint == null) throw new IllegalArgumentException("packagesPoint is undefined");

        IEntityIterator<Artifact> artifactIterator = IteratorFactory.childIterator();
        artifactIterator.reset(artifacts);
        for (Artifact artifact : artifactIterator) {
          artifactIterator.remove();
          packagesPoint.add(artifact);
        }
        break;
      case ArtifactsEntityDescriptorEnum.PackageArtifact_ord:
      case ArtifactsEntityDescriptorEnum.FolderArtifact_ord:
        packagesPoint = (Artifacts) bm.wGet("packagesPoint");
        if (packagesPoint == null) throw new IllegalArgumentException("packagesPoint is undefined");

        packagesPoint.add((Artifact) artifacts);
        break;
      case ArtifactsEntityDescriptorEnum.FileArtifact_ord:
        Artifacts packageArtifactsPoint = (Artifacts) bm.wGet("packageArtifactsPoint");
        if (packageArtifactsPoint == null)
          throw new IllegalArgumentException("packageArtifactsPoint is undefined");

        packageArtifactsPoint.add((FileArtifact) artifacts);
        break;
    }
  }
コード例 #24
0
 public void wSet(int index, IEntity value) {
   switch (index) {
     case 0:
       setLabel(value.wGetAdapter(WorkflowsEntityDescriptorEnum.Label));
       break;
     case 1:
       setModel(value.wGetAdapter(WorkflowsEntityDescriptorEnum.Variable));
       break;
     case 2:
       setPersistence(value.wGetAdapter(WorkflowsEntityDescriptorEnum.Expression));
       break;
     case 3:
       setResourceKind(value.wGetAdapter(WorkflowsEntityDescriptorEnum.ResourceKind));
       break;
     case 4:
       setResource(value.wGetAdapter(WorkflowsEntityDescriptorEnum.Expression));
       break;
     case 5:
       setBindings(value.wGetAdapter(WorkflowsEntityDescriptorEnum.Assignments));
       break;
     default:
       throw new IllegalArgumentException();
   }
 }
コード例 #25
0
 protected int endIndex(IEntity entity) {
   return entity.wSize() + entity.wAdjacentSize();
 }
コード例 #26
0
  @Override
  public void visit(TestSuite entity) {
    if (isLearning()) {
      Map<IEntity, List<IEntity>> learntMap = getLearntMap();

      IEntity result = null;
      for (int cycle = 1; cycle <= learnCycles(); cycle++) {
        printWriter().printf("*** Learning cycle %d ***\n\n", cycle);
        ITransactionScope resettableScope = BindingManagerFactory.instance.createTransactionScope();
        getBindings().wEnterScope(resettableScope);
        try {
          getBindings().wDefValue("learnCycle", cycle);
          super.visit(entity);
          result = getBindings().getResult();
        } finally {
          resettableScope.rollback();
          getBindings().wExitScope();
        }
      }
      getBindings().setResult(result);

      FilterFamily filterFamily = getFilterFamily(entity);
      FilterRules filterRules = filterFamily.getFilterRules();
      FreshNameGenerator fnGen = new FreshNameGenerator();
      for (IEntity name :
          BehaviorUtils.compileAndLazyEvaluate(createFindAllFilterRuleNamesQuery(), filterFamily))
        fnGen.addBoundName(name.wStringValue());

      for (IEntity adapter : learntMap.keySet()) {
        List<IEntity> learntEntities = learntMap.get(adapter);

        IEntity value = learntEntities.get(0);
        if (learntEntities.size() > 1 && EntityUtils.isData(value)) {
          for (IEntity learntEntity : learntEntities) if (!learntEntity.wEquals(value)) continue;
        } else if (learntEntities.size() > 1) {
          for (IEntity learntEntity2 : learntEntities)
            if (EntityUtils.isData(learntEntity2)) continue;

          // generate filter rule
          FilterRule filterRule = TestsHelpers.createFilterRule(learntEntities);
          if (EntityUtils.isNotResolver(filterRule)) {
            String filterName;
            IEntity filterBody;
            if ((filterBody = Matcher.find(filterRule.getBody(), filterRules, false)) != null) {
              // try to reuse a generated filter
              filterName = ((FilterRule) filterBody.wGetParent()).getName().getValue();
            } else {
              // add the filter rule to the filter family
              filterName = fnGen.nextFreshName(GENERATED_FILTER_NAME);
              ITransactionScope resettableScope =
                  BindingManagerFactory.instance.createTransactionScope();
              getBindings().wEnterScope(resettableScope);
              try {
                getBindings().wDefValue("filterName", filterName);
                Matcher.substitute(filterRule, getBindings(), false);
                filterRules.wAdd(filterRule);
              } finally {
                resettableScope.rollback();
                getBindings().wExitScope();
              }
            }

            // wrap SubjectStatement with a UsingFilter
            ITransactionScope resettableScope =
                BindingManagerFactory.instance.createTransactionScope();
            getBindings().wEnterScope(resettableScope);
            try {
              SubjectStatement statement =
                  BehaviorUtils.evaluateFirstResult(
                      createFindAncestorSubjectStatement(), adapter, getBindings());
              UsingFilter usingFilter = createUsingFilter(filterName);
              statement.wGetParent().wSet(statement, usingFilter);
              usingFilter.setSubjectStatement(statement);
            } finally {
              resettableScope.rollback();
              getBindings().wExitScope();
            }
          }
        }

        TestsHelpers.replace(adapter, value);
      }
      // add the newly generated family
      if (!EntityUtils.hasParent(filterFamily) && !filterRules.wIsEmpty())
        entity.getFilterFamilies().wAdd(filterFamily);
    } else super.visit(entity);
  }
コード例 #27
0
 public static IEntity getChildren(IEntity entity) {
   return entity.wGet(entity.wContains(projects) ? projects : artifacts);
 }
コード例 #28
0
 public boolean embedChildren(IEntity entity) {
   return embedChildren(entity.wGetEntityDescriptor());
 }
コード例 #29
0
  @Override
  public void run(IOperationProgressMonitor pm)
      throws InvocationTargetException, InterruptedException {
    IEntity selfEntity =
        EntityUtils.mapEntity(selfModel, EntityUtils.clone(EntityUtils.getCompoundRoot(selfModel)));

    Set<String> initialNames = bm.wNames();

    pm.beginTask("Executing sample...", IOperationProgressMonitor.TOTAL_WORK);

    behaviorModel =
        BehaviorUtils.apply(
            "whole:org.whole.lang.ui.views:SamplePerspectiveSemantics#SampleViewBehavior",
            behaviorModel,
            bm);

    IEntity derivedModel = null;
    try {
      IEntityIterator<?> iterator = BehaviorUtils.lazyEvaluate(behaviorModel, 0, bm);
      iterator.setBindings(selfBindings);
      iterator.reset(selfEntity);

      if (iterator.getClass().equals(ConstantIterator.class)) {
        IEntity result = iterator.next();
        if (result == null || !EntityUtils.isData(result)) derivedModel = result;
        else {
          Object resultValue = result.wGetValue();
          derivedModel =
              IVisitor.class.isInstance(resultValue)
                  ? BindingManagerFactory.instance.createValue(
                      Matcher.match((IVisitor) resultValue, selfEntity))
                  : result;
        }
      } else if (iterator.hasNext()) {
        derivedModel = MiscEntityFactory.instance.createMisc(0);

        ITransactionScope transactionScope =
            BindingManagerFactory.instance.createTransactionScope();
        bm.wEnterScope(transactionScope);
        try {
          for (IEntity result : iterator) {
            transactionScope.commit();
            derivedModel.wAdd(
                GenericEntityFactory.instance.create(
                    CommonsEntityDescriptorEnum.SameStageFragment,
                    // CommonsEntityFactory.instance.createSameStageFragment(
                    EntityUtils.clone(result))); // TODO substitute with a no containment fragment
          }
        } finally {
          transactionScope.rollback();
          bm.wExitScope();
        }
      }
    } catch (MissingVariableException e) {
      addMissingVariables(contextModel, e);
    } catch (OperationCanceledException e) {
      // gracefully terminate execution
    } catch (Exception e) {
      if (e.getCause() instanceof MissingVariableException)
        addMissingVariables(contextModel, (MissingVariableException) e.getCause());
    } finally {
      pm.endTask();
    }

    IEntity variablesModel = null;
    if (derivedModel != null) {
      EnvironmentEntityFactory ef = EnvironmentEntityFactory.instance;
      variablesModel = ef.createBindings(0);
      for (String name : new TreeSet<String>(bm.wLocalNames()))
        if (!initialNames.contains(name))
          variablesModel.wAdd(
              ef.createBinding(ef.createName(name), ef.createValue(BindingUtils.wGet(bm, name))));

      final IEntity contents = derivedModel;
      final IEntity variables = variablesModel;
      context
          .get(UISynchronize.class)
          .asyncExec(
              new Runnable() {
                public void run() {
                  context.get(IEntityPartViewer.class).setContents(null, contents);
                  context
                      .get(IEventBroker.class)
                      .post(IUIConstants.TOPIC_UPDATE_VARIABLES, variables);
                }
              });
    }
  }