Exemple #1
0
 @Test
 public void testGetElementByInstance_01() {
   JvmVoid voidType = TypesFactory.eINSTANCE.createJvmVoid();
   IEObjectDescription element = getTypeScope().getSingleElement(voidType);
   assertNotNull(element);
   assertEquals(voidType.getIdentifier(), element.getName().toString());
 }
 /** @since 2.8 */
 protected boolean isDerived(String typeName, IJavaProject project) {
   QualifiedName qualifiedName = nameConverter.toQualifiedName(typeName);
   Iterable<IEObjectDescription> iterable =
       resourceDescriptions.getExportedObjects(
           TypesPackage.Literals.JVM_TYPE, qualifiedName, false);
   Iterator<IEObjectDescription> iterator = iterable.iterator();
   if (iterator.hasNext()) {
     if (project != null) {
       JavaProjectsState javaProjectsState = getJavaProjectsState();
       List<String> visibleContainers =
           javaProjectsState.getVisibleContainerHandles(project.getHandleIdentifier());
       while (iterator.hasNext()) {
         IEObjectDescription description = iterator.next();
         URI resourceURI = description.getEObjectURI().trimFragment();
         String handle = javaProjectsState.getContainerHandle(resourceURI);
         if (visibleContainers.contains(handle)) {
           return true;
         }
       }
       return false;
     }
     return true;
   }
   return false;
 }
 /** override to add any other implicit feature calls. */
 protected IScope createImplicitFeatureCallScope(
     final EObject call, final IScope parent, IScope localVariableScope) {
   IScope result = parent;
   IEObjectDescription thisVariable = localVariableScope.getSingleElement(THIS);
   if (thisVariable != null) {
     EObject implicitReceiver = thisVariable.getEObjectOrProxy();
     JvmTypeReference implicitReceiverType =
         typeProvider.getTypeForIdentifiable((JvmIdentifiableElement) implicitReceiver);
     if (implicitReceiverType != null && implicitReceiver instanceof JvmIdentifiableElement) {
       XFeatureCall receiver = XbaseFactory.eINSTANCE.createXFeatureCall();
       receiver.setFeature((JvmIdentifiableElement) implicitReceiver);
       result =
           createFeatureScopeForTypeRef(
               implicitReceiverType, call, getContextType(call), receiver, result);
     }
   }
   IEObjectDescription itVariable = localVariableScope.getSingleElement(IT);
   if (itVariable != null) {
     EObject implicitReceiver = itVariable.getEObjectOrProxy();
     JvmTypeReference implicitReceiverType =
         typeProvider.getTypeForIdentifiable((JvmIdentifiableElement) implicitReceiver);
     if (implicitReceiverType != null && implicitReceiver instanceof JvmIdentifiableElement) {
       XFeatureCall receiver = XbaseFactory.eINSTANCE.createXFeatureCall();
       receiver.setFeature((JvmIdentifiableElement) implicitReceiver);
       result =
           createFeatureScopeForTypeRef(
               implicitReceiverType, call, getContextType(call), receiver, result);
     }
   }
   return result;
 }
 protected boolean checkImportedNamespaceExists(String importedNamespace, Resource res) {
   if (importedNamespace.endsWith(".*")) {
     importedNamespace = importedNamespace.substring(0, importedNamespace.length() - 2); // remove
     // wildcard
   }
   IResourceDescriptions resourceDescriptions =
       resourceDescriptionsProvider.getResourceDescriptions(res);
   URI uri = res.getURI();
   IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(uri);
   if (resourceDescription == null) {
     return false; // no resource description could be found, so package
     // cannot be resolved anyway
   }
   for (IContainer container :
       containerManager.getVisibleContainers(resourceDescription, resourceDescriptions)) {
     final Iterable<IResourceDescription> currentDescriptions =
         container.getResourceDescriptions();
     for (IResourceDescription resDesc : currentDescriptions) {
       Iterable<IEObjectDescription> visiblePackages =
           resDesc.getExportedObjectsByType(TypesPackage.Literals.PACKAGE);
       for (IEObjectDescription pkgDesc : visiblePackages) {
         if (pkgDesc.getName().toString().equals(importedNamespace)) {
           return true;
         }
       }
     }
   }
   return false;
 }
 protected boolean isJvmDeclaredType(IEObjectDescription description) {
   EClass eClass = description.getEClass();
   return (eClass == TypesPackage.Literals.JVM_GENERIC_TYPE
           || eClass == TypesPackage.Literals.JVM_ENUMERATION_TYPE
           || eClass == TypesPackage.Literals.JVM_ANNOTATION_TYPE)
       && description.getUserData(IS_NESTED_TYPE) == null;
 }
 protected boolean isAffected(
     Collection<QualifiedName> importedNames, IResourceDescription description) {
   if (description != null) {
     for (IEObjectDescription desc : description.getExportedObjects())
       if (importedNames.contains(desc.getName().toLowerCase())) return true;
   }
   return false;
 }
 protected void addExportedNames(
     Set<QualifiedName> names, IResourceDescription resourceDescriptor) {
   if (resourceDescriptor == null) return;
   Iterable<IEObjectDescription> iterable = resourceDescriptor.getExportedObjects();
   for (IEObjectDescription ieObjectDescription : iterable) {
     names.add(ieObjectDescription.getName().toLowerCase());
   }
 }
