Ejemplo n.º 1
0
 private IScope scope_TextPropertyAssignment_Attribute(EObject context) {
   NodeElement nodeElement = EcoreUtil2.getContainerOfType(context, NodeElement.class);
   EdgeElement edgeElement = EcoreUtil2.getContainerOfType(context, EdgeElement.class);
   if (nodeElement != null || edgeElement != null) {
     Predicate<EObject> filterPredicate =
         new Predicate<EObject>() {
           @Override
           public boolean apply(EObject input) {
             if (input instanceof EAttribute) {
               if (((EAttribute) input).getEType().getName().equals("EString")) {
                 return true;
               }
             }
             return false;
           }
         };
     if (nodeElement != null) {
       return MapBasedScope.createScope(
           IScope.NULLSCOPE,
           Scopes.scopedElementsFor(
               Iterables.filter(nodeElement.getType().getEAllAttributes(), filterPredicate)));
     } else {
       return MapBasedScope.createScope(
           IScope.NULLSCOPE,
           Scopes.scopedElementsFor(
               Iterables.filter(edgeElement.getType().getEAllAttributes(), filterPredicate)));
     }
   } else {
     return IScope.NULLSCOPE;
   }
 }
Ejemplo n.º 2
0
 private IScope scope_MetaClass_Type(EObject context, EReference reference) {
   Diagram diagram = EcoreUtil2.getContainerOfType(context, Diagram.class);
   // all eClasses that are direct containments of context's diagram model type
   final EClass diagramModelType = diagram.getModelType();
   if (diagramModelType == null || diagramModelType.getEPackage() == null) {
     return IScope.NULLSCOPE;
   }
   final Predicate<EClassifier> filter =
       new Predicate<EClassifier>() {
         @Override
         public boolean apply(EClassifier input) {
           return input instanceof EClass
               && input != diagramModelType
               && !((EClass) input).isAbstract();
         }
       };
   final Function<EClassifier, IEObjectDescription> toObjDesc =
       new Function<EClassifier, IEObjectDescription>() {
         @Override
         public IEObjectDescription apply(EClassifier input) {
           return EObjectDescription.create(qnProvider.apply(input), input);
         }
       };
   // Implicit import of the EPackage of the Diagram Model type
   final List<ImportNormalizer> normalizer =
       Collections.singletonList(
           new ImportNormalizer(qnProvider.apply(diagramModelType.getEPackage()), true, false));
   final ImportScope importDiagramTypePackage =
       new ImportScope(normalizer, delegateGetScope(context, reference), null, null, false);
   final Iterable<IEObjectDescription> descriptions =
       Iterables.transform(
           Iterables.filter(diagramModelType.getEPackage().getEClassifiers(), filter), toObjDesc);
   // the delegate scope will provide import scopes
   return MapBasedScope.createScope(importDiagramTypePackage, descriptions);
 }
Ejemplo n.º 3
0
 protected IScope createTypeScope(
     JvmIdentifiableElement context, EReference reference, IScope parentScope) {
   if (context == null) return parentScope;
   if (context.eContainer() instanceof JvmIdentifiableElement) {
     parentScope =
         createTypeScope((JvmIdentifiableElement) context.eContainer(), reference, parentScope);
   }
   if (context instanceof JvmGenericType) {
     JvmGenericType genericType = (JvmGenericType) context;
     List<IEObjectDescription> descriptions = Lists.newArrayList();
     if (genericType.getSimpleName() != null) {
       QualifiedName inferredDeclaringTypeName = QualifiedName.create(genericType.getSimpleName());
       descriptions.add(EObjectDescription.create(inferredDeclaringTypeName, genericType));
     }
     for (JvmTypeParameter param : genericType.getTypeParameters()) {
       if (param.getSimpleName() != null) {
         QualifiedName paramName = QualifiedName.create(param.getSimpleName());
         descriptions.add(EObjectDescription.create(paramName, param));
       }
     }
     if (!descriptions.isEmpty()) return MapBasedScope.createScope(parentScope, descriptions);
   } else if (context instanceof JvmOperation) {
     JvmOperation operation = (JvmOperation) context;
     List<IEObjectDescription> descriptions = null;
     for (JvmTypeParameter param : operation.getTypeParameters()) {
       if (param.getSimpleName() != null) {
         if (descriptions == null) descriptions = Lists.newArrayList();
         QualifiedName paramName = QualifiedName.create(param.getSimpleName());
         descriptions.add(EObjectDescription.create(paramName, param));
       }
     }
     if (descriptions != null && !descriptions.isEmpty())
       return MapBasedScope.createScope(parentScope, descriptions);
   }
   return parentScope;
 }
