use of com.jetbrains.lang.dart.psi.DartExpression in project intellij-plugins by JetBrains.
the class DartNameSuggesterUtil method getSuggestedNames.
public static Collection<String> getSuggestedNames(final DartExpression expression, @Nullable Collection<String> additionalUsedNames) {
Collection<String> candidates = new LinkedHashSet<>();
String text = expression.getText();
if (expression instanceof DartReference) {
DartClass dartClass = ((DartReference) expression).resolveDartClass().getDartClass();
String dartClassName = dartClass == null ? null : dartClass.getName();
if (dartClassName != null && !dartClassName.equals(StringUtil.decapitalize(dartClassName))) {
candidates.add(StringUtil.decapitalize(dartClassName));
}
}
if (expression instanceof DartCallExpression) {
final DartExpression callee = ((DartCallExpression) expression).getExpression();
text = callee.getText();
}
if (text != null) {
candidates.addAll(generateNames(text));
}
final Set<String> usedNames = DartRefactoringUtil.collectUsedNames(expression);
if (additionalUsedNames != null && !additionalUsedNames.isEmpty()) {
usedNames.addAll(additionalUsedNames);
}
final Collection<String> result = new ArrayList<>();
for (String candidate : candidates) {
int index = 0;
String suffix = "";
while (usedNames.contains(candidate + suffix)) {
suffix = Integer.toString(++index);
}
result.add(candidate + suffix);
}
if (result.isEmpty()) {
// never empty
result.add("o");
}
return result;
}
use of com.jetbrains.lang.dart.psi.DartExpression in project intellij-plugins by JetBrains.
the class DartWithExpressionSurrounder method surroundElements.
@Nullable
public TextRange surroundElements(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement[] elements) throws IncorrectOperationException {
PsiElement source = elements[0];
final DartExpression parenthExprNode = getSurroundedNode(source);
if (parenthExprNode == null) {
throw new IncorrectOperationException("Can't create expression for: " + source.getText());
}
final PsiElement replace = source.replace(parenthExprNode);
final int endOffset = replace.getTextRange().getEndOffset();
return TextRange.create(endOffset, endOffset);
}
use of com.jetbrains.lang.dart.psi.DartExpression in project intellij-plugins by JetBrains.
the class DartIntroduceTestBase method buildSuggestions.
protected Collection<String> buildSuggestions(Class<? extends DartExpression> parentClass) {
myFixture.configureByFile(getTestName(false) + getFileExtension());
DartExpression expr = PsiTreeUtil.getParentOfType(myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset()), parentClass);
return DartNameSuggesterUtil.getSuggestedNames(expr);
}
use of com.jetbrains.lang.dart.psi.DartExpression in project intellij-plugins by JetBrains.
the class DartServerExtractLocalVariableDialog method perform.
public void perform() {
final SelectionModel selectionModel = editor.getSelectionModel();
final int offset = selectionModel.getSelectionStart();
final int length = selectionModel.getSelectionEnd() - offset;
// create refactoring
createRefactoring(offset, length);
if (refactoring == null) {
return;
}
// prepare expressions
final java.util.List<DartExpression> expressions;
{
final int[] offsets = refactoring.getCoveringExpressionOffsets();
final int[] lengths = refactoring.getCoveringExpressionLengths();
expressions = getDartExpressions(offsets, lengths);
if (expressions == null) {
return;
}
}
// select the expression to extract
if (expressions.size() == 1 || ApplicationManager.getApplication().isUnitTestMode()) {
performOnExpression(expressions.get(0));
} else if (expressions.size() > 1) {
IntroduceTargetChooser.showChooser(editor, expressions, new Pass<DartExpression>() {
@Override
public void pass(DartExpression expression) {
performOnExpression(expression);
}
}, PsiElement::getText);
}
}
use of com.jetbrains.lang.dart.psi.DartExpression in project intellij-plugins by JetBrains.
the class DartServerExtractLocalVariableDialog method getDartExpressions.
@Nullable
private List<DartExpression> getDartExpressions(int[] offsets, int[] lengths) {
final List<DartExpression> expressions = Lists.newArrayList();
for (int i = 0; i < offsets.length; i++) {
final DartExpression expression = findExpressionWithRange(offsets[i], lengths[i]);
if (expression == null) {
return null;
}
expressions.add(expression);
}
return expressions;
}
Aggregations