Exemple #8
0
 @Test
 public void testGetElementByName_03() {
   IEObjectDescription objectElement =
       getTypeScope().getSingleElement(QualifiedName.create(int.class.getName()));
   assertNotNull(objectElement);
   assertFalse(objectElement.getEObjectOrProxy().eIsProxy());
   assertEquals(QualifiedName.create("int"), objectElement.getName());
 }
Exemple #9
0
 @Test
 public void testGetElementByName_01() {
   IEObjectDescription objectElement =
       getTypeScope().getSingleElement(QualifiedName.create(Object.class.getName()));
   assertNotNull(objectElement);
   assertFalse(objectElement.getEObjectOrProxy().eIsProxy());
   assertEquals("java.lang.Object", objectElement.getName().toString());
 }
 public boolean reject(IEObjectDescription element) {
   return element.getEClass() == TerminologyPackage.Literals.ENTRY
       || element.getEClass() == TerminologyPackage.Literals.SUBJECT
       || element.getEClass() == TerminologyPackage.Literals.TERMINOLOGY
       || element.getEClass() == TerminologyPackage.Literals.PRODUCT
       || element.getEClass() == TerminologyPackage.Literals.GR
       || element.getEClass() == TerminologyPackage.Literals.LANGUAGE
       || element.getEClass() == TerminologyPackage.Literals.CUSTOMER;
 }
 @Override
 protected Iterable<IEObjectDescription> getAllLocalElements() {
   Map<String, IEObjectDescription> result = new HashMap<String, IEObjectDescription>();
   for (IEObjectDescription ePkgDesc : parentScope.getAllElements()) {
     EPackage ePkg = (EPackage) ePkgDesc.getEObjectOrProxy();
     ePkg = (EPackage) EcoreUtil.resolve(ePkg, context);
     result.put(ePkg.getNsURI(), EObjectDescription.create(ePkg.getNsURI(), ePkg));
   }
   return result.values();
 }
 public Sortable(final IEObjectDescription desc) {
   this.object = desc;
   QualifiedName _name = desc.getName();
   this.name = _name;
   final String tempVersion = desc.getUserData(MobaResourceDescriptionStrategy.VERSION);
   String _replace = tempVersion.replace("-SNAPSHOT", "");
   this.version = _replace;
   boolean _endsWith = tempVersion.endsWith("-SNAPSHOT");
   this.snapshot = _endsWith;
 }
 // Non-static methods
 public List<ComplexType> getComplexTypes() {
   ArrayList<ComplexType> types = Lists.newArrayList();
   for (IResourceDescription resourceDescription : index.getAllResourceDescriptions()) {
     for (IEObjectDescription objDesc :
         resourceDescription.getExportedObjectsByType(
             DatamodelPackage.eINSTANCE.getComplexType())) {
       types.add((ComplexType) objDesc.getEObjectOrProxy());
     }
   }
   return types;
 }
 public void testOverriddenExtensionMethods_02() throws Exception {
   XbaseScopeProvider provider = get(XbaseScopeProvider.class);
   XExpression expression = expression("(null as java.util.Collection<String>).map(null)", true);
   IScope scope =
       provider.getScope(expression, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE);
   Iterable<IEObjectDescription> elements = scope.getElements(QualifiedName.create("map"));
   assertEquals(elements.toString(), 1, size(elements));
   IEObjectDescription description = elements.iterator().next();
   JvmFeature feature = (JvmFeature) description.getEObjectOrProxy();
   assertEquals(
       IterableExtensions.class.getCanonicalName(), feature.getDeclaringType().getIdentifier());
 }
 protected List<EObject> lookUp(@NonNull IScope scope, QualifiedName qualifiedName) {
   @NonNull List<EObject> linkedObjects = new ArrayList<EObject>();
   for (IEObjectDescription eObjectDescription : scope.getElements(qualifiedName)) {
     EObject eObjectOrProxy = eObjectDescription.getEObjectOrProxy();
     linkedObjects.add(eObjectOrProxy);
     if (BaseScopeProvider.LOOKUP.isActive()) {
       BaseScopeProvider.LOOKUP.println(
           "" + depth + " Lookup " + qualifiedName + " => " + eObjectOrProxy);
     }
   }
   return linkedObjects;
 }
 protected Map<EObject, URI> createExportedElementsMap(Resource resource) {
   IResourceDescription resourceDescription =
       index.getResourceDescription(EcoreUtil2.getNormalizedURI(resource));
   Map<EObject, URI> exportedElementMap = newHashMap();
   if (resourceDescription != null) {
     for (IEObjectDescription exportedEObjectDescription :
         resourceDescription.getExportedObjects()) {
       EObject eObject =
           resource.getEObject(exportedEObjectDescription.getEObjectURI().fragment());
       if (eObject != null)
         exportedElementMap.put(eObject, exportedEObjectDescription.getEObjectURI());
     }
   }
   return exportedElementMap;
 }
 public String getJavaFileName(IEObjectDescription description) {
   if (!isJvmDeclaredType(description)) {
     return null;
   }
   QualifiedName typeName = description.getName();
   return Strings.concat("/", typeName.getSegments()) + ".java";
 }
 public ComplexType find(Class source) {
   if (types == null) {
     types = Maps.newTreeMap(Comparators.stringComparator);
     for (IResourceDescription desc : index.getAllResourceDescriptions()) {
       for (IEObjectDescription objDesc :
           desc.getExportedObjectsByType(DatamodelPackage.eINSTANCE.getComplexType())) {
         ComplexType t = (ComplexType) objDesc.getEObjectOrProxy();
         types.put(t.getName(), t);
       }
     }
   }
   if (source.eIsProxy()) {
     throw new IllegalStateException("Proxy not resolved: " + source);
   }
   return types.get(source.getName());
 };
  public String getCrossRefText(
      EObject owner,
      CrossReference crossref,
      EObject target,
      RefTextEvaluator refTextEvaluator,
      ITextRegion linkTextRegion,
      StatusWrapper status) {
    try {
      final EReference ref = GrammarUtil.getReference(crossref, owner.eClass());
      final IScope scope = scopeProvider.getScope(owner, ref);
      if (scope == null) {
        throw new IllegalStateException("Could not create scope for the given cross reference.");
      }
      String ruleName = linkingHelper.getRuleNameFrom(crossref);

      Iterable<IEObjectDescription> descriptionsForCrossRef = scope.getElements(target);
      String bestRefText = null;
      for (IEObjectDescription desc : descriptionsForCrossRef) {
        try {
          String unconvertedRefText = qualifiedNameConverter.toString(desc.getName());
          String convertedRefText = valueConverter.toString(unconvertedRefText, ruleName);
          if (refTextEvaluator.isValid(convertedRefText)
              && (bestRefText == null
                  || refTextEvaluator.isBetterThan(convertedRefText, bestRefText)))
            bestRefText = convertedRefText;
        } catch (ValueConverterException e) {
          status.add(
              RefactoringStatus.WARNING,
              "Missconfigured language: New reference text has invalid syntax.",
              owner,
              linkTextRegion);
        }
      }
      if (bestRefText == null)
        status.add(
            RefactoringStatus.ERROR,
            "Refactoring introduces a name conflict.",
            owner,
            linkTextRegion);
      return bestRefText;

    } catch (Exception exc) {
      status.add(ERROR, exc.getMessage(), owner, linkTextRegion);
      return null;
    }
  }
