private static boolean inSameModel(EObject object, EObject other) {
    // is the one object in the other's logical Papyrus model?
    URI model1 = getResourceURI(getRootContainer(object));
    URI model2 = getResourceURI(getRootContainer(other));

    return (model1 != null)
        && (model2 != null)
        && model1.trimFileExtension().equals(model2.trimFileExtension());
  }
 @Override
 public @NonNull String getInitialContentsAsString(
     @NonNull IFile newFile, @NonNull AbstractFileDialog dialog) {
   URI ecoreURI = URI.createPlatformResourceURI(newFile.getFullPath().toString(), true);
   URI oclInEcoreURI = ecoreURI.trimFileExtension().appendFileExtension("oclinecore");
   String initialContentsAsString = super.getInitialContentsAsString(newFile, dialog);
   @SuppressWarnings("null")
   OCL ocl = OCL.newInstance(EPackage.Registry.INSTANCE);
   ResourceSet resourceSet2 = ocl.getResourceSet();
   BaseCSResource csResource =
       ClassUtil.nonNullState((BaseCSResource) resourceSet2.createResource(oclInEcoreURI));
   try {
     ByteArrayInputStream inputStream =
         new ByteArrayInputStream(initialContentsAsString.getBytes());
     csResource.load(inputStream, null);
     ASResource asResource = ocl.cs2as(csResource);
     Resource eResource = ocl.as2ecore(asResource, ecoreURI);
     ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
     eResource.save(outputStream, null);
     @SuppressWarnings("null")
     @NonNull
     String string = outputStream.toString();
     return string;
   } catch (IOException e) {
     logger.error("Failed to create " + ecoreURI, e);
   }
   return initialContentsAsString;
 }
Пример #3
0
  /**
   * Create a resource from the given URI and append a new Network instance to its contents. The
   * resourceSet used must be authorized to write on the disk. This means that the default
   * EditingDomain's resourceSet must be used in a write transaction (for example). If it is not
   * possible, do not provide a resourceSet, the default one will be used.
   *
   * @param resourceSet
   * @param uri
   * @return The created network
   * @throws IOException
   */
  public static Network createNetworkResource(final ResourceSet resourceSet, final URI uri)
      throws IOException {

    final String fileName;
    if (uri.isPlatform()) {
      fileName = uri.toPlatformString(true);
    } else {
      fileName = uri.toString();
    }

    // Create the network
    final Network network = DfFactory.eINSTANCE.createNetwork(fileName);

    // Compute the new network name
    final Path networkPath = new Path(uri.trimFileExtension().path());
    // 3 first segments are resource/<PROJECT>/src
    network.setName(networkPath.removeFirstSegments(3).toString().replace('/', '.'));

    // Create the resource
    Resource res = resourceSet.createResource(uri);
    res.getContents().add(network);
    res.save(Collections.EMPTY_MAP);

    return network;
  }
