Java Code Examples for com.intellij.psi.PsiElement#getLastChild()

The following examples show how to use com.intellij.psi.PsiElement#getLastChild() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PsiAwareLineWrapPositionStrategy.java    From consulo with Apache License 2.0 6 votes vote down vote up
@javax.annotation.Nullable
private static PsiElement getPrevious(@Nonnull PsiElement element) {
  PsiElement result = element.getPrevSibling();
  if (result != null) {
    return result;
  } 
  
  PsiElement parent = element.getParent();
  if (parent == null) {
    return null;
  }

  PsiElement parentSibling = null;
  for (; parent != null && parentSibling == null; parent = parent.getParent()) {
    parentSibling = parent.getPrevSibling();
  }

  if (parentSibling == null) {
    return null;
  }

  result = parentSibling.getLastChild();
  return result == null ? parentSibling : result;
}
 
Example 2
Source File: PsiUtils.java    From intellij with Apache License 2.0 6 votes vote down vote up
/**
 * Walk through entire PSI tree rooted at 'element', processing all children of the given type.
 *
 * @return true if processing was stopped by the processor
 */
private static <T extends PsiElement> boolean processChildrenOfType(
    PsiElement element, Processor<T> processor, Class<T> psiClass, boolean reverseOrder) {
  PsiElement child = reverseOrder ? element.getLastChild() : element.getFirstChild();
  while (child != null) {
    if (psiClass.isInstance(child)) {
      if (!processor.process((T) child)) {
        return true;
      }
    }
    if (processChildrenOfType(child, processor, psiClass, reverseOrder)) {
      return true;
    }
    child = reverseOrder ? child.getPrevSibling() : child.getNextSibling();
  }
  return false;
}
 
Example 3
Source File: PsiScopesUtilCore.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static boolean walkChildrenScopes(@Nonnull PsiElement thisElement,
                                         @Nonnull PsiScopeProcessor processor,
                                         @Nonnull ResolveState state,
                                         PsiElement lastParent,
                                         PsiElement place) {
  PsiElement child = null;
  if (lastParent != null && lastParent.getParent() == thisElement) {
    child = lastParent.getPrevSibling();
    if (child == null) return true; // first element
  }

  if (child == null) {
    child = thisElement.getLastChild();
  }

  while (child != null) {
    if (!child.processDeclarations(processor, state, null, place)) return false;
    child = child.getPrevSibling();
  }

  return true;
}
 
Example 4
Source File: HaxeAbstractEnumUtil.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@Nullable
@Contract("null -> null")
public static ResultHolder getStaticMemberExpression(@Nullable PsiElement expression) {
  if (expression != null) {
    final PsiElement containerElement = expression.getFirstChild();
    final PsiElement memberElement = expression.getLastChild();

    if (containerElement instanceof HaxeReference && memberElement instanceof HaxeIdentifier) {
      final HaxeClass leftClass = ((HaxeReference)containerElement).resolveHaxeClass().getHaxeClass();
      if (isAbstractEnum(leftClass)) {
        final HaxeNamedComponent enumField = leftClass.findHaxeFieldByName(memberElement.getText());
        if (enumField != null) {
          ResultHolder result = getFieldType(enumField);
          if (result != null) {
            return result;
          }
        }
      }
    }
  }
  return null;
}
 
