consulo.ui.annotation.RequiredUIAccess Java Examples

The following examples show how to use consulo.ui.annotation.RequiredUIAccess. 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: CS1612.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredUIAccess
public boolean isAvailable(@Nonnull Project project, Editor editor, PsiFile file)
{
	CSharpFieldDeclaration element = myFieldPointer.getElement();

	DotNetExpression value = myValueExpression.getElement();

	DotNetExpression left = myQualifierPointer.getElement();

	DotNetVariable targetSet = null;
	if(left instanceof CSharpReferenceExpression)
	{
		PsiElement targetSetElement = ((CSharpReferenceExpression) left).resolve();
		if(targetSetElement instanceof DotNetVariable && isWritable(element))
		{
			targetSet = (DotNetVariable) targetSetElement;
		}
	}

	return targetSet != null && element != null && value != null;
}
 
Example #2
Source File: XXXAccessorOwnerChooseMember.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Nonnull
@Override
@RequiredUIAccess
public String getPresentationText()
{
	if(myDeclaration instanceof CSharpPropertyDeclaration)
	{
		return CSharpElementPresentationUtil.formatProperty((DotNetPropertyDeclaration) myDeclaration, 0);
	}
	else if(myDeclaration instanceof CSharpIndexMethodDeclaration)
	{
		return CSharpElementPresentationUtil.formatMethod((CSharpIndexMethodDeclaration) myDeclaration, CSharpElementPresentationUtil.METHOD_WITH_RETURN_TYPE | CSharpElementPresentationUtil
				.METHOD_PARAMETER_NAME);
	}
	throw new UnsupportedOperationException(myDeclaration.getClass().getSimpleName() + " is not supported");
}
 
Example #3
Source File: CSharpChangeSignatureDialog.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredUIAccess
protected JComponent getRowPresentation(ParameterTableModelItemBase<CSharpParameterInfo> item, boolean selected, final boolean focused)
{
	final String typeText = item.typeCodeFragment.getText();
	CSharpModifier modifier = item.parameter.getModifier();
	String text = "";
	if(modifier != null)
	{
		text = modifier.getPresentableText() + " ";
	}
	final String separator = StringUtil.repeatSymbol(' ', getTypesMaxLength() - typeText.length() + 1);

	text += typeText + separator + item.parameter.getName();
	final String defaultValue = item.defaultValueCodeFragment.getText();
	String tail = "";
	if(StringUtil.isNotEmpty(defaultValue))
	{
		tail += " argument value = " + defaultValue;
	}
	if(!StringUtil.isEmpty(tail))
	{
		text += " //" + tail;
	}
	return JBListTable.createEditorTextFieldPresentation(getProject(), getFileType(), " " + text, selected, focused);
}
 
Example #4
Source File: CSharpParenthesesInsertHandler.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nullable
@RequiredUIAccess
protected PsiElement findNextToken(final InsertionContext context)
{
	final PsiFile file = context.getFile();
	PsiElement element = file.findElementAt(context.getTailOffset());
	if(element instanceof PsiWhiteSpace)
	{
		boolean allowParametersOnNextLine = false;
		if(!allowParametersOnNextLine && element.getText().contains("\n"))
		{
			return null;
		}
		element = file.findElementAt(element.getTextRange().getEndOffset());
	}
	return element;
}
 
Example #5
Source File: SyncUnity3dProjectAction.java    From consulo-unity3d with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void update(@Nonnull AnActionEvent e)
{
	Presentation presentation = e.getPresentation();
	Project project = e.getProject();
	if(project == null || Unity3dModuleExtensionUtil.getRootModuleExtension(project) == null)
	{
		presentation.setEnabledAndVisible(false);
		return;
	}

	VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE);
	if(virtualFile == null || !virtualFile.equals(project.getBaseDir()))
	{
		presentation.setEnabledAndVisible(false);
		return;
	}

	if(project.getUserData(Unity3dProjectImportUtil.ourInProgressFlag) == Boolean.TRUE)
	{
		presentation.setEnabled(false);
		presentation.setVisible(true);
	}
}
 
