com.intellij.codeInsight.TailType Java Examples

The following examples show how to use com.intellij.codeInsight.TailType. 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: LookupItem.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static TailType handleCompletionChar(@Nonnull final Editor editor, @Nonnull final LookupElement lookupElement, final char completionChar) {
  final TailType type = getDefaultTailType(completionChar);
  if (type != null) {
    return type;
  }

  if (lookupElement instanceof LookupItem) {
    final LookupItem<?> item = (LookupItem)lookupElement;
    final TailType attr = item.getAttribute(TAIL_TYPE_ATTR);
    if (attr != null) {
      return attr;
    }
  }
  return TailType.NONE;
}
 
Example #2
Source File: TailTypeDecorator.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void handleInsert(InsertionContext context) {
  final LookupElement delegate = getDelegate();
  final TailType tailType = computeTailType(context);

  final LookupItem lookupItem = delegate.as(LookupItem.CLASS_CONDITION_KEY);
  if (lookupItem != null && tailType != null) {
    lookupItem.setTailType(TailType.UNKNOWN);
  }
  delegate.handleInsert(context);
  if (tailType != null && tailType.isApplicable(context)) {
    PostprocessReformattingAspect.getInstance(context.getProject()).doPostponedFormatting();
    int tailOffset = context.getTailOffset();
    if (tailOffset < 0) {
      throw new AssertionError("tailOffset < 0: delegate=" + getDelegate() + "; this=" + this + "; tail=" + tailType);
    }
    tailType.processTail(context.getEditor(), tailOffset);
  }
}
 
Example #3
Source File: CompletionData.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void addLookupItem(Set<LookupElement> set, TailType tailType, @Nonnull Object completion, final CompletionVariant variant) {
  LookupElement ret = objectToLookupItem(completion);
  if (ret == null) return;
  if (!(ret instanceof LookupItem)) {
    set.add(ret);
    return;
  }

  LookupItem item = (LookupItem)ret;

  final InsertHandler insertHandler = variant.getInsertHandler();
  if(insertHandler != null && item.getInsertHandler() == null) {
    item.setInsertHandler(insertHandler);
    item.setTailType(TailType.UNKNOWN);
  }
  else if (tailType != TailType.NONE) {
    item.setTailType(tailType);
  }
  final Map<Object, Object> itemProperties = variant.getItemProperties();
  for (final Object key : itemProperties.keySet()) {
    item.setAttribute(key, itemProperties.get(key));
  }

  set.add(ret);
}
 
Example #4
Source File: SpaceInsertHandler.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public void handleInsert(InsertionContext context, LookupElement item)
{
	if(context.getCompletionChar() != ' ')
	{
		int tailOffset = context.getTailOffset();
		TailType.insertChar(context.getEditor(), tailOffset, ' ');
		context.getEditor().getCaretModel().moveToOffset(tailOffset + 1);
	}
}
 
Example #5
Source File: CSharpStatementCompletionContributor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredReadAction
public void handleInsert(InsertionContext insertionContext, LookupElement item)
{
	Editor editor = insertionContext.getEditor();
	int offset = editor.getCaretModel().getOffset();
	boolean isVoidReturnType = DotNetTypeRefUtil.isVmQNameEqual(myPseudoMethod.getReturnTypeRef(), myPseudoMethod, DotNetTypes.System.Void);

	if(isVoidReturnType)
	{
		if(insertionContext.getCompletionChar() == '\n')
		{
			TailType.insertChar(editor, offset, ';');
			insertionContext.getEditor().getCaretModel().moveToOffset(offset + 1);
		}
	}
	else
	{
		if(insertionContext.getCompletionChar() == '\n')
		{
			TailType.insertChar(editor, offset, ' ');

			insertionContext.getEditor().getCaretModel().moveToOffset(offset + 1);
		}

		AutoPopupController.getInstance(editor.getProject()).autoPopupMemberLookup(editor, null);
	}
}
 
Example #6
Source File: LookupItem.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static TailType getDefaultTailType(final char completionChar) {
  switch(completionChar){
    case '.': return new CharTailType('.', false);
    case ',': return TailType.COMMA;
    case ';': return TailType.SEMICOLON;
    case '=': return TailType.EQ;
    case ' ': return TailType.SPACE;
    case ':': return TailType.CASE_COLON; //?
  }
  return null;
}
 
