Ejemplo n.º 1
0
 public URI getFullURI(ITypeBinding typeBinding) {
   // The URIs for primitive types are cached and indexed by their one character key
   // representation.
   //
   if (typeBinding.isPrimitive()) {
     return PRIMITIVE_URIS[typeBinding.getKey().charAt(0) - 'B'];
   }
   if (typeBinding.isClass()
       || typeBinding.isInterface()
       || typeBinding.isAnnotation()
       || typeBinding.isEnum()) {
     ITypeBinding declaringClass = typeBinding.getDeclaringClass();
     if (declaringClass == null) {
       // This special case handling for common case of top level types that avoids creating a
       // builder.
       //
       String qualifiedName = typeBinding.getErasure().getQualifiedName();
       URI uri = COMMON_URIS.get(qualifiedName);
       if (uri != null) {
         return uri;
       }
       uri = OBJECTS_URI.appendSegment(qualifiedName);
       return uri.appendFragment(uri.lastSegment());
     }
     SegmentSequence.Builder builder = SegmentSequence.newBuilder("");
     URI uri = getFullURI(declaringClass, builder);
     builder.append("$");
     builder.append(typeBinding.getName());
     return uri.appendFragment(builder.toString());
   }
   SegmentSequence.Builder builder = SegmentSequence.newBuilder("");
   URI uri = getFullURI(typeBinding, builder);
   return uri.appendFragment(builder.toString());
 }
Ejemplo n.º 2
0
  @Test
  public void testResolveElements() throws Exception {
    URI resourceURI = URI.createFileURI("testresource.refactoringtestlanguage");
    String textualModel = "A { B { C { ref A.B } } ref B }";
    XtextResource resource = getResource(textualModel, resourceURI.toString());
    Element elementA = (Element) resource.getContents().get(0).eContents().get(0);
    Element elementB = elementA.getContained().get(0);
    Element elementC = elementB.getContained().get(0);

    URI uriB = EcoreUtil.getURI(elementB);
    URI uriC = EcoreUtil.getURI(elementC);
    String newName = "newB";

    List<URI> renamedElementURIs = newArrayList(uriB, uriC);
    IRenameStrategy renameStrategy =
        getInjector().getInstance(IRenameStrategy.Provider.class).get(elementB, null);

    IRenamedElementTracker renamedElementTracker = new RenamedElementTracker();
    Map<URI, URI> original2newElementURIs =
        renamedElementTracker.renameAndTrack(
            renamedElementURIs, newName, resource.getResourceSet(), renameStrategy, null);

    assertEquals("B", elementB.getName());
    assertEquals(2, original2newElementURIs.size());
    assertEquals(resourceURI.appendFragment(newName), original2newElementURIs.get(uriB));
    assertEquals(uriC, original2newElementURIs.get(uriC));
  }
Ejemplo n.º 3
0
 /**
  * @param input
  * @return
  */
 public static URI getUri(IEditorInput input, String editorID) {
   String uriString = null;
   if (input instanceof URIEditorInput) {
     uriString = PathsUtil.getRelativeWorkspaceFromEditorInputWithFragment(input);
   } else {
     uriString = PathsUtil.getRelativeWorkspaceFromEditorInput(input);
     String fragment = MDTUtil.getLastOpenedDiagramPropertyForEditor(uriString, editorID);
     if (fragment != null) {
       uriString = URI.createURI(uriString).appendFragment(fragment).toString();
     }
   }
   if (input != null) {
     URI uri = URI.createURI(uriString);
     if (uri.hasFragment()) {
       return uri;
     }
     ResourceSet resourceSet = new ResourceSetImpl();
     try {
       resourceSet
           .getResourceFactoryRegistry()
           .getExtensionToFactoryMap()
           .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
       Resource resource = resourceSet.getResource(uri, true);
       Diagram diagram = MDTUtil.getFirstDiagramFromResource(resource);
       if (diagram != null) {
         String fragment = resource.getURIFragment(diagram);
         uri = uri.appendFragment(fragment);
       }
     } finally {
       EMFHelper.unload(resourceSet);
     }
     return uri;
   }
   return null;
 }
Ejemplo n.º 4
0
 public URI getFullURI(IVariableBinding binding) {
   SegmentSequence.Builder builder = SegmentSequence.newBuilder("");
   URI uri = getFullURI(binding.getDeclaringClass(), builder);
   builder.append(".");
   builder.append(binding.getName());
   return uri.appendFragment(builder.toString());
 }
Ejemplo n.º 5
0
 protected JvmTypeReference getTypeProxy(EObject pointer) {
   JvmParameterizedTypeReference typeReference =
       typesFactory.createJvmParameterizedTypeReference();
   final Resource eResource = pointer.eResource();
   String fragment = eResource.getURIFragment(pointer);
   URI uri = eResource.getURI();
   uri = uri.appendFragment(Xtend2Resource.FRAGMENT_PREFIX + fragment);
   ((InternalEObject) typeReference).eSetProxyURI(uri);
   return typeReference;
 }
Ejemplo n.º 6
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());
 }
Ejemplo n.º 7
0
  /**
   * Add a reference to a named AD
   *
   * @param element
   * @param referenceURI
   * @param referenceID
   * @param attribute
   */
  @SuppressWarnings("unchecked")
  public static void addReference(
      EPlanElement element, URI referenceURI, String referenceID, String attribute) {
    if (referenceURI != null) {
      EObject data = element.getData();
      EStructuralFeature feature = data.eClass().getEStructuralFeature(attribute);
      EClass referenceClass = (EClass) feature.getEType();
      List groupReferences = (List) data.eGet(data.eClass().getEStructuralFeature(attribute));

      URI uri = referenceURI.appendFragment(referenceID);
      EObject groupObject =
          ActivityDictionary.getInstance().getEFactoryInstance().create(referenceClass);
      ((BasicEObjectImpl) groupObject).eSetProxyURI(uri);
      if (!groupReferences.contains(groupObject)) {
        groupReferences.add(groupObject);
      }
    }
  }
  /**
   * Constructs an URI from a fully qualified classifier name pointing at the file containing the
   * classifier and the classifier itself inside the EMF-model constructed from that resource.
   *
   * @param fullQualifiedName
   * @return the logical URI for the classifier
   */
  public static URI getClassifierURI(String fullQualifiedName) {
    URI logicalUri = getJavaFileResourceURI(fullQualifiedName);

    String classesPart = fullQualifiedName;
    int idx = fullQualifiedName.lastIndexOf(PACKAGE_SEPARATOR);
    if (idx >= 0) {
      classesPart = classesPart.substring(idx + 1);
    }
    String[] classNames = classesPart.split("\\" + CLASSIFIER_SEPARATOR);

    String uriFragment = "";
    for (int i = 0; i < classNames.length; i++) {
      if (i == 0) {
        uriFragment = uriFragment + "//" + CLASSIFIERS_ROOT_PATH_PREFIX;
      } else {
        uriFragment = uriFragment + "/" + CLASSIFIERS_SUB_PATH_PREFIX;
      }
      uriFragment = uriFragment + classNames[i] + CLASSIFIERS_PATH_SUFIX;
    }

    logicalUri = logicalUri.appendFragment(uriFragment);
    return logicalUri;
  }