コード例 #1
0
  public static List<EObject> findMessageReferences(Diagram diagram, Message message) {
    List<EObject> result = new ArrayList<EObject>();
    Definitions definitions = ModelUtil.getDefinitions(message);
    TreeIterator<EObject> iter = definitions.eAllContents();
    while (iter.hasNext()) {
      EObject o = iter.next();
      if (o instanceof MessageFlow) {
        if (((MessageFlow) o).getMessageRef() == message) {
          result.add(o);
        }
      }
      if (o instanceof MessageEventDefinition) {
        if (((MessageEventDefinition) o).getMessageRef() == message) {
          result.add(o);
        }
      }
      if (o instanceof Operation) {
        if (((Operation) o).getInMessageRef() == message
            || ((Operation) o).getOutMessageRef() == message) {
          result.add(o);
        }
      }
      if (o instanceof ReceiveTask) {
        if (((ReceiveTask) o).getMessageRef() == message) {
          result.add(o);
        }
      }
      if (o instanceof SendTask) {
        if (((SendTask) o).getMessageRef() == message) {
          result.add(o);
        }
      }
      if (o instanceof CorrelationPropertyRetrievalExpression) {
        if (((CorrelationPropertyRetrievalExpression) o).getMessageRef() == message) {
          result.add(o);
        }
      }
    }

    if (diagram != null) {
      iter = diagram.eResource().getAllContents();
      while (iter.hasNext()) {
        EObject o = iter.next();
        if (o instanceof ContainerShape && !isLabelShape((ContainerShape) o)) {
          if (BusinessObjectUtil.getFirstBaseElement((ContainerShape) o) == message) result.add(o);
        }
      }
    }
    return result;
  }
コード例 #2
0
ファイル: LanguageConfig.java プロジェクト: huibo-shi/xtext
  /** @since 2.3 */
  protected void validateGrammar(Grammar grammar) {
    validateAllImports(grammar);
    EValidator validator = EValidator.Registry.INSTANCE.getEValidator(XtextPackage.eINSTANCE);
    if (validator != null) {
      DiagnosticChain chain =
          new DiagnosticChain() {

            @Override
            public void add(Diagnostic diagnostic) {
              if (diagnostic.getSeverity() == Diagnostic.ERROR) {
                if (diagnostic.getException() == null)
                  throw new IllegalStateException(diagnostic.getMessage());
                else
                  throw new IllegalStateException(
                      diagnostic.getMessage(), diagnostic.getException());
              }
            }

            @Override
            public void addAll(Diagnostic diagnostic) {
              add(diagnostic);
            }

            @Override
            public void merge(Diagnostic diagnostic) {
              throw new UnsupportedOperationException();
            }
          };
      validator.validate(grammar, chain, null);
      TreeIterator<EObject> iterator = grammar.eAllContents();
      while (iterator.hasNext())
        validator.validate(iterator.next(), chain, new HashMap<Object, Object>());
    }
  }
コード例 #3
0
ファイル: ValidityModel.java プロジェクト: ewillink/ocl
 //
 // Create the ResultValidatableNode,ResultConstrainingNode cross-linkage for all
 // validateableObject,constraint pairs.
 //
 protected void createResults(@NonNull Set<Resource> resources) {
   for (Resource resource : resources) {
     System.out.println("createResults " + resource.getURI());
     System.out.println(resource);
     for (TreeIterator<EObject> tit = resource.getAllContents(); tit.hasNext(); ) {
       @SuppressWarnings("null")
       @NonNull
       EObject eObject = tit.next();
       EClass eClass = eObject.eClass();
       EAnnotation eAnnotation = eClass.getEAnnotation("http://www.eclipse.org/uml2/2.0.0/UML");
       if ((eAnnotation != null)
           && (eAnnotation.getReferences().size() > 0)) { // Stereotype application
         EObject umlClass = eAnnotation.getReferences().get(0);
         if (umlClass != null) {
           createResultNodes(eObject, getURI(umlClass));
           //						eClass = null;
         }
       } else if (eClass != null) {
         for (@SuppressWarnings("null") @NonNull URI aType : getTypeClosure(eClass)) {
           //				System.out.println("  ... " + getLabel(eObject) + " " + getLabel(aType));
           createResultNodes(eObject, aType);
         }
       }
     }
   }
 }
