コード例 #1
0
 /** 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;
 }
コード例 #2
0
 /**
  * This method serves as an entry point for the content assist scoping for features.
  *
  * @param context the context provides access to the resource set. If it is an assignment, it will
  *     be used to restrict scoping.
  * @param receiver the receiver of the feature call.
  */
 public IScope createFeatureCallScopeForReceiver(
     final XExpression context, final XExpression receiver, EReference reference) {
   if (!isFeatureCallScope(reference)) return IScope.NULLSCOPE;
   if (receiver == null || receiver.eIsProxy()) return IScope.NULLSCOPE;
   JvmTypeReference receiverType = typeProvider.getType(receiver, true);
   if (receiverType != null) {
     return createFeatureScopeForTypeRef(
         receiverType, context, getContextType(context), null, IScope.NULLSCOPE);
   }
   return IScope.NULLSCOPE;
 }
コード例 #3
0
  public CharSequence apply(ImportManager importManager) {
    JvmOperation cacheMethod =
        (JvmOperation)
            logicalContainerProvider.getLogicalContainer(createExtensionInfo.getCreateExpression());
    StringBuilderBasedAppendable appendable = new StringBuilderBasedAppendable(importManager);
    JvmDeclaredType containerType = cacheMethod.getDeclaringType();
    JvmTypeReference listType = typeReferences.getTypeForName(ArrayList.class, containerType);
    JvmTypeReference collectonLiterals =
        typeReferences.getTypeForName(CollectionLiterals.class, containerType);
    String cacheVarName = cacheField.getSimpleName();
    String cacheKeyVarName = appendable.declareVariable("CacheKey", "_cacheKey");
    appendable.append("final ");
    typeReferenceSerializer.serialize(listType, containerType, appendable);
    appendable.append(cacheKeyVarName).append(" = ");
    typeReferenceSerializer.serialize(collectonLiterals, containerType, appendable);
    appendable.append(".newArrayList(");
    EList<JvmFormalParameter> list = cacheMethod.getParameters();
    for (Iterator<JvmFormalParameter> iterator = list.iterator(); iterator.hasNext(); ) {
      JvmFormalParameter jvmFormalParameter = iterator.next();
      appendable.append(getVarName(jvmFormalParameter));
      if (iterator.hasNext()) {
        appendable.append(", ");
      }
    }
    appendable.append(");");
    // declare result variable
    JvmTypeReference returnType = typeProvider.getType(createExtensionInfo.getCreateExpression());
    appendable.append("\nfinal ");
    typeReferenceSerializer.serialize(returnType, containerType, appendable);
    String resultVarName = "_result";
    appendable.append(" ").append(resultVarName).append(";");
    // open synchronize block
    appendable.append("\nsynchronized (").append(cacheVarName).append(") {");
    appendable.increaseIndentation();
    // if the cache contains the key return the previously created object.
    appendable
        .append("\nif (")
        .append(cacheVarName)
        .append(".containsKey(")
        .append(cacheKeyVarName)
        .append(")) {");
    appendable.increaseIndentation();
    appendable
        .append("\nreturn ")
        .append(cacheVarName)
        .append(".get(")
        .append(cacheKeyVarName)
        .append(");");
    appendable.decreaseIndentation().append("\n}");
    // execute the creation
    compiler.toJavaStatement(createExtensionInfo.getCreateExpression(), appendable, true);
    appendable.append("\n");
    appendable.append(resultVarName).append(" = ");
    compiler.toJavaExpression(createExtensionInfo.getCreateExpression(), appendable);
    appendable.append(";");

    // store the newly created object in the cache
    appendable
        .append("\n")
        .append(cacheVarName)
        .append(".put(")
        .append(cacheKeyVarName)
        .append(", ")
        .append(resultVarName)
        .append(");");

    // close synchronize block
    appendable.decreaseIndentation();
    appendable.append("\n}");
    appendable
        .append("\n")
        .append(initializerMethod.getSimpleName())
        .append("(")
        .append(resultVarName);
    for (JvmFormalParameter parameter : cacheMethod.getParameters()) {
      appendable.append(", ").append(parameter.getName());
    }
    appendable.append(");");
    // return the result
    appendable.append("\nreturn ");
    appendable.append(resultVarName).append(";");
    return appendable.toString();
  }