Java Code Examples for consulo.annotation.access.RequiredReadAction

The following examples show how to use consulo.annotation.access.RequiredReadAction. These examples are extracted from open source projects. 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
@Nonnull
@RequiredReadAction
public static DotNetTypeRef resolveTypeForParameter(CSharpLambdaExpressionImpl target, int parameterIndex)
{
	CSharpLambdaResolveResult leftTypeRef = resolveLeftLambdaTypeRef(target);
	if(leftTypeRef == null)
	{
		return DotNetTypeRef.ERROR_TYPE;
	}

	if(leftTypeRef == CSharpUndefinedLambdaResolveResult.INSTANCE)
	{
		return DotNetTypeRef.UNKNOWN_TYPE;
	}
	DotNetTypeRef[] leftTypeParameters = leftTypeRef.getParameterTypeRefs();
	DotNetTypeRef typeRef = ArrayUtil2.safeGet(leftTypeParameters, parameterIndex);
	return ObjectUtil.notNull(typeRef, DotNetTypeRef.ERROR_TYPE);
}
 
Example 2
@RequiredReadAction
private String buildQualifiedName()
{
	String parentQualifiedName = null;
	PsiElement parent = getParent();
	if(parent instanceof DotNetNamespaceDeclaration)
	{
		parentQualifiedName = ((DotNetNamespaceDeclaration) parent).getPresentableQName();
	}

	String text = getReferenceText();
	if(!StringUtil.isEmpty(parentQualifiedName))
	{
		return parentQualifiedName + "." + text;
	}
	return text;
}
 
Example 3
Source Project: consulo-csharp   Source File: CS0441.java    License: Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Nonnull
@Override
public List<? extends HighlightInfoFactory> check(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull DotNetTypeDeclaration element)
{
	DotNetModifierList modifierList = element.getModifierList();
	if(modifierList == null)
	{
		return super.check(languageVersion, highlightContext, element);
	}
	PsiElement sealedModifierElement = modifierList.getModifierElement(CSharpModifier.SEALED);
	PsiElement staticModifierElement = modifierList.getModifierElement(CSharpModifier.STATIC);
	if(sealedModifierElement != null && staticModifierElement != null)
	{
		List<HighlightInfoFactory> list = new ArrayList<HighlightInfoFactory>(2);
		String name = formatElement(element);
		list.add(newBuilder(sealedModifierElement, name).addQuickFix(new RemoveModifierFix(DotNetModifier.SEALED, element)));
		list.add(newBuilder(staticModifierElement, name).addQuickFix(new RemoveModifierFix(DotNetModifier.STATIC, element)));
		return list;
	}
	return super.check(languageVersion, highlightContext, element);
}
 
Example 4
Source Project: consulo-csharp   Source File: CSharpBaseResolveContext.java    License: Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public CSharpElementGroup<CSharpMethodDeclaration> findExtensionMethodGroupByName(@Nonnull String name)
{
	Map<String, CSharpElementGroup<PsiElement>> map = myOtherCollectorValue.getValue().toMap();
	if(map == null)
	{
		return null;
	}
	CSharpElementGroup<PsiElement> elementGroup = map.get(name);
	if(elementGroup == null)
	{
		return null;
	}

	return filterElementGroupToExtensionGroup(elementGroup);
}
 
Example 5
Source Project: consulo-csharp   Source File: CSharpVisibilityUtil.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
@RequiredReadAction
private static List<DotNetTypeDeclaration> collectAllTypes(@Nonnull PsiElement place)
{
	List<DotNetTypeDeclaration> typeDeclarations = new SmartList<>();
	if(place instanceof CSharpTypeDeclaration)
	{
		typeDeclarations.add((DotNetTypeDeclaration) place);
	}
	PsiElement type = place;
	while((type = PsiTreeUtil.getContextOfType(type, DotNetTypeDeclaration.class)) != null)
	{
		typeDeclarations.add((DotNetTypeDeclaration) type);
	}
	return typeDeclarations;
}
 
