Examples of TemplateVariable


Examples of com.dubture.symfony.core.model.TemplateVariable

                    FullyQualifiedReference ref = (FullyQualifiedReference) param.getParameterType();
                    NamespaceReference nsRef = createFromFQCN(ref);

                    if (nsRef != null) {
                        TemplateVariable tempVar= new TemplateVariable(currentMethod, param.getName(), param.sourceStart(), param.sourceEnd(), nsRef.namespace, nsRef.className);
                        deferredVariables.push(tempVar);
                    }

                /* public function ($somevar) { } */
                } else {
                    TemplateVariable tempVar= new TemplateVariable(currentMethod, param.getName(), param.sourceStart(), param.sourceEnd(), null, null);
                    deferredVariables.push(tempVar);
                }
            }
        }

View Full Code Here

Examples of com.dubture.symfony.core.model.TemplateVariable

                        // we got it, find the returntype of the
                        // callExpression
                        if (deferred.getName().equals(varRef.getName())) {

                            TemplateVariable tempVar = SymfonyModelAccess.getDefault()
                                    .createTemplateVariableByReturnType(source, currentMethod,
                                            callName, deferred.getClassName(), deferred.getNamespace(),
                                            varRef.getName(), cache);

                            templateVariables.put(tempVar, viewPath);
                            break;
                        }
                    }

                    // this is a direct ClassInstanceCreation, ie:
                    // return array('user' => new User());
                } else if (value.getClass() == ClassInstanceCreation.class) {

                    ClassInstanceCreation instance = (ClassInstanceCreation) value;

                    if (instance.getClassName().getClass() == FullyQualifiedReference.class) {

                        FullyQualifiedReference fqcn = (FullyQualifiedReference) instance.getClassName();
                        NamespaceReference nsRef = createFromFQCN(fqcn);

                        if (nsRef != null) {
                            TemplateVariable variable = new TemplateVariable(currentMethod, varName.getValue(),
                                    varName.sourceStart(), varName.sourceEnd(), nsRef.getNamespace(), nsRef.getClassName());
                            templateVariables.put(variable, viewPath);
                        }
                    }
                } else {
View Full Code Here

Examples of com.dubture.symfony.core.model.TemplateVariable

                        if (service != null) {

                            String fqsn =  service.getNamespace() != null ? service.getNamespace().getQualifiedName() : null;

                            TemplateVariable tempVar= new TemplateVariable(currentMethod, var.getName(), exp.sourceStart(), exp.sourceEnd(), fqsn, service.getClassName());
                            deferredVariables.push(tempVar);
                        }

                        // a more complex expression like
                        // $form = $this->get('form.factory')->create(new ContactType());
                    } else if (exp.getReceiver().getClass() == PHPCallExpression.class) {

                        // try to extract a service if it's a Servicecontainer call
                        service = ModelUtils.extractServiceFromCall((PHPCallExpression) exp.getReceiver(), source.getScriptProject().getPath());

                        // nothing found, return
                        if (service == null || exp.getCallName() == null) {
                            return true;
                        }

                        SimpleReference callName = exp.getCallName();

                        //TODO: this is a problematic case, as during a clean build
                        // it's possible that the SourceModule in which the
                        // called method was declared is not yet in the index, so
                        // the return type cannot be evaluated and therefore
                        // the templatevariable won't be created...
                        //
                        // Possible solution: check if there's an event fired when the
                        // build is completed and store those return types in a global
                        // singleton, evaluate them when the whole build process is finished.


                        String fqsn = service.getNamespace() != null ? service.getNamespace().getQualifiedName() : null;
                        TemplateVariable tempVar = null;

                            tempVar = SymfonyModelAccess.getDefault()
                                    .createTemplateVariableByReturnType(source, currentMethod, callName,
                                            service.getClassName(), fqsn, var.getName(), cache);

                        if (tempVar != null) {

                            deferredVariables.push(tempVar);
                        }

                        // something like $formView = $form->createView();
                    } else if (exp.getReceiver().getClass() == VariableReference.class) {

                        VariableReference varRef = (VariableReference) exp.getReceiver();
                        SimpleReference ref = exp.getCallName();

                        // check for a previosly declared variable
                        for (TemplateVariable tempVar : deferredVariables) {
                            if (tempVar.getName().equals(varRef.getName())) {

                                TemplateVariable tVar = SymfonyModelAccess.getDefault()
                                        .createTemplateVariableByReturnType(source, currentMethod, ref, tempVar.getClassName(), tempVar.getNamespace(), var.getName(), cache);

                                if (tVar != null) {
                                    deferredVariables.push(tVar);
                                    break;
                                }
                            }
                        }
                    }
                    // a simple ClassInstanceCreation, ie. $contact = new ContactType();
                } else if (s.getValue().getClass() == ClassInstanceCreation.class) {

                    ClassInstanceCreation instance = (ClassInstanceCreation) s.getValue();

                    if (instance.getClassName().getClass() == FullyQualifiedReference.class) {

                        FullyQualifiedReference fqcn = (FullyQualifiedReference) instance.getClassName();
                        NamespaceReference nsRef = createFromFQCN(fqcn);

                        if (nsRef != null) {
                            TemplateVariable variable = new TemplateVariable(currentMethod, var.getName(),
                                    var.sourceStart(), var.sourceEnd(), nsRef.getNamespace(), nsRef.getClassName());
                            deferredVariables.push(variable);
                        }
                    }
                } else if (s.getValue().getClass() == Scalar.class) {

                    TemplateVariable variable = new TemplateVariable(currentMethod, var.getName(), var.sourceStart(), var.sourceEnd(), null, null);
                    deferredVariables.push(variable);
                }
            }
        }
        return true;