Ejemplo n.º 4
0
 private IScope scope_EdgeBehaviorSection_source(EObject context, EReference reference) {
   final EdgeElement edgeElement = EcoreUtil2.getContainerOfType(context, EdgeElement.class);
   // filter derived and 'from' from the possible references
   Iterable<EReference> targetReferences =
       Iterables.filter(
           edgeElement.getType().getEAllReferences(),
           new Predicate<EReference>() {
             @Override
             public boolean apply(EReference input) {
               return !input.isDerived();
             }
           });
   final IScope result =
       MapBasedScope.createScope(IScope.NULLSCOPE, Scopes.scopedElementsFor(targetReferences));
   return result;
 }
Ejemplo n.º 5
0
 private IScope getEnumerationLiteralsScopeForShape(JvmGenericType type, String className) {
   JvmEnumerationType enumType = null;
   for (JvmMember member : type.getMembers()) {
     if (member.getSimpleName().equals(className)) {
       enumType = (JvmEnumerationType) member;
     }
   }
   List<IEObjectDescription> descrList = new ArrayList<IEObjectDescription>();
   if (enumType != null) {
     for (JvmEnumerationLiteral literal : enumType.getLiterals()) {
       IEObjectDescription description =
           EObjectDescription.create(literal.getSimpleName(), literal, null);
       descrList.add(description);
     }
   }
   return MapBasedScope.createScope(IScope.NULLSCOPE, descrList);
 }
  protected IScope getLocalElementsScope(
      IScope parent, IScope globalScope, EObject context, EReference reference) {
    IScope result = parent;
    QualifiedName name = getQualifiedNameOfLocalElement(context);
    boolean ignoreCase = isIgnoreCase(reference);
    ISelectable resourceOnlySelectable = getAllDescriptions(context.eResource());
    ISelectable globalScopeSelectable = new ScopeBasedSelectable(globalScope);

    // imports
    List<ImportNormalizer> explicitImports = getImportedNamespaceResolvers(context, ignoreCase);
    if (!explicitImports.isEmpty()) {
      result =
          createImportScope(
              result,
              explicitImports,
              globalScopeSelectable,
              reference.getEReferenceType(),
              ignoreCase);
    }

    // local element
    if (name != null) {
      ImportNormalizer localNormalizer = doCreateImportNormalizer(name, true, ignoreCase);
      result =
          createImportScope(
              result,
              singletonList(localNormalizer),
              resourceOnlySelectable,
              reference.getEReferenceType(),
              ignoreCase);
    }

    // scope for jvm elements
    Set<EObject> elements = associations.getJvmElements(context);
    for (EObject derivedJvmElement : elements) {
      // scope for JvmDeclaredTypes
      if (derivedJvmElement instanceof JvmDeclaredType) {
        JvmDeclaredType declaredType = (JvmDeclaredType) derivedJvmElement;
        QualifiedName jvmTypeName = getQualifiedNameOfLocalElement(declaredType);
        if (declaredType.getDeclaringType() == null
            && !Strings.isEmpty(declaredType.getPackageName())) {
          QualifiedName packageName =
              this.qualifiedNameConverter.toQualifiedName(declaredType.getPackageName());
          ImportNormalizer normalizer = doCreateImportNormalizer(packageName, true, ignoreCase);
          result =
              createImportScope(
                  result,
                  singletonList(normalizer),
                  globalScopeSelectable,
                  reference.getEReferenceType(),
                  ignoreCase);
        }
        if (jvmTypeName != null && !jvmTypeName.equals(name)) {
          ImportNormalizer localNormalizer =
              doCreateImportNormalizer(jvmTypeName, true, ignoreCase);
          result =
              createImportScope(
                  result,
                  singletonList(localNormalizer),
                  resourceOnlySelectable,
                  reference.getEReferenceType(),
                  ignoreCase);
        }
      }
      // scope for JvmTypeParameterDeclarator
      if (derivedJvmElement instanceof JvmTypeParameterDeclarator) {
        JvmTypeParameterDeclarator parameterDeclarator =
            (JvmTypeParameterDeclarator) derivedJvmElement;
        List<IEObjectDescription> descriptions = null;
        for (JvmTypeParameter param : parameterDeclarator.getTypeParameters()) {
          if (param.getSimpleName() != null) {
            if (descriptions == null) descriptions = Lists.newArrayList();
            QualifiedName paramName = QualifiedName.create(param.getSimpleName());
            descriptions.add(EObjectDescription.create(paramName, param));
          }
        }
        if (descriptions != null && !descriptions.isEmpty())
          result = MapBasedScope.createScope(result, descriptions);
      }
    }
    return result;
  }