Java Code Examples for com.intellij.openapi.module.ModuleUtilCore#getExtension()

The following examples show how to use com.intellij.openapi.module.ModuleUtilCore#getExtension() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CSharpClassesMoveProcessor.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
private void notifyNamespaceChange(CSharpNamespaceDeclaration declaration)
{
	PsiElement parent = declaration.getParent();
	if(!(parent instanceof CSharpFile))
	{
		return;
	}

	DotNetSimpleModuleExtension extension = ModuleUtilCore.getExtension(declaration, DotNetSimpleModuleExtension.class);
	if(extension == null)
	{
		return;
	}

	DotNetNamespaceGeneratePolicy namespaceGeneratePolicy = extension.getNamespaceGeneratePolicy();

	String expectedNamespace = namespaceGeneratePolicy.calculateNamespace(declaration.getContainingFile().getContainingDirectory());
	if(expectedNamespace == null)
	{
		return;
	}

	declaration.setNamespace(expectedNamespace);
}
 
Example 2
Source File: UnityEventCSharpMethodLineMarkerProvider.java    From consulo-unity3d with Apache License 2.0 6 votes vote down vote up
@Nullable
@RequiredReadAction
private static LineMarkerInfo createMarker(final PsiElement element)
{
	CSharpMethodDeclaration methodDeclaration = CSharpLineMarkerUtil.getNameIdentifierAs(element, CSharpMethodDeclaration.class);
	if(methodDeclaration != null)
	{
		Unity3dModuleExtension extension = ModuleUtilCore.getExtension(element, Unity3dModuleExtension.class);
		if(extension == null)
		{
			return null;
		}

		UnityFunctionManager.FunctionInfo magicMethod = findMagicMethod(methodDeclaration);
		if(magicMethod != null)
		{
			return new LineMarkerInfo<>(element, element.getTextRange(), Unity3dIcons.EventMethod, Pass.LINE_MARKERS, new ConstantFunction<>(magicMethod.getDescription()), null,
					GutterIconRenderer.Alignment.LEFT);
		}
	}

	return null;
}
 
Example 3
Source File: CSharpLanguageVersionResolver.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nonnull
@RequiredReadAction
@Override
public LanguageVersion getLanguageVersion(@Nonnull Language language, @Nullable Project project, @Nullable VirtualFile virtualFile)
{
	if(project == null || virtualFile == null)
	{
		return CSharpLanguageVersionHelper.getInstance().getHighestVersion();
	}
	Module moduleForPsiElement = ModuleUtilCore.findModuleForFile(virtualFile, project);
	if(moduleForPsiElement == null)
	{
		return CSharpLanguageVersionHelper.getInstance().getHighestVersion();
	}
	CSharpSimpleModuleExtension extension = ModuleUtilCore.getExtension(moduleForPsiElement, CSharpSimpleModuleExtension.class);
	if(extension == null)
	{
		return CSharpLanguageVersionHelper.getInstance().getHighestVersion();
	}
	return CSharpLanguageVersionHelper.getInstance().getWrapper(extension.getLanguageVersion());
}
 
Example 4
Source File: CSharpFileStubElementType.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nullable
@RequiredReadAction
private static List<String> findVariables(@Nonnull VirtualFile virtualFile, @Nonnull Project project)
{
	Module module = ModuleUtilCore.findModuleForFile(virtualFile, project);
	if(module == null)
	{
		return null;
	}
	DotNetSimpleModuleExtension<?> extension = ModuleUtilCore.getExtension(module, DotNetSimpleModuleExtension.class);
	if(extension != null)
	{
		return extension.getVariables();
	}
	return null;
}
 
