本文整理汇总了Java中com.intellij.openapi.module.ModuleUtilCore.findModuleForPsiElement方法的典型用法代码示例。如果您正苦于以下问题:Java ModuleUtilCore.findModuleForPsiElement方法的具体用法?Java ModuleUtilCore.findModuleForPsiElement怎么用?Java ModuleUtilCore.findModuleForPsiElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.module.ModuleUtilCore
的用法示例。
在下文中一共展示了ModuleUtilCore.findModuleForPsiElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findUsages
import com.intellij.openapi.module.ModuleUtilCore; //导入方法依赖的package包/类
@Nullable
@Override
public List<UsageInfo> findUsages( PsiFile psiFile, PsiDirectory newParent, boolean searchInComments, boolean searchInNonJavaFiles )
{
Module mod = ModuleUtilCore.findModuleForPsiElement( psiFile );
ManModule module = ManProject.getModule( mod );
PsiClass psiClass = findPsiClass( psiFile );
if( psiClass == null )
{
return Collections.emptyList();
}
Query<PsiReference> search = ReferencesSearch.search( psiClass, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope( module.getIjModule() ) );
List<UsageInfo> usages = new ArrayList<>();
for( PsiReference ref: search.findAll() )
{
usages.add( new MoveRenameUsageInfo( ref.getElement(), ref, ref.getRangeInElement().getStartOffset(),
ref.getRangeInElement().getEndOffset(), psiClass,
ref.resolve() == null && !(ref instanceof PsiPolyVariantReference && ((PsiPolyVariantReference)ref).multiResolve( true ).length > 0) ) );
}
return usages;
}
示例2: findPsiClass
import com.intellij.openapi.module.ModuleUtilCore; //导入方法依赖的package包/类
@Nullable
private PsiClass findPsiClass( PsiFileSystemItem element )
{
Module mod = ModuleUtilCore.findModuleForPsiElement( element );
if( mod == null )
{
return null;
}
ManModule module = ManProject.getModule( mod );
String[] fqns = module.getTypesForFile( FileUtil.toIFile( module.getProject(), element.getVirtualFile() ) );
PsiClass psiClass = null;
for( String fqn: fqns )
{
psiClass = ManifoldPsiClassCache.instance().getPsiClass( GlobalSearchScope.moduleWithDependenciesAndLibrariesScope( module.getIjModule() ), module, fqn );
if( psiClass != null )
{
break;
}
}
return psiClass;
}
示例3: isDevKitConfig
import com.intellij.openapi.module.ModuleUtilCore; //导入方法依赖的package包/类
private boolean isDevKitConfig(XmlTag tag, XmlFile baseFile) {
Module module = ModuleUtilCore.findModuleForPsiElement(baseFile);
String namespace = tag.getNamespace();
List<XmlSchemaProvider> providers = XmlSchemaProvider.getAvailableProviders(baseFile);
for (XmlSchemaProvider provider : providers) {
Set<String> locations = provider.getLocations(namespace, baseFile);
for (String location : locations) {
XmlFile schema = provider.getSchema(location, module, baseFile);
if (schema != null) {
String schemaFile = schema.getText();
if (schemaFile.contains("http://www.mulesoft.org/schema/mule/devkit")) {
return true;
}
}
}
}
return false;
}
示例4: actionPerformed
import com.intellij.openapi.module.ModuleUtilCore; //导入方法依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
final PsiClass psiClass = getPsiClass(e);
if (psiClass == null) return;
final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
final Module module = ModuleUtilCore.findModuleForPsiElement(psiClass);
if (module == null || virtualFile == null) return;
final String className = ClassUtil.getJVMClassName(psiClass);
final Project project = getEventProject(e);
CompilerManager.getInstance(project).make(new FileSetCompileScope(Collections.singletonList(virtualFile), new Module[]{module}), new CompileStatusNotification() {
@Override
public void finished(boolean aborted, int errors, int warnings, CompileContext compileContext) {
if (aborted || errors > 0) return;
generateAndShowXml(module, className);
}
});
}
示例5: isAvailable
import com.intellij.openapi.module.ModuleUtilCore; //导入方法依赖的package包/类
@Override
public boolean isAvailable(@NotNull final Project project, Editor editor, PsiFile file) {
final PsiElement leaf = file.findElementAt(editor.getCaretModel().getOffset());
final PsiModifierListOwner owner = ExternalAnnotationsLineMarkerProvider.getAnnotationOwner(leaf);
if (owner != null && !(owner instanceof PsiCompiledElement) && owner.getLanguage().isKindOf(JavaLanguage.INSTANCE) &&
ModuleUtilCore.findModuleForPsiElement(file) != null &&
PsiUtil.getLanguageLevel(file).isAtLeast(LanguageLevel.JDK_1_5)) {
final PsiAnnotation[] annotations = InferredAnnotationsManager.getInstance(project).findInferredAnnotations(owner);
if (annotations.length > 0) {
final String annos = StringUtil.join(annotations, new Function<PsiAnnotation, String>() {
@Override
public String fun(PsiAnnotation annotation) {
final PsiJavaCodeReferenceElement nameRef = correctAnnotation(annotation).getNameReferenceElement();
final String name = nameRef != null ? nameRef.getReferenceName() : annotation.getQualifiedName();
return "@" + name + annotation.getParameterList().getText();
}
}, " ");
setText("Insert '" + annos + "'");
return true;
}
}
return false;
}
示例6: generateDoc
import com.intellij.openapi.module.ModuleUtilCore; //导入方法依赖的package包/类
@Override
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) {
if (originalElement == null) {
return null;
}
ResourceReferenceType referenceType = AndroidPsiUtils.getResourceReferenceType(originalElement);
if (referenceType == ResourceReferenceType.NONE) {
return null;
}
Module module = ModuleUtilCore.findModuleForPsiElement(originalElement);
if (module == null) {
return null;
}
ResourceType type = AndroidPsiUtils.getResourceType(originalElement);
if (type == null) {
return null;
}
String name = AndroidPsiUtils.getResourceName(originalElement);
boolean isFrameworkResource = referenceType == ResourceReferenceType.FRAMEWORK;
return AndroidJavaDocRenderer.render(module, type, name, isFrameworkResource);
}
示例7: getFqnsForFile
import com.intellij.openapi.module.ModuleUtilCore; //导入方法依赖的package包/类
private String[] getFqnsForFile( PsiFile element )
{
Module mod = ModuleUtilCore.findModuleForPsiElement( element );
if( mod == null )
{
return new String[0];
}
ManModule module = ManProject.getModule( mod );
return module.getTypesForFile( FileUtil.toIFile( module.getProject(), element.getVirtualFile() ) );
}
示例8: storeTypeManifoldReferences
import com.intellij.openapi.module.ModuleUtilCore; //导入方法依赖的package包/类
private void storeTypeManifoldReferences( @NotNull PsiElement element )
{
Module mod = ModuleUtilCore.findModuleForPsiElement( element );
if( mod == null )
{
return;
}
ManModule module = ManProject.getModule( mod );
PsiClass psiClass = findPsiClass( (PsiFileSystemItem)element, module );
if( psiClass == null )
{
return;
}
Query<PsiReference> search = ReferencesSearch.search( psiClass, GlobalSearchScope.projectScope( mod.getProject() ) );
List<UsageInfo> usages = new ArrayList<>();
for( PsiReference ref: search.findAll() )
{
usages.add( new MoveRenameUsageInfo( ref.getElement(), ref, ref.getRangeInElement().getStartOffset(),
ref.getRangeInElement().getEndOffset(), element,
ref.resolve() == null && !(ref instanceof PsiPolyVariantReference && ((PsiPolyVariantReference)ref).multiResolve( true ).length > 0) ) );
}
_usages = usages;
if( psiClass instanceof ManifoldPsiClass )
{
PsiElement fakeElement = ManGotoDeclarationHandler.find( psiClass, (ManifoldPsiClass)psiClass );
if( fakeElement instanceof PsiNamedElement && isTopLevelClassDeclaration( fakeElement ) )
{
_classDeclElement = (PsiNamedElement)fakeElement;
}
}
}
示例9: isCorrectModule
import com.intellij.openapi.module.ModuleUtilCore; //导入方法依赖的package包/类
private static boolean isCorrectModule(PsiFile file) {
final Module module = ModuleUtilCore.findModuleForPsiElement(file);
if (module == null) {
return false;
}
final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
if (sdk == null) {
return false;
}
return file.getOriginalFile().getVirtualFile() != null && sdk.getSdkType() instanceof JavaSdkType;
}
示例10: checkForAvailableTasks
import com.intellij.openapi.module.ModuleUtilCore; //导入方法依赖的package包/类
private static void checkForAvailableTasks(int level,
@Nullable String taskName,
@NotNull PsiScopeProcessor processor,
@NotNull ResolveState state,
@NotNull PsiElement place) {
if (taskName == null) return;
final GroovyPsiManager psiManager = GroovyPsiManager.getInstance(place.getProject());
PsiClass gradleApiProjectClass = psiManager.findClassWithCache(GRADLE_API_PROJECT, place.getResolveScope());
if (canBeMethodOf(taskName, gradleApiProjectClass)) return;
if (canBeMethodOf(GroovyPropertyUtils.getGetterNameNonBoolean(taskName), gradleApiProjectClass)) return;
final String className = BUILT_IN_TASKS.get(taskName);
if (className != null) {
if (level <= 1) {
GradleResolverUtil.addImplicitVariable(processor, state, place, className);
}
processTask(taskName, className, psiManager, processor, state, place);
return;
}
Module module = ModuleUtilCore.findModuleForPsiElement(place);
if (module == null) return;
String path = module.getOptionValue(ExternalSystemConstants.ROOT_PROJECT_PATH_KEY);
GradleLocalSettings localSettings = GradleLocalSettings.getInstance(place.getProject());
Collection<ExternalTaskPojo> taskPojos = localSettings.getAvailableTasks().get(path);
if (taskPojos == null) return;
for (ExternalTaskPojo taskPojo : taskPojos) {
if (taskName.equals(taskPojo.getName())) {
processTask(taskName, GRADLE_API_TASK, psiManager, processor, state, place);
return;
}
}
}
示例11: getElementModuleName
import com.intellij.openapi.module.ModuleUtilCore; //导入方法依赖的package包/类
@Override
public String getElementModuleName(final Object element) {
if (element instanceof PsiMethod) {
PsiMethod aMethod = (PsiMethod)element;
Module module = ModuleUtilCore.findModuleForPsiElement(aMethod);
return module != null ? module.getName() : null;
}
return null;
}
示例12: visitPyFile
import com.intellij.openapi.module.ModuleUtilCore; //导入方法依赖的package包/类
@Override
public void visitPyFile(PyFile node) {
final Module module = ModuleUtilCore.findModuleForPsiElement(node);
if (module != null) {
if (isRunningPackagingTasks(module)) {
return;
}
final Sdk sdk = PythonSdkType.findPythonSdk(module);
if (sdk != null) {
final List<PyRequirement> unsatisfied = findUnsatisfiedRequirements(module, sdk, myIgnoredPackages);
if (unsatisfied != null && !unsatisfied.isEmpty()) {
final boolean plural = unsatisfied.size() > 1;
String msg = String.format("Package requirement%s %s %s not satisfied",
plural ? "s" : "",
requirementsToString(unsatisfied),
plural ? "are" : "is");
final Set<String> unsatisfiedNames = new HashSet<String>();
for (PyRequirement req : unsatisfied) {
unsatisfiedNames.add(req.getName());
}
final List<LocalQuickFix> quickFixes = new ArrayList<LocalQuickFix>();
quickFixes.add(new PyInstallRequirementsFix(null, module, sdk, unsatisfied));
quickFixes.add(new IgnoreRequirementFix(unsatisfiedNames));
registerProblem(node, msg,
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, null,
quickFixes.toArray(new LocalQuickFix[quickFixes.size()]));
}
}
}
}
示例13: getImportPriority
import com.intellij.openapi.module.ModuleUtilCore; //导入方法依赖的package包/类
@NotNull
public static ImportPriority getImportPriority(@NotNull PsiElement importLocation, @NotNull PsiFileSystemItem toImport) {
final VirtualFile vFile = toImport.getVirtualFile();
if (vFile == null) {
return ImportPriority.THIRD_PARTY;
}
final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(toImport.getProject());
if (projectRootManager.getFileIndex().isInContent(vFile)) {
return ImportPriority.PROJECT;
}
final Module module = ModuleUtilCore.findModuleForPsiElement(importLocation);
final Sdk pythonSdk = module != null ? PythonSdkType.findPythonSdk(module) : projectRootManager.getProjectSdk();
return PythonSdkType.isStdLib(vFile, pythonSdk) ? ImportPriority.BUILTIN : ImportPriority.THIRD_PARTY;
}
示例14: annotateResourceReference
import com.intellij.openapi.module.ModuleUtilCore; //导入方法依赖的package包/类
private static void annotateResourceReference(@NotNull ResourceType type,
@NotNull AnnotationHolder holder,
@NotNull PsiElement element,
@NotNull String name,
boolean isFramework) {
Module module = ModuleUtilCore.findModuleForPsiElement(element);
if (module == null) {
return;
}
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null) {
return;
}
PsiFile file = PsiTreeUtil.getParentOfType(element, PsiFile.class);
if (file == null) {
return;
}
Configuration configuration = pickConfiguration(facet, module, file);
if (configuration == null) {
return;
}
ResourceValue value = findResourceValue(type, name, isFramework, module, configuration);
if (value != null) {
// TODO: Use a *shared* fallback resolver for this?
ResourceResolver resourceResolver = configuration.getResourceResolver();
if (resourceResolver != null) {
annotateResourceValue(type, holder, element, value, resourceResolver);
}
}
}
示例15: getRuntimeScriptName
import com.intellij.openapi.module.ModuleUtilCore; //导入方法依赖的package包/类
@NotNull
public String getRuntimeScriptName(@NotNull final String originalName, GroovyFile groovyFile) {
VirtualFile virtualFile = groovyFile.getVirtualFile();
if (virtualFile == null) return "";
final Module module = ModuleUtilCore.findModuleForPsiElement(groovyFile);
if (module == null) {
return "";
}
final File scriptFile = VfsUtilCore.virtualToIoFile(virtualFile);
final String className = CachedValuesManager.getManager(module.getProject())
.getCachedValue(module, GRADLE_CLASS_NAME, new ScriptSourceMapCalculator(module), false).get(scriptFile);
return className == null ? "" : className;
}