Example 6
Source Project: consulo-csharp   Source File: CS1985.java    License: Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public HighlightInfoFactory checkImpl(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull CSharpAwaitExpressionImpl element)
{
	if(languageVersion.isAtLeast(CSharpLanguageVersion._6_0))
	{
		return null;
	}
	CSharpCatchStatementImpl catchStatement = PsiTreeUtil.getParentOfType(element, CSharpCatchStatementImpl.class);
	if(catchStatement != null)
	{
		return newBuilder(element.getAwaitKeywordElement(), "await");
	}
	return null;
}
 
Example 7
Source Project: consulo-csharp   Source File: CSharpFindUsagesProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
@RequiredReadAction
public String getDescriptiveName(@Nonnull PsiElement element)
{
	if(element instanceof CSharpPreprocessorVariable)
	{
		return ((CSharpPreprocessorVariable) element).getName();
	}
	if(element instanceof DotNetNamedElement)
	{
		String name = ((DotNetNamedElement) element).getName();
		return name == null ? "null" : name;
	}
	if(element instanceof CSharpLocalVariableDeclarationStatement)
	{
		return StringUtil.join(((CSharpLocalVariableDeclarationStatement) element).getVariables(), PsiNamedElement::getName, ", ");
	}
	return debugText("getDescriptiveName", element);
}
 
Example 8
@Nullable
@RequiredReadAction
public static Module findModuleByPsiDirectory(final PsiDirectory directory)
{
	LightVirtualFile l = new LightVirtualFile("test.cs", CSharpFileType.INSTANCE, "")
	{
		@Override
		public VirtualFile getParent()
		{
			return directory.getVirtualFile();
		}

		@Nonnull
		@Override
		public VirtualFileSystem getFileSystem()
		{
			return LocalFileSystem.getInstance();
		}
	};
	return CreateFileFromTemplateAction.ModuleResolver.EP_NAME.composite().resolveModule(directory, CSharpFileType.INSTANCE);
}
 
Example 9
Source Project: consulo-csharp   Source File: CSharpArrayTypeRef.java    License: Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
private static void addIndexMethodWithType(String parameterQName, CSharpLightTypeDeclarationBuilder builder, PsiElement scope, int dimensions, DotNetTypeRef innerType)
{
	int parameterCount = dimensions + 1;

	CSharpLightIndexMethodDeclarationBuilder methodDeclarationBuilder = new CSharpLightIndexMethodDeclarationBuilder(builder.getProject(), dimensions);
	methodDeclarationBuilder.addModifier(DotNetModifier.PUBLIC);

	for(int i = 0; i < parameterCount; i++)
	{
		CSharpLightParameterBuilder parameter = new CSharpLightParameterBuilder(scope);
		parameter.withName("index" + i);
		parameter.withTypeRef(new CSharpTypeRefByQName(scope, parameterQName));

		methodDeclarationBuilder.addParameter(parameter);
	}

	methodDeclarationBuilder.withReturnType(innerType);

	builder.addMember(methodDeclarationBuilder);
}
 
Example 10
Source Project: consulo-csharp   Source File: CSharpErrorExpressionImpl.java    License: Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nonnull
@Override
public DotNetTypeRef toTypeRefImpl(boolean resolveFromParent)
{
	return DotNetTypeRef.ERROR_TYPE;
}
 
Example 11
@RequiredReadAction
@Nullable
@Override
public String getPresentableParentQName()
{
	return myOriginal.getPresentableParentQName();
}
 
Example 12
Source Project: consulo-csharp   Source File: CS1980.java    License: Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
private boolean noRuntimeType(@Nonnull CSharpNativeType element)
{
	DotNetTypeDeclaration type = DotNetPsiSearcher.getInstance(element.getProject()).findType(ourCheckType, element.getResolveScope());
	if(type == null)
	{
		if(DotNetPsiSearcher.getInstance(element.getProject()).findType(ourCheckType2, element.getResolveScope()) == null)
		{
			return true;
		}
	}
	return false;
}
 
