Search in sources :

Example 1 with DartCallExpression

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;
}
Also used : DartClass(com.jetbrains.lang.dart.psi.DartClass) DartReference(com.jetbrains.lang.dart.psi.DartReference) DartCallExpression(com.jetbrains.lang.dart.psi.DartCallExpression) DartExpression(com.jetbrains.lang.dart.psi.DartExpression)

Example 2 with DartCallExpression

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartFile(com.jetbrains.lang.dart.psi.DartFile) PsiFile(com.intellij.psi.PsiFile) DartCallExpression(com.jetbrains.lang.dart.psi.DartCallExpression)

Aggregations

DartCallExpression (com.jetbrains.lang.dart.psi.DartCallExpression)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 DartClass (com.jetbrains.lang.dart.psi.DartClass)1 DartExpression (com.jetbrains.lang.dart.psi.DartExpression)1 DartFile (com.jetbrains.lang.dart.psi.DartFile)1 DartReference (com.jetbrains.lang.dart.psi.DartReference)1