Пример #4
0
  /**
   * From diagram URI get Apdl URI. set it to private field.
   *
   * @param diagramFileURI
   */
  public void setAPDLFileName(URI diagramFileURI) {
    IPreferenceStore store = BpwmeDiagramEditorPlugin.getInstance().getPreferenceStore();
    String dot = "\\.";
    String[] names = diagramFileURI.lastSegment().split(dot);
    if (names.length == 2) {
      apdlURI = diagramFileURI.trimFileExtension().appendFileExtension("xml");
      // apdlURI =
      // URI.createFileURI(store.getString(PreferenceConstants.P_APDL_DIR)+names[0]+".xml");
      store.setValue(PreferenceConstants.P_APDL_FILE, apdlURI.toFileString());

      File f = new File(apdlURI.toFileString());
      if (!f.exists()) {

        try {
          f.createNewFile();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }

      IPath location = new Path(f.getAbsolutePath());
      PathEditorInput input = new PathEditorInput(location);
      SimpleEditor.setEditorInput(input);

    } else {
      System.err.println("Error in MainControl.getFileName");
    }
  }
  private static boolean inUnit(EObject object, URI unit) {
    boolean result = false;

    if (unit != null) {
      // get the extension-less model URIs
      URI uri = getResourceURI(object);

      if (uri != null) {
        uri = uri.trimFileExtension();
        URI otherURI = unit.trimFileExtension();

        result = uri.equals(otherURI);
      }
    }

    return result;
  }
  /** @generated */
  public StateMachine_MAVONewDiagramFileWizard(
      URI domainModelURI, EObject diagramRoot, TransactionalEditingDomain editingDomain) {
    assert domainModelURI != null : "Domain model uri must be specified"; // $NON-NLS-1$
    assert diagramRoot != null : "Doagram root element must be specified"; // $NON-NLS-1$
    assert editingDomain != null : "Editing domain must be specified"; // $NON-NLS-1$

    myFileCreationPage =
        new WizardNewFileCreationPage(
            edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages
                .StateMachine_MAVONewDiagramFileWizard_CreationPageName,
            StructuredSelection.EMPTY);
    myFileCreationPage.setTitle(
        edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages
            .StateMachine_MAVONewDiagramFileWizard_CreationPageTitle);
    myFileCreationPage.setDescription(
        NLS.bind(
            edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages
                .StateMachine_MAVONewDiagramFileWizard_CreationPageDescription,
            edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.edit.parts.StateMachineEditPart
                .MODEL_ID));
    IPath filePath;
    String fileName = URI.decode(domainModelURI.trimFileExtension().lastSegment());
    if (domainModelURI.isPlatformResource()) {
      filePath = new Path(domainModelURI.trimSegments(1).toPlatformString(true));
    } else if (domainModelURI.isFile()) {
      filePath = new Path(domainModelURI.trimSegments(1).toFileString());
    } else {
      // TODO : use some default path
      throw new IllegalArgumentException("Unsupported URI: " + domainModelURI); // $NON-NLS-1$
    }
    myFileCreationPage.setContainerFullPath(filePath);
    myFileCreationPage.setFileName(
        edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part
            .StateMachine_MAVODiagramEditorUtil.getUniqueFileName(
            filePath, fileName, "statemachinediag_mavo")); // $NON-NLS-1$

    diagramRootElementSelectionPage =
        new DiagramRootElementSelectionPage(
            edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages
                .StateMachine_MAVONewDiagramFileWizard_RootSelectionPageName);
    diagramRootElementSelectionPage.setTitle(
        edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages
            .StateMachine_MAVONewDiagramFileWizard_RootSelectionPageTitle);
    diagramRootElementSelectionPage.setDescription(
        edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages
            .StateMachine_MAVONewDiagramFileWizard_RootSelectionPageDescription);
    diagramRootElementSelectionPage.setModelElement(diagramRoot);

    myEditingDomain = editingDomain;
  }
Пример #7
0
 public static void saveToModelFile(final EObject obj, final Diagram d)
     throws CoreException, IOException {
   URI uri = d.eResource().getURI();
   uri = uri.trimFragment();
   uri = uri.trimFileExtension();
   uri = uri.appendFileExtension("model");
   ResourceSet rSet = d.eResource().getResourceSet();
   final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
   IResource file = workspaceRoot.findMember(uri.toPlatformString(true));
   if (file == null || !file.exists()) {
     Resource createResource = rSet.createResource(uri);
     createResource.save(new HashMap());
     createResource.setTrackingModification(true);
   }
   final Resource resource = rSet.getResource(uri, true);
   resource.getContents().add(obj);
 }
Пример #8
0
  /**
   * Create a resource from the given URI and append a new Diagram instance to its contents. The
   * resourceSet used must be authorized to write on the disk. This means that the default
   * EditingDomain's resourceSet must be used in a write transaction (for example). If it is not
   * possible, do not provide a resourceSet, the default one will be used.
   *
   * @param resourceSet
   * @param uri
   * @return The Diagram created
   * @throws IOException
   */
  public static Diagram createDiagramResource(final ResourceSet resourceSet, final URI uri)
      throws IOException {
    // Compute the new diagram name
    final String name = uri.trimFileExtension().lastSegment();

    // Create the diagram
    final Diagram diagram =
        Graphiti.getPeCreateService().createDiagram(Activator.DIAGRAM_TYPE, name, true);

    // Create the resource
    Resource res = resourceSet.createResource(uri);
    res.getContents().add(diagram);
    res.setTrackingModification(true);
    res.save(Collections.EMPTY_MAP);

    return diagram;
  }
 protected void _infer(
     final Script script,
     final IJvmDeclaredTypeAcceptor acceptor,
     final boolean isPreIndexingPhase) {
   Resource _eResource = script.eResource();
   URI _uRI = _eResource.getURI();
   URI _trimFileExtension = _uRI.trimFileExtension();
   final String className = _trimFileExtension.lastSegment();
   JvmGenericType _class = this._jvmTypesBuilder.toClass(script, className);
   IPostIndexingInitializing<JvmGenericType> _accept = acceptor.<JvmGenericType>accept(_class);
   final Procedure1<JvmGenericType> _function =
       new Procedure1<JvmGenericType>() {
         public void apply(final JvmGenericType it) {
           EList<JvmMember> _members = it.getMembers();
           JvmTypeReference _newTypeRef =
               ScriptingJvmModelInferrer.this._jvmTypesBuilder.newTypeRef(script, Void.TYPE);
           final Procedure1<JvmOperation> _function =
               new Procedure1<JvmOperation>() {
                 public void apply(final JvmOperation it) {
                   EList<JvmFormalParameter> _parameters = it.getParameters();
                   JvmTypeReference _newTypeRef =
                       ScriptingJvmModelInferrer.this._jvmTypesBuilder.newTypeRef(
                           script, String.class);
                   JvmTypeReference _addArrayTypeDimension =
                       ScriptingJvmModelInferrer.this._jvmTypesBuilder.addArrayTypeDimension(
                           _newTypeRef);
                   JvmFormalParameter _parameter =
                       ScriptingJvmModelInferrer.this._jvmTypesBuilder.toParameter(
                           script, "args", _addArrayTypeDimension);
                   ScriptingJvmModelInferrer.this._jvmTypesBuilder
                       .<JvmFormalParameter>operator_add(_parameters, _parameter);
                   it.setStatic(true);
                   ScriptingJvmModelInferrer.this._jvmTypesBuilder.setBody(it, script);
                 }
               };
           JvmOperation _method =
               ScriptingJvmModelInferrer.this._jvmTypesBuilder.toMethod(
                   script, "main", _newTypeRef, _function);
           ScriptingJvmModelInferrer.this._jvmTypesBuilder.<JvmOperation>operator_add(
               _members, _method);
         }
       };
   _accept.initializeLater(_function);
 }
  /**
   * Iterates all of the proper contents of the resources comprising the logical model unit
   * indicated by the representative {@code unitURI}.
   *
   * @param rset a resource set in which to load and/or iterate the resource contents
   * @param unitURI the URI of one of the resources in the logical model unit, which therefore is
   *     representative of the unit
   * @return an iterator over the entire logical model unit's proper contents
   */
  static Iterable<EObject> getAllPersistentSubunitContents(ResourceSet rset, URI unitURI) {
    final URI base = unitURI.trimFileExtension();
    Iterable<Resource> resources =
        filter(
            rset.getResources(),
            new Predicate<Resource>() {

              @Override
              public boolean apply(Resource input) {
                return input.getURI().trimFileExtension().equals(base);
              }
            });

    Iterable<EObject> result =
        concat(
            transform(
                resources,
                new Function<Resource, Iterable<EObject>>() {

                  @Override
                  public Iterable<EObject> apply(final Resource input) {
                    return new Iterable<EObject>() {

                      @Override
                      public Iterator<EObject> iterator() {
                        return EcoreUtil.getAllProperContents(input, false);
                      }
                    };
                  }
                }));

    result =
        filter(
            result,
            new Predicate<EObject>() {

              @Override
              public boolean apply(EObject input) {
                return isPersistentObject(input);
              }
            });

    return result;
  }
Пример #11
0
 public static @NonNull URI getNonASURI(@NonNull URI uri) {
   assert isASURI(uri);
   return uri.trimFileExtension();
 }
  @Override
  protected IStatus run(IProgressMonitor monitor) {
    IStatus ret = Status.OK_STATUS;
    SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
    Injector injector =
        TargetPlatformActivator.getInstance()
            .getInjector(TargetPlatformActivator.FR_OBEO_RELENG_TARGETPLATFORM_TARGETPLATFORM);
    Converter converter = new Converter();
    injector.injectMembers(converter);
    Diagnostic diagnostic = null;
    final String path = selectedElement.getLocation().toFile().getAbsolutePath();
    URI targetplatformFileURI = URI.createFileURI(path);

    try {
      diagnostic =
          converter.generateTargetDefinitionFile(targetplatformFileURI, subMonitor.newChild(95));
    } catch (OperationCanceledException cancel) {
      ret =
          new Status(
              IStatus.CANCEL,
              TargetPlatformActivator.FR_OBEO_RELENG_TARGETPLATFORM_TARGETPLATFORM,
              cancel.getMessage(),
              cancel);
    } catch (Exception e) {
      ret =
          new Status(
              IStatus.ERROR,
              TargetPlatformActivator.FR_OBEO_RELENG_TARGETPLATFORM_TARGETPLATFORM,
              e.getMessage(),
              e);
    }
    IContainer container = selectedElement.getParent();
    if (container != null) {
      try {
        container.refreshLocal(IResource.DEPTH_ONE, subMonitor.newChild(5));
      } catch (CoreException e) {
        return new Status(
            IStatus.ERROR,
            TargetPlatformActivator.getInstance().getBundle().getSymbolicName(),
            e.getMessage(),
            e);
      }
    }

    if (setTargetPlatform) {
      PDEIntegration pdeIntegration = new PDEIntegration();

      final URI targetFileURI =
          targetplatformFileURI.trimFileExtension().appendFileExtension("target");
      try {
        pdeIntegration.setTargetPlatform(targetFileURI, monitor);
      } catch (CoreException e) {
        ret =
            new Status(
                IStatus.ERROR,
                TargetPlatformActivator.FR_OBEO_RELENG_TARGETPLATFORM_TARGETPLATFORM,
                e.getMessage(),
                e);
      }
    }

    if (diagnostic != null) {
      return BasicDiagnostic.toIStatus(diagnostic);
    } else {
      return ret;
    }
  }
 protected void _infer(
     final Model model, final IJvmDeclaredTypeAcceptor acceptor, final boolean isPrelinkingPhase) {
   Resource _eResource = model.eResource();
   URI _uRI = _eResource.getURI();
   URI _trimFileExtension = _uRI.trimFileExtension();
   final String postfix = _trimFileExtension.lastSegment();
   JvmGenericType _class =
       this._jvmTypesBuilder.toClass(model, (IModelQueryConstants.INFERRED_CLASS_NAME + postfix));
   final Procedure1<JvmGenericType> _function =
       (JvmGenericType it) -> {
         EList<JvmMember> _members = it.getMembers();
         JvmTypeReference _typeRef =
             this._typeReferenceBuilder.typeRef(IResourceDescriptions.class);
         JvmField _field =
             this._jvmTypesBuilder.toField(model, IModelQueryConstants.INDEX, _typeRef);
         this._jvmTypesBuilder.<JvmField>operator_add(_members, _field);
         EList<JvmMember> _members_1 = it.getMembers();
         JvmTypeReference _typeRef_1 = this._typeReferenceBuilder.typeRef(IProject.class);
         JvmField _field_1 =
             this._jvmTypesBuilder.toField(model, IModelQueryConstants.PROJECT, _typeRef_1);
         this._jvmTypesBuilder.<JvmField>operator_add(_members_1, _field_1);
         EList<JvmMember> _members_2 = it.getMembers();
         JvmTypeReference _typeRef_2 = this._typeReferenceBuilder.typeRef(ResourceSet.class);
         JvmField _field_2 =
             this._jvmTypesBuilder.toField(model, IModelQueryConstants.RESOURCESET, _typeRef_2);
         this._jvmTypesBuilder.<JvmField>operator_add(_members_2, _field_2);
         EList<JvmMember> _members_3 = it.getMembers();
         JvmTypeReference _typeRef_3 = this._typeReferenceBuilder.typeRef(Injector.class);
         JvmField _field_3 =
             this._jvmTypesBuilder.toField(model, IModelQueryConstants.INJECTOR, _typeRef_3);
         this._jvmTypesBuilder.<JvmField>operator_add(_members_3, _field_3);
         EList<JvmMember> _members_4 = it.getMembers();
         JvmTypeReference _typeRef_4 = this._typeReferenceBuilder.typeRef(Void.TYPE);
         final Procedure1<JvmOperation> _function_1 =
             (JvmOperation it_1) -> {
               XBlockExpression _body = model.getBody();
               this._jvmTypesBuilder.setBody(it_1, _body);
               EList<JvmTypeReference> _exceptions = it_1.getExceptions();
               JvmTypeReference _typeRef_5 = this._typeReferenceBuilder.typeRef(Exception.class);
               this._jvmTypesBuilder.<JvmTypeReference>operator_add(_exceptions, _typeRef_5);
             };
         JvmOperation _method =
             this._jvmTypesBuilder.toMethod(model, "main", _typeRef_4, _function_1);
         this._jvmTypesBuilder.<JvmOperation>operator_add(_members_4, _method);
         EList<XMethodDeclaration> _methods = model.getMethods();
         for (final XMethodDeclaration op : _methods) {
           EList<JvmMember> _members_5 = it.getMembers();
           String _name = op.getName();
           JvmTypeReference _elvis = null;
           JvmTypeReference _type = op.getType();
           if (_type != null) {
             _elvis = _type;
           } else {
             JvmTypeReference _inferredType = this._jvmTypesBuilder.inferredType();
             _elvis = _inferredType;
           }
           final Procedure1<JvmOperation> _function_2 =
               (JvmOperation it_1) -> {
                 EList<JvmFormalParameter> _parameters = op.getParameters();
                 for (final JvmFormalParameter p : _parameters) {
                   EList<JvmFormalParameter> _parameters_1 = it_1.getParameters();
                   String _name_1 = p.getName();
                   JvmTypeReference _parameterType = p.getParameterType();
                   JvmFormalParameter _parameter =
                       this._jvmTypesBuilder.toParameter(p, _name_1, _parameterType);
                   this._jvmTypesBuilder.<JvmFormalParameter>operator_add(
                       _parameters_1, _parameter);
                 }
                 EList<JvmTypeParameter> _typeParameters = op.getTypeParameters();
                 this.copyAndFixTypeParameters(_typeParameters, it_1);
                 XExpression _body = op.getBody();
                 this._jvmTypesBuilder.setBody(it_1, _body);
               };
           JvmOperation _method_1 = this._jvmTypesBuilder.toMethod(op, _name, _elvis, _function_2);
           this._jvmTypesBuilder.<JvmOperation>operator_add(_members_5, _method_1);
         }
       };
   acceptor.<JvmGenericType>accept(_class, _function);
 }