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


Java PsiSubstitutor.substitute方法代码示例

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


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

示例1: createBuildMethod

import com.intellij.psi.PsiSubstitutor; //导入方法依赖的package包/类
@NotNull
private PsiMethod createBuildMethod(@NotNull PsiClass parentClass, @Nullable PsiMethod psiMethod, @NotNull PsiClass builderClass, @NotNull PsiSubstitutor builderSubstitutor,
                                    @NotNull String buildMethodName, @NotNull String buildMethodPrepare, @NotNull String buildMethodParameters) {
  final PsiType builderType = getReturnTypeOfBuildMethod(parentClass, psiMethod);
  final PsiType returnType = builderSubstitutor.substitute(builderType);

  final LombokLightMethodBuilder methodBuilder = new LombokLightMethodBuilder(parentClass.getManager(), buildMethodName)
    .withMethodReturnType(returnType)
    .withContainingClass(builderClass)
    .withNavigationElement(parentClass)
    .withModifier(PsiModifier.PUBLIC)
    .withBody(createBuildMethodCodeBlock(psiMethod, builderClass, returnType, buildMethodPrepare, buildMethodParameters));

  if (null == psiMethod) {
    final Collection<PsiMethod> classConstructors = PsiClassUtil.collectClassConstructorIntern(parentClass);
    if (!classConstructors.isEmpty()) {
      final PsiMethod constructor = classConstructors.iterator().next();
      addExceptions(methodBuilder, constructor);
    }
  } else {
    addExceptions(methodBuilder, psiMethod);
  }

  return methodBuilder;
}
 
开发者ID:mplushnikov,项目名称:lombok-intellij-plugin,代码行数:26,代码来源:BuilderHandler.java

示例2: extractTypeParameters

import com.intellij.psi.PsiSubstitutor; //导入方法依赖的package包/类
@NotNull
public static PsiType[] extractTypeParameters(@NotNull PsiType psiType, @NotNull PsiManager psiManager) {
  if (!(psiType instanceof PsiClassType)) {
    return PsiType.EMPTY_ARRAY;
  }

  final PsiClassType classType = (PsiClassType) psiType;
  final PsiClassType.ClassResolveResult classResolveResult = classType.resolveGenerics();
  final PsiClass psiClass = classResolveResult.getElement();
  if (psiClass == null) {
    return PsiType.EMPTY_ARRAY;
  }
  final PsiSubstitutor psiSubstitutor = classResolveResult.getSubstitutor();

  final PsiTypeParameter[] typeParameters = psiClass.getTypeParameters();

  final PsiType[] psiTypes = PsiType.createArray(typeParameters.length);
  for (int i = 0; i < typeParameters.length; i++) {
    PsiType psiSubstituteKeyType = psiSubstitutor.substitute(typeParameters[i]);
    if (null == psiSubstituteKeyType) {
      psiSubstituteKeyType = PsiType.getJavaLangObject(psiManager, GlobalSearchScope.allScope(psiManager.getProject()));
    }
    psiTypes[i] = psiSubstituteKeyType;
  }
  return psiTypes;
}
 
开发者ID:mplushnikov,项目名称:lombok-intellij-plugin,代码行数:27,代码来源:PsiTypeUtil.java

示例3: findRedundantArgument

