Search in sources :

Example 16 with JavaPsiFacade

use of com.intellij.psi.JavaPsiFacade in project android by JetBrains.

the class AndroidCompileUtil method removeDuplicatingClasses.

// must be invoked in a read action!
public static void removeDuplicatingClasses(final Module module, @NotNull final String packageName, @NotNull String className, @Nullable File classFile, String sourceRootPath) {
    if (sourceRootPath == null) {
        return;
    }
    VirtualFile sourceRoot = LocalFileSystem.getInstance().findFileByPath(sourceRootPath);
    if (sourceRoot == null) {
        return;
    }
    final Project project = module.getProject();
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
    final String interfaceQualifiedName = packageName + '.' + className;
    PsiClass[] classes = facade.findClasses(interfaceQualifiedName, GlobalSearchScope.moduleScope(module));
    final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    for (PsiClass c : classes) {
        PsiFile psiFile = c.getContainingFile();
        if (className.equals(FileUtil.getNameWithoutExtension(psiFile.getName()))) {
            VirtualFile virtualFile = psiFile.getVirtualFile();
            if (virtualFile != null && Comparing.equal(projectFileIndex.getSourceRootForFile(virtualFile), sourceRoot)) {
                final String path = virtualFile.getPath();
                final File f = new File(path);
                if (!FileUtil.filesEqual(f, classFile) && f.exists()) {
                    if (f.delete()) {
                        virtualFile.refresh(true, false);
                    } else {
                        ApplicationManager.getApplication().invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                Messages.showErrorDialog(project, "Can't delete file " + path, CommonBundle.getErrorTitle());
                            }
                        }, project.getDisposed());
                    }
                }
            }
        }
    }
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) Project(com.intellij.openapi.project.Project) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File)

Example 17 with JavaPsiFacade

use of com.intellij.psi.JavaPsiFacade in project intellij-community by JetBrains.

the class JUnitDevKitPatcher method patchJavaParameters.

@Override
public void patchJavaParameters(@Nullable Module module, JavaParameters javaParameters) {
    Sdk jdk = javaParameters.getJdk();
    if (jdk == null)
        return;
    ParametersList vm = javaParameters.getVMParametersList();
    if (module != null && PsiUtil.isIdeaProject(module.getProject()) && !vm.hasProperty(SYSTEM_CL_PROPERTY) && !JavaSdk.getInstance().isOfVersionOrHigher(jdk, JavaSdkVersion.JDK_1_9)) {
        JavaPsiFacade facade = JavaPsiFacade.getInstance(module.getProject());
        String qualifiedName = UrlClassLoader.class.getName();
        PsiClass loader = ReadAction.compute(() -> facade.findClass(qualifiedName, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module)));
        if (loader != null) {
            vm.addProperty(SYSTEM_CL_PROPERTY, qualifiedName);
        }
    }
    jdk = IdeaJdk.findIdeaJdk(jdk);
    if (jdk == null)
        return;
    String libPath = jdk.getHomePath() + File.separator + "lib";
    vm.add("-Xbootclasspath/a:" + libPath + File.separator + "boot.jar");
    if (!vm.hasProperty("idea.load.plugins.id") && module != null && PluginModuleType.isOfType(module)) {
        String id = DescriptorUtil.getPluginId(module);
        if (id != null) {
            vm.defineProperty("idea.load.plugins.id", id);
        }
    }
    File sandboxHome = getSandboxPath(jdk);
    if (sandboxHome != null) {
        if (!vm.hasProperty("idea.home.path")) {
            File homeDir = new File(sandboxHome, "test");
            FileUtil.createDirectory(homeDir);
            String buildNumber = IdeaJdk.getBuildNumber(jdk.getHomePath());
            if (buildNumber != null) {
                try {
                    FileUtil.writeToFile(new File(homeDir, "build.txt"), buildNumber);
                } catch (IOException e) {
                    LOG.warn("failed to create build.txt in " + homeDir + ": " + e.getMessage(), e);
                }
            } else {
                LOG.warn("Cannot determine build number for " + jdk.getHomePath());
            }
            vm.defineProperty("idea.home.path", homeDir.getAbsolutePath());
        }
        if (!vm.hasProperty("idea.plugins.path")) {
            vm.defineProperty("idea.plugins.path", new File(sandboxHome, "plugins").getAbsolutePath());
        }
    }
    javaParameters.getClassPath().addFirst(libPath + File.separator + "idea.jar");
    javaParameters.getClassPath().addFirst(libPath + File.separator + "resources.jar");
    javaParameters.getClassPath().addFirst(((JavaSdkType) jdk.getSdkType()).getToolsPath(jdk));
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) ParametersList(com.intellij.execution.configurations.ParametersList) PsiClass(com.intellij.psi.PsiClass) IOException(java.io.IOException) File(java.io.File)