Exemple #20
0
  private void buildExportedObjectsIndex(
      IResourceDescription descr, IResourceDescriptions descriptionIndex) {
    // The current (possibly dirty) exported resources
    IResourceDescription dirty =
        resourceServiceProvider.getResourceDescriptionManager().getResourceDescription(resource);
    String pathToCurrent = resource.getURI().path();

    Multimap<String, IEObjectDescription> map = ArrayListMultimap.create();
    // add all (possibly dirty in global index)
    for (IEObjectDescription d : dirty.getExportedObjects())
      map.put(d.getQualifiedName().getLastSegment(), d);
    // add all from global index, except those for current resource
    for (IEObjectDescription d : getExportedObjects(descr, descriptionIndex))
      if (!d.getEObjectURI().path().equals(pathToCurrent))
        map.put(d.getQualifiedName().getLastSegment(), d);
    exportedPerLastSegment = map;
  }
    protected boolean isAcceptedByPPTP(IEObjectDescription od) {
      // Contributions from .pptp files are not meaningful to open
      String path = od.getEObjectURI().path();
      if (path != null && path.endsWith(".pptp")) return false;

      // all other are ok (i.e. typically from .rb)
      // Only included those that are meaningful for user to open
      switch (od.getEClass().getClassifierID()) {
        case PPTPPackage.TYPE:
        case PPTPPackage.FUNCTION:
        case PPTPPackage.PARAMETER:
        case PPTPPackage.PROPERTY:
        case PPTPPackage.META_TYPE:
        case PPTPPackage.META_VARIABLE:
          return true;
      }
      return false;
    }