Example 13
Source Project: consulo-csharp   Source File: CSharpTypeUtil.java    License: Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
private static boolean isMethodGeneric(PsiElement element)
{
	if(!(element instanceof DotNetGenericParameter))
	{
		return false;
	}
	PsiElement parent = element.getParent();
	if(!(parent instanceof DotNetGenericParameterList))
	{
		return false;
	}
	PsiElement parentParent = parent.getParent();
	return parentParent instanceof DotNetLikeMethodDeclaration;
}
 
Example 14
@Nullable
@RequiredReadAction
public String buildArgumentTypeRefs()
{
	CSharpReferenceExpression element = myPointer.getElement();
	if(element == null)
	{
		return null;
	}

	StringBuilder builder = new StringBuilder();

	CSharpSimpleParameterInfo[] parameterInfos = myLikeMethod.getParameterInfos();

	for(int i = 0; i < parameterInfos.length; i++)
	{
		if(i != 0)
		{
			builder.append(", ");
		}

		CSharpSimpleParameterInfo parameterInfo = parameterInfos[i];

		builder.append(CSharpTypeRefPresentationUtil.buildShortText(parameterInfo.getTypeRef(), element));
	}
	return builder.toString();
}
 
Example 15
Source Project: consulo-csharp   Source File: CSharpLightTypeDeclaration.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
@RequiredReadAction
public DotNetNamedElement[] getMembers()
{
	return myMembersValue.getValue();
}
 
Example 16
Source Project: consulo-csharp   Source File: CSharpHighlightContext.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
@RequiredReadAction
protected Module compute()
{
	return ModuleUtilCore.findModuleForPsiElement(myFile);
}
 
Example 17
@RequiredReadAction
@Nonnull
@Override
public Collection<DotNetModifierListOwner> getItems(@Nonnull CSharpTypeDeclaration typeDeclaration)
{
	if(typeDeclaration.isInterface())
	{
		return Collections.emptyList();
	}
	return OverrideUtil.collectMembersWithModifier(typeDeclaration, DotNetGenericExtractor.EMPTY, CSharpModifier.ABSTRACT);
}
 
Example 18
Source Project: consulo-csharp   Source File: CSharpSwitchStatementImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@RequiredReadAction
public boolean processDeclarations(@Nonnull PsiScopeProcessor processor, @Nonnull ResolveState state, PsiElement lastParent, @Nonnull PsiElement place)
{
	CSharpSwitchLabelStatement[] statements = getStatements();
	for(CSharpSwitchLabelStatement statement : statements)
	{
		if(!statement.processDeclarations(processor, state, lastParent, place))
		{
			return false;
		}
	}
	return super.processDeclarations(processor, state, lastParent, place);
}
 
Example 19
Source Project: consulo-csharp   Source File: CS0102.java    License: Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nonnull
@Override
public List<CompilerCheckBuilder> check(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull CSharpTypeDeclaration element)
{
	return doCheck(this, element);
}
 
Example 20
@Nonnull
@Override
@RequiredReadAction
public ResolveResult[] multiResolve(final boolean incompleteCode)
{
	return multiResolve(incompleteCode, true);
}
 
Example 21
@RequiredReadAction
@Nullable
@Override
public String getPresentableQName()
{
	String parentQName = getPresentableParentQName();
	if(StringUtil.isEmpty(parentQName))
	{
		return getName();
	}
	return parentQName + "." + getName();
}
 
