public boolean satisfiedBy(PsiElement element) { if (!(element instanceof PsiJavaToken)) { return false; } final PsiJavaToken token = (PsiJavaToken)element; final IElementType tokenType = token.getTokenType(); if (!JavaTokenType.WHILE_KEYWORD.equals(tokenType)) { return false; } final PsiElement parent = element.getParent(); if (!(parent instanceof PsiWhileStatement)) { return false; } final PsiWhileStatement whileStatement = (PsiWhileStatement)parent; return !(whileStatement.getCondition() == null || whileStatement.getBody() == null); }
@Override public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException { if(psiElement instanceof PsiWhileStatement) { final Document doc = editor.getDocument(); final PsiWhileStatement whileStatement = (PsiWhileStatement) psiElement; final PsiJavaToken rParenth = whileStatement.getRParenth(); final PsiJavaToken lParenth = whileStatement.getLParenth(); final PsiExpression condition = whileStatement.getCondition(); if(condition == null) { if(lParenth == null || rParenth == null) { int stopOffset = doc.getLineEndOffset(doc.getLineNumber(whileStatement.getTextRange().getStartOffset())); final PsiStatement block = whileStatement.getBody(); if(block != null) { stopOffset = Math.min(stopOffset, block.getTextRange().getStartOffset()); } stopOffset = Math.min(stopOffset, whileStatement.getTextRange().getEndOffset()); doc.replaceString(whileStatement.getTextRange().getStartOffset(), stopOffset, "while ()"); processor.registerUnresolvedError(whileStatement.getTextRange().getStartOffset() + "while (".length()); } else { processor.registerUnresolvedError(lParenth.getTextRange().getEndOffset()); } } else if(rParenth == null) { doc.insertString(condition.getTextRange().getEndOffset(), ")"); } } }
@Override public void visitWhileStatement(PsiWhileStatement statement) { mVisitor.report("PsiWhileStatement", statement.getText(), statement); super.visitStatement(statement); }
@Override public void visitWhileStatement( @NotNull PsiWhileStatement statement) { super.visitWhileStatement(statement); checkStatement(statement); }
@Override public void visitWhileStatement(@NotNull PsiWhileStatement statement) { super.visitWhileStatement(statement); checkStatement(statement); }