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


Java PsiPolyExpressionUtil类代码示例

本文整理汇总了Java中com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil的典型用法代码示例。如果您正苦于以下问题:Java PsiPolyExpressionUtil类的具体用法?Java PsiPolyExpressionUtil怎么用?Java PsiPolyExpressionUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PsiPolyExpressionUtil类属于com.intellij.psi.impl.source.resolve.graphInference包,在下文中一共展示了PsiPolyExpressionUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitConditionalExpression

import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil; //导入依赖的package包/类
@Override
public void visitConditionalExpression(PsiConditionalExpression expression) {
  super.visitConditionalExpression(expression);
  if (myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8) && PsiPolyExpressionUtil.isPolyExpression(expression)) {
    final PsiExpression thenExpression = expression.getThenExpression();
    final PsiExpression elseExpression = expression.getElseExpression();
    if (thenExpression != null && elseExpression != null) {
      final PsiType conditionalType = expression.getType();
      if (conditionalType != null) {
        final PsiExpression[] sides = {thenExpression, elseExpression};
        for (PsiExpression side : sides) {
          final PsiType sideType = side.getType();
          if (sideType != null && !TypeConversionUtil.isAssignable(conditionalType, sideType)) {
            myHolder.add(HighlightUtil.checkAssignability(conditionalType, sideType, side, side));
          }
        }
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:HighlightVisitorImpl.java

示例2: processMemberType

import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil; //导入依赖的package包/类
private void processMemberType(final PsiElement element,
		final Set<PsiTypeParameter> typeParameters,
		final PsiClass psiClass,
		final PsiSubstitutor substitutor,
		final Map<PsiElement, Pair<PsiReference[], PsiType>> roots)
{
	final PsiType elementType = TypeMigrationLabeler.getElementType(element);
	if(elementType != null && PsiPolyExpressionUtil.mentionsTypeParameters(elementType, typeParameters))
	{
		final PsiType memberType = substitutor.substitute(elementType);

		prepareMethodsChangeSignature(psiClass, element, memberType);

		final List<PsiReference> refs = TypeMigrationLabeler.filterReferences(psiClass, ReferencesSearch.search(element, psiClass.getUseScope()));

		roots.put(element, Pair.create(myLabeler.markRootUsages(element, memberType, refs.toArray(PsiReference.EMPTY_ARRAY)), memberType));
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:19,代码来源:ClassTypeArgumentMigrationProcessor.java

示例3: testPolyConditionExpression

import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil; //导入依赖的package包/类
public void testPolyConditionExpression() throws Exception {
  myFixture.configureByText("Foo.java", "import java.util.*;" +
                                        "class Foo {" +
                                        "  String foo(int i) {" +
                                        "     return i == 0 <caret>? bar() : bar();" +
                                        "  }" +
                                        "  String bar() {return null;}" +
                                        "}");
  final PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
  assertNotNull(elementAtCaret);
  final PsiExpression psiExpression = PsiTreeUtil.getParentOfType(elementAtCaret, PsiExpression.class);
  assertInstanceOf(psiExpression, PsiConditionalExpression.class);
  assertFalse(PsiPolyExpressionUtil.hasStandaloneForm(psiExpression));
  assertTrue(PsiPolyExpressionUtil.isPolyExpression(psiExpression));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:PsiPolyExpressionUtilTest.java

示例4: testMethodCallInsideArrayCreation

import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil; //导入依赖的package包/类
public void testMethodCallInsideArrayCreation() throws Exception {
  myFixture.configureByText("Foo.java", "import java.util.*;" +
                                        "class Foo {" +
                                        "  <T> T bar() {return null;}" +
                                        "  void foo() {" +
                                        "    String[] a = new String[] {ba<caret>r()};" +
                                        "  }" +
                                        "}");
  final PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
  assertNotNull(elementAtCaret);
  final PsiExpression psiExpression = PsiTreeUtil.getParentOfType(elementAtCaret, PsiMethodCallExpression.class);
  assertInstanceOf(psiExpression, PsiMethodCallExpression.class);
  assertTrue(PsiPolyExpressionUtil.isPolyExpression(psiExpression));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:PsiPolyExpressionUtilTest.java

示例5: testConditional

import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil; //导入依赖的package包/类
public void testConditional() throws Exception {
  myFixture.configureByText("Foo.java", "import java.util.function.Supplier;" +
                                        "class Foo {" +
                                        "    private static <R> void map(Supplier<R> fn) {}\n" +
                                        "    public static void main(String[] args) {\n" +
                                        "        Runnable r = null;\n" +
                                        "        map(() -> (true <caret>? r : r));\n" +
                                        "    }" +
                                        "}");
  final PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
  assertNotNull(elementAtCaret);
  final PsiExpression psiExpression = PsiTreeUtil.getParentOfType(elementAtCaret, PsiExpression.class);
  assertInstanceOf(psiExpression, PsiConditionalExpression.class);
  assertTrue(PsiPolyExpressionUtil.isPolyExpression(psiExpression));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:PsiPolyExpressionUtilTest.java

示例6: testConditionalInAssignment

import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil; //导入依赖的package包/类
public void testConditionalInAssignment() throws Exception {
  myFixture.configureByText("Foo.java", "class Foo {" +
                                        "    public static void main(String[] args) {\n" +
                                        "        Object obj = new Object();\n" +
                                        "        String str = \"\";\n" +
                                        "        str += args.length == 0 <caret>? obj : args[0];\n" +
                                        "    }" +
                                        "}");
  final PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
  assertNotNull(elementAtCaret);
  final PsiExpression psiExpression = PsiTreeUtil.getParentOfType(elementAtCaret, PsiExpression.class);
  assertInstanceOf(psiExpression, PsiConditionalExpression.class);
  assertFalse(PsiPolyExpressionUtil.isPolyExpression(psiExpression));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:PsiPolyExpressionUtilTest.java

示例7: isAssignable

import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil; //导入依赖的package包/类
private static boolean isAssignable(CallArgumentInfo callArgumentInfo, PsiSubstitutor substitutor)
{
	PsiType substitutedType = substitutor.substitute(callArgumentInfo.getParameter().getType());
	if(PsiPolyExpressionUtil.isPolyExpression(callArgumentInfo.getArgument()))
	{
		return true;
	}
	PsiType type = callArgumentInfo.getArgument().getType();
	if(type == null)
	{
		return false;
	}
	return isAssignableTo(type, substitutedType);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:15,代码来源:JavaInlayHintsProvider.java

示例8: visitConditionalExpression

import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil; //导入依赖的package包/类
@Override
public void visitConditionalExpression(PsiConditionalExpression expression)
{
	super.visitConditionalExpression(expression);
	if(myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8) && PsiPolyExpressionUtil.isPolyExpression(expression))
	{
		final PsiExpression thenExpression = expression.getThenExpression();
		final PsiExpression elseExpression = expression.getElseExpression();
		if(thenExpression != null && elseExpression != null)
		{
			final PsiType conditionalType = expression.getType();
			if(conditionalType != null)
			{
				final PsiExpression[] sides = {
						thenExpression,
						elseExpression
				};
				for(PsiExpression side : sides)
				{
					final PsiType sideType = side.getType();
					if(sideType != null && !TypeConversionUtil.isAssignable(conditionalType, sideType))
					{
						myHolder.add(HighlightUtil.checkAssignability(conditionalType, sideType, side, side));
					}
				}
			}
		}
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:30,代码来源:HighlightVisitorImpl.java

示例9: getType

import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil; //导入依赖的package包/类
/**
 * JLS 15.25
 */
@Override
public PsiType getType() {
  PsiExpression expr1 = getThenExpression();
  PsiExpression expr2 = getElseExpression();
  PsiType type1 = expr1 == null ? null : expr1.getType();
  PsiType type2 = expr2 == null ? null : expr2.getType();
  if (type1 == null) return type2;
  if (type2 == null) return type1;

  if (type1.equals(type2)) return type1;
  final int typeRank1 = TypeConversionUtil.getTypeRank(type1);
  final int typeRank2 = TypeConversionUtil.getTypeRank(type2);

  // bug in JLS3, see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6888770
  if (type1 instanceof PsiClassType && type2.equals(PsiPrimitiveType.getUnboxedType(type1))) return type2;
  if (type2 instanceof PsiClassType && type1.equals(PsiPrimitiveType.getUnboxedType(type2))) return type1;

  if (TypeConversionUtil.isNumericType(typeRank1) && TypeConversionUtil.isNumericType(typeRank2)){
    if (typeRank1 == TypeConversionUtil.BYTE_RANK && typeRank2 == TypeConversionUtil.SHORT_RANK) {
      return type2 instanceof PsiPrimitiveType ? type2 : PsiPrimitiveType.getUnboxedType(type2);
    }
    if (typeRank1 == TypeConversionUtil.SHORT_RANK && typeRank2 == TypeConversionUtil.BYTE_RANK) {
      return type1 instanceof PsiPrimitiveType ? type1 : PsiPrimitiveType.getUnboxedType(type1);
    }
    if (typeRank2 == TypeConversionUtil.INT_RANK && (typeRank1 == TypeConversionUtil.BYTE_RANK || typeRank1 == TypeConversionUtil.SHORT_RANK || typeRank1 == TypeConversionUtil.CHAR_RANK)){
      if (TypeConversionUtil.areTypesAssignmentCompatible(type1, expr2)) return type1;
    }
    if (typeRank1 == TypeConversionUtil.INT_RANK && (typeRank2 == TypeConversionUtil.BYTE_RANK || typeRank2 == TypeConversionUtil.SHORT_RANK || typeRank2 == TypeConversionUtil.CHAR_RANK)){
      if (TypeConversionUtil.areTypesAssignmentCompatible(type2, expr1)) return type2;
    }
    return TypeConversionUtil.binaryNumericPromotion(type1, type2);
  }
  if (TypeConversionUtil.isNullType(type1) && !(type2 instanceof PsiPrimitiveType)) return type2;
  if (TypeConversionUtil.isNullType(type2) && !(type1 instanceof PsiPrimitiveType)) return type1;

  if (PsiUtil.isLanguageLevel8OrHigher(this) && 
      PsiPolyExpressionUtil.isPolyExpression(this) && 
      !MethodCandidateInfo.ourOverloadGuard.currentStack().contains(PsiUtil.skipParenthesizedExprUp(this.getParent()))) {
    //15.25.3 Reference Conditional Expressions 
    // The type of a poly reference conditional expression is the same as its target type.
    return InferenceSession.getTargetType(this);
  }

  if (TypeConversionUtil.isAssignable(type1, type2, false)) return type1;
  if (TypeConversionUtil.isAssignable(type2, type1, false)) return type2;
  if (!PsiUtil.isLanguageLevel5OrHigher(this)) {
    return null;
  }
  if (TypeConversionUtil.isPrimitiveAndNotNull(type1)) {
    type1 = ((PsiPrimitiveType)type1).getBoxedType(this);
    if (type1 == null) return null;
  }
  if (TypeConversionUtil.isPrimitiveAndNotNull(type2)) {
    type2 = ((PsiPrimitiveType)type2).getBoxedType(this);
    if (type2 == null) return null;
  }

  if (type1 instanceof PsiLambdaParameterType || type2 instanceof PsiLambdaParameterType) return null;
  final PsiType leastUpperBound = GenericsUtil.getLeastUpperBound(type1, type2, getManager());
  return leastUpperBound != null ? PsiUtil.captureToplevelWildcards(leastUpperBound, this) : null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:65,代码来源:PsiConditionalExpressionImpl.java

示例10: testPrefixExpression

import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil; //导入依赖的package包/类
public void testPrefixExpression() throws Exception {
  final PsiExpression psiExpression = findExpression("     int j = i<caret>++;");
  assertInstanceOf(psiExpression, PsiPostfixExpression.class);
  assertTrue(PsiPolyExpressionUtil.hasStandaloneForm(psiExpression));
  assertFalse(PsiPolyExpressionUtil.isPolyExpression(psiExpression));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:PsiPolyExpressionUtilTest.java

示例11: testNumericConditionExpression

import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil; //导入依赖的package包/类
public void testNumericConditionExpression() throws Exception {
  final PsiExpression psiExpression = findExpression("     int j = i == 0 <caret>? i + 1 : i - 1;");
  assertInstanceOf(psiExpression, PsiConditionalExpression.class);
  assertFalse(PsiPolyExpressionUtil.hasStandaloneForm(psiExpression));
  assertFalse(PsiPolyExpressionUtil.isPolyExpression(psiExpression));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:PsiPolyExpressionUtilTest.java

示例12: testNewExpressionDiamond

import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil; //导入依赖的package包/类
public void testNewExpressionDiamond() throws Exception {
  final PsiExpression psiExpression = findExpression("     List<String> l = new Arr<caret>ayList<>();");
  assertInstanceOf(psiExpression, PsiNewExpression.class);
  assertFalse(PsiPolyExpressionUtil.hasStandaloneForm(psiExpression));
  assertTrue(PsiPolyExpressionUtil.isPolyExpression(psiExpression));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:PsiPolyExpressionUtilTest.java

示例13: testNewExpression

import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil; //导入依赖的package包/类
public void testNewExpression() throws Exception {
  final PsiExpression psiExpression = findExpression("     List<String> l = new Arr<caret>ayList<String>();");
  assertInstanceOf(psiExpression, PsiNewExpression.class);
  assertFalse(PsiPolyExpressionUtil.hasStandaloneForm(psiExpression));
  assertFalse(PsiPolyExpressionUtil.isPolyExpression(psiExpression));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:PsiPolyExpressionUtilTest.java

示例14: isBoxingUsed

import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil; //导入依赖的package包/类
private static boolean isBoxingUsed(PsiType parameterType, @Nullable PsiType argType, PsiExpression arg)
{
	ProgressManager.checkCanceled();
	final boolean isExpressionTypePrimitive = argType != null ? argType instanceof PsiPrimitiveType : PsiPolyExpressionUtil.isExpressionOfPrimitiveType(arg);
	return parameterType instanceof PsiPrimitiveType ^ isExpressionTypePrimitive;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:7,代码来源:JavaMethodsConflictResolver.java

示例15: getType

import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil; //导入依赖的package包/类
@Nullable
public <T extends PsiExpression> PsiType getType(@NotNull T expr, @NotNull Function<T, PsiType> f)
{
	final boolean isOverloadCheck = MethodCandidateInfo.isOverloadCheck() || LambdaUtil.isLambdaParameterCheck();
	final boolean polyExpression = PsiPolyExpressionUtil.isPolyExpression(expr);
	PsiType type = isOverloadCheck && polyExpression ? null : myCalculatedTypes.get(expr);
	if(type == null)
	{
		final RecursionGuard.StackStamp dStackStamp = PsiDiamondType.ourDiamondGuard.markStack();
		type = f.fun(expr);
		if(!dStackStamp.mayCacheNow())
		{
			return type;
		}

		//cache standalone expression types as they do not depend on the context
		if(isOverloadCheck && polyExpression)
		{
			return type;
		}

		if(type == null)
		{
			type = TypeConversionUtil.NULL_TYPE;
		}
		myCalculatedTypes.put(expr, type);

		if(type instanceof PsiClassReferenceType)
		{
			// convert reference-based class type to the PsiImmediateClassType, since the reference may become invalid
			PsiClassType.ClassResolveResult result = ((PsiClassReferenceType) type).resolveGenerics();
			PsiClass psiClass = result.getElement();
			type = psiClass == null ? type // for type with unresolved reference, leave it in the cache
					// for clients still might be able to retrieve its getCanonicalText() from the reference text
					: new PsiImmediateClassType(psiClass, result.getSubstitutor(), ((PsiClassReferenceType) type).getLanguageLevel(), type.getAnnotationProvider());
		}
	}

	if(!type.isValid())
	{
		if(expr.isValid())
		{
			PsiJavaCodeReferenceElement refInside = type instanceof PsiClassReferenceType ? ((PsiClassReferenceType) type).getReference() : null;
			@NonNls String typeinfo = type + " (" + type.getClass() + ")" + (refInside == null ? "" : "; ref inside: " + refInside + " (" + refInside.getClass() + ") valid:" + refInside.isValid
					());
			LOG.error("Type is invalid: " + typeinfo + "; expr: '" + expr + "' (" + expr.getClass() + ") is valid");
		}
		else
		{
			LOG.error("Expression: '" + expr + "' is invalid, must not be used for getType()");
		}
	}

	return type == TypeConversionUtil.NULL_TYPE ? null : type;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:56,代码来源:JavaResolveCache.java


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