use of com.intellij.psi.PsiLiteralExpression in project intellij-community by JetBrains.
the class I18nizeTest method doTest.
private void doTest(@NonNls String ext) throws Exception {
configureByFile(getBasePath() + "/before" + getTestName(false) + "." + ext);
I18nizeAction action = new I18nizeAction();
DataContext dataContext = DataManager.getInstance().getDataContext(myEditor.getComponent());
AnActionEvent event = AnActionEvent.createFromAnAction(action, null, "place", dataContext);
action.update(event);
@NonNls String afterFile = getBasePath() + "/after" + getTestName(false) + "." + ext;
boolean afterFileExists = new File(PathManagerEx.getTestDataPath() + afterFile).exists();
I18nQuickFixHandler handler = I18nizeAction.getHandler(event);
try {
if (handler != null) {
handler.checkApplicability(getFile(), getEditor());
}
} catch (IncorrectOperationException e) {
event.getPresentation().setEnabled(false);
}
assertEquals(afterFileExists, event.getPresentation().isEnabled());
if (afterFileExists) {
PsiLiteralExpression literalExpression = I18nizeAction.getEnclosingStringLiteral(getFile(), getEditor());
assertNotNull(handler);
ApplicationManager.getApplication().runWriteAction(() -> handler.performI18nization(getFile(), getEditor(), literalExpression, Collections.<PropertiesFile>emptyList(), "key1", "value1", "i18nizedExpr", PsiExpression.EMPTY_ARRAY, JavaI18nUtil.DEFAULT_PROPERTY_CREATION_HANDLER));
checkResultByFile(afterFile);
}
}
use of com.intellij.psi.PsiLiteralExpression in project intellij-community by JetBrains.
the class ConvertToScientificNotationPredicate method satisfiedBy.
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof PsiLiteralExpression)) {
return false;
}
final PsiLiteralExpression expression = (PsiLiteralExpression) element;
final PsiType type = expression.getType();
if (!PsiType.DOUBLE.equals(type) && !PsiType.FLOAT.equals(type)) {
return false;
}
String text = expression.getText();
if (text == null) {
return false;
}
text = text.toLowerCase();
text = StringUtil.trimStart(text, "-");
if (!text.contains(".") && text.startsWith("0")) {
//Octal integer
return false;
}
return !text.contains("e");
}
use of com.intellij.psi.PsiLiteralExpression in project intellij-community by JetBrains.
the class ConvertIntegerToDecimalPredicate method satisfiedBy.
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof PsiLiteralExpression)) {
return false;
}
final PsiLiteralExpression expression = (PsiLiteralExpression) element;
final PsiType type = expression.getType();
if (PsiType.INT.equals(type) || PsiType.LONG.equals(type)) {
@NonNls final String text = expression.getText();
if (text == null || text.length() < 2) {
return false;
}
if ("0".equals(text) || "0L".equals(text) || "0l".equals(text)) {
return false;
}
return text.charAt(0) == '0';
}
if (PsiType.DOUBLE.equals(type) || PsiType.FLOAT.equals(type)) {
@NonNls final String text = expression.getText();
if (text == null || text.length() < 2) {
return false;
}
return text.startsWith("0x") || text.startsWith("0X");
}
return false;
}
use of com.intellij.psi.PsiLiteralExpression in project intellij-community by JetBrains.
the class ConvertToPlainPredicate method satisfiedBy.
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof PsiLiteralExpression)) {
return false;
}
final PsiLiteralExpression expression = (PsiLiteralExpression) element;
final PsiType type = expression.getType();
if (!PsiType.DOUBLE.equals(type) && !PsiType.FLOAT.equals(type)) {
return false;
}
final String text = expression.getText();
return text != null && (text.contains("e") || text.contains("E"));
}
use of com.intellij.psi.PsiLiteralExpression in project intellij-community by JetBrains.
the class CharToStringIntention method processIntention.
@Override
public void processIntention(@NotNull PsiElement element) throws IncorrectOperationException {
final PsiLiteralExpression charLiteral = (PsiLiteralExpression) element;
final String charLiteralText = charLiteral.getText();
final String stringLiteral = stringForCharLiteral(charLiteralText);
PsiReplacementUtil.replaceExpression(charLiteral, stringLiteral);
}
Aggregations