コード例 #4
0
 @Override
 public String toString() {
   List<ITextSegment> list = toTokenAndGapList();
   if (list.isEmpty()) return "(empty)";
   Multimap<IHiddenRegion, IEObjectRegion> hiddens = LinkedListMultimap.create();
   List<String> errors = Lists.newArrayList();
   ITextRegionAccess access = list.get(0).getTextRegionAccess();
   TreeIterator<EObject> all = EcoreUtil2.eAll(access.regionForRootEObject().getSemanticElement());
   while (all.hasNext()) {
     EObject element = all.next();
     IEObjectRegion obj = access.regionForEObject(element);
     if (obj == null) continue;
     IHiddenRegion previous = obj.getPreviousHiddenRegion();
     IHiddenRegion next = obj.getNextHiddenRegion();
     if (previous == null)
       errors.add("ERROR: " + EmfFormatter.objPath(element) + " has no leading HiddenRegion.");
     else hiddens.put(previous, obj);
     if (previous != next) {
       if (next == null)
         errors.add("ERROR: " + EmfFormatter.objPath(element) + " has no trailing HiddenRegion.");
       else hiddens.put(next, obj);
     }
   }
   TextRegionListToString result = new TextRegionListToString();
   if (!hideColumnExplanation) {
     result.add("Columns: 1:offset 2:length 3:kind 4: text 5:grammarElement", false);
     result.add("Kind: H=IHiddenRegion S=ISemanticRegion B/E=IEObjectRegion", false);
     result.add("", false);
   }
   for (String error : errors) result.add(error, false);
   int indentation = 0;
   for (ITextSegment region : list) {
     List<IEObjectRegion> previous = Lists.newArrayList();
     List<IEObjectRegion> next = Lists.newArrayList();
     List<String> middle = Lists.newArrayList(toString(region));
     if (region instanceof IHiddenRegion) {
       Collection<IEObjectRegion> found = hiddens.get((IHiddenRegion) region);
       for (IEObjectRegion obj : found) {
         boolean p = obj.getNextHiddenRegion().equals(region);
         boolean n = obj.getPreviousHiddenRegion().equals(region);
         if (p && n) middle.add(EMPTY_TITLE + "Semantic " + toString(obj));
         else if (p) previous.add(obj);
         else if (n) next.add(obj);
       }
       Collections.sort(previous, AstRegionComparator.CHILDREN_FIRST);
       Collections.sort(next, AstRegionComparator.CONTAINER_FIRST);
     }
     for (IEObjectRegion obj : previous) {
       indentation--;
       result.add(indent(indentation) + EOBJECT_END_PADDED + toString(obj));
     }
     String indent = indent(indentation);
     result.add(region, indent + Joiner.on("\n").join(middle).replace("\n", "\n" + indent));
     for (IEObjectRegion obj : next) {
       result.add(indent(indentation) + EOBJECT_BEGIN_PADDED + toString(obj));
       indentation++;
     }
   }
   return result.toString();
 }
コード例 #5
0
ファイル: OCLConnector.java プロジェクト: ranass/ReqCycle
  protected void fillRequirements(RequirementSource requirementSource) throws Exception {
    requirementSource.clearContent();
    Collection<MappingElement> mapping = requirementSource.getMappings();
    ResourceSet resourceSet = new ResourceSetImpl();

    String repositoryUri = requirementSource.getRepositoryUri();

    Resource resource =
        resourceSet.getResource(URI.createPlatformResourceURI(repositoryUri, true), true);
    OCLEvaluator evaluator =
        ZigguratOCLPlugin.compileOCL(
            resourceSet, URI.createPlatformResourceURI(bean.getOclUri(), true));

    TreeIterator<EObject> contents = resource.getAllContents();
    Collection<IRequirementType> requirementTypes = bean.getDataPackage().getRequirementTypes();
    while (contents.hasNext()) {
      EObject eObject = contents.next();
      for (IRequirementType reqType : requirementTypes) {
        if (OCLUtilities.isDataType(evaluator, eObject, reqType)) {
          AbstractElement requirement = createRequirement(evaluator, mapping, eObject, reqType);
          dataManager.addElementsToSource(requirementSource, requirement);
        }
      }
    }
  }
