Package com.puppetlabs.geppetto.pp

Examples of com.puppetlabs.geppetto.pp.ResourceBody


        if(result == null)
          result = defaultCase(theEObject);
        return result;
      }
      case PPPackage.RESOURCE_BODY: {
        ResourceBody resourceBody = (ResourceBody) theEObject;
        T result = caseResourceBody(resourceBody);
        if(result == null)
          result = defaultCase(theEObject);
        return result;
      }
View Full Code Here


    switch(bodyCount) {
      case 0:
        stream.appendBreaks(1);
        break;
      case 1:
        ResourceBody body = o.getResourceData().get(0);
        // no space after brace if first body has no title
        if(body.getNameExpr() != null)
          stream.appendSpace();
        internalFormatResourceBody(body, true, stream);
        stream.appendBreaks(1);
        break;
      default:
View Full Code Here

    // System.err.println("completeAttributeOperation_Key assignment to feature: " + assignment.getFeature() +
    // " model: " + model.eClass().getName() + " Text: " + context.getCurrentNode().getText());
    // super.completeAttributeOperation_Key(model, assignment, context, acceptor);

    // Proposal for AttributeOperation depends on context (the resource body)
    ResourceBody resourceBody = null;
    if(model.eClass() == PPPackage.Literals.RESOURCE_BODY) {
      // The model is a resource body if an AttributeOperation has not yet been detected by the grammar
      resourceBody = (ResourceBody) model;
    }
    else if(model.eClass() == PPPackage.Literals.ATTRIBUTE_OPERATION) {
      // The grammar is lenient with (=> value) being optional (or it is impossible to
      // get a ResourceBody context). Special handling is required to avoid producing a
      // new list o suggestions for the op position (as the grammar thinks a property name OR and op can
      // follow).
      resourceBody = (ResourceBody) model.eContainer().eContainer();

      // If the current caret position is after the end of the key (+1), do not offer any values
      String key = ((AttributeOperation) model).getKey();
      if(key != null && key.length() > 0 //
          && context.getOffset() > NodeModelUtils.getNode(model).getOffset() + key.length())
        return;

    }
    else
      // can not determine a context
      return;

    // INode lastCompleteNode = context.getLastCompleteNode();
    // EObject ge = lastCompleteNode.getGrammarElement();
    // if(ge instanceof RuleCall) {
    // RuleCall lastCompletedRuleCall = (RuleCall) ge;
    // System.err.println(lastCompletedRuleCall.getRule().getName());
    // }
    // if(context.getCurrentNode() instanceof HiddenLeafNode) {
    // PPGrammarAccess ppga = (PPGrammarAccess) grammarAccess;
    // if(ppga.getWSRule() == context.getCurrentNode().getGrammarElement())
    // return;
    // }
    try {
      // figure out the shape of the resource
      ResourceExpression resourceExpr = (ResourceExpression) resourceBody.eContainer();

      ClassifierAdapter adapter = ClassifierAdapterFactory.eINSTANCE.adapt(resourceExpr);
      int resourceType = adapter.getClassifier();
      // If resource is good, and not 'class', then it must have a known reference type.
      // the resource type - also requires getting the type name from the override's expression).
      if(resourceType == RESOURCE_IS_CLASSPARAMS) {
        // resource is pp: class { classname : parameter => value }

        // Find parameters for the class
        // Find the class
        final String className = stringConstantEvaluator.doToString(resourceBody.getNameExpr());
        if(className == null)
          return; // not a static expression
        // Need the class to get its full name
        ppFinder.configure(model.eResource());
        List<IEObjectDescription> descs = ppFinder.findHostClasses(resourceBody, className, null).getAdjusted();
View Full Code Here

   */
  @Override
  public void completeAttributeOperation_Op(EObject model, Assignment assignment, ContentAssistContext context,
      ICompletionProposalAcceptor acceptor) {
    // Proposal for AttributeOperation depends on context (the resource body)
    ResourceBody resourceBody = null;
    if(model.eClass() == PPPackage.Literals.RESOURCE_BODY) {
      // The model is a resource body if an AttributeOperation has not yet been detected by the grammar
      resourceBody = (ResourceBody) model;
    }
    else if(model.eClass() == PPPackage.Literals.ATTRIBUTE_OPERATION) {
      // The grammar is lenient with (=> value) being optional (or it is imposible to
      // get a ResourceBody context). Special handling is required to avoid producing a
      // new list o suggestions for the op position (as the grammar thinks a property name OR and op can
      // follow).
      resourceBody = (ResourceBody) model.eContainer().eContainer();

    }
    else {
      // can not determine a context
      super.completeAttributeOperation_Op(model, assignment, context, acceptor);
      return;
    }
    try {
      // figure out the shape of the resource
      ResourceExpression resourceExpr = (ResourceExpression) resourceBody.eContainer();

      ClassifierAdapter adapter = ClassifierAdapterFactory.eINSTANCE.adapt(resourceExpr);
      int resourceType = adapter.getClassifier();
      acceptor.accept(createCompletionProposal("=>", context));
      if(resourceType == RESOURCE_IS_OVERRIDE)
View Full Code Here

    o.setValue(name);
    return o;
  }

  protected ResourceBody createResourceBody(boolean additive, Expression titleExpr, Object... keyValPairs) {
    ResourceBody rb = pf.createResourceBody();
    rb.setNameExpr(titleExpr);
    AttributeOperations aos = pf.createAttributeOperations();
    EList<AttributeOperation> aoList = aos.getAttributes();
    for(int i = 0; i < keyValPairs.length; i++) {
      AttributeOperation ao = pf.createAttributeOperation();
      ao.setOp(additive
          ? "+>"
          : "=>");
      if(!(keyValPairs[i] instanceof String))
        throw new IllegalArgumentException("Bad test spec, key not a String");
      ao.setKey((String) (keyValPairs[i++]));

      if(keyValPairs[i] instanceof String) {
        SingleQuotedString valueExpr = pf.createSingleQuotedString();
        valueExpr.setText((String) (keyValPairs[i]));
        ao.setValue(valueExpr);
      }
      else if(keyValPairs[i] instanceof Expression)
        ao.setValue((Expression) keyValPairs[i]);
      else
        throw new IllegalArgumentException("Bad test spec, keyValPair value neither String not expression");
      aoList.add(ao);
    }
    if(aos.getAttributes().size() > 0)
      rb.setAttributes(aos);
    return rb;
  }
View Full Code Here

TOP

Related Classes of com.puppetlabs.geppetto.pp.ResourceBody

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.