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());
}
}
}
}
}
}
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));
}
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));
}
}
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);
}
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();
});
}
Aggregations