コード例 #6
0
  public void testMappedEObjectMetrics() throws IOException {
    UMLData umlData = new UMLData(2000);
    Resource leftUML = umlData.getLeftUML();

    final Metric<EObject> metric = new EObjectFullMetric();
    FastMap<EObject> fastMap =
        new FastMap<EObject>(3) {
          @Override
          protected double distance(EObject target1, EObject target2) {
            return metric.distance(target1, target2);
          }
        };

    TreeIterator<EObject> it = leftUML.getAllContents();
    while (it.hasNext()) {
      EObject object = it.next();
      fastMap.add(object);
    }
    ;

    Space<EObject> space = new TreeBackedSpace<EObject>();
    fastMap.map(true, space);

    List<double[]> coordinates = new ArrayList<double[]>();

    int count = 0;
    for (EObject object : space) {
      if (++count % 100 == 0) coordinates.add(space.getCoordinates(object));
    }

    checkNormalized(coordinates, EuclideanMetric.INSTANCE);
    checkSymmetric(coordinates, EuclideanMetric.INSTANCE);
  }
コード例 #7
0
 @Override
 public boolean canDelete(IDeleteContext context) {
   // Participant bands in a ChoreographyTask only be "deleted" (from the model)
   // if there are no other references to the participant; but they can be "removed"
   // (from the ChoreographyTask's participantRef list) at any time.
   // @see RemoveChoreographyParticipantFeature
   PictogramElement pe = context.getPictogramElement();
   if (ChoreographyUtil.isChoreographyParticipantBand(pe)) {
     int referenceCount = 0;
     Participant participant = BusinessObjectUtil.getFirstElementOfType(pe, Participant.class);
     Definitions definitions = ModelUtil.getDefinitions(participant);
     TreeIterator<EObject> iter = definitions.eAllContents();
     while (iter.hasNext()) {
       EObject o = iter.next();
       for (EReference reference : o.eClass().getEAllReferences()) {
         if (!reference.isContainment() && !(o instanceof DiagramElement)) {
           if (reference.isMany()) {
             List list = (List) o.eGet(reference);
             for (Object referencedObject : list) {
               if (referencedObject == participant) ++referenceCount;
             }
           } else {
             Object referencedObject = o.eGet(reference);
             if (referencedObject == participant) ++referenceCount;
           }
         }
       }
     }
     return referenceCount <= 1;
   }
   return true;
 }
コード例 #8
0
  public void enrich(EObject model, Element e) {
    String defaultNamespace = e.getAttribute("base");
    sigNodeMap = createMapping(theoryXPath, e, "name");
    viewNodeMap = createMapping(viewXPath, e, "name");
    sigObjMap = new HashMap<String, EObject>();
    viewObjMap = new HashMap<String, EObject>();

    TreeIterator<EObject> iter = model.eAllContents();
    while (iter.hasNext()) {
      EObject obj = iter.next();
      if (obj instanceof signatureDeclaration) {
        signatureDeclaration sig = (signatureDeclaration) obj;
        if (sigNodeMap.containsKey(sig.getSigName())) {
          sigObjMap.put(sig.getSigName(), obj);
          Element elem = sigNodeMap.get(sig.getSigName());
          String bs = defaultNamespace;
          if (elem.hasAttribute("base")) bs = elem.getAttribute("base");
          sig.setFullURI(bs + "?" + sig.getSigName());
          syncConstructs(sig.getDefs().getConstucts(), elem);
        }
      }
      if (obj instanceof viewDeclaration) {
        viewDeclaration view = (viewDeclaration) obj;
        if (viewNodeMap.containsKey(view.getViewID())) {
          Element elem = sigNodeMap.get(view.getViewID());
          viewObjMap.put(view.getViewID(), obj);
          String bs = defaultNamespace;
          if (elem.hasAttribute("base")) bs = elem.getAttribute("base");
          view.setFullURI(bs + "?" + view.getViewID());
          syncConstructs(view.getViewDefs().getConstucts(), elem);
        }
      }
    }
  }