import com.intellij.psi.PsiSubstitutor; //导入方法依赖的package包/类
@Nullable
private static PsiExpression[] findRedundantArgument(@NotNull PsiExpression[] arguments,
                                                     @NotNull PsiParameter[] parameters,
                                                     @NotNull PsiSubstitutor substitutor) {
  if (arguments.length <= parameters.length) return null;

  for (int i = 0; i < parameters.length; i++) {
    final PsiExpression argument = arguments[i];
    final PsiParameter parameter = parameters[i];

    final PsiType argumentType = argument.getType();
    if (argumentType == null) return null;
    final PsiType parameterType = substitutor.substitute(parameter.getType());

    if (!TypeConversionUtil.isAssignable(parameterType, argumentType)) {
      return null;
    }
  }

  return Arrays.copyOfRange(arguments, parameters.length, arguments.length);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:22,代码来源:RemoveRedundantArgumentsFix.java

示例4: isAcceptable

import com.intellij.psi.PsiSubstitutor; //导入方法依赖的package包/类
@Override
public boolean isAcceptable(Object element, PsiElement context)
{
	if(element == null)
	{
		return false;
	}
	if(element instanceof PsiType)
	{
		return myType.isAssignableFrom((PsiType) element);
	}
	PsiSubstitutor substitutor = null;
	if(element instanceof CandidateInfo)
	{
		final CandidateInfo info = (CandidateInfo) element;
		substitutor = info.getSubstitutor();
		element = info.getElement();
	}

	PsiType typeByElement = FilterUtil.getTypeByElement((PsiElement) element, context);
	if(substitutor != null)
	{
		typeByElement = substitutor.substitute(typeByElement);
	}
	return typeByElement != null && typeByElement.isAssignableFrom(myType) && !typeByElement.equals(myType);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:27,代码来源:AssignableToFilter.java

示例5: isAcceptable

import com.intellij.psi.PsiSubstitutor; //导入方法依赖的package包/类
@Override
public boolean isAcceptable(Object element, PsiElement context){
  if(element == null) return false;
  if (element instanceof PsiType) return myType.isAssignableFrom((PsiType) element);
  PsiSubstitutor substitutor = null;
  if(element instanceof CandidateInfo){
    final CandidateInfo info = (CandidateInfo)element;
    substitutor = info.getSubstitutor();
    element = info.getElement();
  }

  PsiType typeByElement = FilterUtil.getTypeByElement((PsiElement)element, context);
  if(substitutor != null) typeByElement = substitutor.substitute(typeByElement);
  return typeByElement != null && typeByElement.isAssignableFrom(myType) && !typeByElement.equals(myType);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:AssignableToFilter.java

示例6: addBuilderMethod

import com.intellij.psi.PsiSubstitutor; //导入方法依赖的package包/类
@Override
public void addBuilderMethod(@NotNull List<PsiMethod> methods, @NotNull PsiVariable psiVariable, @NotNull String fieldName, @NotNull PsiClass innerClass, boolean fluentBuilder, PsiType returnType, String singularName, PsiSubstitutor builderSubstitutor) {
  final PsiType psiFieldType = builderSubstitutor.substitute(psiVariable.getType());
  final PsiManager psiManager = psiVariable.getManager();

  final LombokLightMethodBuilder oneAddMethod = new LombokLightMethodBuilder(psiManager, singularName)
    .withMethodReturnType(returnType)
    .withContainingClass(innerClass)
    .withNavigationElement(psiVariable)
    .withModifier(PsiModifier.PUBLIC);

  addOneMethodParameter(oneAddMethod, psiFieldType, singularName);
  oneAddMethod.withBody(createOneAddMethodCodeBlock(innerClass, fluentBuilder, singularName, fieldName, psiFieldType));
  methods.add(oneAddMethod);

  final LombokLightMethodBuilder allAddMethod = new LombokLightMethodBuilder(psiManager, fieldName)
    .withMethodReturnType(returnType)
    .withContainingClass(innerClass)
    .withNavigationElement(psiVariable)
    .withModifier(PsiModifier.PUBLIC);

  addAllMethodParameter(allAddMethod, psiFieldType, fieldName);
  allAddMethod.withBody(createAllAddMethodCodeBlock(innerClass, fluentBuilder, fieldName, psiFieldType));
  methods.add(allAddMethod);

  final LombokLightMethodBuilder clearMethod = new LombokLightMethodBuilder(psiManager, "clear" + StringUtil.capitalize(fieldName))
    .withMethodReturnType(returnType)
    .withContainingClass(innerClass)
    .withNavigationElement(psiVariable)
    .withModifier(PsiModifier.PUBLIC)
    .withBody(createClearMethodCodeBlock(innerClass, fluentBuilder, fieldName));

  methods.add(clearMethod);
}
 
开发者ID:mplushnikov,项目名称:lombok-intellij-plugin,代码行数:35,代码来源:AbstractSingularHandler.java

示例7: generateDelegateMethod

import com.intellij.psi.PsiSubstitutor; //导入方法依赖的package包/类
@NotNull
private <T extends PsiModifierListOwner & PsiNamedElement> PsiMethod generateDelegateMethod(@NotNull PsiClass psiClass, @NotNull T psiElement, @NotNull PsiAnnotation psiAnnotation, @NotNull PsiMethod psiMethod, @NotNull PsiSubstitutor psiSubstitutor) {
  final PsiType returnType = psiSubstitutor.substitute(psiMethod.getReturnType());

  final LombokLightMethodBuilder methodBuilder = new LombokLightMethodBuilder(psiClass.getManager(), psiMethod.getName())
    .withModifier(PsiModifier.PUBLIC)
    .withMethodReturnType(returnType)
    .withContainingClass(psiClass)
    //Have to go to original method, or some refactoring action will not work (like extract parameter oder change signature)
    .withNavigationElement(psiMethod);

  for (PsiTypeParameter typeParameter : psiMethod.getTypeParameters()) {
    methodBuilder.withTypeParameter(typeParameter);
  }

  final PsiReferenceList throwsList = psiMethod.getThrowsList();
  for (PsiClassType psiClassType : throwsList.getReferencedTypes()) {
    methodBuilder.withException(psiClassType);
  }

  final PsiParameterList parameterList = psiMethod.getParameterList();

  final PsiParameter[] psiParameters = parameterList.getParameters();
  for (int parameterIndex = 0; parameterIndex < psiParameters.length; parameterIndex++) {
    final PsiParameter psiParameter = psiParameters[parameterIndex];
    final PsiType psiParameterType = psiSubstitutor.substitute(psiParameter.getType());
    final String generatedParameterName = StringUtils.defaultIfEmpty(psiParameter.getName(), "p" + parameterIndex);
    methodBuilder.withParameter(generatedParameterName, psiParameterType);
  }

  methodBuilder.withBody(createCodeBlock(psiClass, psiElement, psiMethod, returnType, psiParameters));

  return methodBuilder;
}
 
开发者ID:mplushnikov,项目名称:lombok-intellij-plugin,代码行数:35,代码来源:DelegateHandler.java

示例8: methodMatches

import com.intellij.psi.PsiSubstitutor; //导入方法依赖的package包/类
public static boolean methodMatches(@NotNull Pair<PsiMethod, PsiSubstitutor> firstPair, @NotNull Pair<PsiMethod, PsiSubstitutor> secondPair) {
  final PsiMethod firstMethod = firstPair.getFirst();
  final PsiMethod secondMethod = secondPair.getFirst();
  if (!firstMethod.getName().equals(secondMethod.getName())) {
    return false;
  }

  PsiParameterList firstMethodParameterList = firstMethod.getParameterList();
  PsiParameterList secondMethodParameterList = secondMethod.getParameterList();
  if (firstMethodParameterList.getParametersCount() != secondMethodParameterList.getParametersCount()) {
    return false;
  }

  PsiParameter[] firstMethodParameterListParameters = firstMethodParameterList.getParameters();
  PsiParameter[] secondMethodParameterListParameters = secondMethodParameterList.getParameters();
  PsiSubstitutor firstSubstitutor = firstPair.getSecond();
  PsiSubstitutor secondSubstitutor = secondPair.getSecond();
  for (int i = 0; i < firstMethodParameterListParameters.length; i++) {
    PsiType firstMethodParameterListParameterType = firstSubstitutor.substitute(firstMethodParameterListParameters[i].getType());
    PsiType secondMethodParameterListParameterType = secondSubstitutor.substitute(secondMethodParameterListParameters[i].getType());
    if (PsiType.NULL.equals(firstMethodParameterListParameterType)) {
      continue;
    }
    if (!typesAreEquivalent(firstMethodParameterListParameterType, secondMethodParameterListParameterType)) {
      return false;
    }
  }

  return true;
}
 
开发者ID:mplushnikov,项目名称:lombok-intellij-plugin,代码行数:31,代码来源:PsiElementUtil.java

示例9: registerFix

import com.intellij.psi.PsiSubstitutor; //导入方法依赖的package包/类
public static void registerFix(HighlightInfo info, PsiCall callExpression, final CandidateInfo[] candidates, final TextRange fixRange) {
  PsiExpression[] expressions = callExpression.getArgumentList().getExpressions();
  if (expressions.length < 2) return;
  List<PsiCall> permutations = new ArrayList<PsiCall>();

  for (CandidateInfo candidate : candidates) {
    if (candidate instanceof MethodCandidateInfo) {
      MethodCandidateInfo methodCandidate = (MethodCandidateInfo)candidate;
      PsiMethod method = methodCandidate.getElement();
      PsiSubstitutor substitutor = methodCandidate.getSubstitutor();

      PsiParameter[] parameters = method.getParameterList().getParameters();
      if (expressions.length != parameters.length || parameters.length ==0) continue;
      int minIncompatibleIndex = parameters.length;
      int maxIncompatibleIndex = 0;
      int incompatibilitiesCount = 0;
      for (int i = 0; i < parameters.length; i++) {
        PsiParameter parameter = parameters[i];
        PsiType type = substitutor.substitute(parameter.getType());
        if (TypeConversionUtil.areTypesAssignmentCompatible(type, expressions[i])) continue;
        if (minIncompatibleIndex == parameters.length) minIncompatibleIndex = i;
        maxIncompatibleIndex = i;
        incompatibilitiesCount++;
      }

      try {
        registerSwapFixes(expressions, callExpression, permutations, methodCandidate, incompatibilitiesCount, minIncompatibleIndex, maxIncompatibleIndex);
        registerShiftFixes(expressions, callExpression, permutations, methodCandidate, minIncompatibleIndex, maxIncompatibleIndex);
      }
      catch (IncorrectOperationException e) {
        LOG.error(e);
      }
    }
  }
  if (permutations.size() == 1) {
    PermuteArgumentsFix fix = new PermuteArgumentsFix(callExpression, permutations.get(0));
    QuickFixAction.registerQuickFixAction(info, fixRange, fix);
  }
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:40,代码来源:PermuteArgumentsFix.java

示例10: formatTypeParameters

import com.intellij.psi.PsiSubstitutor; //导入方法依赖的package包/类
@Nullable
private static String formatTypeParameters(@NotNull final PsiSubstitutor substitutor, final PsiTypeParameter[] params)
{
	final boolean space = showSpaceAfterComma(params[0]);
	StringBuilder buffer = new StringBuilder();
	buffer.append("<");
	for(int i = 0; i < params.length; i++)
	{
		final PsiTypeParameter param = params[i];
		final PsiType type = substitutor.substitute(param);
		if(type == null)
		{
			return "";
		}
		if(type instanceof PsiClassType && ((PsiClassType) type).getParameters().length > 0)
		{
			buffer.append(((PsiClassType) type).rawType().getPresentableText()).append("<...>");
		}
		else
		{
			buffer.append(type.getPresentableText());
		}

		if(i < params.length - 1)
		{
			buffer.append(",");
			if(space)
			{
				buffer.append(" ");
			}
		}
	}
	buffer.append(">");
	return buffer.toString();
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:36,代码来源:JavaPsiClassReferenceElement.java

示例11: isApplicable

import com.intellij.psi.PsiSubstitutor; //导入方法依赖的package包/类
@Override
protected boolean isApplicable(PsiMethod method, PsiElement place)
{
	final PsiExpressionList argumentList = ((PsiMethodCallExpression) place).getArgumentList();
	final MethodCandidateInfo candidateInfo = new MethodCandidateInfo(method, PsiSubstitutor.EMPTY, false, false, argumentList, null, argumentList.getExpressionTypes(), null);
	PsiSubstitutor substitutorForMethod = candidateInfo.getSubstitutor();
	if(PsiUtil.isApplicable(method, substitutorForMethod, argumentList))
	{
		final PsiType returnType = substitutorForMethod.substitute(method.getReturnType());
		final PsiType expectedType = getExpectedType();
		return expectedType == null || returnType == null || TypeConversionUtil.isAssignable(expectedType, returnType);
	}
	return false;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:15,代码来源:StaticImportMethodFix.java

示例12: apply

import com.intellij.psi.PsiSubstitutor; //导入方法依赖的package包/类
@Override
public void apply(PsiSubstitutor substitutor, boolean cache) {
  myT = substitutor.substitute(myT);
  myS = substitutor.substitute(myS);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:6,代码来源:SubtypingConstraint.java

示例13: GrImmediateClosureParameterImpl

import com.intellij.psi.PsiSubstitutor; //导入方法依赖的package包/类
public GrImmediateClosureParameterImpl(@NotNull PsiParameter parameter, @NotNull PsiSubstitutor substitutor) {
  this(substitutor.substitute(getParameterType(parameter)), getParameterName(parameter), isParameterOptional(parameter), getDefaultInitializer(parameter));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:4,代码来源:GrImmediateClosureParameterImpl.java

示例14: extractTypeFromIterable

import com.intellij.psi.PsiSubstitutor; //导入方法依赖的package包/类
@Nullable
private static PsiType extractTypeFromIterable(VtlExpression expr)
{
	if(expr == null)
	{
		return null;
	}
	PsiType type = expr.getPsiType();
	if(type == null)
	{
		return null;
	}
	if(type instanceof PsiArrayType)
	{
		return ((PsiArrayType) type).getComponentType();
	}
	if(!(type instanceof PsiClassType))
	{
		return null;
	}
	PsiClassType classType = (PsiClassType) type;
	PsiElementFactory factory = JavaPsiFacade.getInstance(expr.getProject()).getElementFactory();
	GlobalSearchScope scope = expr.getResolveScope();

	for(Object[] iterable : VELOCITY_ITERABLES)
	{
		PsiClassType iterableClassType = factory.createTypeByFQClassName((String) iterable[0], scope);
		if(!TypeConversionUtil.isAssignable(iterableClassType, classType))
		{
			continue;
		}
		final PsiClass iterableClass = iterableClassType.resolve();
		if(iterableClass == null)
		{
			continue;
		}
		final PsiSubstitutor substitutor = PsiUtil.getSuperClassSubstitutor(iterableClass, classType);
		PsiTypeParameter[] paremeters = iterableClass.getTypeParameters();
		int paramIndex = ((Integer) iterable[1]).intValue();
		PsiType result = paramIndex < paremeters.length ? substitutor.substitute(paremeters[paramIndex]) : null;
		return result != null ? result : factory.createTypeByFQClassName(JavaClassNames.JAVA_LANG_OBJECT, scope);
	}
	return null;
}
 
开发者ID:consulo,项目名称:consulo-apache-velocity,代码行数:45,代码来源:VtlLoopVariable.java

示例15: apply

import com.intellij.psi.PsiSubstitutor; //导入方法依赖的package包/类
@Override
public void apply(PsiSubstitutor substitutor, boolean cache)
{
	myT = substitutor.substitute(myT);
	myS = substitutor.substitute(myS);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:7,代码来源:SubtypingConstraint.java


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