protected String getRawTypeIdentifier(JvmTypeReference reference) {
   if (reference instanceof JvmParameterizedTypeReference) {
     JvmType typeOrProxy =
         (JvmType)
             reference.eGet(TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, false);
     if (typeOrProxy.eIsProxy()) {
       URI uri = ((InternalEObject) typeOrProxy).eProxyURI();
       if (URIHelperConstants.PROTOCOL.equals(uri.scheme())) {
         if (URIHelperConstants.PRIMITIVES.regionMatches(
             1, uri.segment(0), 0, URIHelperConstants.PRIMITIVES.length() - 1)) {
           String fragment = uri.fragment();
           return fragment;
         } else if (URIHelperConstants.OBJECTS.regionMatches(
             1, uri.segment(0), 0, URIHelperConstants.OBJECTS.length() - 2)) {
           String fragment = uri.fragment();
           if (fragment.lastIndexOf('/') == -1) return fragment;
         }
       }
     }
   }
   RawTypeReferenceComputer strategy = new RawTypeReferenceComputer(TypesFactory.eINSTANCE);
   JvmTypeReference result = strategy.getRawTypeReference(reference, eResource());
   if (result == null) return null;
   JvmType rawResult = result.getType();
   return rawResult == null ? null : rawResult.getIdentifier();
 }
Пример #2
0
 public static @NonNull URI getASURI(@NonNull URI uri) {
   if (uri.fragment() != null) {
     logger.error("Unexpected fragment ignored for '" + uri.toString() + "'");
     uri = uri.trimFragment();
   }
   URI asURI = uri.appendFileExtension(PivotConstants.OCL_AS_FILE_EXTENSION);
   if (!isASURI(asURI)) {
     asURI = uri.appendSegment(PivotConstants.DOT_OCL_AS_FILE_EXTENSION);
   }
   assert isASURI(asURI);
   return asURI;
 }
Пример #3
0
  private static JsonNode findNode(URI nodeURI, EClass eClass, JsonNode root) {
    EAttribute eID = eClass.getEIDAttribute();
    if (eID == null) {
      final EStructuralFeature featureName = eClass.getEStructuralFeature("name");
      if (featureName != null && featureName instanceof EAttribute) {
        eID = (EAttribute) featureName;
      } else {
        return null;
      }
    }

    String fragment =
        nodeURI.fragment().startsWith("//") ? nodeURI.fragment().substring(2) : nodeURI.fragment();

    for (JsonNode node : root.findParents(eID.getName())) {
      String value = node.get(eID.getName()).getTextValue();
      if (value.equals(fragment)) {
        return node;
      }
    }
    return null;
  }
Пример #4
0
 public static URI getPivotURI(URI uri) {
   String oldScheme = uri.scheme();
   if (oldScheme == null) {
     oldScheme = "null";
   }
   String[] oldSegments = uri.segments();
   String[] newSegments = new String[oldSegments.length + 1];
   newSegments[0] = oldScheme;
   System.arraycopy(oldSegments, 0, newSegments, 1, oldSegments.length);
   URI pivotURI =
       URI.createHierarchicalURI(
           SCHEME_PIVOT, uri.authority(), uri.device(), newSegments, uri.query(), uri.fragment());
   return pivotURI;
 }
Пример #5
0
 public URI getFullURI(ITypeBinding typeBinding, String method) {
   SegmentSequence.Builder builder = SegmentSequence.newBuilder("");
   URI uri = getFullURI(typeBinding, builder);
   URI[] uris = COMMON_METHOD_URIS.get(uri.lastSegment());
   if (uris != null) {
     for (URI methodURI : uris) {
       String fragment = methodURI.fragment();
       if (fragment.startsWith(method, fragment.length() - method.length() - 2)) {
         return methodURI;
       }
     }
   }
   builder.append(".").append(method).append("()");
   return uri.appendFragment(builder.toString());
 }
Пример #6
0
 public static URI getNonPivotURI(URI uri) {
   assert isPivotURI(uri);
   String[] oldSegments = uri.segments();
   String[] newSegments = new String[oldSegments.length - 1];
   newSegments[0] = uri.scheme();
   System.arraycopy(oldSegments, 1, newSegments, 0, oldSegments.length - 1);
   URI pivotURI =
       URI.createHierarchicalURI(
           oldSegments[0],
           uri.authority(),
           uri.device(),
           newSegments,
           uri.query(),
           uri.fragment());
   return pivotURI;
 }
