use of com.intellij.psi.PsiJavaToken in project intellij-community by JetBrains.
the class TypeCastSelectioner method select.
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
List<TextRange> result = new ArrayList<>();
result.addAll(expandToWholeLine(editorText, e.getTextRange(), false));
PsiTypeCastExpression expression = (PsiTypeCastExpression) e;
PsiElement[] children = expression.getChildren();
PsiElement lParen = null;
PsiElement rParen = null;
for (PsiElement child : children) {
if (child instanceof PsiJavaToken) {
PsiJavaToken token = (PsiJavaToken) child;
if (token.getTokenType() == JavaTokenType.LPARENTH)
lParen = token;
if (token.getTokenType() == JavaTokenType.RPARENTH)
rParen = token;
}
}
if (lParen != null && rParen != null) {
result.addAll(expandToWholeLine(editorText, new TextRange(lParen.getTextRange().getStartOffset(), rParen.getTextRange().getEndOffset()), false));
}
return result;
}
use of com.intellij.psi.PsiJavaToken in project intellij-community by JetBrains.
the class MissingSwitchBodyFixer method apply.
@Override
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException {
if (!(psiElement instanceof PsiSwitchStatement))
return;
PsiSwitchStatement switchStatement = (PsiSwitchStatement) psiElement;
final Document doc = editor.getDocument();
final PsiCodeBlock body = switchStatement.getBody();
if (body != null)
return;
final PsiJavaToken rParenth = switchStatement.getRParenth();
assert rParenth != null;
doc.insertString(rParenth.getTextRange().getEndOffset(), "{}");
}
use of com.intellij.psi.PsiJavaToken in project intellij-community by JetBrains.
the class ConstantSubexpressionIntention method getTextForElement.
@Override
protected String getTextForElement(PsiElement element) {
final PsiJavaToken token;
if (element instanceof PsiJavaToken) {
token = (PsiJavaToken) element;
} else {
final PsiElement prevSibling = element.getPrevSibling();
if (prevSibling instanceof PsiJavaToken) {
token = (PsiJavaToken) prevSibling;
} else {
throw new AssertionError();
}
}
final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression) element.getParent();
final PsiPolyadicExpression subexpression = ConstantSubexpressionPredicate.getSubexpression(polyadicExpression, token);
final String text = HighlightUtil.getPresentableText(subexpression);
return IntentionPowerPackBundle.message("constant.expression.intention.name", text);
}
use of com.intellij.psi.PsiJavaToken in project intellij-community by JetBrains.
the class NegateComparisonIntention method getTextForElement.
public String getTextForElement(PsiElement element) {
String operatorText = "";
String negatedOperatorText = "";
final PsiBinaryExpression exp = (PsiBinaryExpression) element;
if (exp != null) {
final PsiJavaToken sign = exp.getOperationSign();
operatorText = sign.getText();
negatedOperatorText = ComparisonUtils.getNegatedComparison(sign.getTokenType());
}
if (operatorText.equals(negatedOperatorText)) {
return IntentionPowerPackBundle.message("negate.comparison.intention.name", operatorText);
} else {
return IntentionPowerPackBundle.message("negate.comparison.intention.name1", operatorText, negatedOperatorText);
}
}
use of com.intellij.psi.PsiJavaToken in project intellij-community by JetBrains.
the class ExpressionPredicate method satisfiedBy.
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof PsiJavaToken)) {
return false;
}
final PsiElement parent = element.getParent();
if (!(parent instanceof PsiPolyadicExpression)) {
return false;
}
final PsiPolyadicExpression expression = (PsiPolyadicExpression) parent;
final PsiExpression[] operands = expression.getOperands();
if (operands.length < 2) {
return false;
}
PsiExpression prevOperand = null;
for (PsiExpression operand : operands) {
final PsiJavaToken token = expression.getTokenBeforeOperand(operand);
if (element == token) {
if (prevOperand == null || operand.getText().equals(prevOperand.getText())) {
return false;
}
break;
}
prevOperand = operand;
}
return !ComparisonUtils.isComparison(expression);
}
Aggregations