Example #6
Source File: CSharpEnterInDocLineCommentHandler.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredUIAccess
public Result preprocessEnter(@Nonnull final PsiFile file,
		@Nonnull final Editor editor,
		@Nonnull final Ref<Integer> caretOffsetRef,
		@Nonnull final Ref<Integer> caretAdvance,
		@Nonnull final DataContext dataContext,
		final EditorActionHandler originalHandler)
{
	final int caretOffset = caretOffsetRef.get();
	final Document document = editor.getDocument();
	final PsiElement psiAtOffset = file.findElementAt(caretOffset);
	final PsiElement probablyDocComment = psiAtOffset instanceof PsiWhiteSpace && psiAtOffset.getText().startsWith("\n") ? psiAtOffset.getPrevSibling() : psiAtOffset == null && caretOffset > 0
			&& caretOffset == document.getTextLength() ? file.findElementAt(caretOffset - 1) : psiAtOffset;

	if(probablyDocComment != null && PsiTreeUtil.getParentOfType(probablyDocComment, CSharpDocRoot.class, false) != null)
	{
		document.insertString(caretOffset, DOC_LINE_START + " ");
		caretAdvance.set(4);
		return Result.Default;
	}

	return Result.Continue;
}
 
Example #7
Source File: SyncUnity3dProjectAction.java    From consulo-unity3d with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredUIAccess
public void actionPerformed(@Nonnull AnActionEvent anActionEvent)
{
	final Project project = anActionEvent.getProject();
	if(project == null)
	{
		return;
	}
	final Unity3dRootModuleExtension rootModuleExtension = Unity3dModuleExtensionUtil.getRootModuleExtension(project);
	if(rootModuleExtension == null)
	{
		return;
	}

	Unity3dProjectImportUtil.syncProjectStep1(project, rootModuleExtension.getSdk(), null, true);
}
 
Example #8
Source File: CSharpChangeSignatureDialog.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
@RequiredUIAccess
public List<CSharpParameterInfo> getParameters()
{
	List<CSharpParameterInfo> result = new ArrayList<>(myParametersTableModel.getRowCount());
	int i = 0;
	for(ParameterTableModelItemBase<CSharpParameterInfo> item : myParametersTableModel.getItems())
	{
		DotNetParameter parameter = item.parameter.getParameter();
		DotNetTypeRef typeRef = parameter == null ? new CSharpTypeRefByQName(myDefaultValueContext, DotNetTypes.System.Object) : parameter.toTypeRef(true);

		CSharpParameterInfo e = new CSharpParameterInfo(item.parameter.getName(), item.parameter.getParameter(), typeRef, i++);

		DotNetType type = PsiTreeUtil.getChildOfType(item.typeCodeFragment, DotNetType.class);
		e.setTypeText(type == null ? "" : type.getText());
		e.setModifier(item.parameter.getModifier());
		e.setTypeRef(type == null ? null : type.toTypeRef());

		DotNetExpression expression = PsiTreeUtil.getChildOfType(item.defaultValueCodeFragment, DotNetExpression.class);
		e.setDefaultValue(expression == null ? "" : expression.getText());

		result.add(e);
	}
	return result;
}
 
Example #9
Source File: CSharpElementTreeNode.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
@RequiredUIAccess
protected Collection<AbstractTreeNode> getChildrenImpl()
{
	final ViewSettings settings = getSettings();
	if(!settings.isShowMembers() && !BitUtil.isSet(myFlags, FORCE_EXPAND))
	{
		return Collections.emptyList();
	}

	DotNetNamedElement[] members = filterNamespaces(getValue());
	if(members.length == 0)
	{
		return Collections.emptyList();
	}

	List<AbstractTreeNode> list = new ArrayList<>(members.length);
	for(DotNetNamedElement dotNetElement : members)
	{
		list.add(new CSharpElementTreeNode(dotNetElement, settings, 0));
	}
	return list;
}
 
Example #10
Source File: CSharpElementTreeNode.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredUIAccess
protected void updateImpl(PresentationData presentationData)
{
	DotNetNamedElement value = getValue();

	presentationData.setPresentableText(getPresentableText(value));

	if(BitUtil.isSet(myFlags, ALLOW_GRAY_FILE_NAME))
	{
		PsiFile containingFile = value.getContainingFile();
		if(containingFile != null)
		{
			if(!Comparing.equal(FileUtil.getNameWithoutExtension(containingFile.getName()), value.getName()))
			{
				presentationData.setLocationString(containingFile.getName());
			}
		}
	}
}
 