コード例 #9
0
 protected List<EPackageInfo> createEPackageInfosFromGenModel(
     URI genModelURI, Resource genModelResource) {
   //		ResourceSet resourceSet = createResourceSet(genModelURI);
   //		Resource resource = resourceSet.getResource(genModelURI, true);
   List<EPackageInfo> ePackageInfos = Lists.newArrayList();
   for (TreeIterator<EObject> i = genModelResource.getAllContents(); i.hasNext(); ) {
     EObject next = i.next();
     if (next instanceof GenPackage) {
       GenPackage genPackage = (GenPackage) next;
       EPackage ePackage = genPackage.getEcorePackage();
       URI importURI;
       if (ePackage.eResource() == null) {
         importURI = URI.createURI(ePackage.getNsURI());
       } else {
         importURI = ePackage.eResource().getURI();
       }
       EPackageInfo ePackageInfo =
           new EPackageInfo(
               ePackage,
               importURI,
               genModelURI,
               genPackage.getQualifiedPackageInterfaceName(),
               genPackage.getGenModel().getModelPluginID());
       ePackageInfos.add(ePackageInfo);
     } else if (!(next instanceof GenModel)) {
       i.prune();
     }
   }
   return ePackageInfos;
 }
コード例 #10
0
 /**
  * Gather the resources of the specified type that match the current pattern string.
  *
  * @param resources resources that match
  */
 private void getMatchingResources(final ArrayList resources) {
   for (TreeIterator iterator = resourceSet.getAllContents(); iterator.hasNext(); ) {
     Object object = iterator.next();
     if (typeClass.isAssignableFrom(object.getClass())
         && match(((ENamedElement) object).getName())) resources.add(object);
   }
 }
コード例 #11
0
 @SuppressWarnings("unchecked")
 protected void createEntryExitPoints(Diagram subdiagram) {
   TreeIterator<EObject> eAllContents = subdiagram.eAllContents();
   List<Edge> entryPointsToCreate = new ArrayList<Edge>();
   List<Edge> exitPointstoCreate = new ArrayList<Edge>();
   while (eAllContents.hasNext()) {
     EObject next = eAllContents.next();
     if (next instanceof View) {
       EList<Edge> targetEdges = ((View) next).getTargetEdges();
       for (Edge edge : targetEdges) {
         if (!EcoreUtil.isAncestor(subdiagram, edge.getSource())) entryPointsToCreate.add(edge);
       }
       EList<Edge> sourceEdges = ((View) next).getSourceEdges();
       for (Edge edge : sourceEdges) {
         if (!EcoreUtil.isAncestor(subdiagram, edge.getTarget())) exitPointstoCreate.add(edge);
       }
     }
   }
   for (Edge edge : entryPointsToCreate) {
     createEntryPoint(edge, subdiagram);
   }
   for (Edge edge : exitPointstoCreate) {
     createExitPoint(edge, subdiagram);
   }
 }
コード例 #12
0
  public Collection<StructuredType> getAllBindableElements(ServiceDTO dto) {
    // Collect all entities and dtos
    Collection<StructuredType> bindableElements = new ArrayList<StructuredType>();

    // First, get all semantic resources in session
    Collection<Resource> semanticResources = EcoreService.getAllSemanticResourcesInSession(dto);

    for (Resource resource : semanticResources) {
      TreeIterator<EObject> iterator = EcoreUtil.getAllContents(resource, true);
      while (iterator.hasNext()) {
        EObject eObject = (EObject) iterator.next();
        if (eObject instanceof ServiceDTO || eObject instanceof Entity) {
          if (!eObject.equals(dto)) {
            bindableElements.add((StructuredType) eObject);
          }
        } else if (!(eObject instanceof Root
            || eObject instanceof Block
            || eObject instanceof org.obeonetwork.dsl.overview.Root
            || eObject instanceof System
            || eObject instanceof DTORegistry
            || eObject instanceof Category)) {
          iterator.prune();
        }
      }
    }

    return bindableElements;
  }
コード例 #13
0
  private static int numberOfStatusObjects(
      org.eclipse.epp.internal.logging.aeri.ui.model.Status status) {
    final AtomicInteger counter = new AtomicInteger();
    ModelSwitch<AtomicInteger> visitor =
        new ModelSwitch<AtomicInteger>() {

          @Override
          public AtomicInteger caseStatus(
              org.eclipse.epp.internal.logging.aeri.ui.model.Status object) {
            counter.incrementAndGet();
            return counter;
          }

          @Override
          public AtomicInteger caseThrowable(Throwable object) {
            return counter;
          }
        };

    visitor.doSwitch(status);
    for (TreeIterator<EObject> it = getAllContents(status, true); it.hasNext(); ) {
      visitor.doSwitch(it.next());
    }
    return counter.get();
  }
