use of com.intellij.psi.PsiWhileStatement in project Main by SpartanRefactoring.
the class BooleanLiteralTest method testTipper.
public void testTipper() throws Exception {
File f = new File(Resources.getResource("BooleanLiteralTestTip.java").getPath());
LeonidasTipper lt = new LeonidasTipper("BooleanLiteralTestTip.java", IOUtils.toString(new BufferedReader(new InputStreamReader(new FileInputStream(f)))));
PsiWhileStatement pws1 = createTestWhileStatementFromString("while (true) {\nx++;\n}");
assertTrue(lt.canTip(pws1));
PsiWhileStatement pws2 = createTestWhileStatementFromString("while (false) {\nx++;\n}");
assertTrue(lt.canTip(pws2));
PsiWhileStatement pws3 = createTestWhileStatementFromString("while (x > 2) {\nx++;\n}");
assertFalse(lt.canTip(pws3));
PsiWhileStatement pws4 = createTestWhileStatementFromString("while (true) {\nx++; x--;\n}");
assertFalse(lt.canTip(pws4));
}
use of com.intellij.psi.PsiWhileStatement in project Main by SpartanRefactoring.
the class OptionalTest method testTip1.
public void testTip1() throws Exception {
File f = new File(Resources.getResource("OptionalTestTipper1.java").getPath());
LeonidasTipper lt = new LeonidasTipper("OptionalTestTipper1", IOUtils.toString(new BufferedReader(new InputStreamReader(new FileInputStream(f)))));
PsiWhileStatement pws1 = createTestWhileStatementFromString("while (x > 2) {\nx++; y--; x--; \n}");
assertTrue(lt.canTip(pws1));
PsiWhileStatement pws2 = createTestWhileStatementFromString("while (x > 2) {\nx++; x--; \n}");
assertTrue(lt.canTip(pws2));
PsiWhileStatement pws3 = createTestWhileStatementFromString("while (x > 2) {\nx++;\n}");
assertFalse(lt.canTip(pws3));
PsiWhileStatement pws4 = createTestWhileStatementFromString("while (x > 2) {\nx++; x--; x--; \n}");
assertTrue(lt.canTip(pws4));
PsiWhileStatement pws5 = createTestWhileStatementFromString("while (x > 2) {\nx++; x++; x--; \n}");
assertTrue(lt.canTip(pws5));
}
use of com.intellij.psi.PsiWhileStatement in project intellij-community by JetBrains.
the class MissingWhileBodyFixer method apply.
@Override
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException {
if (!(psiElement instanceof PsiWhileStatement))
return;
PsiWhileStatement whileStatement = (PsiWhileStatement) psiElement;
final Document doc = editor.getDocument();
PsiElement body = whileStatement.getBody();
if (body instanceof PsiBlockStatement)
return;
if (body != null && startLine(doc, body) == startLine(doc, whileStatement) && whileStatement.getCondition() != null)
return;
final PsiJavaToken rParenth = whileStatement.getRParenth();
assert rParenth != null;
doc.insertString(rParenth.getTextRange().getEndOffset(), "{}");
}
use of com.intellij.psi.PsiWhileStatement in project intellij-community by JetBrains.
the class WhileLoopPredicate method satisfiedBy.
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);
}
use of com.intellij.psi.PsiWhileStatement in project Main by SpartanRefactoring.
the class AnyNumberOfTest method testTipper.
public void testTipper() throws Exception {
File f = new File(Resources.getResource("AnyNumberOfTipperTest.java").getPath());
LeonidasTipper lt = new LeonidasTipper("AnyNumberOfTipperTest", IOUtils.toString(new BufferedReader(new InputStreamReader(new FileInputStream(f)))));
PsiWhileStatement pws1 = createTestWhileStatementFromString("while (x > 2) {\nx++; y--; x--; \n}");
assertTrue(lt.canTip(pws1));
PsiWhileStatement pws2 = createTestWhileStatementFromString("while (x > 2) {\nx++; x--; \n}");
assertTrue(lt.canTip(pws2));
PsiWhileStatement pws3 = createTestWhileStatementFromString("while (x > 2) {\nx++;\n}");
assertFalse(lt.canTip(pws3));
PsiWhileStatement pws4 = createTestWhileStatementFromString("while (x > 2) {\nx++; x--; x--; \n}");
assertTrue(lt.canTip(pws4));
PsiWhileStatement pws5 = createTestWhileStatementFromString("while (x > 2) {\nx++; x++; x--; \n}");
assertTrue(lt.canTip(pws5));
PsiWhileStatement pws6 = createTestWhileStatementFromString("while (x > 2) {\nx++; y--; y++; x--; \n}");
assertTrue(lt.canTip(pws6));
}
Aggregations