Package org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks

Examples of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock


    builder.replaceElement(pattern,
                           new TextRange(1, patternText.length() - 1),
                           patternText.substring(1, patternText.length() - 1));

    // block vars
    GrClosableBlock closure = methodCall.getClosureArguments()[0];
    final GrParameter[] blockVars = closure.getAllParameters();
    for (GrParameter var : blockVars) {
      PsiElement identifier = var.getNameIdentifierGroovy();
      builder.replaceElement(identifier, identifier.getText());
    }

    TemplateManager manager = TemplateManager.getInstance(project);

    final Editor editorToRunTemplate;
    if (editor == null) {
      editorToRunTemplate = IntentionUtils.positionCursor(project, file, methodCall);
    }
    else {
      editorToRunTemplate = editor;
    }

    Template template = builder.buildTemplate();

    TextRange range = methodCall.getTextRange();
    editorToRunTemplate.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
    editorToRunTemplate.getCaretModel().moveToOffset(range.getStartOffset());

    manager.startTemplate(editorToRunTemplate, template, new TemplateEditingAdapter() {
      @Override
      public void templateFinished(Template template, boolean brokenOff) {
        if (brokenOff) return;

        ApplicationManager.getApplication().runWriteAction(new Runnable() {
          @Override
          public void run() {
            PsiDocumentManager.getInstance(project).commitDocument(editorToRunTemplate.getDocument());
            final int offset = editorToRunTemplate.getCaretModel().getOffset();
            GrMethodCall methodCall = PsiTreeUtil.findElementOfClassAtOffset(file, offset - 1, GrMethodCall.class, false);
            if (methodCall != null) {
              GrClosableBlock[] closures = methodCall.getClosureArguments();
              if (closures.length == 1) {
                GrClosableBlock closure = closures[0];
                selectBody(closure, editor);
              }
            }
          }
        });
View Full Code Here


                                     @NotNull ResolveState state) {
    if (place instanceof GrReferenceExpression &&
        ((GrReferenceExpression)place).getQualifier() == null &&
        qualifierType.equalsToText(GroovyCommonClassNames.GROOVY_LANG_CLOSURE)) {

      final GrClosableBlock closureContainer = PsiTreeUtil.getParentOfType(place, GrClosableBlock.class, true, GrMember.class);
      if (closureContainer != null) {
        PsiElement parent = closureContainer.getParent();
        if (parent instanceof GrArgumentList && isLastArg((GrArgumentList)parent, closureContainer)) {
          parent = parent.getParent();
        }

        if (parent instanceof GrMethodCall && (GrCucumberUtil.isStepDefinition(parent) || GrCucumberUtil.isHook((GrMethodCall)parent))) {
View Full Code Here

      @Nullable
      @Override
      public Result<PsiType> compute() {
        for (GrStatement statement : stepFile.getStatements()) {
          if (statement instanceof GrMethodCall && isWorldDeclaration((GrMethodCall)statement)) {
            final GrClosableBlock closure = getClosureArg((GrMethodCall)statement);
            return Result.create(closure == null ? null : closure.getReturnType(), stepFile);
          }
        }
        return Result.create(null, stepFile);
      }
    });
View Full Code Here

TOP

Related Classes of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock

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.