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 String getDisplayString(
     final EObject element, final String givenQualifiedNameAsString, final String shortName) {
   String qualifiedNameAsString = givenQualifiedNameAsString;
   boolean _equals = Objects.equal(qualifiedNameAsString, null);
   if (_equals) {
     qualifiedNameAsString = shortName;
   }
   boolean _equals_1 = Objects.equal(qualifiedNameAsString, null);
   if (_equals_1) {
     boolean _notEquals = (!Objects.equal(element, null));
     if (_notEquals) {
       ILabelProvider _labelProvider = this.getLabelProvider();
       String _text = _labelProvider.getText(element);
       qualifiedNameAsString = _text;
     } else {
       return null;
     }
   }
   if ((!(element instanceof MobaApplication))) {
     IQualifiedNameConverter _qualifiedNameConverter = this.getQualifiedNameConverter();
     final QualifiedName qualifiedName =
         _qualifiedNameConverter.toQualifiedName(qualifiedNameAsString);
     int _segmentCount = qualifiedName.getSegmentCount();
     boolean _greaterThan = (_segmentCount > 1);
     if (_greaterThan) {
       String _lastSegment = qualifiedName.getLastSegment();
       String _plus = (_lastSegment + " - ");
       return (_plus + qualifiedNameAsString);
     }
   }
   return qualifiedNameAsString;
 }
Esempio n. 3
0
 public List<IEObjectDescription> findHostClasses(
     EObject scopeDetermeningResource, String name, PPImportedNamesAdapter importedNames) {
   if (name == null) throw new IllegalArgumentException("name is null");
   QualifiedName fqn = converter.toQualifiedName(name);
   // make last segments initial char lower case (for references to the type itself - eg. 'File'
   // instead of
   // 'file'.
   fqn = fqn.skipLast(1).append(toInitialLowerCase(fqn.getLastSegment()));
   return findExternal(scopeDetermeningResource, fqn, importedNames, false, CLASS_AND_TYPE);
 }
Esempio n. 4
0
 @Override
 protected JvmType findNestedType(JvmType result, int index, QualifiedName name) {
   if (result.eContainer() instanceof JvmDeclaredType && name.getSegmentCount() == 1) {
     QualifiedName importName = importNames.get(index);
     if (importName != null && importName.getLastSegment().equals(name.getFirstSegment())) {
       return result;
     }
   }
   return super.findNestedType(result, index, name);
 }
Esempio n. 5
0
 @Override
 protected void doGetDescriptions(
     JvmType type, JvmType knownType, int i, List<IEObjectDescription> result) {
   super.doGetDescriptions(type, knownType, i, result);
   QualifiedName importName = importNames.get(i);
   if (type == knownType && importName != null) {
     result.add(
         EObjectDescription.create(QualifiedName.create(importName.getLastSegment()), type));
   }
 }
 protected Map<String, QualifiedName> getImplicitAliases() {
   if (implicitAliases == null) {
     implicitAliases = newHashMap();
     for (final EDataType eDataType : XcoreImportedNamespaceAwareScopeProvider.IMPLICIT_ALIASES) {
       String instanceClassName = eDataType.getInstanceClassName();
       final QualifiedName actualQualifiedName =
           QualifiedName.create("org", "eclipse", "emf", "ecore", eDataType.getName());
       final QualifiedName qualifiedName = nameConverter.toQualifiedName(instanceClassName);
       implicitAliases.put(instanceClassName, actualQualifiedName);
       implicitAliases.put(qualifiedName.getLastSegment(), actualQualifiedName);
     }
   }
   return implicitAliases;
 }
 /**
  * Create a new {@link ImportNormalizer} for the given namespace.
  *
  * @param namespace the namespace.
  * @param ignoreCase <code>true</code> if the resolver should be case insensitive.
  * @return a new {@link ImportNormalizer} or <code>null</code> if the namespace cannot be
  *     converted to a valid qualified name.
  */
 protected ImportNormalizer createImportedNamespaceResolver(
     final String namespace, boolean ignoreCase) {
   if (Strings.isEmpty(namespace)) return null;
   QualifiedName importedNamespace = qualifiedNameConverter.toQualifiedName(namespace);
   if (importedNamespace == null || importedNamespace.getSegmentCount() < 1) {
     return null;
   }
   boolean hasWildcard =
       ignoreCase
           ? importedNamespace.getLastSegment().equalsIgnoreCase(getWildcard())
           : importedNamespace.getLastSegment().equals(getWildcard());
   if (hasWildcard) {
     if (importedNamespace.getSegmentCount() <= 1) return null;
     return doCreateImportNormalizer(importedNamespace.skipLast(1), true, ignoreCase);
   } else {
     return doCreateImportNormalizer(importedNamespace, false, ignoreCase);
   }
 }
 protected void addNameAndDescription(
     final ContentAssistEntry entry,
     final EObject element,
     final String qualifiedNameAsString,
     final String shortName) {
   IQualifiedNameConverter _qualifiedNameConverter = this.getQualifiedNameConverter();
   final QualifiedName qualifiedName =
       _qualifiedNameConverter.toQualifiedName(qualifiedNameAsString);
   int _segmentCount = qualifiedName.getSegmentCount();
   boolean _greaterThan = (_segmentCount > 1);
   if (_greaterThan) {
     String _lastSegment = qualifiedName.getLastSegment();
     entry.setLabel(_lastSegment);
     entry.setDescription(qualifiedNameAsString);
   } else {
     entry.setLabel(qualifiedNameAsString);
   }
 }