Example 5
Source File: CsvIntentionHelper.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
public static void quoteAll(@NotNull Project project, @NotNull PsiFile psiFile) {
    try {
        Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
        List<Integer> quotePositions = new ArrayList<>();
        Collection<PsiElement> fields = getAllFields(psiFile);
        PsiElement separator;
        for (PsiElement field : fields) {
            if (field.getFirstChild() == null || CsvHelper.getElementType(field.getFirstChild()) != CsvTypes.QUOTE) {
                separator = CsvHelper.getPreviousSeparator(field);
                if (separator == null) {
                    quotePositions.add(field.getParent().getTextOffset());
                } else {
                    quotePositions.add(separator.getTextOffset() + separator.getTextLength());
                }
            }
            if (field.getLastChild() == null || CsvHelper.getElementType(field.getLastChild()) != CsvTypes.QUOTE) {
                separator = CsvHelper.getNextSeparator(field);
                if (separator == null) {
                    quotePositions.add(field.getParent().getTextOffset() + field.getParent().getTextLength());
                } else {
                    quotePositions.add(separator.getTextOffset());
                }
            }
        }
        String text = addQuotes(document.getText(), quotePositions);
        document.setText(text);
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
 
Example 6
Source File: CsvIntentionHelper.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
public static int getOpeningQuotePosition(PsiElement errorElement) {
    PsiElement lastFieldElement = errorElement;
    while (CsvHelper.getElementType(lastFieldElement) != CsvTypes.RECORD) {
        lastFieldElement = lastFieldElement.getPrevSibling();
    }
    lastFieldElement = lastFieldElement.getLastChild();
    if (CsvHelper.getElementType(lastFieldElement) != CsvTypes.FIELD) {
        throw new IllegalArgumentException("Field element expected");
    }
    return getOpeningQuotePosition(lastFieldElement.getFirstChild(), lastFieldElement.getLastChild());
}
 
Example 7
Source File: CsvHelper.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
public static PsiElement getParentFieldElement(final PsiElement element) {
    PsiElement currentElement = element;
    IElementType elementType = CsvHelper.getElementType(currentElement);

    if (elementType == CsvTypes.COMMA || elementType == CsvTypes.CRLF) {
        currentElement = currentElement.getPrevSibling();
        elementType = CsvHelper.getElementType(currentElement);
    }

    if (elementType == CsvTypes.RECORD) {
        currentElement = currentElement.getLastChild();
        elementType = CsvHelper.getElementType(currentElement);
    }

    if (elementType == TokenType.WHITE_SPACE) {
        if (CsvHelper.getElementType(currentElement.getParent()) == CsvTypes.FIELD) {
            currentElement = currentElement.getParent();
        } else if (CsvHelper.getElementType(currentElement.getPrevSibling()) == CsvTypes.FIELD) {
            currentElement = currentElement.getPrevSibling();
        } else if (CsvHelper.getElementType(currentElement.getNextSibling()) == CsvTypes.FIELD) {
            currentElement = currentElement.getNextSibling();
        } else {
            currentElement = null;
        }
    } else {
        while (currentElement != null && elementType != CsvTypes.FIELD) {
            currentElement = currentElement.getParent();
            elementType = CsvHelper.getElementType(currentElement);
        }
    }
    return currentElement;
}
 
Example 8
Source File: PsiUtils.java    From intellij with Apache License 2.0 5 votes vote down vote up
/** The last element in the tree rooted at the given element. */
public static PsiElement lastElementInSubtree(PsiElement element) {
  PsiElement lastChild;
  while ((lastChild = element.getLastChild()) != null) {
    element = lastChild;
  }
  return element;
}
 
Example 9
Source File: BuckFoldingBuilder.java    From buck with Apache License 2.0 5 votes vote down vote up
private static PsiElement deepLast(PsiElement element) {
  while (true) {
    PsiElement child = element.getLastChild();
    if (child == null) {
      break;
    }
    element = child;
  }
  return element;
}
 
Example 10
Source File: WhitespaceUtils.java    From bamboo-soy with Apache License 2.0 5 votes vote down vote up
@Nullable
public static PsiElement getLastMeaningChild(PsiElement element) {
  PsiElement last = element.getLastChild();
  return last instanceof PsiWhiteSpace || last instanceof PsiComment
      ? getPrevMeaningSibling(last)
      : last;
}
 
Example 11
Source File: ANTLRv4FoldingBuilder.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void addTokensFoldingDescriptor(List<FoldingDescriptor> descriptors, PsiElement root) {
    PsiElement tokensSpec = MyPsiUtils.findFirstChildOfType(root, TOKENSSPEC);
    if (tokensSpec != null) {
        PsiElement tokens = tokensSpec.getFirstChild();
        if ( tokens.getNode().getElementType() == TOKENS ) {
            PsiElement rbrace = tokensSpec.getLastChild();
            if ( rbrace.getNode().getElementType()==RBRACE ) {
                descriptors.add(new FoldingDescriptor(tokensSpec,
                                                      new TextRange(tokens.getTextRange().getEndOffset(), rbrace.getTextRange().getEndOffset())));
            }
        }
    }
}
 
Example 12
Source File: ResolveUtil.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
public static <T extends XQueryPsiElement> boolean processChildren(PsiElement element, PsiScopeProcessor processor,
        ResolveState substitutor, PsiElement lastParent, PsiElement place, Class<T>... childClassesToSkip) {
    PsiElement run = lastParent == null ? element.getLastChild() : lastParent.getPrevSibling();
    while (run != null) {
        if (!isAnyOf(run, childClassesToSkip) &&PsiTreeUtil.findCommonParent(place, run) != run && !run.processDeclarations(processor, substitutor,
                null, place)) {
            return false;
        }
        run = run.getPrevSibling();
    }

    return true;
}
 
Example 13
Source File: AtAction.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
public String getActionBlockText() {
	PsiElement actionBlock = findChildByType(ANTLRv4TokenTypes.getRuleElementType(ANTLRv4Parser.RULE_actionBlock));

	if (actionBlock != null) {
		PsiElement openingBrace = actionBlock.getFirstChild();
		PsiElement closingBrace = actionBlock.getLastChild();

		return actionBlock.getText().substring(openingBrace.getStartOffsetInParent() + 1, closingBrace.getStartOffsetInParent());
	}

	return "";
}
 
Example 14
Source File: LtGtInsertHandler.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Override
public void handleInsert(final InsertionContext context, final T item)
{
	final Editor editor = context.getEditor();
	final Document document = editor.getDocument();
	context.commitDocument();
	PsiElement element = findNextToken(context);

	final char completionChar = context.getCompletionChar();
	final boolean putCaretInside = completionChar == '<' || placeCaretInsideParentheses(context, item);

	if(completionChar == '<')
	{
		context.setAddCompletionChar(false);
	}

	if(isToken(element, "<"))
	{
		int lparenthOffset = element.getTextRange().getStartOffset();
		if(mySpaceBeforeParentheses && lparenthOffset == context.getTailOffset())
		{
			document.insertString(context.getTailOffset(), " ");
			lparenthOffset++;
		}

		if(completionChar == '<' || completionChar == '\t')
		{
			editor.getCaretModel().moveToOffset(lparenthOffset + 1);
		}
		else
		{
			editor.getCaretModel().moveToOffset(context.getTailOffset());
		}

		context.setTailOffset(lparenthOffset + 1);

		PsiElement list = element.getParent();
		PsiElement last = list.getLastChild();
		if(isToken(last, ">"))
		{
			int rparenthOffset = last.getTextRange().getStartOffset();
			context.setTailOffset(rparenthOffset + 1);
			if(!putCaretInside)
			{
				for(int i = lparenthOffset + 1; i < rparenthOffset; i++)
				{
					if(!Character.isWhitespace(document.getCharsSequence().charAt(i)))
					{
						return;
					}
				}
				editor.getCaretModel().moveToOffset(context.getTailOffset());
			}
			else if(mySpaceBetweenParentheses && document.getCharsSequence().charAt(lparenthOffset) == ' ')
			{
				editor.getCaretModel().moveToOffset(lparenthOffset + 2);
			}
			else
			{
				editor.getCaretModel().moveToOffset(lparenthOffset + 1);
			}
			return;
		}
	}
	else
	{
		document.insertString(context.getTailOffset(), getSpace(mySpaceBeforeParentheses) + "<" + getSpace(mySpaceBetweenParentheses));
		editor.getCaretModel().moveToOffset(context.getTailOffset());
	}

	if(!myMayInsertRightParenthesis)
	{
		return;
	}

	if(context.getCompletionChar() == '<')
	{
		//todo use BraceMatchingUtil.isPairedBracesAllowedBeforeTypeInFileType
		int tail = context.getTailOffset();
		if(tail < document.getTextLength() && StringUtil.isJavaIdentifierPart(document.getCharsSequence().charAt(tail)))
		{
			return;
		}
	}

	document.insertString(context.getTailOffset(), getSpace(mySpaceBetweenParentheses) + ">");
	if(!putCaretInside)
	{
		editor.getCaretModel().moveToOffset(context.getTailOffset());
	}
}
 
Example 15
Source File: ParenthesesInsertHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void handleInsert(final InsertionContext context, final T item) {
  final Editor editor = context.getEditor();
  final Document document = editor.getDocument();
  context.commitDocument();
  PsiElement lParen = findExistingLeftParenthesis(context);

  final char completionChar = context.getCompletionChar();
  final boolean putCaretInside = completionChar == myLeftParenthesis || placeCaretInsideParentheses(context, item);

  if (completionChar == myLeftParenthesis) {
    context.setAddCompletionChar(false);
  }

  if (lParen != null) {
    int lparenthOffset = lParen.getTextRange().getStartOffset();
    if (mySpaceBeforeParentheses && lparenthOffset == context.getTailOffset()) {
      document.insertString(context.getTailOffset(), " ");
      lparenthOffset++;
    }

    if (completionChar == myLeftParenthesis || completionChar == '\t') {
      editor.getCaretModel().moveToOffset(lparenthOffset + 1);
    }
    else {
      editor.getCaretModel().moveToOffset(context.getTailOffset());
    }

    context.setTailOffset(lparenthOffset + 1);

    PsiElement list = lParen.getParent();
    PsiElement last = list.getLastChild();
    if (isToken(last, String.valueOf(myRightParenthesis))) {
      int rparenthOffset = last.getTextRange().getStartOffset();
      context.setTailOffset(rparenthOffset + 1);
      if (!putCaretInside) {
        for (int i = lparenthOffset + 1; i < rparenthOffset; i++) {
          if (!Character.isWhitespace(document.getCharsSequence().charAt(i))) {
            return;
          }
        }
        editor.getCaretModel().moveToOffset(context.getTailOffset());
      }
      else if (mySpaceBetweenParentheses && document.getCharsSequence().charAt(lparenthOffset) == ' ') {
        editor.getCaretModel().moveToOffset(lparenthOffset + 2);
      }
      else {
        editor.getCaretModel().moveToOffset(lparenthOffset + 1);
      }
      return;
    }
  }
  else {
    document.insertString(context.getTailOffset(), getSpace(mySpaceBeforeParentheses) + myLeftParenthesis + getSpace(mySpaceBetweenParentheses));
    editor.getCaretModel().moveToOffset(context.getTailOffset());
  }

  if (!myMayInsertRightParenthesis) return;

  if (context.getCompletionChar() == myLeftParenthesis) {
    //todo use BraceMatchingUtil.isPairedBracesAllowedBeforeTypeInFileType
    int tail = context.getTailOffset();
    if (tail < document.getTextLength() && StringUtil.isJavaIdentifierPart(document.getCharsSequence().charAt(tail))) {
      return;
    }
  }

  document.insertString(context.getTailOffset(), getSpace(mySpaceBetweenParentheses) + myRightParenthesis);
  if (!putCaretInside) {
    editor.getCaretModel().moveToOffset(context.getTailOffset());
  }
}
 
Example 16
Source File: CS1547.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public HighlightInfoFactory checkImpl(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull CSharpNativeType element)
{
	if(highlightContext.getFile().getUserData(ourReturnTypeFlag) == Boolean.TRUE)
	{
		return null;
	}

	IElementType typeElementType = element.getTypeElementType();
	if(typeElementType == CSharpTokens.VOID_KEYWORD)
	{
		PsiElement parent = element.getParent();
		if(parent instanceof CSharpTypeOfExpressionImpl)
		{
			return null;
		}
		if(!(parent instanceof DotNetLikeMethodDeclaration))
		{
			if(parent instanceof DotNetFieldDeclaration)
			{
				if(((DotNetFieldDeclaration) parent).isConstant() || ((DotNetFieldDeclaration) parent).getInitializer() != null)
				{
					return newBuilder(element, VOID);
				}

				PsiElement lastChild = parent.getLastChild();
				// dont show error while typing
				if(lastChild instanceof PsiErrorElement)
				{
					return null;
				}
			}
			return newBuilder(element, VOID);
		}

		DotNetType returnType = ((DotNetLikeMethodDeclaration) parent).getReturnType();
		if(returnType != element)
		{
			return newBuilder(element, VOID);
		}
	}
	return null;
}
 
Example 17
Source File: CSharpParenthesesInsertHandler.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@RequiredUIAccess
@Override
public void handleInsert(final InsertionContext context, final LookupElement item)
{
	final Editor editor = context.getEditor();
	final Document document = editor.getDocument();
	context.commitDocument();
	PsiElement element = findNextToken(context);

	final char completionChar = context.getCompletionChar();
	final boolean putCaretInside = completionChar == '(' || placeCaretInsideParentheses();

	if(completionChar == '(')
	{
		context.setAddCompletionChar(false);
	}

	if(isToken(element, "("))
	{
		int lparenthOffset = element.getTextRange().getStartOffset();

		if(completionChar == '(' || completionChar == '\t')
		{
			editor.getCaretModel().moveToOffset(lparenthOffset + 1);
		}
		else
		{
			editor.getCaretModel().moveToOffset(context.getTailOffset());
		}

		context.setTailOffset(lparenthOffset + 1);

		PsiElement list = element.getParent();
		PsiElement last = list.getLastChild();
		if(isToken(last, ")"))
		{
			int rparenthOffset = last.getTextRange().getStartOffset();
			context.setTailOffset(rparenthOffset + 1);
			if(!putCaretInside)
			{
				for(int i = lparenthOffset + 1; i < rparenthOffset; i++)
				{
					if(!Character.isWhitespace(document.getCharsSequence().charAt(i)))
					{
						return;
					}
				}
				editor.getCaretModel().moveToOffset(context.getTailOffset());
			}
			else
			{
				AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(editor, CSharpParameterInfoHandler.item(myLikeMethodDeclaration));

				editor.getCaretModel().moveToOffset(lparenthOffset + 1);
			}
			return;
		}
	}
	else
	{
		document.insertString(context.getTailOffset(), "" + "(" + "");
		editor.getCaretModel().moveToOffset(context.getTailOffset());
	}

	if(context.getCompletionChar() == '(')
	{
		//todo use BraceMatchingUtil.isPairedBracesAllowedBeforeTypeInFileType
		int tail = context.getTailOffset();
		if(tail < document.getTextLength() && StringUtil.isJavaIdentifierPart(document.getCharsSequence().charAt(tail)))
		{
			return;
		}
	}

	document.insertString(context.getTailOffset(), ")");
	if(!putCaretInside)
	{
		editor.getCaretModel().moveToOffset(context.getTailOffset());
	}
	else
	{
		AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(editor, CSharpParameterInfoHandler.item(myLikeMethodDeclaration));
	}
}
 
Example 18
Source File: ExpressionOrStatementInsertHandler.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
private void handleInsertImpl(InsertionContext context, T item, Editor editor, Document document)
{
	PsiElement element = findNextToken(context);

	final char completionChar = context.getCompletionChar();

	final boolean putCaretInside = completionChar == myOpenChar || placeCaretInsideParentheses(context, item);

	if(completionChar == myOpenChar)
	{
		context.setAddCompletionChar(false);
	}

	boolean canAddSpaceBeforePair = canAddSpaceBeforePair(context, item);

	if(isToken(element, myOpenChar))
	{
		int lparenthOffset = element.getTextRange().getStartOffset();
		if(canAddSpaceBeforePair && lparenthOffset == context.getTailOffset())
		{
			document.insertString(context.getTailOffset(), " ");
			lparenthOffset++;
		}

		if(completionChar == myOpenChar || completionChar == '\t')
		{
			editor.getCaretModel().moveToOffset(lparenthOffset + 1);
		}
		else
		{
			editor.getCaretModel().moveToOffset(context.getTailOffset());
		}

		context.setTailOffset(lparenthOffset + 1);

		PsiElement list = element.getParent();
		PsiElement last = list.getLastChild();
		if(isToken(last, myCloseChar))
		{
			int rparenthOffset = last.getTextRange().getStartOffset();
			context.setTailOffset(rparenthOffset + 1);
			if(!putCaretInside)
			{
				for(int i = lparenthOffset + 1; i < rparenthOffset; i++)
				{
					if(!Character.isWhitespace(document.getCharsSequence().charAt(i)))
					{
						return;
					}
				}
				editor.getCaretModel().moveToOffset(context.getTailOffset());
			}
			else
			{
				editor.getCaretModel().moveToOffset(lparenthOffset + 1);
			}
			return;
		}
	}
	else
	{
		document.insertString(context.getTailOffset(), getSpace(canAddSpaceBeforePair) + myOpenChar);
		editor.getCaretModel().moveToOffset(context.getTailOffset());
	}

	if(context.getCompletionChar() == myOpenChar)
	{
		int tail = context.getTailOffset();
		if(tail < document.getTextLength() && StringUtil.isJavaIdentifierPart(document.getCharsSequence().charAt(tail)))
		{
			return;
		}
	}

	document.insertString(context.getTailOffset(), String.valueOf(myCloseChar));
	if(!putCaretInside)
	{
		editor.getCaretModel().moveToOffset(context.getTailOffset());
	}
}
 
Example 19
Source File: BracesInsertHandler.java    From consulo-unity3d with Apache License 2.0 4 votes vote down vote up
@Override
public void handleInsert(final InsertionContext context, final T item)
{
	final Editor editor = context.getEditor();
	final Document document = editor.getDocument();
	context.commitDocument();
	PsiElement element = findNextToken(context);

	final char completionChar = context.getCompletionChar();
	final boolean putCaretInside = completionChar == '{' || placeCaretInsideParentheses(context, item);

	if(completionChar == '{')
	{
		context.setAddCompletionChar(false);
	}

	if(isToken(element, "{"))
	{
		int lparenthOffset = element.getTextRange().getStartOffset();
		if(mySpaceBeforeParentheses && lparenthOffset == context.getTailOffset())
		{
			document.insertString(context.getTailOffset(), " ");
			lparenthOffset++;
		}

		if(completionChar == '{' || completionChar == '\t')
		{
			editor.getCaretModel().moveToOffset(lparenthOffset + 1);
		}
		else
		{
			editor.getCaretModel().moveToOffset(context.getTailOffset());
		}

		context.setTailOffset(lparenthOffset + 1);

		PsiElement list = element.getParent();
		PsiElement last = list.getLastChild();
		if(isToken(last, "}"))
		{
			int rparenthOffset = last.getTextRange().getStartOffset();
			context.setTailOffset(rparenthOffset + 1);
			if(!putCaretInside)
			{
				for(int i = lparenthOffset + 1; i < rparenthOffset; i++)
				{
					if(!Character.isWhitespace(document.getCharsSequence().charAt(i)))
					{
						return;
					}
				}
				editor.getCaretModel().moveToOffset(context.getTailOffset());
			}
			else if(mySpaceBetweenParentheses && document.getCharsSequence().charAt(lparenthOffset) == ' ')
			{
				editor.getCaretModel().moveToOffset(lparenthOffset + 2);
			}
			else
			{
				editor.getCaretModel().moveToOffset(lparenthOffset + 1);
			}
			return;
		}
	}
	else
	{
		document.insertString(context.getTailOffset(), getSpace(mySpaceBeforeParentheses) + '{' + getSpace(mySpaceBetweenParentheses));
		editor.getCaretModel().moveToOffset(context.getTailOffset());
	}

	if(!myMayInsertRightParenthesis)
	{
		return;
	}

	if(context.getCompletionChar() == '{')
	{
		int tail = context.getTailOffset();
		if(tail < document.getTextLength() && StringUtil.isJavaIdentifierPart(document.getCharsSequence().charAt(tail)))
		{
			return;
		}
	}

	document.insertString(context.getTailOffset(), getSpace(mySpaceBetweenParentheses) + "}");
	if(!putCaretInside)
	{
		editor.getCaretModel().moveToOffset(context.getTailOffset());
	}
}
 
Example 20
Source File: SoyBlock.java    From bamboo-soy with Apache License 2.0 4 votes vote down vote up
private static <T> T findLastDescendantOfType(PsiElement el, Class<T> clazz) {
  while (el != null && !clazz.isInstance(el)) {
    el = el.getLastChild();
  }
  return clazz.cast(el);
}