use of com.intellij.psi.PsiElement in project intellij-community by JetBrains.
the class GroovyTypedHandler method beforeCharTyped.
@Override
public Result beforeCharTyped(final char c, final Project project, final Editor editor, final PsiFile file, final FileType fileType) {
int offsetBefore = editor.getCaretModel().getOffset();
//important to calculate before inserting charTyped
myJavaLTTyped = '<' == c && file instanceof GroovyFile && CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET && isAfterClassLikeIdentifier(offsetBefore, editor);
if ('>' == c) {
if (file instanceof GroovyFile && CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET) {
if (JavaTypedHandler.handleJavaGT(editor, GroovyTokenTypes.mLT, GroovyTokenTypes.mGT, INVALID_INSIDE_REFERENCE))
return Result.STOP;
}
}
if (c == '@' && file instanceof GroovyFile) {
autoPopupMemberLookup(project, editor, file12 -> {
int offset = editor.getCaretModel().getOffset();
PsiElement lastElement = file12.findElementAt(offset - 1);
if (lastElement == null)
return false;
final PsiElement prevSibling = PsiTreeUtil.prevVisibleLeaf(lastElement);
return prevSibling != null && ".".equals(prevSibling.getText());
});
}
if (c == '&' && file instanceof GroovyFile) {
autoPopupMemberLookup(project, editor, file1 -> {
int offset = editor.getCaretModel().getOffset();
PsiElement lastElement = file1.findElementAt(offset - 1);
return lastElement != null && ".&".equals(lastElement.getText());
});
}
return Result.CONTINUE;
}
use of com.intellij.psi.PsiElement in project intellij-community by JetBrains.
the class GroovyStatementSelectioner method inferBlockRange.
private static TextRange inferBlockRange(PsiElement first, PsiElement last) {
while (true) {
PsiElement prev = first.getPrevSibling();
prev = skipWhitespaceBack(prev);
if (isOneLineFeed(prev))
prev = prev.getPrevSibling();
prev = skipWhitespaceBack(prev);
if (prev != null && prev.getNode().getElementType() == GroovyTokenTypes.mSEMI || prev instanceof GrStatement) {
first = prev;
} else {
break;
}
}
while (true) {
PsiElement next = last.getNextSibling();
next = skipWhitespacesForward(next);
if (isOneLineFeed(next))
next = next.getNextSibling();
next = skipWhitespacesForward(next);
if (next != null && next.getNode().getElementType() == GroovyTokenTypes.mSEMI || next instanceof GrStatement) {
last = next;
} else {
break;
}
}
return new TextRange(first.getTextRange().getStartOffset(), last.getTextRange().getEndOffset());
}
use of com.intellij.psi.PsiElement in project intellij-community by JetBrains.
the class GrHighlightExitPointHandler method computeUsages.
@Override
public void computeUsages(List<PsiElement> targets) {
PsiElement parent = myTarget.getParent();
if (!(parent instanceof GrReturnStatement) && !(parent instanceof GrThrowStatement))
return;
final GrControlFlowOwner flowOwner = ControlFlowUtils.findControlFlowOwner(parent);
ControlFlowUtils.visitAllExitPoints(flowOwner, new ControlFlowUtils.ExitPointVisitor() {
@Override
public boolean visitExitPoint(Instruction instruction, @Nullable GrExpression returnValue) {
final PsiElement returnElement = instruction.getElement();
if (returnElement != null && isCorrectReturn(returnElement)) {
final TextRange range = returnElement.getTextRange();
myReadUsages.add(range);
}
return true;
}
});
}
use of com.intellij.psi.PsiElement in project intellij-community by JetBrains.
the class GrImportFilteringRule method isVisible.
@Override
public boolean isVisible(@NotNull Usage usage) {
if (usage instanceof PsiElementUsage) {
final PsiElement psiElement = ((PsiElementUsage) usage).getElement();
final PsiFile containingFile = psiElement.getContainingFile();
if (containingFile instanceof GroovyFile) {
// check whether the element is in the import list
return PsiTreeUtil.getParentOfType(psiElement, GrImportStatement.class, true) == null;
}
}
return true;
}
use of com.intellij.psi.PsiElement in project intellij-community by JetBrains.
the class GroovyBlockGenerator method addBinaryChildrenRecursively.
/**
* Adds all children of specified element to given list
*
* @param elem
* @param list
* @param indent
* @param aligner
*/
private void addBinaryChildrenRecursively(PsiElement elem, List<Block> list, Indent indent, @Nullable AlignmentProvider.Aligner aligner) {
if (elem == null)
return;
// For binary expressions
if ((elem instanceof GrBinaryExpression)) {
GrBinaryExpression myExpr = ((GrBinaryExpression) elem);
if (myExpr.getLeftOperand() instanceof GrBinaryExpression) {
addBinaryChildrenRecursively(myExpr.getLeftOperand(), list, Indent.getContinuationWithoutFirstIndent(), aligner);
}
PsiElement op = ((GrBinaryExpression) elem).getOperationToken();
for (ASTNode childNode : visibleChildren(elem.getNode())) {
PsiElement psi = childNode.getPsi();
if (!(psi instanceof GrBinaryExpression)) {
if (op != psi && aligner != null) {
aligner.append(psi);
}
list.add(new GroovyBlock(childNode, indent, getChildWrap(childNode), myContext));
}
}
if (myExpr.getRightOperand() instanceof GrBinaryExpression) {
addBinaryChildrenRecursively(myExpr.getRightOperand(), list, Indent.getContinuationWithoutFirstIndent(), aligner);
}
}
}
Aggregations