View Full Code Here

Examples of com.dubture.symfony.core.model.TemplateVariable

            Map<TemplateVariable, String> variables = controllerIndexer.getTemplateVariables();
            Iterator it = variables.keySet().iterator();

            while(it.hasNext()) {

                TemplateVariable variable = (TemplateVariable) it.next();
                String viewPath = variables.get(variable);
                int start = variable.sourceStart();
                int length = variable.sourceEnd() - variable.sourceStart();
                String name = null;

                if (variable.isReference()) {

                    name = variable.getName();
                    String phpClass = variable.getClassName();
                    String namespace = variable.getNamespace();
                    String method = variable.getMethod().getName();
                    String metadata = JsonUtils.createReference(phpClass, namespace, viewPath, method);

                    if (viewPath.contains(".")) {
                        viewPath = viewPath.substring(0, viewPath.indexOf("."));
                    }

                    Logger.debugMSG("add reference info: " + name +  " =>  " + viewPath + " with metadata " + metadata);
                    ReferenceInfo info = new ReferenceInfo(ISymfonyModelElement.TEMPLATE_VARIABLE, start, length, name, metadata, viewPath);
                    requestor.addReference(info);

                } else if (variable.isScalar()) {

                    name = variable.getName();
                    String method = variable.getMethod().getName();
                    String metadata = JsonUtils.createScalar(name, viewPath, method);

                    if (viewPath.contains(".")) {
                        viewPath = viewPath.substring(0, viewPath.indexOf("."));
                    }

                    Logger.debugMSG("add scalar info: " + name +  " => " + viewPath + " with metadata: "  + metadata );
                    ReferenceInfo info = new ReferenceInfo(ISymfonyModelElement.TEMPLATE_VARIABLE, start, length, name, metadata, viewPath);
                    requestor.addReference(info);
                } else {
                    Logger.debugMSG("Unable to resolve template variable: " + variable.getClass().toString());
                }
            }

            Stack<Route> routes = controllerIndexer.getRoutes();
            for (Route route : routes) {
View Full Code Here

Examples of org.eclipse.jface.text.templates.TemplateVariable

    String str = buffer.getString();
    if (Strings.containsOnlyWhitespaces(str)) {
      return null;
    }

    TemplateVariable position = findVariable(buffer,
        CodeTemplateContextType.TAGS); // look if PHPDoc tags have to
    // be added
    if (position == null) {
      return str;
    }

    IDocument document = new Document(str);
    int[] tagOffsets = position.getOffsets();
    for (int i = tagOffsets.length - 1; i >= 0; i--) { // from last to first
      try {
        insertTag(document, tagOffsets[i], position.getLength(), EMPTY,
            null, typeParameterNames, false, lineDelim, null);
      } catch (BadLocationException e) {
        throw new CoreException(DLTKUIStatus.createError(IStatus.ERROR,
            e));
      }
View Full Code Here

Examples of org.eclipse.jface.text.templates.TemplateVariable

    String str = buffer.getString();
    if (Strings.containsOnlyWhitespaces(str)) {
      return null;
    }
    TemplateVariable position = findVariable(buffer,
        CodeTemplateContextType.TAGS); // look if PHPDoc tags have to
    // be added
    if (position == null) {
      return str;
    }

    IDocument document = new Document(str);

    int[] tagOffsets = position.getOffsets();
    for (int i = tagOffsets.length - 1; i >= 0; i--) { // from last to first
      try {
        insertTag(document, tagOffsets[i], position.getLength(),
            paramNames, retTypeSig, typeParameterNames, false,
            lineDelimiter, newExceptions);
      } catch (BadLocationException e) {
        throw new CoreException(new Status(IStatus.ERROR,
            PHPUiPlugin.ID, e.getClass().getName(), e));
View Full Code Here

Examples of org.eclipse.jface.text.templates.TemplateVariable

    IDocument doc = new Document(buffer.getString());
    int nLines = doc.getNumberOfLines();
    MultiTextEdit edit = new MultiTextEdit();
    HashSet<Integer> removedLines = new HashSet<Integer>();
    for (int i = 0; i < variables.length; i++) {
      TemplateVariable position = findVariable(buffer, variables[i]); // look
      // if
      // Javadoc
      // tags
      // have
      // to
      // be
      // added
      if (position == null || position.getLength() > 0) {
        continue;
      }
      int[] offsets = position.getOffsets();
      for (int k = 0; k < offsets.length; k++) {
        int line = doc.getLineOfOffset(offsets[k]);
        IRegion lineInfo = doc.getLineInformation(line);
        int offset = lineInfo.getOffset();
        String str = doc.get(offset, lineInfo.getLength());
View Full Code Here

Examples of org.eclipse.jface.text.templates.TemplateVariable

  private static TemplateVariable findVariable(TemplateBuffer buffer,
      String variable) {
    TemplateVariable[] positions = buffer.getVariables();
    for (int i = 0; i < positions.length; i++) {
      TemplateVariable curr = positions[i];
      if (variable.equals(curr.getType())) {
        return curr;
      }
    }
    return null;
  }
View Full Code Here

Examples of org.eclipse.jface.text.templates.TemplateVariable

      templateBuffer.setContent(newTemplateString, variables);
    }
   
    private static void positionsToVariables(Position[] positions, TemplateVariable[] variables, int start) {
    for (int i= 0; i != variables.length; i++) {
        TemplateVariable variable= variables[i];
       
      int[] offsets= new int[variable.getOffsets().length];
      for (int j= 0; j != offsets.length; j++) {
        offsets[j]= positions[j].getOffset() - start;
      }
     
       variable.setOffsets(offsets);  
    }
  } 
View Full Code Here

Examples of org.eclipse.jface.text.templates.TemplateVariable

      list[x]= (new Integer(soFar.length()*x));
    }
    indented.setLength(indented.lastIndexOf(fLineDelimiter));
      TemplateVariable[] variables= templateBuffer.getVariables();
    for (int i= 0; i != variables.length; i++) {
        TemplateVariable variable= variables[i];
      int[] offsets= new int[variable.getOffsets().length];
      for (int j= 0; j != offsets.length; j++) {
        int offset = variable.getOffsets()[j];
        int varLine = pattern.substring(0,offset).split(fLineDelimiter).length;
        offsets[j]= offset + list[varLine-1];
      }     
       variable.setOffsets(offsets);  
    }
    templateBuffer.setContent(indented.toString(), variables);

   
    return templateBuffer;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.