コード例 #14
0
 @Check(CheckType.FAST)
 public void checkValueReferenedBeforeDefined(Scope scope) {
   EList<Declaration> declarations = scope.getDeclarations();
   Set<QualifiedName> defined = Sets.newHashSet();
   for (Declaration declaration : declarations) {
     if (declaration instanceof VariableDefinition) {
       VariableDefinition definition = (VariableDefinition) declaration;
       if (!definition.isConst()) return;
       Expression initialValue = definition.getInitialValue();
       List<Expression> toCheck = Lists.newArrayList(initialValue);
       TreeIterator<EObject> eAllContents = initialValue.eAllContents();
       while (eAllContents.hasNext()) {
         EObject next = eAllContents.next();
         if (next instanceof Expression) toCheck.add((Expression) next);
       }
       for (Expression expression : toCheck) {
         EObject referencedObject = null;
         if (expression instanceof FeatureCall)
           referencedObject = ((FeatureCall) expression).getFeature();
         else if (expression instanceof ElementReferenceExpression)
           referencedObject = ((ElementReferenceExpression) expression).getReference();
         if (referencedObject instanceof VariableDefinition) {
           if (!defined.contains(nameProvider.getFullyQualifiedName(referencedObject)))
             error(
                 REFERENCE_CONSTANT_BEFORE_DEFINED,
                 definition,
                 StextPackage.Literals.VARIABLE_DEFINITION__INITIAL_VALUE);
         }
       }
       defined.add(nameProvider.getFullyQualifiedName(definition));
     }
   }
 }
コード例 #15
0
  private Collection<StructuredType> getAllStructuredTypes(EObject any) {
    // Collect all structured types
    Collection<StructuredType> structuredTypes = new ArrayList<StructuredType>();

    // First, get all semantic resources in session
    Collection<Resource> semanticResources = getAllSemanticResourcesInSession(any);

    for (Resource resource : semanticResources) {
      TreeIterator<EObject> iterator = EcoreUtil.getAllContents(resource, true);
      while (iterator.hasNext()) {
        EObject eObject = (EObject) iterator.next();
        if (eObject instanceof StructuredType) {
          structuredTypes.add((StructuredType) eObject);
        } else {
          if (!(eObject instanceof TypesDefinition
              || eObject instanceof NamespacesContainer
              || isOverviewRootInstance(eObject))) {
            iterator.prune();
          }
        }
      }
    }

    return structuredTypes;
  }
コード例 #16
0
 private EObject getEObjectByID(String id) {
   TreeIterator<EObject> eAllContents = resourceLoader.getResource().getAllContents();
   while (eAllContents.hasNext()) {
     EObject next = eAllContents.next();
     if (EcoreUtil.getIdentification(next).equals(id)) return next;
   }
   throw new WebApplicationException(Response.Status.NOT_FOUND);
 }
コード例 #17
0
 protected void printAdapters() {
   walk(this);
   for (TreeIterator<Mapping> mappings = treeIterator(); mappings.hasNext(); ) {
     for (EObject eObject : mappings.next().getMappedObjects()) {
       walk(eObject);
     }
   }
 }
コード例 #18
0
  @Requires(IRepositoryConfig.CAPABILITY_AUDITING)
  public void testReloadingRevisions() throws Exception {
    final String RESOURCE_NAME = "resource";

    Set<CDOID> ids = new HashSet<CDOID>();
    long timeStampOfHoleCommit;

    CDOSession initialSession = openSession();
    {
      // create model history
      CDOTransaction openTransaction = initialSession.openTransaction();
      CDOResource resource = openTransaction.getOrCreateResource(getResourcePath(RESOURCE_NAME));

      // creating initial commit
      Company createdCompany = getModel1Factory().createCompany();
      createdCompany.setName("CompanyTesting");
      createdCompany.setCity("City");
      createdCompany.setStreet("Street");

      resource.getContents().add(createdCompany);

      openTransaction.commit();

      // collect id's
      for (TreeIterator<EObject> allContents = resource.getAllContents(); allContents.hasNext(); ) {
        CDOObject next = CDOUtil.getCDOObject(allContents.next());
        ids.add(next.cdoID());
      }

      // making holes - detaching
      List<EObject> contents = new ArrayList<EObject>(resource.getContents());
      for (int i = 0; i < contents.size(); i++) {
        EcoreUtil.delete(contents.get(i), true);
      }

      timeStampOfHoleCommit = openTransaction.commit().getTimeStamp();
    }

    // check when locally cached elements are availabe
    checkRevisionsOnGivenSession(ids, timeStampOfHoleCommit, 2, initialSession);

    // turn of revision download by timestamp
    checkRevisionsOnGivenSession(ids, -1, 2, initialSession);
    initialSession.close();

    checkRevisions(ids, timeStampOfHoleCommit, 2);

    // turn of revision download by timestamp
    checkRevisions(ids, -1, 2);

    // clear caches
    clearCache(getRepository().getRevisionManager());
    checkRevisions(ids, timeStampOfHoleCommit, 2);

    // turn of revision download by timestamp
    clearCache(getRepository().getRevisionManager());
    checkRevisions(ids, -1, 2);
  }
