consulo.annotation.access.RequiredReadAction Java Examples

The following examples show how to use consulo.annotation.access.RequiredReadAction. 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: CSharpVisibilityUtil.java    From consulo-csharp with 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 #2
Source File: CS0441.java    From consulo-csharp with 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 #3
Source File: CSharpNamespaceDeclarationImpl.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: CSharpCreateFromTemplateHandler.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@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 #5
Source File: CSharpLambdaExpressionImplUtil.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@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 #6
Source File: CSharpBaseResolveContext.java    From consulo-csharp with 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 #7
Source File: CSharpArrayTypeRef.java    From consulo-csharp with 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 #8
Source File: CSharpFindUsagesProvider.java    From consulo-csharp with 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 #9
Source File: CS1985.java    From consulo-csharp with 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 #10
Source File: CSharpPreprocessorDefineImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public String getVarName()
{
	PsiElement nameIdentifier = getVarElement();
	return nameIdentifier != null ? nameIdentifier.getText() : null;
}
 
Example #11
Source File: CSharpReferenceExpressionStubElementType.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Override
public CSharpReferenceExpressionStub createStub(@Nonnull CSharpReferenceExpression psi, StubElement parentStub)
{
	String referenceName = psi.getReferenceNameWithAt();
	CSharpReferenceExpression.ResolveToKind kind = psi.kind();
	boolean global = psi.isGlobalElement();
	CSharpReferenceExpression.AccessType memberAccessType = psi.getMemberAccessType();
	return new CSharpReferenceExpressionStub(parentStub, this, referenceName, kind.ordinal(), memberAccessType.ordinal(), global);
}
 
Example #12
Source File: CSharpElementDescriptionProvider.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
@RequiredReadAction
public String getElementDescription(@Nonnull PsiElement element, @Nonnull ElementDescriptionLocation location)
{
	if(location == UsageViewShortNameLocation.INSTANCE && element instanceof CSharpNamedElement)
	{
		return ((CSharpNamedElement) element).getNameWithAt();
	}
	return null;
}
 
Example #13
Source File: CSharpStubBuilderVisitor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredReadAction
public static List<StubBlock> buildBlocks(PsiElement qualifiedElement, boolean compiled)
{
	CSharpStubBuilderVisitor visitor = new CSharpStubBuilderVisitor(compiled);
	qualifiedElement.accept(visitor);
	return visitor.getBlocks();
}
 
Example #14
Source File: CSharpLambdaExpressionImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredReadAction
public DotNetTypeRef toTypeRefForInference()
{
	// recursion when child lambda reference to parameter from parent lambda
	DotNetTypeRef returnType = RecursionManager.doPreventingRecursion("C# lambda return type", false, this::findPossibleReturnTypeRef);
	if(returnType == null)
	{
		returnType = DotNetTypeRef.ERROR_TYPE;
	}
	return new CSharpLambdaTypeRef(this, null, getParameterInfos(true), returnType);
}
 
Example #15
Source File: CSharpIsExpressionImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nonnull
@Override
public DotNetTypeRef toTypeRefImpl(boolean resolveFromParent)
{
	return new CSharpTypeRefByQName(this, DotNetTypes.System.Boolean);
}
 
Example #16
Source File: CSharpNullableTypeImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Override
@Nonnull
public PsiElement getQuestElement()
{
	return findNotNullChildByType(CSharpTokens.QUEST);
}
 
Example #17
Source File: CSharpTypeElementImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
@RequiredReadAction
public DotNetTypeRef fun(CSharpTypeElementImpl typeElement)
{
	return typeElement.toTypeRefImpl();
}
 
Example #18
Source File: MsilToCSharpUtil.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
private static boolean hasAttribute(DotNetModifierList modifierList, String qName)
{
	for(DotNetAttribute attribute : modifierList.getAttributes())
	{
		DotNetTypeDeclaration typeDeclaration = attribute.resolveToType();
		if(typeDeclaration != null && Comparing.equal(typeDeclaration.getPresentableQName(), qName))
		{
			return true;
		}
	}
	return false;
}
 
Example #19
Source File: CS0151.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
private boolean isValidTypeRef(DotNetTypeRef typeRef)
{
	DotNetTypeResolveResult typeResolveResult = typeRef.resolve();
	PsiElement resolvedElement = typeResolveResult.getElement();

	if(resolvedElement instanceof CSharpTypeDeclaration)
	{
		CSharpTypeDeclaration typeDeclaration = (CSharpTypeDeclaration) resolvedElement;
		if(typeDeclaration.isEnum())
		{
			return true;
		}
		String vmQName = typeDeclaration.getVmQName();
		if(ArrayUtil.contains(vmQName, ourSwitchTypes))
		{
			return true;
		}

		if(DotNetTypes.System.Nullable$1.equals(vmQName))
		{
			int genericParametersCount = typeDeclaration.getGenericParametersCount();
			if(genericParametersCount > 0)
			{
				DotNetGenericParameter genericParameter = typeDeclaration.getGenericParameters()[0];

				DotNetGenericExtractor genericExtractor = typeResolveResult.getGenericExtractor();
				DotNetTypeRef extractedTypRef = genericExtractor.extract(genericParameter);
				if(extractedTypRef == null)
				{
					return false;
				}

				return isValidTypeRef(extractedTypRef);
			}
		}
	}

	return false;
}
 
