本文整理汇总了Java中com.intellij.codeInsight.TailType类的典型用法代码示例。如果您正苦于以下问题:Java TailType类的具体用法?Java TailType怎么用?Java TailType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TailType类属于com.intellij.codeInsight包,在下文中一共展示了TailType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleInsert
import com.intellij.codeInsight.TailType; //导入依赖的package包/类
@Override
public void handleInsert(InsertionContext context) {
if (getObject() instanceof PsiVariable && context.getCompletionChar() == Lookup.REPLACE_SELECT_CHAR) {
context.commitDocument();
replaceMethodCallIfNeeded(context);
}
context.commitDocument();
myPosition = getPosition(context, this);
TailType tailType = computeTailType(context);
super.handleInsert(context);
if (tailType == TailType.COMMA) {
AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(context.getEditor(), null);
}
}
示例2: addCompletions
import com.intellij.codeInsight.TailType; //导入依赖的package包/类
@Override
protected void addCompletions(@NotNull final CompletionParameters parameters, final ProcessingContext processingContext, @NotNull final CompletionResultSet resultSet) {
final PsiElement context = parameters.getPosition();
final Pair<PsiClass, Integer> pair = getTypeParameterInfo(context);
if (pair == null) return;
PsiExpression expression = PsiTreeUtil.getContextOfType(context, PsiExpression.class, true);
if (expression != null) {
ExpectedTypeInfo[] types = ExpectedTypesProvider.getExpectedTypes(expression, true, false, false);
if (types.length > 0) {
for (ExpectedTypeInfo info : types) {
PsiType type = info.getType();
if (type instanceof PsiClassType && !type.equals(expression.getType())) {
fillExpectedTypeArgs(resultSet, context, pair.first, pair.second, ((PsiClassType)type).resolveGenerics(), mySmart ? info.getTailType() : TailType.NONE);
}
}
return;
}
}
if (mySmart) {
addInheritors(parameters, resultSet, pair.first, pair.second);
}
}
示例3: getExpectedTypes
import com.intellij.codeInsight.TailType; //导入依赖的package包/类
@NotNull
public static ExpectedTypeInfo[] getExpectedTypes(PsiElement position, boolean voidable) {
if (psiElement().withParent(psiElement(PsiReferenceExpression.class).withParent(PsiThrowStatement.class)).accepts(position)) {
final PsiElementFactory factory = JavaPsiFacade.getInstance(position.getProject()).getElementFactory();
final PsiClassType classType = factory
.createTypeByFQClassName(CommonClassNames.JAVA_LANG_RUNTIME_EXCEPTION, position.getResolveScope());
final List<ExpectedTypeInfo> result = new SmartList<ExpectedTypeInfo>();
result.add(new ExpectedTypeInfoImpl(classType, ExpectedTypeInfo.TYPE_OR_SUBTYPE, classType, TailType.SEMICOLON, null, ExpectedTypeInfoImpl.NULL));
final PsiMethod method = PsiTreeUtil.getContextOfType(position, PsiMethod.class, true);
if (method != null) {
for (final PsiClassType type : method.getThrowsList().getReferencedTypes()) {
result.add(new ExpectedTypeInfoImpl(type, ExpectedTypeInfo.TYPE_OR_SUBTYPE, type, TailType.SEMICOLON, null, ExpectedTypeInfoImpl.NULL));
}
}
return result.toArray(new ExpectedTypeInfo[result.size()]);
}
PsiExpression expression = PsiTreeUtil.getContextOfType(position, PsiExpression.class, true);
if (expression == null) return ExpectedTypeInfo.EMPTY_ARRAY;
return ExpectedTypesProvider.getExpectedTypes(expression, true, voidable, false);
}
示例4: getReturnTail
import com.intellij.codeInsight.TailType; //导入依赖的package包/类
private static TailType getReturnTail(PsiElement position) {
PsiElement scope = position;
while(true){
if (scope instanceof PsiFile || scope instanceof PsiClassInitializer){
return TailType.NONE;
}
if (scope instanceof PsiMethod){
final PsiMethod method = (PsiMethod)scope;
if(method.isConstructor() || PsiType.VOID.equals(method.getReturnType())) {
return TailType.SEMICOLON;
}
return TailType.HUMBLE_SPACE_BEFORE_WORD;
}
if (scope instanceof PsiLambdaExpression) {
final PsiType returnType = LambdaUtil.getFunctionalInterfaceReturnType(((PsiLambdaExpression)scope));
if (PsiType.VOID.equals(returnType)) {
return TailType.SEMICOLON;
}
return TailType.HUMBLE_SPACE_BEFORE_WORD;
}
scope = scope.getParent();
}
}
示例5: addFinal
import com.intellij.codeInsight.TailType; //导入依赖的package包/类
private static void addFinal(Consumer<LookupElement> result, PsiElement position, @Nullable PsiElement prevLeaf) {
PsiStatement statement = PsiTreeUtil.getParentOfType(position, PsiExpressionStatement.class);
if (statement == null) {
statement = PsiTreeUtil.getParentOfType(position, PsiDeclarationStatement.class);
}
if (statement != null && statement.getTextRange().getStartOffset() == position.getTextRange().getStartOffset()) {
if (!psiElement().withSuperParent(2, PsiSwitchStatement.class).afterLeaf("{").accepts(statement)) {
PsiTryStatement tryStatement = PsiTreeUtil.getParentOfType(prevLeaf, PsiTryStatement.class);
if (tryStatement == null || tryStatement.getCatchSections().length > 0 || tryStatement.getFinallyBlock() != null || tryStatement.getResourceList() != null) {
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.FINAL), TailType.HUMBLE_SPACE_BEFORE_WORD));
return;
}
}
}
if ((isInsideParameterList(position) || isAtResourceVariableStart(position) || isAtCatchVariableStart(position)) &&
!psiElement().afterLeaf(PsiKeyword.FINAL).accepts(position) &&
!AFTER_DOT.accepts(position)) {
result.consume(TailTypeDecorator.withTail(createKeyword(position, PsiKeyword.FINAL), TailType.HUMBLE_SPACE_BEFORE_WORD));
}
}
示例6: addExpressionKeywords
import com.intellij.codeInsight.TailType; //导入依赖的package包/类
private static void addExpressionKeywords(CompletionParameters parameters, Consumer<LookupElement> result, PsiElement position, @Nullable PsiElement prevLeaf) {
if (psiElement(JavaTokenType.DOUBLE_COLON).accepts(prevLeaf)) {
PsiMethodReferenceExpression parent = PsiTreeUtil.getParentOfType(parameters.getPosition(), PsiMethodReferenceExpression.class);
TailType tail = parent != null && !LambdaHighlightingUtil.insertSemicolon(parent.getParent()) ? TailType.SEMICOLON : TailType.NONE;
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.NEW), tail));
return;
}
if (isExpressionPosition(position)) {
if (PsiTreeUtil.getParentOfType(position, PsiAnnotation.class) == null) {
result.consume(TailTypeDecorator.withTail(createKeyword(position, PsiKeyword.NEW), TailType.INSERT_SPACE));
result.consume(createKeyword(position, PsiKeyword.NULL));
}
if (mayExpectBoolean(parameters)) {
result.consume(createKeyword(position, PsiKeyword.TRUE));
result.consume(createKeyword(position, PsiKeyword.FALSE));
}
}
}
示例7: addFileHeaderKeywords
import com.intellij.codeInsight.TailType; //导入依赖的package包/类
private static void addFileHeaderKeywords(Consumer<LookupElement> result, PsiElement position, @Nullable PsiElement prevLeaf) {
PsiFile file = position.getContainingFile();
if (!(file instanceof PsiExpressionCodeFragment) &&
!(file instanceof PsiJavaCodeReferenceCodeFragment) &&
!(file instanceof PsiTypeCodeFragment)) {
if (prevLeaf == null) {
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.PACKAGE), TailType.HUMBLE_SPACE_BEFORE_WORD));
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.IMPORT), TailType.HUMBLE_SPACE_BEFORE_WORD));
}
else if (END_OF_BLOCK.getValue().isAcceptable(position, position) && PsiTreeUtil.getParentOfType(position, PsiMember.class) == null) {
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.IMPORT), TailType.HUMBLE_SPACE_BEFORE_WORD));
}
}
if (PsiUtil.isLanguageLevel5OrHigher(position) && prevLeaf != null && prevLeaf.textMatches(PsiKeyword.IMPORT)) {
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.STATIC), TailType.HUMBLE_SPACE_BEFORE_WORD));
}
}
示例8: addClassKeywords
import com.intellij.codeInsight.TailType; //导入依赖的package包/类
private static void addClassKeywords(Consumer<LookupElement> result, PsiElement position, @Nullable PsiElement prevLeaf) {
if (isSuitableForClass(position)) {
for (String s : ModifierChooser.getKeywords(position)) {
result.consume(new OverrideableSpace(createKeyword(position, s), TailType.HUMBLE_SPACE_BEFORE_WORD));
}
if (PsiUtil.isLanguageLevel8OrHigher(position)) {
PsiClass containingClass = PsiTreeUtil.getParentOfType(position, PsiClass.class);
if (containingClass != null && containingClass.isInterface()) {
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.DEFAULT), TailType.HUMBLE_SPACE_BEFORE_WORD));
}
}
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.CLASS), TailType.HUMBLE_SPACE_BEFORE_WORD));
if (PsiTreeUtil.getParentOfType(position, PsiCodeBlock.class, true, PsiMember.class) == null) {
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.INTERFACE), TailType.HUMBLE_SPACE_BEFORE_WORD));
if (PsiUtil.isLanguageLevel5OrHigher(position)) {
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.ENUM), TailType.INSERT_SPACE));
}
}
}
if (psiElement().withText("@").andNot(psiElement().inside(PsiParameterList.class)).andNot(psiElement().inside(psiNameValuePair()))
.accepts(prevLeaf)) {
result.consume(new OverrideableSpace(createKeyword(position, PsiKeyword.INTERFACE), TailType.HUMBLE_SPACE_BEFORE_WORD));
}
}
示例9: addBreakContinue
import com.intellij.codeInsight.TailType; //导入依赖的package包/类
private static void addBreakContinue(Consumer<LookupElement> result, PsiElement position) {
PsiLoopStatement loop = PsiTreeUtil.getParentOfType(position, PsiLoopStatement.class);
LookupElement br = createKeyword(position, PsiKeyword.BREAK);
LookupElement cont = createKeyword(position, PsiKeyword.CONTINUE);
TailType tailType;
if (psiElement().insideSequence(true, psiElement(PsiLabeledStatement.class),
or(psiElement(PsiFile.class), psiElement(PsiMethod.class),
psiElement(PsiClassInitializer.class))).accepts(position)) {
tailType = TailType.HUMBLE_SPACE_BEFORE_WORD;
}
else {
tailType = TailType.SEMICOLON;
}
br = TailTypeDecorator.withTail(br, tailType);
cont = TailTypeDecorator.withTail(cont, tailType);
if (loop != null && PsiTreeUtil.isAncestor(loop.getBody(), position, false)) {
result.consume(br);
result.consume(cont);
}
if (psiElement().inside(PsiSwitchStatement.class).accepts(position)) {
result.consume(br);
}
}
示例10: addConstantsFromReferencedClassesInSwitch
import com.intellij.codeInsight.TailType; //导入依赖的package包/类
private void addConstantsFromReferencedClassesInSwitch(final Consumer<LookupElement> results) {
final Set<PsiField> fields = ReferenceExpressionCompletionContributor.findConstantsUsedInSwitch(myPlace);
final Set<PsiClass> classes = new HashSet<PsiClass>();
for (PsiField field : fields) {
ContainerUtil.addIfNotNull(classes, field.getContainingClass());
}
for (PsiClass aClass : classes) {
processMembers(new Consumer<LookupElement>() {
@Override
public void consume(LookupElement element) {
//noinspection SuspiciousMethodCalls
if (!fields.contains(element.getObject())) {
results.consume(TailTypeDecorator.withTail(element, TailType.CASE_COLON));
}
}
}, aClass, true, false);
}
}
示例11: addLookupItem
import com.intellij.codeInsight.TailType; //导入依赖的package包/类
protected void addLookupItem(Set<LookupElement> set, TailType tailType, @NotNull 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);
}
示例12: handleInsert
import com.intellij.codeInsight.TailType; //导入依赖的package包/类
@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);
}
}
示例13: handleCompletionChar
import com.intellij.codeInsight.TailType; //导入依赖的package包/类
@NotNull
public static TailType handleCompletionChar(@NotNull final Editor editor, @NotNull 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;
}
示例14: addPreColonStatements
import com.intellij.codeInsight.TailType; //导入依赖的package包/类
private void addPreColonStatements() {
extend(
CompletionType.BASIC,
psiElement()
.withLanguage(PythonLanguage.getInstance())
.and(FIRST_ON_LINE)
//.andNot(RIGHT_AFTER_COLON)
.andNot(IN_IMPORT_STMT)
.andNot(IN_PARAM_LIST)
.andNot(IN_ARG_LIST)
.andNot(BEFORE_COND)
.andNot(AFTER_QUALIFIER).andNot(IN_STRING_LITERAL)
,
new CompletionProvider<CompletionParameters>() {
protected void addCompletions(
@NotNull final CompletionParameters parameters, final ProcessingContext context, @NotNull final CompletionResultSet result
) {
putKeywords(result, TailType.NONE, PyNames.DEF, PyNames.CLASS, PyNames.FOR, PyNames.IF, PyNames.WHILE, PyNames.WITH);
putKeywords(result, TailType.CASE_COLON, PyNames.TRY);
}
}
);
}
示例15: addStatements
import com.intellij.codeInsight.TailType; //导入依赖的package包/类
private void addStatements() {
PsiElementPattern.Capture<PsiElement> inStatement = psiElement()
.withLanguage(PythonLanguage.getInstance())
.and(IN_BEGIN_STMT)
.andNot(IN_IMPORT_STMT)
.andNot(IN_PARAM_LIST)
.andNot(IN_ARG_LIST)
.andNot(BEFORE_COND)
.andNot(AFTER_QUALIFIER);
extend(
CompletionType.BASIC,
inStatement,
new CompletionProvider<CompletionParameters>() {
protected void addCompletions(
@NotNull final CompletionParameters parameters, final ProcessingContext context, @NotNull final CompletionResultSet result
) {
putKeywords(result, TailType.SPACE, PyNames.ASSERT, PyNames.DEL, PyNames.EXEC, PyNames.FROM, PyNames.IMPORT, PyNames.RAISE);
putKeywords(result, TailType.NONE, PyNames.PASS);
}
}
);
extend(CompletionType.BASIC, inStatement.andNot(PY3K), new PyKeywordCompletionProvider(TailType.SPACE, PyNames.PRINT));
}