Exemple #22
0
 public boolean namesIntersect(
     final IResourceDescription resourceDescription, final Set<QualifiedName> names) {
   boolean _xblockexpression = false;
   {
     boolean _equals = Objects.equal(resourceDescription, null);
     if (_equals) {
       return false;
     }
     Iterable<IEObjectDescription> _exportedObjects = resourceDescription.getExportedObjects();
     for (final IEObjectDescription objectDescription : _exportedObjects) {
       QualifiedName _qualifiedName = objectDescription.getQualifiedName();
       boolean _contains = names.contains(_qualifiedName);
       if (_contains) {
         return true;
       }
     }
     _xblockexpression = (false);
   }
   return _xblockexpression;
 }
 protected boolean isAcceptedByPP(IEObjectDescription od) {
   switch (od.getEClass().getClassifierID()) {
     case PPPackage.HOST_CLASS_DEFINITION:
     case PPPackage.DEFINITION:
     case PPPackage.DEFINITION_ARGUMENT:
     case PPPackage.VARIABLE_EXPRESSION:
     case PPPackage.NODE_DEFINITION:
       return true;
   }
   return false;
 }
Exemple #24
0
  protected List<IEObjectDescription> findAttributesWithGuard(
      EObject scopeDetermeningObject,
      QualifiedName fqn,
      PPImportedNamesAdapter importedNames,
      List<QualifiedName> stack,
      boolean prefixMatch) {
    // Protect against circular inheritance
    QualifiedName containerName = fqn.skipLast(1);
    if (stack.contains(containerName)) return Collections.emptyList();
    stack.add(containerName);

    // find a regular DefinitionArgument, Property or Parameter
    final List<IEObjectDescription> result =
        findExternal(
            scopeDetermeningObject, fqn, importedNames, prefixMatch, DEF_AND_TYPE_ARGUMENTS);

    // Search up the inheritance chain if no match (on exact match), or if a prefix search
    if (result.isEmpty() || prefixMatch) {
      // find the parent type
      List<IEObjectDescription> parentResult =
          findExternal(scopeDetermeningObject, fqn.skipLast(1), importedNames, false, DEF_AND_TYPE);
      if (!parentResult.isEmpty()) {
        IEObjectDescription firstFound = parentResult.get(0);
        String parentName = firstFound.getUserData(PPDSLConstants.PARENT_NAME_DATA);
        if (parentName != null && parentName.length() > 1) {
          // find attributes for parent

          QualifiedName attributeFqn = converter.toQualifiedName(parentName);
          attributeFqn = attributeFqn.append(fqn.getLastSegment());
          if (prefixMatch)
            result.addAll(
                findAttributesWithGuard(
                    scopeDetermeningObject, attributeFqn, importedNames, stack, prefixMatch));
          else
            return findAttributesWithGuard(
                scopeDetermeningObject, attributeFqn, importedNames, stack, prefixMatch);
        }
      }
    }
    return result;
  }