Example 18 with JavaPsiFacade

use of com.intellij.psi.JavaPsiFacade in project intellij-community by JetBrains.

the class GrExpressionCategory method getClassType.

@Nullable
public static PsiClass getClassType(GrExpression expr) {
    final PsiType type = expr.getType();
    if (type instanceof PsiClassType) {
        PsiClassType classType = (PsiClassType) type;
        return classType.resolve();
    } else {
        final String text = type.getPresentableText();
        final Project project = expr.getProject();
        final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
        return facade.findClass(text, GlobalSearchScope.allScope(project));
    }
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) PsiClassType(com.intellij.psi.PsiClassType) Project(com.intellij.openapi.project.Project) PsiType(com.intellij.psi.PsiType) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with JavaPsiFacade

use of com.intellij.psi.JavaPsiFacade in project intellij-community by JetBrains.

the class GrMapType method create.

public static GrMapType create(GlobalSearchScope scope) {
    JavaPsiFacade facade = JavaPsiFacade.getInstance(scope.getProject());
    List<Couple<PsiType>> otherEntries = Collections.emptyList();
    LinkedHashMap<String, PsiType> stringEntries = ContainerUtil.newLinkedHashMap();
    return new GrMapTypeImpl(facade, scope, stringEntries, otherEntries, LanguageLevel.JDK_1_5);
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) Couple(com.intellij.openapi.util.Couple) PsiType(com.intellij.psi.PsiType)

Example 20 with JavaPsiFacade

use of com.intellij.psi.JavaPsiFacade in project intellij-community by JetBrains.

the class RenameMethodMultiTest method doTest.

private void doTest(final String className, final String methodSignature, final String newName) throws Exception {
    doTest((rootDir, rootAfter) -> {
        final JavaPsiFacade manager = getJavaFacade();
        final PsiClass aClass = manager.findClass(className, GlobalSearchScope.moduleScope(myModule));
        assertNotNull(aClass);
        final PsiMethod methodBySignature = aClass.findMethodBySignature(manager.getElementFactory().createMethodFromText(methodSignature + "{}", null), false);
        assertNotNull(methodBySignature);
        final RenameProcessor renameProcessor = new RenameProcessor(myProject, methodBySignature, newName, false, false);
        renameProcessor.run();
        FileDocumentManager.getInstance().saveAllDocuments();
    });
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) RenameProcessor(com.intellij.refactoring.rename.RenameProcessor) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass)

Aggregations

JavaPsiFacade (com.intellij.psi.JavaPsiFacade)52 PsiClass (com.intellij.psi.PsiClass)30 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)20 Module (com.intellij.openapi.module.Module)15 Project (com.intellij.openapi.project.Project)12 PsiPackage (com.intellij.psi.PsiPackage)8 LanguageLevel (com.intellij.pom.java.LanguageLevel)7 PsiElement (com.intellij.psi.PsiElement)7 Nullable (org.jetbrains.annotations.Nullable)6 NotNull (org.jetbrains.annotations.NotNull)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 PsiMethod (com.intellij.psi.PsiMethod)4 PsiType (com.intellij.psi.PsiType)4 File (java.io.File)3 List (java.util.List)3 Configuration (com.android.tools.idea.configurations.Configuration)2 MergedManifest (com.android.tools.idea.model.MergedManifest)2 CompletionParameters (com.intellij.codeInsight.completion.CompletionParameters)2 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2 ClassFilter (com.intellij.ide.util.ClassFilter)2