Esempio n. 9
0
  /**
   * @param resourceBody
   * @param fqn
   * @return
   */
  public List<IEObjectDescription> findAttributesWithPrefix(
      ResourceBody resourceBody, QualifiedName fqn) {
    // Must be configured for the resource containing resourceBody
    List<IEObjectDescription> result = Lists.newArrayList();

    // do meta lookup first as this is made fast via a cache and these are used more frequent
    // than other parameters (measured).
    // TODO: VERIFY that empty last segment matches ok
    // TODO: Make sure that length of match is same number of segments
    if (metaCache == null) cacheMetaParameters(resourceBody);
    String fqnLast = fqn.getLastSegment();
    for (String name : metaCache.keySet())
      if (name.startsWith(fqnLast)) result.add(metaCache.get(name));

    result.addAll(
        findAttributesWithGuard(
            resourceBody, fqn, null, Lists.<QualifiedName>newArrayList(), true));
    return result;
  }
Esempio n. 10
0
  /**
   * Find an attribute being a DefinitionArgument, Property, or Parameter for the given type, or a
   * meta Property or Parameter defined for the type 'Type'.
   *
   * @param scopeDetermeningObject
   * @param fqn
   * @return
   */
  protected List<IEObjectDescription> findAttributes(
      EObject scopeDetermeningObject, QualifiedName fqn, PPImportedNamesAdapter importedNames) {
    List<IEObjectDescription> result = null;

    // do meta lookup first as this is made fast via a cache and these are used more frequent
    // than other parameters (measured).
    if (metaCache == null) cacheMetaParameters(scopeDetermeningObject);
    IEObjectDescription d = metaCache.get(fqn.getLastSegment());
    if (d == null)
      result =
          findAttributesWithGuard(
              scopeDetermeningObject,
              fqn,
              importedNames,
              Lists.<QualifiedName>newArrayList(),
              false);
    else result = Lists.newArrayList(d);
    return result;
  }
Esempio n. 11
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;
  }
Esempio n. 12
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);
        }
      }
    }
  }
Esempio n. 13
0
  protected List<IEObjectDescription> findExternal(
      EObject scopeDetermeningObject,
      QualifiedName fqn,
      PPImportedNamesAdapter importedNames,
      boolean prefixMatch,
      EClass... eClasses) {
    if (scopeDetermeningObject == null)
      throw new IllegalArgumentException("scope determening object is null");
    if (fqn == null) throw new IllegalArgumentException("name is null");
    if (eClasses == null || eClasses.length < 1)
      throw new IllegalArgumentException("eClass is null or empty");

    if (fqn.getSegmentCount() == 1 && "".equals(fqn.getSegment(0)))
      throw new IllegalArgumentException("FQN has one empty segment");

    // Not meaningful to record the fact that an Absolute reference was used as nothing
    // is named with an absolute FQN (i.e. it is only used to do lookup).
    final boolean absoluteFQN = fqn.getSegmentCount() > 0 && "".equals(fqn.getSegment(0));
    if (importedNames != null) importedNames.add(absoluteFQN ? fqn.skipFirst(1) : fqn);

    List<IEObjectDescription> targets = Lists.newArrayList();
    Resource scopeDetermeningResource = scopeDetermeningObject.eResource();

    if (scopeDetermeningResource != resource) {
      // This is a lookup in the perspective of some other resource
      IResourceDescriptions descriptionIndex =
          indexProvider.getResourceDescriptions(scopeDetermeningResource);
      IResourceDescription descr =
          descriptionIndex.getResourceDescription(scopeDetermeningResource.getURI());

      // GIVE UP (the system is performing a build clean).
      if (descr == null) return targets;
      QualifiedName nameOfScope = getNameOfScope(scopeDetermeningObject);

      // for(IContainer visibleContainer : manager.getVisibleContainers(descr, descriptionIndex)) {
      // for(EClass aClass : eClasses)
      for (IEObjectDescription objDesc :
          new NameInScopeFilter(
              prefixMatch,
              getExportedObjects(descr, descriptionIndex),
              // visibleContainer.getExportedObjects(),
              fqn,
              nameOfScope,
              eClasses)) targets.add(objDesc);
    } else {
      // This is lookup from the main resource perspective
      QualifiedName nameOfScope = getNameOfScope(scopeDetermeningObject);
      for (IEObjectDescription objDesc :
          new NameInScopeFilter(
              prefixMatch, //
              prefixMatch
                  ? exportedPerLastSegment.values()
                  : exportedPerLastSegment.get(fqn.getLastSegment()), //
              fqn,
              nameOfScope,
              eClasses)) targets.add(objDesc);
    }
    if (tracer.isTracing()) {
      for (IEObjectDescription d : targets)
        tracer.trace("    : ", converter.toString(d.getName()), " in: ", d.getEObjectURI().path());
    }
    return searchPathAdjusted(targets);
  }
Esempio n. 14
0
 protected boolean isLegacyMatch(int index, QualifiedName relativeName) {
   QualifiedName importedName = importNames.get(index);
   return importedName != null
       && relativeName.getSegmentCount() == 1
       && importedName.getLastSegment().equals(relativeName.getFirstSegment());
 }