Пример #7
0
  private EClass findEClass(
      EClass eReferenceType, JsonNode node, JsonNode root, Resource resource) {
    if (eReferenceType.isAbstract() || node.get(EJS_TYPE_KEYWORD) != null) {

      if (node.has(EJS_REF_KEYWORD)) {

        URI refURI = getEObjectURI(node.get(EJS_REF_KEYWORD), resource.getURI(), nsMap);
        EObject eObject = resourceSet.getEObject(refURI, false);
        if (eObject != null) {
          return resourceSet.getEObject(refURI, false).eClass();
        }

        if (node.has(EJS_TYPE_KEYWORD)) {
          refURI = URI.createURI(node.get(EJS_TYPE_KEYWORD).asText());
          eObject = resourceSet.getEObject(refURI, false);
          if (eObject != null) {
            return (EClass) eObject;
          }
        }

        JsonNode refNode = findNode(refURI, eReferenceType, rootNode);
        if (refNode != null) {
          return findEClass(eReferenceType, refNode, root, resource);
        }

      } else if (node.has(EJS_TYPE_KEYWORD)) {
        final URI typeURI =
            getEObjectURI(node.get(EJS_TYPE_KEYWORD), eReferenceType.eResource().getURI(), nsMap);

        if (typeURI.fragment().equals(eReferenceType.getName())) {
          return eReferenceType;
        } else {
          try {
            return (EClass) this.resourceSet.getEObject(typeURI, false);
          } catch (ClassCastException e) {
            e.printStackTrace();
            return null;
          }
        }
      }
    }
    return eReferenceType;
  }
Пример #8
0
 protected void loadImports(@NonNull EPackage ePackage, @Nullable URI baseURI) {
   if (ClassUtil.basicGetMetamodelAnnotation(ePackage) != null) {
     if (asMetamodels == null) {
       asMetamodels = new HashSet<EPackage>();
     }
     asMetamodels.add(ePackage);
   }
   EAnnotation importAnnotation = ePackage.getEAnnotation(PivotConstants.IMPORT_ANNOTATION_SOURCE);
   if (importAnnotation != null) {
     EMap<String, String> details = importAnnotation.getDetails();
     for (String key : details.keySet()) {
       URI uri = URI.createURI(details.get(key));
       uri = resolveImportURI(uri, ePackage, baseURI);
       assert uri != null;
       ResourceSet resourceSet = environmentFactory.getResourceSet();
       EObject importedEObject = null;
       String fragment = uri.fragment();
       if (fragment == null) {
         importedEObject = resourceSet.getPackageRegistry().getEPackage(uri.toString());
       } else {
         importedEObject = resourceSet.getEObject(uri, true);
       }
       if (importedEObject != null) {
         if (importedEObjects == null) {
           importedEObjects = new HashSet<EObject>();
         }
         if (importedEObjects.add(importedEObject) && (importedEObject instanceof EPackage)) {
           Resource importedResource = importedEObject.eResource();
           if (importedResource != null) {
             URI baseURI2 = getBaseURI(importedResource);
             loadImports((EPackage) importedEObject, baseURI2);
           }
         }
       }
     }
   }
   for (EPackage eSubPackage : ePackage.getESubpackages()) {
     if (eSubPackage != null) {
       loadImports(eSubPackage, baseURI);
     }
   }
 }
 private GenModel loadGenmodel(String resourceOrNsURI, ResourceSet resourceSet) {
   URI uri = null;
   try {
     uri = URI.createURI(resourceOrNsURI);
     if (uri.fragment() == null) {
       Resource resource = resourceSet.getResource(uri, true);
       return (GenModel) resource.getContents().get(0);
     }
     return (GenModel) resourceSet.getEObject(uri, true);
   } catch (IllegalArgumentException ex) {
     LOG.trace("Invalid package URI: '" + resourceOrNsURI + "'", ex);
     return null;
   } catch (RuntimeException ex) {
     if (uri != null && uri.isPlatformResource()) {
       String platformString = uri.toPlatformString(true);
       URI platformPluginURI = URI.createPlatformPluginURI(platformString, true);
       return loadGenmodel(platformPluginURI.toString(), resourceSet);
     }
     LOG.trace("Cannot load package with URI '" + resourceOrNsURI + "'", ex);
     return null;
   }
 }
