use of com.jetbrains.lang.dart.psi.DartCallExpression 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.DartCallExpression in project intellij-plugins by JetBrains.
the class DartTestRunConfigurationProducer method setupRunnerParametersForFile.
private static boolean setupRunnerParametersForFile(@NotNull final DartTestRunnerParameters runnerParams, @NotNull final PsiElement psiElement) {
if (psiElement instanceof DartCallExpression) {
final String testName = TestUtil.findGroupOrTestName((DartCallExpression) psiElement);
final List<VirtualFile> virtualFiles = DartResolveUtil.findLibrary(psiElement.getContainingFile());
if (testName == null || virtualFiles.isEmpty()) {
return false;
}
runnerParams.setTestName(testName);
runnerParams.setScope(DartTestRunnerParameters.Scope.GROUP_OR_TEST_BY_NAME);
final VirtualFile dartFile = virtualFiles.iterator().next();
final String dartFilePath = dartFile.getPath();
runnerParams.setFilePath(dartFilePath);
return true;
} else {
final PsiFile psiFile = psiElement.getContainingFile();
if (psiFile instanceof DartFile) {
final VirtualFile virtualFile = DartResolveUtil.getRealVirtualFile((DartFile) psiElement);
if (virtualFile == null || !DartResolveUtil.isLibraryRoot((DartFile) psiElement)) {
return false;
}
runnerParams.setTestName(DartResolveUtil.getLibraryName((DartFile) psiElement));
runnerParams.setScope(DartTestRunnerParameters.Scope.FILE);
final String dartFilePath = FileUtil.toSystemIndependentName(virtualFile.getPath());
runnerParams.setFilePath(dartFilePath);
return true;
}
}
return false;
}
Aggregations