当前位置: 首页>>代码示例>>Java>>正文


Java ExpectedTypesProvider.getExpectedTypes方法代码示例

本文整理汇总了Java中com.intellij.codeInsight.ExpectedTypesProvider.getExpectedTypes方法的典型用法代码示例。如果您正苦于以下问题:Java ExpectedTypesProvider.getExpectedTypes方法的具体用法?Java ExpectedTypesProvider.getExpectedTypes怎么用?Java ExpectedTypesProvider.getExpectedTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.codeInsight.ExpectedTypesProvider的用法示例。


在下文中一共展示了ExpectedTypesProvider.getExpectedTypes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addCompletions

import com.intellij.codeInsight.ExpectedTypesProvider; //导入方法依赖的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);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:TypeArgumentCompletionProvider.java

示例2: shouldInsertParentheses

import com.intellij.codeInsight.ExpectedTypesProvider; //导入方法依赖的package包/类
private static boolean shouldInsertParentheses(PsiElement position) {
  final PsiJavaCodeReferenceElement ref = PsiTreeUtil.getParentOfType(position, PsiJavaCodeReferenceElement.class);
  if (ref == null) {
    return false;
  }

  final PsiReferenceParameterList parameterList = ref.getParameterList();
  if (parameterList != null && parameterList.getTextLength() > 0) {
    return false;
  }

  final PsiElement prevElement = FilterPositionUtil.searchNonSpaceNonCommentBack(ref);
  if (prevElement != null && prevElement.getParent() instanceof PsiNewExpression) {
    for (ExpectedTypeInfo info : ExpectedTypesProvider.getExpectedTypes((PsiExpression)prevElement.getParent(), true)) {
      if (info.getType() instanceof PsiArrayType) {
        return false;
      }
    }

    return true;
  }

  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:JavaClassNameInsertHandler.java

示例3: getExpectedTypes

import com.intellij.codeInsight.ExpectedTypesProvider; //导入方法依赖的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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:JavaSmartCompletionContributor.java

示例4: suggestByExpectedType

import com.intellij.codeInsight.ExpectedTypesProvider; //导入方法依赖的package包/类
private boolean suggestByExpectedType(Consumer<LookupElement> result, PsiElement context, PsiTypeParameterListOwner paramOwner, int index)
{
	PsiExpression expression = PsiTreeUtil.getContextOfType(context, PsiExpression.class, true);
	ExpectedTypeInfo[] types = ExpectedTypesProvider.getExpectedTypes(expression, true, false, false);
	if(expression == null || types.length == 0)
	{
		return false;
	}

	for(ExpectedTypeInfo info : types)
	{
		PsiType type = info.getType();
		if(type instanceof PsiClassType && !type.equals(expression.getType()))
		{
			JBIterable<PsiTypeParameter> remainingParams = JBIterable.of(paramOwner.getTypeParameters()).skip(index);
			List<PsiType> expectedArgs = getExpectedTypeArgs(context, paramOwner, remainingParams, (PsiClassType) type);
			createLookupItems(result, context, info, expectedArgs, paramOwner);
		}
	}
	return true;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:22,代码来源:TypeArgumentCompletionProvider.java

示例5: isRawTypeExpected

import com.intellij.codeInsight.ExpectedTypesProvider; //导入方法依赖的package包/类
static boolean isRawTypeExpected(InsertionContext context, PsiTypeLookupItem delegate)
{
	PsiNewExpression newExpr = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiNewExpression.class, false);
	if(newExpr != null)
	{
		for(ExpectedTypeInfo info : ExpectedTypesProvider.getExpectedTypes(newExpr, true))
		{
			PsiType expected = info.getDefaultType();
			if(expected.isAssignableFrom(delegate.getType()))
			{
				if(expected instanceof PsiClassType && ((PsiClassType) expected).isRaw())
				{
					return true;
				}
			}
		}
	}
	return false;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:20,代码来源:ConstructorInsertHandler.java

示例6: isRawTypeExpected

import com.intellij.codeInsight.ExpectedTypesProvider; //导入方法依赖的package包/类
static boolean isRawTypeExpected(InsertionContext context, PsiTypeLookupItem delegate) {
  PsiNewExpression newExpr =
    PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiNewExpression.class, false);
  if (newExpr != null) {
    for (ExpectedTypeInfo info : ExpectedTypesProvider.getExpectedTypes(newExpr, true)) {
      PsiType expected = info.getDefaultType();
      if (expected.isAssignableFrom(delegate.getType())) {
        if (expected instanceof PsiClassType && ((PsiClassType)expected).isRaw()) {
          return true;
        }
      }
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:ConstructorInsertHandler.java

示例7: shouldShowExplicitLambdaType

import com.intellij.codeInsight.ExpectedTypesProvider; //导入方法依赖的package包/类
@Override
protected boolean shouldShowExplicitLambdaType(PsiAnonymousClass anonymousClass, PsiNewExpression expression) {
  PsiElement parent = expression.getParent();
  if (parent instanceof PsiReferenceExpression || parent instanceof PsiAssignmentExpression) {
    return true;
  }

  ExpectedTypeInfo[] types = ExpectedTypesProvider.getExpectedTypes(expression, false);
  return types.length != 1 || !types[0].getType().equals(anonymousClass.getBaseClassType());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:JavaFoldingBuilder.java

示例8: getDefaultExpectedType

import com.intellij.codeInsight.ExpectedTypesProvider; //导入方法依赖的package包/类
@Override
public PsiType getDefaultExpectedType(PsiCallExpression methodCall) {
  ExpectedTypeInfo[] expectedTypes = ExpectedTypesProvider.getExpectedTypes(methodCall, true);
  if (expectedTypes.length > 0) {
    return expectedTypes[0].getType();
  }
  return PsiType.NULL;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:CompletionParameterTypeInferencePolicy.java

示例9: getTypesForMain

import com.intellij.codeInsight.ExpectedTypesProvider; //导入方法依赖的package包/类
private PsiType[] getTypesForMain() {
  final ExpectedTypeInfo[] expectedTypes = ExpectedTypesProvider.getExpectedTypes(myMainOccurrence, false, myOccurrenceClassProvider, false);
  final ArrayList<PsiType> allowedTypes = new ArrayList<PsiType>();
  RefactoringHierarchyUtil.processSuperTypes(getDefaultType(), new RefactoringHierarchyUtil.SuperTypeVisitor() {
    @Override
    public void visitType(PsiType aType) {
      checkIfAllowed(aType);
    }

    @Override
    public void visitClass(PsiClass aClass) {
      checkIfAllowed(myFactory.createType(aClass));
    }

    private void checkIfAllowed(PsiType type) {
      if (expectedTypes.length > 0) {
        final ExpectedTypeInfo typeInfo = ExpectedTypesProvider.createInfo(type, ExpectedTypeInfo.TYPE_STRICTLY, type, TailType.NONE);
        for (ExpectedTypeInfo expectedType : expectedTypes) {
          if (expectedType.intersect(typeInfo).length != 0) {
            allowedTypes.add(type);
            break;
          }
        }
      }
      else {
        allowedTypes.add(type);
      }
    }
  });

  collectAllSameShapedTypes(expectedTypes, allowedTypes);

  ArrayList<PsiType> result = normalizeTypeList(allowedTypes);
  return result.toArray(PsiType.createArray(result.size()));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:TypeSelectorManagerImpl.java

示例10: isRawTypeExpected

import com.intellij.codeInsight.ExpectedTypesProvider; //导入方法依赖的package包/类
static boolean isRawTypeExpected(InsertionContext context, PsiTypeLookupItem delegate) {
  PsiNewExpression newExpr =
    PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiNewExpression.class, false);
  if (newExpr != null) {
    for (ExpectedTypeInfo info : ExpectedTypesProvider.getExpectedTypes(newExpr, true)) {
      PsiType expected = info.getDefaultType();
      if (expected.isAssignableFrom(delegate.getPsiType())) {
        if (expected instanceof PsiClassType && ((PsiClassType)expected).isRaw()) {
          return true;
        }
      }
    }
  }
  return false;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:16,代码来源:ConstructorInsertHandler.java

示例11: getTypesForMain

import com.intellij.codeInsight.ExpectedTypesProvider; //导入方法依赖的package包/类
private PsiType[] getTypesForMain() {
  final ExpectedTypeInfo[] expectedTypes = ExpectedTypesProvider.getExpectedTypes(myMainOccurrence, false, myOccurrenceClassProvider, false);
  final ArrayList<PsiType> allowedTypes = new ArrayList<PsiType>();
  RefactoringHierarchyUtil.processSuperTypes(getDefaultType(), new RefactoringHierarchyUtil.SuperTypeVisitor() {
    public void visitType(PsiType aType) {
      checkIfAllowed(aType);
    }

    public void visitClass(PsiClass aClass) {
      checkIfAllowed(myFactory.createType(aClass));
    }

    private void checkIfAllowed(PsiType type) {
      if (expectedTypes.length > 0) {
        final ExpectedTypeInfo typeInfo = ExpectedTypesProvider.createInfo(type, ExpectedTypeInfo.TYPE_STRICTLY, type, TailType.NONE);
        for (ExpectedTypeInfo expectedType : expectedTypes) {
          if (expectedType.intersect(typeInfo).length != 0) {
            allowedTypes.add(type);
            break;
          }
        }
      }
      else {
        allowedTypes.add(type);
      }
    }
  });

  ArrayList<PsiType> result = normalizeTypeList(allowedTypes);
  return result.toArray(new PsiType[result.size()]);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:32,代码来源:TypeSelectorManagerImpl.java

示例12: getExpectedTypes

import com.intellij.codeInsight.ExpectedTypesProvider; //导入方法依赖的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<>();
		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);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:29,代码来源:JavaSmartCompletionContributor.java

示例13: getExpectedTypeInternal

import com.intellij.codeInsight.ExpectedTypesProvider; //导入方法依赖的package包/类
private PsiType getExpectedTypeInternal()
{
	if(!(myPlace instanceof PsiExpression))
	{
		return null;
	}
	ExpectedTypeInfo[] types = ExpectedTypesProvider.getExpectedTypes((PsiExpression) myPlace, false);
	return types.length > 0 ? types[0].getType() : null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:10,代码来源:StaticMembersProcessor.java

示例14: shouldShowExplicitLambdaType

import com.intellij.codeInsight.ExpectedTypesProvider; //导入方法依赖的package包/类
@Override
protected boolean shouldShowExplicitLambdaType(@NotNull PsiAnonymousClass anonymousClass, @NotNull PsiNewExpression expression)
{
	PsiElement parent = expression.getParent();
	if(parent instanceof PsiReferenceExpression || parent instanceof PsiAssignmentExpression)
	{
		return true;
	}

	ExpectedTypeInfo[] types = ExpectedTypesProvider.getExpectedTypes(expression, false);
	return types.length != 1 || !types[0].getType().equals(anonymousClass.getBaseClassType());
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:13,代码来源:JavaFoldingBuilder.java

示例15: getDefaultExpectedType

import com.intellij.codeInsight.ExpectedTypesProvider; //导入方法依赖的package包/类
@Override
public PsiType getDefaultExpectedType(PsiCallExpression methodCall)
{
	ExpectedTypeInfo[] expectedTypes = ExpectedTypesProvider.getExpectedTypes(methodCall, true);
	if(expectedTypes.length > 0)
	{
		return expectedTypes[0].getType();
	}
	return PsiType.NULL;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:11,代码来源:CompletionParameterTypeInferencePolicy.java


注:本文中的com.intellij.codeInsight.ExpectedTypesProvider.getExpectedTypes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。