Example 5
Source File: PsiPackageManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private PsiPackage createPackageFromLibrary(@Nonnull VirtualFile virtualFile,
                                            @Nonnull Class<? extends ModuleExtension> extensionClass,
                                            @Nonnull String qualifiedName) {
  if (myProjectFileIndex.isInLibraryClasses(virtualFile)) {
    List<OrderEntry> orderEntriesForFile = myProjectFileIndex.getOrderEntriesForFile(virtualFile);
    for (OrderEntry orderEntry : orderEntriesForFile) {
      Module ownerModule = orderEntry.getOwnerModule();
      ModuleExtension extension = ModuleUtilCore.getExtension(ownerModule, extensionClass);
      if (extension != null) {
        for (PsiPackageSupportProvider p : PsiPackageSupportProvider.EP_NAME.getExtensionList()) {
          if (p.isSupported(extension)) {
            return p.createPackage(myPsiManager, this, extensionClass, qualifiedName);
          }
        }
      }
    }
  }
  return null;
}
 
Example 6
Source File: CSharpCustomCompilerSdkPointer.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public String getItemNameFromModule(@Nonnull Module module)
{
	final CSharpModuleExtension<?> extension = (CSharpModuleExtension) ModuleUtilCore.getExtension(module, myExtensionId);
	if(extension != null)
	{
		return extension.getCustomCompilerSdkPointer().getName();
	}
	return null;
}
 
Example 7
Source File: CS1644.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredUIAccess
public boolean isAvailable(@Nonnull Project project, Editor editor, @Nonnull PsiElement element)
{
	CSharpSimpleModuleExtension extension = ModuleUtilCore.getExtension(element, CSharpSimpleModuleExtension.class);
	return extension != null && extension.isSupportedLanguageVersion(myLanguageVersion) && extension.getLanguageVersion().ordinal() < myLanguageVersion.ordinal();
}
 
Example 8
Source File: SdkModuleInheritableNamedPointerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Sdk getItemFromModule(@Nonnull Module module) {
  final ModuleExtensionWithSdk<?> extension = (ModuleExtensionWithSdk)  ModuleUtilCore.getExtension(module, myExtensionId);
  if (extension != null) {
    return extension.getInheritableSdk().get();
  }
  return null;
}
 
Example 9
Source File: CSharpCreateFromTemplateHandler.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredReadAction
public void prepareProperties(Map<String, Object> props)
{
	PsiDirectory directory = (PsiDirectory) props.get("psiDirectory");
	if(directory == null)
	{
		return;
	}

	Module module = ModuleUtilCore.findModuleForPsiElement(directory);
	if(module != null)
	{
		props.put("MODULE", module.getName());
	}
	props.put("GUID", UUID.randomUUID().toString());

	DotNetSimpleModuleExtension<?> extension = ModuleUtilCore.getExtension(directory, DotNetSimpleModuleExtension.class);
	if(extension == null)
	{
		Module moduleByPsiDirectory = findModuleByPsiDirectory(directory);
		if(moduleByPsiDirectory != null)
		{
			extension = ModuleUtilCore.getExtension(moduleByPsiDirectory, DotNetSimpleModuleExtension.class);
		}
	}

	String namespace = null;
	if(extension != null)
	{
		namespace = formatNamespace(extension.getNamespaceGeneratePolicy().calculateNamespace(directory));
	}
	props.put("NAMESPACE_NAME", namespace);
}
 
Example 10
Source File: MatchNamespaceInspection.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
@RequiredReadAction
public PsiElementVisitor buildVisitor(@Nonnull ProblemsHolder holder, boolean isOnTheFly, @Nonnull LocalInspectionToolSession session)
{
	PsiFile file = holder.getFile();
	if(!(file instanceof CSharpFile))
	{
		return PsiElementVisitor.EMPTY_VISITOR;
	}

	if(file instanceof PsiCodeFragment)
	{
		return PsiElementVisitor.EMPTY_VISITOR;
	}

	DotNetSimpleModuleExtension extension = ModuleUtilCore.getExtension(file, DotNetSimpleModuleExtension.class);
	if(extension == null)
	{
		return PsiElementVisitor.EMPTY_VISITOR;
	}

	MatchNamespaceVisitor visitor = session.getUserData(KEY);
	if(visitor == null)
	{
		session.putUserData(KEY, visitor = new MatchNamespaceVisitor(holder, extension));
	}
	return visitor;
}
 