Example #11
Source File: Unity3dAttachRunner.java    From consulo-unity3d with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
private static void setRunDescriptor(AsyncResult<RunContentDescriptor> result,
		ExecutionEnvironment environment,
		ExecutionResult executionResult,
		@Nullable UnityProcess process,
		@Nullable UnityProcess editorProcess)
{
	if(process == null)
	{
		result.rejectWithThrowable(new ExecutionException("Process not find for attach"));
		return;
	}

	boolean isEditor = editorProcess != null && Comparing.equal(editorProcess, process);

	try
	{
		result.setDone(runContentDescriptor(executionResult, environment, process, null, isEditor));
	}
	catch(ExecutionException e)
	{
		result.rejectWithThrowable(e);
	}
}
 
Example #12
Source File: CSharpParameterInfoHandler.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredUIAccess
public void updateUI(ItemToShow p, ParameterInfoUIContext context)
{
	if(p == null)
	{
		context.setUIComponentEnabled(false);
		return;
	}

	ParameterPresentationBuilder<CSharpSimpleParameterInfo> build = CSharpParametersInfo.build(p.myLikeMethod, p.myScope);

	String text = build.toString();

	TextRange parameterRange = build.getParameterRange(context.getCurrentParameterIndex());

	context.setupUIComponentPresentation(text, parameterRange.getStartOffset(), parameterRange.getEndOffset(), !context.isUIComponentEnabled(), p.isObsolete(), false, context
			.getDefaultParameterColor());
}
 
Example #13
Source File: Unity3dTestDebuggerRunner.java    From consulo-unity3d with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredUIAccess
protected RunContentDescriptor doExecute(@Nonnull RunProfileState state, @Nonnull ExecutionEnvironment env) throws ExecutionException
{
	UnityProcess editorProcess = UnityEditorCommunication.findEditorProcess();
	if(editorProcess == null)
	{
		throw new ExecutionException("Editor is not responding");
	}
	FileDocumentManager.getInstance().saveAllDocuments();

	ExecutionResult executionResult = state.execute(env.getExecutor(), this);
	if(executionResult == null)
	{
		return null;
	}
	return Unity3dAttachRunner.runContentDescriptor(executionResult, env, editorProcess, (ConsoleView) executionResult.getExecutionConsole(), true);
}
 
Example #14
Source File: CastExpressionToTypeRef.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredUIAccess
public void invoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException
{
	DotNetExpression element = myExpressionPointer.getElement();
	if(element == null)
	{
		return;
	}

	String typeText = CSharpTypeRefPresentationUtil.buildShortText(myExpectedTypeRef, element);

	DotNetExpression expression = CSharpFileFactory.createExpression(project, "(" + typeText + ") " + element.getText());

	element.replace(expression);
}
 
Example #15
Source File: CastExpressionToTypeRef.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredUIAccess
public boolean isAvailable(@Nonnull Project project, Editor editor, PsiFile file)
{
	if(myExpectedTypeRef == DotNetTypeRef.UNKNOWN_TYPE)
	{
		return false;
	}
	DotNetExpression element = myExpressionPointer.getElement();
	if(element == null)
	{
		return false;
	}

	if(DotNetTypeRefUtil.isVmQNameEqual(myExpectedTypeRef, element, DotNetTypes.System.Void))
	{
		return false;
	}
	return true;
}
 
Example #16
Source File: ChangeVariableToTypeRefFix.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredUIAccess
public void invoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException
{
	PsiDocumentManager.getInstance(project).commitAllDocuments();

	DotNetVariable element = myVariablePointer.getElement();
	if(element == null)
	{
		return;
	}

	DotNetType typeOfVariable = element.getType();
	if(typeOfVariable == null)
	{
		return;
	}
	String typeText = CSharpTypeRefPresentationUtil.buildShortText(myToTypeRef, element);

	DotNetType type = CSharpFileFactory.createMaybeStubType(project, typeText, typeOfVariable);

	typeOfVariable.replace(type);
}
 
Example #17
Source File: IntroduceLocalVariableIntention.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredUIAccess
public boolean isAvailable(@Nonnull Project project, Editor editor, @Nonnull PsiElement psi)
{
	CSharpExpressionStatementImpl exprStmt = PsiTreeUtil.getParentOfType(psi, CSharpExpressionStatementImpl.class);
	if(psi instanceof SyntheticElement || exprStmt == null)
	{
		return false;
	}

	DotNetExpression expression = exprStmt.getExpression();
	if(expression instanceof CSharpAssignmentExpressionImpl)
	{
		return false;
	}

	DotNetTypeRef ref = expression.toTypeRef(true);
	return !(ref == DotNetTypeRef.ERROR_TYPE || DotNetTypeRefUtil.isVmQNameEqual(ref, expression, DotNetTypes.System.Void));
}
 