Example #20
Source File: CSharpCompositeTypeDeclaration.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public DotNetModifierList getModifierList()
{
	return null;
}
 
Example #21
Source File: CSharpDisabledFormattingBlock.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
@RequiredReadAction
public TextRange getTextRange()
{
	return myNode.getTextRange();
}
 
Example #22
Source File: CSharpParameterImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredReadAction
public PsiElement setName(@NonNls @Nonnull String s) throws IncorrectOperationException
{
	CSharpRefactoringUtil.replaceNameIdentifier(this, s);
	return this;
}
 
Example #23
Source File: CSharpConversionMethodDeclarationImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public PsiElement getNameIdentifier()
{
	return getReturnType();
}
 
Example #24
Source File: CSharpDocReferenceInspection.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public PsiElementVisitor buildVisitor(@Nonnull final ProblemsHolder holder, boolean isOnTheFly)
{
	return new CSharpElementVisitor()
	{
		@Override
		@RequiredReadAction
		public void visitReferenceExpression(CSharpReferenceExpression expression)
		{
			PsiElement referenceElement = expression.getReferenceElement();
			if(referenceElement == null || expression.isSoft() || !CSharpDocUtil.isInsideDoc(expression))
			{
				return;
			}

			List<CompilerCheck.HighlightInfoFactory> factories = CC0001.checkReference(expression, Arrays.asList(referenceElement));
			if(factories.isEmpty())
			{
				return;
			}

			for(CompilerCheck.HighlightInfoFactory factory : factories)
			{
				HighlightInfo highlightInfo = factory.create(true);
				if(highlightInfo == null)
				{
					continue;
				}
				holder.registerProblem(expression, highlightInfo.getDescription());
			}
		}
	};
}
 
Example #25
Source File: SimpleNamedScopeProcessor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Override
public boolean execute(@Nonnull PsiElement element, ResolveState state)
{
	if(!(element instanceof PsiNamedElement) || !ExecuteTargetUtil.isMyElement(this, element))
	{
		return true;
	}

	String name = ((PsiNamedElement) element).getName();
	if(name == null)
	{
		return true;
	}

	if(myCompletion)
	{
		return myCompletionProcessor.process(new CSharpResolveResult(element));
	}
	else
	{
		CSharpResolveSelector selector = state.get(CSharpResolveUtil.SELECTOR);
		if(!(selector instanceof CSharpNamedResolveSelector))
		{
			return true;
		}

		if(((CSharpNamedResolveSelector) selector).isNameEqual(name))
		{
			myCompletionProcessor.process(new CSharpResolveResult(element));
			return false;
		}
	}
	return true;
}
 
Example #26
Source File: CSharpSmartEnterProcessor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredReadAction
public boolean process(@Nonnull Project project, @Nonnull Editor editor, @Nonnull PsiFile psiFile)
{
	for(Fixer fixer : myFixers)
	{
		if(fixer.process(editor, psiFile))
		{
			return true;
		}
	}
	return false;
}
 
Example #27
Source File: CSharpTypeUtil.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
@RequiredReadAction
public static Pair<String, DotNetTypeDeclaration> resolveTypeElement(@Nonnull DotNetTypeRef typeRef)
{
	DotNetTypeResolveResult typeResolveResult = typeRef.resolve();

	PsiElement typeResolveResultElement = typeResolveResult.getElement();
	if(typeResolveResultElement instanceof DotNetTypeDeclaration)
	{
		return Pair.create(((DotNetTypeDeclaration) typeResolveResultElement).getVmQName(), (DotNetTypeDeclaration) typeResolveResultElement);
	}
	return null;
}
 
Example #28
Source File: CSharpCompletionContributor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Override
public void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result)
{
	CompletionResultSet resultSet = CSharpCompletionSorting.modifyResultSet(parameters, result);

	super.fillCompletionVariants(parameters, resultSet);

	CSharpNoVariantsDelegator.fillCompletionVariants(parameters, resultSet);
}
 
Example #29
Source File: CSharpElementGroupTypeRef.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nonnull
@Override
protected DotNetTypeResolveResult resolveResult()
{
	return DotNetTypeResolveResult.EMPTY;
}
 
Example #30
Source File: CSharpArrayInitializerCompositeValueImpl.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nonnull
@Override
public CSharpCallArgument[] getArguments()
{
	return findChildrenByClass(CSharpCallArgument.class);
}