Пример #10
0
 public static void dumpURI(URI uri, Logger logger) {
   logger.debug("URI: " + uri);
   logger.debug("authority: " + uri.authority());
   logger.debug("device: " + uri.device());
   logger.debug("devicePath: " + uri.devicePath());
   logger.debug("fileExtension: " + uri.fileExtension());
   logger.debug("fragment: " + uri.fragment());
   logger.debug("host: " + uri.host());
   logger.debug("lastSegment: " + uri.lastSegment());
   logger.debug("opaquePart: " + uri.opaquePart());
   logger.debug("path: " + uri.path());
   logger.debug("port: " + uri.port());
   logger.debug("query: " + uri.query());
   logger.debug("scheme: " + uri.scheme());
   logger.debug("segmentCount: " + uri.segmentCount());
   logger.debug("toFileString: " + uri.toFileString());
   logger.debug("userInfo: " + uri.userInfo());
   logger.debug("hasAbsolutePath: " + uri.hasAbsolutePath());
   logger.debug("schemehasAbsolutePath: " + uri.hasAbsolutePath());
   logger.debug("hasAuthority: " + uri.hasAuthority());
   logger.debug("hasDevice: " + uri.hasDevice());
   logger.debug("hasEmptyPath: " + uri.hasEmptyPath());
   logger.debug("hasFragment: " + uri.hasFragment());
   logger.debug("hasOpaquePart: " + uri.hasOpaquePart());
   logger.debug("hasPath: " + uri.hasPath());
   logger.debug("hasQuery: " + uri.hasQuery());
   logger.debug("hasRelativePath: " + uri.hasRelativePath());
   logger.debug("hasTrailingPathSeparator: " + uri.hasTrailingPathSeparator());
   logger.debug("isCurrentDocumentReference: " + uri.isCurrentDocumentReference());
   logger.debug("isEmpty: " + uri.isEmpty());
   logger.debug("isFile: " + uri.isFile());
   logger.debug("isHierarchical: " + uri.isHierarchical());
   logger.debug("isPrefix: " + uri.isPrefix());
   logger.debug("isRelative: " + uri.isRelative());
   logger.debug("segments: " + uri.segments());
 }
Пример #11
0
 /** @generated */
 protected void setDocumentContent(IDocument document, IEditorInput element) throws CoreException {
   IDiagramDocument diagramDocument = (IDiagramDocument) document;
   TransactionalEditingDomain domain = diagramDocument.getEditingDomain();
   if (element instanceof URIEditorInput) {
     URI uri = ((URIEditorInput) element).getURI();
     Resource resource = null;
     try {
       resource = domain.getResourceSet().getResource(uri.trimFragment(), false);
       if (resource == null) {
         resource = domain.getResourceSet().createResource(uri.trimFragment());
       }
       if (!resource.isLoaded()) {
         try {
           Map options = new HashMap(GMFResourceFactory.getDefaultLoadOptions());
           // @see 171060
           // options.put(org.eclipse.emf.ecore.xmi.XMLResource.OPTION_RECORD_UNKNOWN_FEATURE,
           // Boolean.TRUE);
           resource.load(options);
         } catch (IOException e) {
           resource.unload();
           throw e;
         }
       }
       if (uri.fragment() != null) {
         EObject rootElement = resource.getEObject(uri.fragment());
         if (rootElement instanceof Diagram) {
           document.setContent((Diagram) rootElement);
           return;
         }
       } else {
         for (Iterator it = resource.getContents().iterator(); it.hasNext(); ) {
           Object rootElement = it.next();
           if (rootElement instanceof Diagram) {
             document.setContent((Diagram) rootElement);
             return;
           }
         }
       }
       throw new RuntimeException(Messages.StateChartDocumentProvider_NoDiagramInResourceError);
     } catch (Exception e) {
       CoreException thrownExcp = null;
       if (e instanceof CoreException) {
         thrownExcp = (CoreException) e;
       } else {
         String msg = e.getLocalizedMessage();
         thrownExcp =
             new CoreException(
                 new Status(
                     IStatus.ERROR,
                     StateChartDiagramEditorPlugin.ID,
                     0,
                     msg != null ? msg : Messages.StateChartDocumentProvider_DiagramLoadingError,
                     e));
       }
       throw thrownExcp;
     }
   } else {
     throw new CoreException(
         new Status(
             IStatus.ERROR,
             StateChartDiagramEditorPlugin.ID,
             0,
             NLS.bind(
                 Messages.StateChartDocumentProvider_IncorrectInputError,
                 new Object[] {
                   element, "org.eclipse.emf.common.ui.URIEditorInput"
                 }), //$NON-NLS-1$
             null));
   }
 }