Example #18
Source File: CSharpCodeGenerationSettingsConfigurable.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void reset()
{
	myFieldPrefixField.setText(mySettings.FIELD_PREFIX);
	myStaticFieldPrefixField.setText(mySettings.STATIC_FIELD_PREFIX);
	myPropertyPrefixField.setText(mySettings.PROPERTY_PREFIX);
	myStaticPropertyPrefixField.setText(mySettings.STATIC_PROPERTY_PREFIX);

	myFieldSuffixField.setText(mySettings.FIELD_SUFFIX);
	myStaticFieldSuffixField.setText(mySettings.STATIC_FIELD_SUFFIX);
	myPropertySuffixField.setText(mySettings.PROPERTY_SUFFIX);
	myStaticPropertySuffixField.setText(mySettings.STATIC_PROPERTY_SUFFIX);
	myUseLanguageKeywordsCheckBox.setSelected(mySettings.USE_LANGUAGE_DATA_TYPES);
	myCommenterForm.reset(mySettings.getContainer());
}
 
Example #19
Source File: CSharpChangeSignatureDialog.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
@RequiredUIAccess
protected String validateAndCommitData()
{
	String methodName = getMethodName();
	if(StringUtil.isEmpty(methodName) || CSharpNameSuggesterUtil.isKeyword(methodName))
	{
		return "Bad method name";
	}

	for(CSharpParameterInfo parameterInfo : getParameters())
	{
		String name = parameterInfo.getName();
		if(StringUtil.isEmpty(name) || CSharpNameSuggesterUtil.isKeyword(name))
		{
			return "Bad parameter name";
		}

		if(parameterInfo.getTypeRef() == null)
		{
			return "Parameter '" + name + "' have bad type";
		}
	}
	return null;
}
 
Example #20
Source File: CSharpTypedHandler.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
private static void autoPopupMemberLookup(Project project, final Editor editor)
{
	AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, new Condition<PsiFile>()
	{
		@Override
		@RequiredReadAction
		public boolean value(final PsiFile file)
		{
			int offset = editor.getCaretModel().getOffset();

			PsiElement lastElement = file.findElementAt(offset - 1);
			if(lastElement == null)
			{
				return false;
			}

			final PsiElement prevSibling = PsiTreeUtil.prevVisibleLeaf(lastElement);
			if(prevSibling == null || ".".equals(prevSibling.getText()))
			{
				return false;
			}
			PsiElement parent = prevSibling;
			do
			{
				parent = parent.getParent();
			}
			while(parent instanceof CSharpReferenceExpression);

			return true;
		}
	});
}
 
Example #21
Source File: CSharpTypedHandler.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
private static boolean handleDotAtPointerType(Editor editor, PsiFile file)
{
	if(DumbService.isDumb(file.getProject()))
	{
		return false;
	}
	int offset = editor.getCaretModel().getOffset();

	PsiElement lastElement = file.findElementAt(offset - 1);
	if(lastElement == null)
	{
		return false;
	}

	DotNetExpression expression = null;
	if(lastElement.getParent() instanceof DotNetExpression)
	{
		expression = (DotNetExpression) lastElement.getParent();
	}

	if(expression == null)
	{
		return false;
	}

	DotNetTypeRef typeRef = expression.toTypeRef(true);
	if(typeRef instanceof DotNetPointerTypeRef)
	{
		editor.getDocument().insertString(offset, "->");
		editor.getCaretModel().moveToOffset(offset + 2);
		editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
		return true;
	}
	return false;
}
 
Example #22
Source File: CSharpQualifiedElementPresentationProvider.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
@RequiredUIAccess
public String getLocationString()
{
	String presentableParentQName = myDeclaration.getPresentableParentQName();
	if(StringUtil.isEmpty(presentableParentQName))
	{
		return null;
	}
	return "(" + presentableParentQName + ")";
}
 