Example 22
Source Project: consulo-csharp   Source File: OperatorsProvider.java    License: Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Override
public void processAdditionalMembers(@Nonnull DotNetElement element, @Nonnull DotNetGenericExtractor extractor, @Nonnull Consumer<PsiElement> consumer)
{
	if(element instanceof CSharpTypeDeclaration)
	{
		Project project = element.getProject();
		GlobalSearchScope resolveScope = element.getResolveScope();

		CSharpTypeDeclaration typeDeclaration = (CSharpTypeDeclaration) element;

		CSharpMethodDeclaration methodDeclaration = typeDeclaration.getUserData(CSharpResolveUtil.DELEGATE_METHOD_TYPE);
		DotNetTypeRef selfTypeRef;
		if(methodDeclaration != null)
		{
			selfTypeRef = new CSharpLambdaTypeRef(element, methodDeclaration, extractor);
		}
		else
		{
			selfTypeRef = new CSharpTypeRefByTypeDeclaration(typeDeclaration, extractor);
		}

		buildOperators(project, resolveScope, selfTypeRef, element, OperatorStubsLoader.INSTANCE.myTypeOperators.get(typeDeclaration.getVmQName()), consumer);

		if(typeDeclaration.isEnum())
		{
			buildOperators(project, resolveScope, selfTypeRef, element, OperatorStubsLoader.INSTANCE.myEnumOperators, consumer);
		}

		if(DotNetTypes.System.Nullable$1.equals(typeDeclaration.getVmQName()))
		{
			buildNullableOperators(project, resolveScope, selfTypeRef, typeDeclaration, extractor, consumer);
		}

		if(methodDeclaration != null)
		{
			buildOperatorsForDelegates(consumer, project, typeDeclaration, selfTypeRef);
		}
	}
}
 
Example 23
@RequiredReadAction
@Nullable
@Override
public DotNetModifierList getModifierList()
{
	return null;
}
 
Example 24
Source Project: consulo-csharp   Source File: CSharpTypeRefCacher.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
@RequiredReadAction
public DotNetTypeRef fun(E e)
{
	return myCacher.toTypeRefImpl(e, myValue);
}
 
Example 25
@RequiredReadAction
public static TextRange getRangeInElement(@Nonnull CSharpReferenceExpression referenceExpression)
{
	PsiElement referenceElement = referenceExpression.getReferenceElement();
	if(referenceElement == null)
	{
		return TextRange.EMPTY_RANGE;
	}

	int startOffset = referenceElement.getStartOffsetInParent();
	return new TextRange(startOffset, referenceElement.getTextLength() + startOffset);
}
 
Example 26
Source Project: consulo-csharp   Source File: CSharpTypeListImpl.java    License: Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nonnull
@Override
public DotNetType[] getTypes()
{
	return findChildrenByClass(DotNetType.class);
}
 
Example 27
Source Project: consulo-csharp   Source File: CS1644.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@RequiredReadAction
public PsiElement fun(PsiElement element)
{
	if(element instanceof CSharpAwaitExpressionImpl)
	{
		DotNetStatement statement = PsiTreeUtil.getParentOfType(element, CSharpFinallyStatementImpl.class, CSharpCatchStatementImpl.class);
		if(statement != null)
		{
			return ((CSharpAwaitExpressionImpl) element).getAwaitKeywordElement();
		}
		return null;
	}
	return null;
}
 
Example 28
Source Project: consulo-csharp   Source File: CSharpModuleUtil.java    License: 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 29
Source Project: consulo-csharp   Source File: CSharpIsExpressionImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredReadAction
public DotNetTypeRef getIsTypeRef()
{
	DotNetType type = findChildByClass(DotNetType.class);
	return type == null ? DotNetTypeRef.ERROR_TYPE : type.toTypeRef();
}
 
Example 30
@RequiredReadAction
public void consumeAsMethodGroup()
{
	if(myCompletion || myResolvedElements.isEmpty())
	{
		return;
	}

	CSharpMethodDeclaration methodDeclaration = myResolvedElements.get(0);
	assert methodDeclaration != null;
	CSharpElementGroupImpl element = new CSharpElementGroupImpl<>(myExpression.getProject(), methodDeclaration.getName(), myResolvedElements);
	myProcessor.pushResultExternally(new CSharpResolveResult(element, true));
}