Example 11
Source File: ExternalSystemApiUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Contract("null -> false, _")
public static String getExtensionSystemOption(@Nullable Module module, @Nonnull String key) {
  if (module == null) {
    return null;
  }
  ExternalSystemModuleExtension extension = ModuleUtilCore.getExtension(module, ExternalSystemModuleExtension.class);
  if (extension == null) {
    return null;
  }
  return extension.getOption(key);
}
 
Example 12
Source File: CSharpLanguageVersionPointer.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public String getItemNameFromModule(@Nonnull Module module)
{
	final CSharpSimpleModuleExtension extension = (CSharpSimpleModuleExtension) ModuleUtilCore.getExtension(module, myExtensionId);
	if(extension != null)
	{
		return extension.getLanguageVersion().getName();
	}
	return null;
}
 
Example 13
Source File: CSharpHighlightContext.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
protected DotNetSimpleModuleExtension<?> compute()
{
	Module value = myModuleValue.getValue();
	if(value == null)
	{
		return null;
	}
	return ModuleUtilCore.getExtension(value, DotNetSimpleModuleExtension.class);
}
 
Example 14
Source File: CSharpModuleUtil.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredReadAction
public static CSharpLanguageVersion findLanguageVersion(@Nullable PsiElement element)
{
	if(element == null)
	{
		return CSharpLanguageVersion.HIGHEST;
	}
	CSharpSimpleModuleExtension<?> extension = ModuleUtilCore.getExtension(element, CSharpSimpleModuleExtension.class);
	if(extension == null)
	{
		return CSharpLanguageVersion.HIGHEST;
	}
	return extension.getLanguageVersion();
}
 
Example 15
Source File: CSharpFilePropertyPusher.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
@RequiredReadAction
public CSharpFileAttribute getImmediateValue(@Nonnull Module module)
{
	DotNetSimpleModuleExtension<?> extension = ModuleUtilCore.getExtension(module, DotNetSimpleModuleExtension.class);
	if(extension != null)
	{
		CSharpSimpleModuleExtension csharpExtension = ModuleUtilCore.getExtension(module, CSharpSimpleModuleExtension.class);
		return new CSharpFileAttribute(csharpExtension == null ? CSharpLanguageVersion.HIGHEST : csharpExtension.getLanguageVersion(), varHashCode(extension.getVariables()));
	}
	return CSharpFileAttribute.DEFAULT;
}
 
Example 16
Source File: CS0227.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredUIAccess
public boolean isAvailable(@Nonnull Project project, Editor editor, PsiFile file)
{
	CSharpSimpleModuleExtension extension = ModuleUtilCore.getExtension(file, CSharpSimpleModuleExtension.class);
	return extension != null && !extension.isAllowUnsafeCode();
}
 
Example 17
Source File: UnitySpecificMethodCompletion.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Override
public void processCompletion(@Nonnull CompletionParameters completionParameters,
		@Nonnull ProcessingContext processingContext,
		@Nonnull Consumer<LookupElement> completionResultSet,
		@Nonnull CSharpTypeDeclaration typeDeclaration)
{
	Unity3dModuleExtension extension = ModuleUtilCore.getExtension(typeDeclaration, Unity3dModuleExtension.class);
	if(extension == null)
	{
		return;
	}

	for(Map.Entry<String, Map<String, UnityFunctionManager.FunctionInfo>> entry : UnityFunctionManager.getInstance().getFunctionsByType().entrySet())
	{
		String typeName = entry.getKey();

		if(!DotNetInheritUtil.isParent(typeName, typeDeclaration, true))
		{
			continue;
		}

		for(UnityFunctionManager.FunctionInfo functionInfo : entry.getValue().values())
		{
			UnityFunctionManager.FunctionInfo nonParameterListCopy = functionInfo.createNonParameterListCopy();
			if(nonParameterListCopy != null)
			{
				completionResultSet.consume(buildLookupItem(nonParameterListCopy, typeDeclaration));
			}

			completionResultSet.consume(buildLookupItem(functionInfo, typeDeclaration));
		}
	}
}
 