Example #23
Source File: XXXAccessorOwnerChooseMember.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredUIAccess
public String getText()
{
	StringBuilder builder = new StringBuilder();
	CSharpAccessModifier modifier = CSharpAccessModifier.findModifier(myDeclaration);
	boolean canGenerateCodeBlock = myCanGenerateBlock;
	if(modifier != CSharpAccessModifier.NONE && canGenerateCodeBlock)
	{
		builder.append(modifier.getPresentableText()).append(" ");
	}

	builder.append(getPresentationText());
	builder.append(" {\n");
	for(DotNetXAccessor accessor : myDeclaration.getAccessors())
	{
		DotNetXAccessor.Kind accessorKind = accessor.getAccessorKind();
		if(accessorKind == null)
		{
			continue;
		}
		builder.append(accessorKind.name().toLowerCase(Locale.US));
		if(myCanGenerateBlock)
		{
			builder.append(" {\n");
			myReturnAppender.consume(accessor, builder);
			builder.append("}");
		}
		else
		{
			builder.append(";");
		}
	}
	builder.append("}");
	return builder.toString();
}
 
Example #24
Source File: CastExpressionToTypeRef.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
@RequiredUIAccess
public String getText()
{
	DotNetExpression element = myExpressionPointer.getElement();
	if(element == null)
	{
		return "invalid";
	}
	return BundleBase.format("Cast to ''{0}''", CSharpTypeRefPresentationUtil.buildTextWithKeyword(myExpectedTypeRef, element));
}
 
Example #25
Source File: CS0017.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)
{
	DotNetModuleExtension extension = ModuleUtilCore.getExtension(element, DotNetModuleExtension.class);
	return extension != null && extension.getMainType() == null;
}
 
Example #26
Source File: MethodChooseMember.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredUIAccess
public String getText()
{
	StringBuilder builder = new StringBuilder();
	CSharpAccessModifier modifier = CSharpAccessModifier.findModifier(myDeclaration);
	if(modifier != CSharpAccessModifier.NONE && myCanGenerateBlock)
	{
		builder.append(modifier.getPresentableText()).append(" ");
	}

	myAdditionalModifiersAppender.consume(myDeclaration, builder);

	int flags = CSharpElementPresentationUtil.METHOD_WITH_RETURN_TYPE | CSharpElementPresentationUtil.METHOD_PARAMETER_NAME | CSharpElementPresentationUtil.NON_QUALIFIED_TYPE;
	String text = CSharpElementPresentationUtil.formatMethod(myDeclaration, flags);
	builder.append(text);

	if(myCanGenerateBlock)
	{
		builder.append(" {\n");
		myReturnAppender.consume(myDeclaration, builder);
		builder.append("}");
	}
	else
	{
		builder.append(";");
	}
	return builder.toString();
}
 
Example #27
Source File: CastNArgumentToTypeRefFix.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Nonnull
@Override
public String getText()
{
	DotNetExpression element = myExpressionPointer.getElement();
	if(element == null)
	{
		return "invalid";
	}
	return BundleBase.format("Cast ''{0}'' argument to ''{1}''", myParameterName, CSharpTypeRefPresentationUtil.buildTextWithKeyword
			(myExpectedTypeRef, element));
}
 
Example #28
Source File: AddXModifierFix.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)
{
	DotNetModifierListOwner owner = CSharpIntentionUtil.findOwner(element);
	return owner != null && !hasModifiers(owner) && isAllow(owner, myModifiers) && owner.isWritable();
}
 
Example #29
Source File: CSharpMemberChooseObject.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredUIAccess
public void renderTreeNode(SimpleColoredComponent component, JTree tree)
{
	component.setIcon(IconDescriptorUpdaters.getIcon(myDeclaration, Iconable.ICON_FLAG_VISIBILITY));
	component.append(getPresentationText());
}
 
Example #30
Source File: HidingOrOverridingElementCollector.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredUIAccess
public void navigate(MouseEvent mouseEvent, PsiElement element)
{
	DotNetVirtualImplementOwner virtualImplementOwner = CSharpLineMarkerUtil.findElementForLineMarker(element);
	if(virtualImplementOwner == null)
	{
		return;
	}

	Collection<DotNetVirtualImplementOwner> members = OverrideUtil.collectOverridingMembers(virtualImplementOwner);

	if(members.isEmpty())
	{
		return;
	}

	if(members.size() == 1)
	{
		DotNetVirtualImplementOwner firstItem = ContainerUtil.getFirstItem(members);
		if(firstItem instanceof Navigatable)
		{
			((Navigatable) firstItem).navigate(true);
		}
	}
	else
	{
		CSharpLineMarkerUtil.openTargets(members, mouseEvent, "Searching for overriding", CSharpLineMarkerUtil.BY_PARENT);
	}
}