Example #7
Source File: LookupItem.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void handleInsert(final InsertionContext context) {
  final InsertHandler<? extends LookupElement> handler = getInsertHandler();
  if (handler != null) {
    //noinspection unchecked
    ((InsertHandler)handler).handleInsert(context, this);
  }
  if (getTailType() != TailType.UNKNOWN && myInsertHandler == null) {
    context.setAddCompletionChar(false);
    final TailType type = handleCompletionChar(context.getEditor(), this, context.getCompletionChar());
    type.processTail(context.getEditor(), context.getTailOffset());
  }
}
 
Example #8
Source File: TailTypeDecorator.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static <T extends LookupElement> TailTypeDecorator<T> withTail(T element, final TailType type) {
  return new TailTypeDecorator<T>(element) {
    @Override
    protected TailType computeTailType(InsertionContext context) {
      return type;
    }
  };
}
 
Example #9
Source File: CompletionData.java    From consulo with Apache License 2.0 5 votes vote down vote up
void addKeywords(Set<LookupElement> set, CompletionVariant variant, Object comp, TailType tailType) {
  if (!(comp instanceof String)) return;

  for (final LookupElement item : set) {
    if (item.getObject().toString().equals(comp)) {
      return;
    }
  }
  addLookupItem(set, tailType, comp, variant);
}
 
Example #10
Source File: CompletionData.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static LookupElement objectToLookupItem(final @Nonnull Object object) {
  if (object instanceof LookupElement) return (LookupElement)object;

  String s = null;
  TailType tailType = TailType.NONE;
  if (object instanceof PsiElement){
    s = PsiUtilCore.getName((PsiElement)object);
  }
  else if (object instanceof PsiMetaData) {
    s = ((PsiMetaData)object).getName();
  }
  else if (object instanceof String) {
    s = (String)object;
  }
  else if (object instanceof Template) {
    s = ((Template) object).getKey();
  }
  else if (object instanceof PresentableLookupValue) {
    s = ((PresentableLookupValue)object).getPresentation();
  }
  if (s == null) {
    throw new AssertionError("Null string for object: " + object + " of class " + object.getClass());
  }

  LookupItem item = new LookupItem(object, s);

  if (object instanceof LookupValueWithUIHint && ((LookupValueWithUIHint) object).isBold()) {
    item.setBold();
  }
  item.setAttribute(LookupItem.TAIL_TYPE_ATTR, tailType);
  return item;
}
 
Example #11
Source File: CompletionData.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
void addReferenceCompletions(PsiReference reference, PsiElement position, Set<LookupElement> set, final PsiFile file,
                             final CompletionData completionData) {
  completeReference(reference, position, set, TailType.NONE, TrueFilter.INSTANCE, this);
}
 
Example #12
Source File: LookupItem.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public LookupItem<T> setTailType(@Nonnull TailType type) {
  setAttribute(TAIL_TYPE_ATTR, type);
  return this;
}
 
Example #13
Source File: LookupItem.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public TailType getTailType(){
  final TailType tailType = getAttribute(TAIL_TYPE_ATTR);
  return tailType != null ? tailType : TailType.UNKNOWN;
}
 
Example #14
Source File: TailTypeDecorator.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
protected abstract TailType computeTailType(InsertionContext context);
 
Example #15
Source File: CSharpExpressionCompletionContributor.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@RequiredReadAction
private static LookupElement buildForMethodReference(final CSharpMethodDeclaration methodDeclaration, CSharpTypeDeclaration contextType, final CSharpReferenceExpressionEx expression)
{
	LookupElementBuilder builder = LookupElementBuilder.create(methodDeclaration.getName());
	builder = builder.withIcon((Image) AllIcons.Nodes.MethodReference);

	final DotNetTypeRef[] parameterTypes = methodDeclaration.getParameterTypeRefs();

	String genericText = DotNetElementPresentationUtil.formatGenericParameters(methodDeclaration);

	String parameterText = genericText + "(" + StringUtil.join(parameterTypes, new Function<DotNetTypeRef, String>()
	{
		@Override
		@RequiredReadAction
		public String fun(DotNetTypeRef parameter)
		{
			return CSharpTypeRefPresentationUtil.buildShortText(parameter, methodDeclaration);
		}
	}, ", ") + ")";

	if(CSharpMethodImplUtil.isExtensionWrapper(methodDeclaration))
	{
		builder = builder.withItemTextUnderlined(true);
	}
	builder = builder.withTypeText(CSharpTypeRefPresentationUtil.buildShortText(methodDeclaration.getReturnTypeRef(), methodDeclaration), true);
	builder = builder.withTailText(parameterText, true);
	if(DotNetAttributeUtil.hasAttribute(methodDeclaration, DotNetTypes.System.ObsoleteAttribute))
	{
		builder = builder.withStrikeoutness(true);
	}
	builder = builder.withInsertHandler(new InsertHandler<LookupElement>()
	{
		@Override
		@RequiredWriteAction
		public void handleInsert(InsertionContext context, LookupElement item)
		{
			char completionChar = context.getCompletionChar();
			switch(completionChar)
			{
				case ',':
					if(expression != null && expression.getParent() instanceof CSharpCallArgument)
					{
						context.setAddCompletionChar(false);
						TailType.COMMA.processTail(context.getEditor(), context.getTailOffset());
					}
					break;
			}
		}
	});

	if(contextType != null && contextType.isEquivalentTo(methodDeclaration.getParent()))
	{
		builder = builder.bold();
	}

	CSharpCompletionSorting.force(builder, CSharpCompletionSorting.KindSorter.Type.member);
	return builder;
}
 