Exemple #25
0
  protected void cacheMetaParameters(EObject scopeDetermeningObject) {
    // System.err.println("Computing meta cache");
    metaCache = Maps.newHashMap();
    Resource scopeDetermeningResource = scopeDetermeningObject.eResource();

    IResourceDescriptions descriptionIndex =
        indexProvider.getResourceDescriptions(scopeDetermeningResource);
    IResourceDescription descr =
        descriptionIndex.getResourceDescription(scopeDetermeningResource.getURI());
    if (descr == null) return; // give up - some sort of clean build
    EClass wantedType = PPTPPackage.Literals.TYPE_ARGUMENT;
    for (IContainer visibleContainer : manager.getVisibleContainers(descr, descriptionIndex)) {
      for (IEObjectDescription objDesc : visibleContainer.getExportedObjects()) {
        QualifiedName q = objDesc.getQualifiedName();
        if ("Type".equals(q.getFirstSegment())) {
          if (wantedType == objDesc.getEClass() || wantedType.isSuperTypeOf(objDesc.getEClass()))
            metaCache.put(q.getLastSegment(), objDesc);
        }
      }
    }
  }
    protected boolean isNameMatches(
        SearchPattern searchPattern, IEObjectDescription eObjectDescription) {
      String qualifiedName = qualifiedNameConverter.toString(eObjectDescription.getQualifiedName());
      if (qualifiedName == null) return false;

      if (searchPattern.matches(qualifiedName)) return true;

      int index = qualifiedName.lastIndexOf("::");
      if (index != -1 && searchPattern.matches(qualifiedName.substring(index + 1))) return true;

      return false;
    }
    protected boolean isClassAccepted(IEObjectDescription od, Collection<EClass> acceptedClasses) {
      EClass eclass = od.getEClass();
      EPackage epackage = eclass.getEPackage();
      // user supplied filter
      if (acceptedClasses != null
          && acceptedClasses.size() != 0
          && !acceptedClasses.contains(eclass)) return false;

      if (epackage == PPPackage.eINSTANCE) return isAcceptedByPP(od);
      if (epackage == PPTPPackage.eINSTANCE) return isAcceptedByPPTP(od);
      return false;
    }
  public String getJavaStubSource(IEObjectDescription description) {
    if (!isJvmDeclaredType(description)) {
      return null;
    }
    QualifiedName qualifiedName = description.getQualifiedName();

    StringBuilder classSignatureBuilder = new StringBuilder();
    if (qualifiedName.getSegments().size() > 1) {
      String string = qualifiedName.toString();
      classSignatureBuilder.append("package " + string.substring(0, string.lastIndexOf('.')) + ";");
      classSignatureBuilder.append("\n");
    }
    classSignatureBuilder.append("public ");
    if (description.getEClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) {
      if (description.getUserData(JvmTypesResourceDescriptionStrategy.IS_INTERFACE) != null) {
        classSignatureBuilder.append("interface ");
      } else {
        classSignatureBuilder.append("class ");
      }
    } else if (description.getEClass() == TypesPackage.Literals.JVM_ENUMERATION_TYPE) {
      classSignatureBuilder.append("enum ");
    } else if (description.getEClass() == TypesPackage.Literals.JVM_ANNOTATION_TYPE) {
      classSignatureBuilder.append("@interface ");
    }
    classSignatureBuilder.append(qualifiedName.getLastSegment());
    String typeParameters =
        description.getUserData(JvmTypesResourceDescriptionStrategy.TYPE_PARAMETERS);
    if (typeParameters != null) {
      classSignatureBuilder.append(typeParameters);
    }
    classSignatureBuilder.append("{}");
    return classSignatureBuilder.toString();
  }
 @Override
 public Object[] getVariants() {
   ArrayList<LookupElementBuilder> _xblockexpression = null;
   {
     ProgressIndicatorProvider.checkCanceled();
     ICrossReferenceDescription crossReferenceDescription = this.getCrossReferenceDescription();
     boolean _equals = Objects.equal(crossReferenceDescription, null);
     if (_equals) {
       return ((Object[])
           Conversions.unwrapArray(CollectionLiterals.<Object>emptyList(), Object.class));
     }
     ArrayList<LookupElementBuilder> variants =
         CollectionLiterals.<LookupElementBuilder>newArrayList();
     Iterable<IEObjectDescription> _variants = crossReferenceDescription.getVariants();
     for (final IEObjectDescription objectDescription : _variants) {
       {
         ProgressIndicatorProvider.checkCanceled();
         QualifiedName _name = objectDescription.getName();
         String name = this.qualifiedNameConverter.toString(_name);
         BaseXtextFile _xtextFile = this.myElement.getXtextFile();
         XtextResource _resource = _xtextFile.getResource();
         PsiElement element =
             this.psiModelAssociations.getPsiElement(objectDescription, _resource);
         boolean _notEquals = (!Objects.equal(element, null));
         if (_notEquals) {
           LookupElementBuilder _create = LookupElementBuilder.create(name);
           PsiElement _navigationElement = element.getNavigationElement();
           PsiFile _containingFile = _navigationElement.getContainingFile();
           String _name_1 = _containingFile.getName();
           LookupElementBuilder _withTypeText = _create.withTypeText(_name_1);
           variants.add(_withTypeText);
         }
       }
     }
     _xblockexpression = variants;
   }
   return ((Object[]) Conversions.unwrapArray(_xblockexpression, Object.class));
 }
 @Override
 public Object text(final IEObjectDescription ele) {
   QualifiedName _name = ele.getName();
   return ("" + _name);
 }