コード例 #19
0
 private boolean isChildOrSibling(Vertex source, Vertex target) {
   TreeIterator<EObject> iter = source.getParentRegion().eAllContents();
   while (iter.hasNext()) {
     if (target == iter.next()) {
       return true;
     }
   }
   return false;
 }
コード例 #20
0
 private int internalGetSize() {
   int resourceSize = 0;
   TreeIterator<EObject> iterator = getAllContents();
   while (iterator.hasNext()) {
     iterator.next();
     resourceSize++;
   }
   return resourceSize;
 }
コード例 #21
0
 /**
  * Take care that widgets reference in the content existing BDAttributes
  *
  * @see org.eclipse.emf.edit.command.OverrideableCommand#doExecute()
  */
 public void doExecute() {
   // replace all copied BDAttributes thru ther origials
   for (TreeIterator i = EcoreUtil.getAllContents(collection); i.hasNext(); ) {
     EObject next = (EObject) i.next();
     if (next instanceof IBDAttachable) {
       AddIBDAttachableHelper.replaceBDAttribute((IBDAttachable) next, owner);
     }
   }
   super.doExecute();
 }
コード例 #22
0
ファイル: Workload.java プロジェクト: ThitGaRang/moliz.nfr
 public Model getModelElement() {
   if (modelElement == null && getUMLModelResource() != null) {
     TreeIterator<EObject> elements = getUMLModelResource().getAllContents();
     while (elements.hasNext()) {
       EObject element = elements.next();
       if (element instanceof Model) return (Model) element;
     }
   }
   return modelElement;
 }
コード例 #23
0
 private static void getAllKeywords(Set<String> kws, AbstractRule parserRule) {
   for (TreeIterator<EObject> tit = parserRule.eAllContents(); tit.hasNext(); ) {
     Object ele = tit.next();
     if (ele instanceof Keyword) {
       kws.add(((Keyword) ele).getValue());
     } else if (ele instanceof RuleCall) {
       getAllKeywords(kws, ((RuleCall) ele).getRule());
     }
   }
 }
コード例 #24
0
ファイル: DataGit.java プロジェクト: eclipse/emf.compare
  public void dispose() {
    comparison = null;
    for (ResourceSet rs : resourceSets) {
      EList<Resource> resources = rs.getResources();
      for (Resource resource : resources) {
        TreeIterator<EObject> allContents = EcoreUtil.getAllProperContents(resource, false);
        while (allContents.hasNext()) {
          final EObject next = allContents.next();
          next.eAdapters().clear();
        }
        resource.eAdapters().clear();
      }

      rs.getResources().clear();
      rs.eAdapters().clear();
    }

    resourceSets = null;

    Job cleanJob =
        new Job("ClearWorkspace") {
          @Override
          protected IStatus run(IProgressMonitor monitor) {
            try {
              // Close & delete projects from workspace
              IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
              for (IProject project : projects) {
                project.close(new NullProgressMonitor());
                project.delete(false, new NullProgressMonitor());
              }
            } catch (CoreException e) {
              Throwables.propagate(e);
            }
            return Status.OK_STATUS;
          }
        };
    cleanJob.schedule();
    try {
      cleanJob.join();
    } catch (InterruptedException e) {
      Throwables.propagate(e);
    }

    if (repository != null) {
      repository.close();
      repository = null;
    }
    for (Runnable disposer : disposers) {
      disposer.run();
    }
    disposers.clear();

    // Delete repository from temp directory
    GitUtil.deleteRepo(repoFile);
  }