Example #16
Source File: CompletionVariant.java    From consulo with Apache License 2.0 4 votes vote down vote up
public CompletionVariantItem(Object completion, TailType tailtype){
  myCompletion = completion;
  myTailType = tailtype;
}
 
Example #17
Source File: CompletionVariant.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void addCompletion(Object completion, TailType tail){
  myCompletionsList.add(new CompletionVariantItem(completion, tail));
}
 
Example #18
Source File: CompletionVariant.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void addCompletion(@NonNls String keyword, TailType tailType){
  addCompletion((Object)keyword, tailType);
}
 
Example #19
Source File: CompletionVariant.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void addCompletionFilter(ElementFilter filter){
  addCompletionFilter(filter, TailType.NONE);
}
 
Example #20
Source File: CompletionVariant.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void addCompletionFilter(ElementFilter filter, TailType tailType){
  addCompletion(filter, tailType);
}
 
Example #21
Source File: MutableLookupElement.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public abstract MutableLookupElement<T> setTailType(@Nonnull TailType type);
 
Example #22
Source File: CSharpTailInsertHandlerWithChar.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
public CSharpTailInsertHandlerWithChar(TailType tailType, char enterChar)
{
	myTailType = tailType;
	myEnterChar = enterChar;
}
 
Example #23
Source File: CSharpTailInsertHandler.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
public CSharpTailInsertHandler(TailType tailType)
{
	myTailType = tailType;
}
 
Example #24
Source File: CSharpParenthesesWithSemicolonInsertHandler.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Override
@RequiredUIAccess
public void handleInsert(InsertionContext context, LookupElement item)
{
	boolean isMethodLike = myDeclaration instanceof DotNetLikeMethodDeclaration;
	if(isMethodLike)
	{
		new CSharpParenthesesInsertHandler((DotNetLikeMethodDeclaration) myDeclaration).handleInsert(context, item);
	}

	if(context.getCompletionChar() != '\n' || context.getFile() instanceof CSharpCodeFragment)
	{
		return;
	}

	// for void method we always insert semicolon
	if(isMethodLike && !(myDeclaration instanceof CSharpConstructorDeclaration) && DotNetTypeRefUtil.isVmQNameEqual(((DotNetLikeMethodDeclaration) myDeclaration).getReturnTypeRef(),
			myDeclaration, DotNetTypes.System.Void))
	{
		if(TailType.SEMICOLON.isApplicable(context))
		{
			TailType.SEMICOLON.processTail(context.getEditor(), context.getTailOffset());
		}
	}
	/*else
	{
		context.commitDocument();
		PsiElement elementAt = context.getFile().findElementAt(context.getStartOffset());
		PsiElement parent = PsiTreeUtil.getParentOfType(elementAt, CSharpMethodCallExpressionImpl.class);
		if(parent != null && parent.getNextSibling() instanceof PsiErrorElement)
		{
			TailType.SEMICOLON.processTail(context.getEditor(), context.getTailOffset());
		}

		parent = PsiTreeUtil.getParentOfType(elementAt, CSharpLocalVariable.class);
		if(parent != null && parent.getNextSibling() instanceof PsiErrorElement)
		{
			TailType.SEMICOLON.processTail(context.getEditor(), context.getTailOffset());
		}
	}*/
}