mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 06:05:01 +07:00
[java] module references in compiled code
This commit is contained in:
+10
@@ -64,6 +64,16 @@ class ClsJavaModuleReferenceElementImpl extends ClsElementImpl implements PsiJav
|
||||
return myReference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return myText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTextLength() {
|
||||
return myText.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull PsiElementVisitor visitor) {
|
||||
if (visitor instanceof JavaElementVisitor) {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.psi.impl.source;
|
||||
|
||||
import com.intellij.core.JavaCoreBundle;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.FileIndexFacade;
|
||||
@@ -56,6 +57,9 @@ public class PsiJavaModuleReference extends PsiReferenceBase.Poly<PsiJavaModuleR
|
||||
@Override
|
||||
public PsiElement handleElementRename(@NotNull String newName) throws IncorrectOperationException {
|
||||
PsiJavaModuleReferenceElement element = getElement();
|
||||
if (element instanceof PsiCompiledElement) {
|
||||
throw new IncorrectOperationException(JavaCoreBundle.message("psi.error.attempt.to.edit.class.file", element.getContainingFile()));
|
||||
}
|
||||
PsiElementFactory factory = PsiElementFactory.SERVICE.getInstance(element.getProject());
|
||||
PsiJavaModuleReferenceElement newElement = factory.createModuleFromText("module " + newName + " {}").getNameElement();
|
||||
return element.replace(newElement);
|
||||
@@ -74,18 +78,19 @@ public class PsiJavaModuleReference extends PsiReferenceBase.Poly<PsiJavaModuleR
|
||||
Project project = reference.getProject();
|
||||
|
||||
GlobalSearchScope scope = null;
|
||||
if (!incompleteCode) {
|
||||
VirtualFile file = reference.getElement().getContainingFile().getVirtualFile();
|
||||
if (file != null) {
|
||||
Module module = FileIndexFacade.getInstance(project).getModuleForFile(file);
|
||||
PsiFile file = reference.getElement().getContainingFile();
|
||||
if (incompleteCode || file.getOriginalFile() instanceof PsiCompiledFile) {
|
||||
scope = GlobalSearchScope.allScope(project);
|
||||
}
|
||||
else {
|
||||
VirtualFile vFile = file.getVirtualFile();
|
||||
if (vFile != null) {
|
||||
Module module = FileIndexFacade.getInstance(project).getModuleForFile(vFile);
|
||||
if (module != null) {
|
||||
scope = module.getModuleWithDependenciesAndLibrariesScope(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
scope = GlobalSearchScope.allScope(project);
|
||||
}
|
||||
|
||||
if (scope != null) {
|
||||
JavaFileManager service = JavaFileManager.SERVICE.getInstance(project);
|
||||
|
||||
Reference in New Issue
Block a user