Example 18
Source File: UnityScriptLineBreakpointTypeResolver.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public XLineBreakpointType<?> resolveBreakpointType(@Nonnull Project project, @Nonnull VirtualFile virtualFile, int line)
{
	Unity3dScriptModuleExtension extension = ModuleUtilCore.getExtension(project, virtualFile, Unity3dScriptModuleExtension.class);
	if(extension != null)
	{
		return DotNetLineBreakpointType.getInstance();
	}
	return null;
}
 
Example 19
Source File: UnityScriptEventFunctionLineMarkerProvider.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public LineMarkerInfo getLineMarkerInfo(@Nonnull PsiElement element)
{
	if(element.getNode().getElementType() == JSTokenTypes.IDENTIFIER && element.getParent() instanceof JSReferenceExpression && element.getParent().getParent() instanceof JSFunction)
	{
		UnityFunctionManager functionManager = UnityFunctionManager.getInstance();
		Map<String, UnityFunctionManager.FunctionInfo> map = functionManager.getFunctionsByType().get(Unity3dTypes.UnityEngine.MonoBehaviour);
		if(map == null)
		{
			return null;
		}
		UnityFunctionManager.FunctionInfo functionInfo = map.get(element.getText());
		if(functionInfo == null)
		{
			return null;
		}
		Unity3dModuleExtension extension = ModuleUtilCore.getExtension(element, Unity3dModuleExtension.class);
		if(extension == null)
		{
			return null;
		}
		JSFunction jsFunction = (JSFunction) element.getParent().getParent();
		if(jsFunction.getParent() instanceof JSFile)
		{
			if(!isEqualParameters(functionInfo.getParameters(), jsFunction))
			{
				return null;
			}

			return new LineMarkerInfo<>(element, element.getTextRange(), Unity3dIcons.EventMethod, Pass.LINE_MARKERS, new ConstantFunction<>(functionInfo.getDescription()), null,
					GutterIconRenderer.Alignment.LEFT);
		}
	}
	return null;
}
 
Example 20
Source File: CSharpLocationUtil.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
public static boolean isValidLocation(@Nonnull Project project, @Nullable VirtualFile virtualFile)
{
	if(virtualFile == null || virtualFile.getFileType() != CSharpFileType.INSTANCE)
	{
		// if not virtual file - we dont need break highlight
		return true;
	}

	// msil representation highlight always
	if(virtualFile instanceof MsilFileRepresentationVirtualFile)
	{
		return true;
	}

	Module moduleForFile = ModuleUtilCore.findModuleForFile(virtualFile, project);
	if(moduleForFile == null)
	{
		return false;
	}
	DotNetSimpleModuleExtension extension = ModuleUtilCore.getExtension(moduleForFile, DotNetSimpleModuleExtension.class);
	if(extension == null)
	{
		return false;
	}

	if(ModuleUtilCore.getExtension(moduleForFile, CSharpSimpleModuleExtension.class) == null)
	{
		return false;
	}

	if(extension instanceof DotNetModuleExtension)
	{
		if(!((DotNetModuleExtension) extension).isAllowSourceRoots())
		{
			return true;
		}
		else
		{
			ModuleFileIndex fileIndex = ModuleRootManager.getInstance(moduleForFile).getFileIndex();
			return fileIndex.isInSourceContent(virtualFile) || fileIndex.isInTestSourceContent(virtualFile);
		}
	}
	else
	{
		return true;
	}
}