コード例 #25
0
  protected List<Type> getChoiceOfValues(org.eclipse.uml2.uml.Package package_) {
    List<Type> choiceOfValues = new ArrayList<Type>();

    Resource eResource = package_.eResource();
    ResourceSet resourceSet = eResource == null ? null : eResource.getResourceSet();

    if (resourceSet != null) {

      try {
        resourceSet.getResource(URI.createURI(UMLResource.UML_PRIMITIVE_TYPES_LIBRARY_URI), true);
      } catch (Exception e) {
        // ignore
      }

      try {
        resourceSet.getResource(URI.createURI(UMLResource.JAVA_PRIMITIVE_TYPES_LIBRARY_URI), true);
      } catch (Exception e) {
        // ignore
      }

      try {
        resourceSet.getResource(URI.createURI(UMLResource.ECORE_PRIMITIVE_TYPES_LIBRARY_URI), true);
      } catch (Exception e) {
        // ignore
      }

      try {
        resourceSet.getResource(URI.createURI(UMLResource.XML_PRIMITIVE_TYPES_LIBRARY_URI), true);
      } catch (Exception e) {
        // ignore
      }
    }

    if (eResource != null) {
      EList<NamedElement> members = package_.getMembers();
      TreeIterator<?> allContents =
          resourceSet == null ? eResource.getAllContents() : resourceSet.getAllContents();

      while (allContents.hasNext()) {
        Object object = allContents.next();

        if (object instanceof Type && !members.contains(object)) {
          Type type = (Type) object;

          if (type.getNearestPackage().makesVisible(type)) {
            choiceOfValues.add(type);
          }
        }
      }
    }

    Collections.<Type>sort(choiceOfValues, new TextComparator<Type>());

    return choiceOfValues;
  }
コード例 #26
0
 @Lock(LockType.WRITE)
 private EObject getEObjectByID(String type, String id) {
   TreeIterator<EObject> eAllContents = resourceLoader.getResource().getAllContents();
   while (eAllContents.hasNext()) {
     EObject next = eAllContents.next();
     if (next.eClass().getInstanceTypeName().equals(type)
         && EcoreUtil.getID(next) != null
         && EcoreUtil.getID(next).equals(id)) return next;
   }
   throw new WebApplicationException(Response.Status.NOT_FOUND);
 }
コード例 #27
0
  private long computeMaxWidgetId() {
    long maxId = 0;

    for (TreeIterator<Widget> i = getAllDirectWidgets(); i.hasNext(); ) {
      Widget widget = i.next();
      Long id = widget.getId();
      if (id != null) maxId = Math.max(maxId, id.longValue());
    }

    return maxId;
  }
 private <T extends EObject> T getFirstElement(Resource sessionResource, Class<T> type) {
   T result = null;
   TreeIterator<EObject> allContents = sessionResource.getAllContents();
   while (allContents.hasNext() && result == null) {
     EObject next = allContents.next();
     if (type.isInstance(next)) {
       result = type.cast(next);
     }
   }
   return result;
 }
コード例 #29
0
 /**
  * Retrieves all children, direct and indirect, and returns them as a set. The <code>amountOfWork
  * </code> for the progress monitor is also computed in this method.
  *
  * @param root the root EObject of the hierarchy
  * @return all direct and indirect contents of <code>root</code>
  */
 protected static Set<EObject> getAllChildren(EObject root) {
   TreeIterator<EObject> allContents = root.eAllContents();
   Set<EObject> result = new LinkedHashSet<EObject>();
   while (allContents.hasNext()) {
     result.add(allContents.next());
     // count every element three times: once for deletion,
     // once for setting attributes, once for setting references
     amountOfWork += 3;
   }
   return result;
 }
コード例 #30
0
  public static List<Expression> getAllExpressions(ThingMLElement self, Class clazz) {
    List<Expression> result = new ArrayList<Expression>();
    TreeIterator<EObject> it = self.eAllContents();
    while (it.hasNext()) {
      EObject o = it.next();
      if (clazz.isInstance(o)) result.add((Expression) o);
    }

    if (clazz.isInstance(self)) result.add((Expression) self);
    return result;
  }