• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java PsiUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: isStructuralType

import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
private boolean isStructuralType( PsiTypeElement typeElem )
{
  if( typeElem != null )
  {
    PsiClass psiClass = PsiUtil.resolveClassInType( typeElem.getType() );
    if( psiClass == null )
    {
      return false;
    }
    PsiAnnotation structuralAnno = psiClass.getModifierList() == null
                                   ? null
                                   : psiClass.getModifierList().findAnnotation( "manifold.ext.api.Structural" );
    if( structuralAnno != null )
    {
      return true;
    }
  }
  return false;
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:20,代码来源:ManHighlightInfoFilter.java


示例2: visitAssertStatement

import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
@Override
public void visitAssertStatement(PsiAssertStatement statement) {
  super.visitAssertStatement(statement);
  final PsiExpression assertCondition =
    statement.getAssertCondition();
  final PsiExpression expression =
    ParenthesesUtils.stripParentheses(assertCondition);
  if (expression == null) {
    return;
  }
  if (BoolUtils.isFalse(expression)) {
    return;
  }
  if (!PsiUtil.isConstantExpression(expression)) {
    return;
  }
  registerError(expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ConstantAssertConditionInspection.java


示例3: getBoxedPropertyType

import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
@Nullable
private static String getBoxedPropertyType(PsiElement declaration) {
  PsiType attrType = null;
  if (declaration instanceof PsiField) {
    attrType = JavaFxPsiUtil.getWrappedPropertyType((PsiField)declaration, declaration.getProject(), JavaFxCommonClassNames.ourWritableMap);
  } else if (declaration instanceof PsiMethod) {
    final PsiParameter[] parameters = ((PsiMethod)declaration).getParameterList().getParameters();
    final boolean isStatic = ((PsiMethod)declaration).hasModifierProperty(PsiModifier.STATIC);
    if (isStatic && parameters.length == 2 || !isStatic && parameters.length == 1) {
      attrType = parameters[parameters.length - 1].getType();
    }
  }

  String boxedQName = null;
  if (attrType instanceof PsiPrimitiveType) {
    boxedQName = ((PsiPrimitiveType)attrType).getBoxedTypeName();
  } else if (PsiPrimitiveType.getUnboxedType(attrType) != null) {
    final PsiClass attrClass = PsiUtil.resolveClassInType(attrType);
    boxedQName = attrClass != null ? attrClass.getQualifiedName() : null;
  }
  return boxedQName;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:JavaFxPropertyAttributeDescriptor.java


示例4: getIteratedType

import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
private static PsiType getIteratedType(PsiElement parent, PsiType collection) {
  if (parent instanceof GrReferenceExpression) {
    final GrExpression qualifier = ((GrReferenceExpression)parent).getQualifier();
    if (qualifier != null) {
      return ClosureParameterEnhancer.findTypeForIteration(qualifier, parent);
    }
  }

  final PsiType iterable = PsiUtil.extractIterableTypeParameter(collection, true);
  if (iterable != null && parent instanceof GrExpression) {
    return PsiImplUtil.normalizeWildcardTypeByPosition(iterable, (GrExpression)parent);
  }
  else {
    return iterable;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:EachWithIndexClosureCompleter.java


示例5: getVariablesVisibleAt

import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
@NotNull public static PsiVariable[] getVariablesVisibleAt(@Nullable final PsiElement place, String prefix) {
  if (place == null) {
    return new PsiVariable[0];
  }

  final Set<String> usedNames = ContainerUtil.newHashSet();
  final List<PsiVariable> list = new ArrayList<PsiVariable>();
  VariablesProcessor varproc = new VariablesProcessor(prefix, true, list) {
    @Override
    public boolean execute(@NotNull PsiElement pe, @NotNull ResolveState state) {
      if (pe instanceof PsiVariable) {
        if (!usedNames.add(((PsiVariable)pe).getName())) {
          return false;
        }
        //exclude variables that are initialized in 'place'
        final PsiExpression initializer = ((PsiVariable)pe).getInitializer();
        if (initializer != null && PsiTreeUtil.isAncestor(initializer, place, false)) return true;
      }
      return pe instanceof PsiField && !PsiUtil.isAccessible((PsiField)pe, place, null) || super.execute(pe, state);
    }
  };
  PsiScopesUtil.treeWalkUp(varproc, place, null);
  return varproc.getResultsAsArray();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:MacroUtil.java


示例6: inferIteratorType

import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
private PsiType inferIteratorType(GroovyResolveResult iteratorMethodResult, GrExpression tupleInitializer) {
  PsiElement method = iteratorMethodResult.getElement();
  if (method instanceof PsiMethod) {
    return iteratorMethodResult.getSubstitutor().substitute(((PsiMethod)method).getReturnType());
  }
  else {
    PsiType initializerType = tupleInitializer.getType();
    PsiType iterableParam = PsiUtil.extractIterableTypeParameter(initializerType, false);

    JavaPsiFacade facade = JavaPsiFacade.getInstance(context.project);
    PsiClass iterableClass = facade.findClass(CommonClassNames.JAVA_UTIL_ITERATOR, tupleInitializer.getResolveScope());
    if (iterableClass != null && iterableParam != null) {
      return facade.getElementFactory().createType(iterableClass, iterableParam);
    }
    else {
      return facade.getElementFactory().createTypeFromText(CommonClassNames.JAVA_UTIL_ITERATOR, tupleInitializer);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:CodeBlockGenerator.java


示例7: hasStaticInitializer

import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
private static boolean hasStaticInitializer(PsiField field) {
  if (field.hasModifierProperty(PsiModifier.STATIC)) {
    final PsiExpression initializer = field.getInitializer();
    if (initializer == null) {
      return false;
    }
    final PsiType fieldType = field.getType();
    final PsiType stringType = TypeUtils.getStringType(field);
    if (field.hasModifierProperty(PsiModifier.FINAL) && (fieldType instanceof PsiPrimitiveType || fieldType.equals(stringType))) {
      return !PsiUtil.isConstantExpression(initializer);
    }
    else {
      return true;
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:SerialVersionUIDBuilder.java


示例8: visitConditionalExpression

import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
@Override
public void visitConditionalExpression(PsiConditionalExpression expression) {
  super.visitConditionalExpression(expression);
  final PsiExpression condition = PsiUtil.skipParenthesizedExprDown(expression.getCondition());
  if (!(condition instanceof PsiBinaryExpression)) {
    return;
  }
  final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)condition;
  final PsiReferenceExpression referenceExpression = extractVariableReference(binaryExpression);
  if (referenceExpression == null) {
    return;
  }
  final IElementType tokenType = binaryExpression.getOperationTokenType();
  if (tokenType == JavaTokenType.EQEQ) {
    if (checkVariableUsage(referenceExpression, expression.getThenExpression(), expression.getElseExpression())) {
      registerError(referenceExpression, Boolean.FALSE);
    }
  }
  else if (tokenType == JavaTokenType.NE) {
    if (checkVariableUsage(referenceExpression, expression.getElseExpression(), expression.getThenExpression())) {
      registerError(referenceExpression, Boolean.FALSE);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:VariableNotUsedInsideIfInspection.java


示例9: isReferencedForWrite

import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
boolean isReferencedForWrite(@NotNull PsiVariable variable) {
  Collection<PsiReference> array;
  synchronized (myLocalRefsMap) {
    array = myLocalRefsMap.get(variable);
  }
  if (array.isEmpty()) return false;
  for (PsiReference ref : array) {
    final PsiElement refElement = ref.getElement();
    if (!(refElement instanceof PsiExpression)) { // possible with incomplete code
      return true;
    }
    if (PsiUtil.isAccessedForWriting((PsiExpression)refElement)) {
      return true;
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:RefCountHolder.java


示例10: addExprTypesByDerivedClasses

import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
private void addExprTypesByDerivedClasses(LinkedHashSet<PsiType> set, PsiExpression expr) {
  PsiType type = expr.getType();
  if (!(type instanceof PsiClassType)) return;
  PsiClass refClass = PsiUtil.resolveClassInType(type);
  if (refClass == null) return;

  PsiManager manager = PsiManager.getInstance(myProject);
  PsiElementProcessor.CollectElementsWithLimit<PsiClass> processor = new PsiElementProcessor.CollectElementsWithLimit<PsiClass>(5);
  ClassInheritorsSearch.search(refClass, true).forEach(new PsiElementProcessorAdapter<PsiClass>(processor));
  if (processor.isOverflow()) return;

  for (PsiClass derivedClass : processor.getCollection()) {
    if (derivedClass instanceof PsiAnonymousClass) continue;
    PsiType derivedType = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createType(derivedClass);
    set.add(derivedType);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:GuessManagerImpl.java


示例11: registerSwapFixes

import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
private static void registerSwapFixes(final PsiExpression[] expressions, final PsiCall callExpression, final List<PsiCall> permutations,
                                      MethodCandidateInfo candidate, final int incompatibilitiesCount, final int minIncompatibleIndex,
                                      final int maxIncompatibleIndex) throws IncorrectOperationException {
  PsiMethod method = candidate.getElement();
  PsiSubstitutor substitutor = candidate.getSubstitutor();
  if (incompatibilitiesCount >= 3) return; // no way we can fix it by swapping

  for (int i = minIncompatibleIndex; i < maxIncompatibleIndex; i++) {
    for (int j = i+1; j <= maxIncompatibleIndex; j++) {
      ArrayUtil.swap(expressions, i, j);
      if (PsiUtil.isApplicable(method, substitutor, expressions)) {
        PsiCall copy = (PsiCall)callExpression.copy();
        PsiExpression[] copyExpressions = copy.getArgumentList().getExpressions();
        copyExpressions[i].replace(expressions[i]);
        copyExpressions[j].replace(expressions[j]);
        JavaResolveResult result = copy.resolveMethodGenerics();
        if (result.getElement() != null && result.isValidResult()) {
          permutations.add(copy);
          if (permutations.size() > 1) return;
        }
      }
      ArrayUtil.swap(expressions, i, j);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:PermuteArgumentsFix.java


示例12: checkExpression

import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
private void checkExpression(PsiExpression expression) {
  expression = PsiUtil.deparenthesizeExpression(expression);
  if (negate) {
    if (expression instanceof PsiPrefixExpression) {
      final PsiPrefixExpression prefixExpression =
        (PsiPrefixExpression)expression;
      final IElementType tokenType =
        prefixExpression.getOperationTokenType();
      if (tokenType != JavaTokenType.EXCL) {
        return;
      }
      expression = PsiUtil.deparenthesizeExpression(
        prefixExpression.getOperand());
      checkInstanceOfExpression(expression);
    }
  }
  else {
    checkInstanceOfExpression(expression);
  }
  if (expression instanceof PsiPolyadicExpression) {
    final PsiPolyadicExpression binaryExpression =
      (PsiPolyadicExpression)expression;
    visitPolyadicExpression(binaryExpression);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:InstanceOfUtils.java


示例13: createInitialStates

import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
@Nullable
private Collection<DfaMemoryState> createInitialStates(@NotNull PsiElement psiBlock, InstructionVisitor visitor) {
  PsiClass containingClass = PsiTreeUtil.getParentOfType(psiBlock, PsiClass.class);
  if (containingClass != null && PsiUtil.isLocalOrAnonymousClass(containingClass)) {
    final PsiElement parent = containingClass.getParent();
    final PsiCodeBlock block = DfaPsiUtil.getTopmostBlockInSameClass(parent);
    if ((parent instanceof PsiNewExpression || parent instanceof PsiDeclarationStatement) && block != null) {
      final RunnerResult result = analyzeMethod(block, visitor);
      if (result == RunnerResult.OK) {
        final Collection<DfaMemoryState> closureStates = myNestedClosures.get(DfaPsiUtil.getTopmostBlockInSameClass(psiBlock));
        if (!closureStates.isEmpty()) {
          return closureStates;
        }
      }
      return null;
    }
  }

  return Collections.singletonList(createMemoryState());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:DataFlowRunner.java


示例14: addBound

import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
public boolean addBound(PsiType classType, InferenceBound inferenceBound) {
  if (inferenceBound == InferenceBound.EQ &&
      PsiUtil.resolveClassInClassTypeOnly(classType) == this) {
    return false;
  }
  List<PsiType> list = myBounds.get(inferenceBound);
  if (list == null) {
    list = new ArrayList<PsiType>();
    myBounds.put(inferenceBound, list);
  }
  final int idx = list.indexOf(classType);
  if (idx < 0) {
    list.add(classType);
    return true;
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:InferenceVariable.java


示例15: chooseAndImplement

import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
protected static void chooseAndImplement(PsiClass psiClass, Project project, @NotNull PsiClass targetClass, Editor editor) {
  boolean hasNonTrivialConstructor = false;
  final PsiMethod[] constructors = psiClass.getConstructors();
  for (PsiMethod constructor : constructors) {
    if (constructor.getParameterList().getParametersCount() > 0) {
      hasNonTrivialConstructor = true;
      break;
    }
  }
  if (hasNonTrivialConstructor) {
    final PsiSubstitutor substitutor = TypeConversionUtil.getSuperClassSubstitutor(psiClass, targetClass, PsiSubstitutor.EMPTY);
    final List<PsiMethodMember> baseConstructors = new ArrayList<PsiMethodMember>();
    for (PsiMethod baseConstr : constructors) {
      if (PsiUtil.isAccessible(project, baseConstr, targetClass, targetClass)) {
        baseConstructors.add(new PsiMethodMember(baseConstr, substitutor));
      }
    }
    final int offset = editor.getCaretModel().getOffset();
    CreateConstructorMatchingSuperFix.chooseConstructor2Delegate(project, editor,
                                                                 substitutor,
                                                                 baseConstructors, constructors, targetClass);
    editor.getCaretModel().moveToOffset(offset);
  }

  OverrideImplementUtil.chooseAndImplementMethods(project, editor, targetClass);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:CreateSubclassAction.java


示例16: createTempVar

import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
public static String createTempVar(PsiExpression expr, PsiElement context, boolean declareFinal) throws IncorrectOperationException {
  PsiElement anchorStatement = getParentStatement(context, true);
  LOG.assertTrue(anchorStatement != null && anchorStatement.getParent() != null);

  Project project = expr.getProject();
  String[] suggestedNames =
    JavaCodeStyleManager.getInstance(project).suggestVariableName(VariableKind.LOCAL_VARIABLE, null, expr, null).names;
  final String prefix = suggestedNames.length > 0 ? suggestedNames[0] : "var";
  final String id = JavaCodeStyleManager.getInstance(project).suggestUniqueVariableName(prefix, context, true);

  PsiElementFactory factory = JavaPsiFacade.getInstance(expr.getProject()).getElementFactory();

  if (expr instanceof PsiParenthesizedExpression) {
    PsiExpression expr1 = ((PsiParenthesizedExpression)expr).getExpression();
    if (expr1 != null) {
      expr = expr1;
    }
  }
  PsiDeclarationStatement decl = factory.createVariableDeclarationStatement(id, expr.getType(), expr);
  if (declareFinal) {
    PsiUtil.setModifierProperty(((PsiLocalVariable)decl.getDeclaredElements()[0]), PsiModifier.FINAL, true);
  }
  anchorStatement.getParent().addBefore(decl, anchorStatement);

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


示例17: calculateReplacementMap

import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
@Nullable
private static Map<PsiTypeParameter, PsiTypeParameter> calculateReplacementMap(final PsiSubstitutor substitutor,
                                                                        final PsiClass targetClass,
                                                                        final PsiElement containingElement) {
  final HashMap<PsiTypeParameter, PsiTypeParameter> result = new HashMap<PsiTypeParameter, PsiTypeParameter>();
  for (PsiTypeParameter classTypeParameter : PsiUtil.typeParametersIterable(targetClass)) {
    final PsiType substitution = substitutor.substitute(classTypeParameter);
    if (!(substitution instanceof PsiClassType)) return null;
    final PsiClass aClass = ((PsiClassType)substitution).resolve();
    if (!(aClass instanceof PsiTypeParameter)) return null;
    final PsiTypeParameter methodTypeParameter = (PsiTypeParameter)aClass;
    if (methodTypeParameter.getOwner() != containingElement) return null;
    if (result.keySet().contains(methodTypeParameter)) return null;
    result.put(methodTypeParameter, classTypeParameter);
  }
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:ConvertToInstanceMethodProcessor.java


示例18: getExpectedArgumentsTypesForNewExpression

import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
private void getExpectedArgumentsTypesForNewExpression(@NotNull final PsiNewExpression newExpr,
                                                       @NotNull final PsiExpressionList list) {
  PsiType newType = newExpr.getType();
  if (newType instanceof PsiClassType) {
    JavaResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(newType);
    PsiClass newClass = (PsiClass)resolveResult.getElement();
    final PsiSubstitutor substitutor;
    if (newClass instanceof PsiAnonymousClass) {
      final PsiAnonymousClass anonymous = (PsiAnonymousClass)newClass;
      newClass = anonymous.getBaseClassType().resolve();
      if (newClass == null) return;

      substitutor = TypeConversionUtil.getSuperClassSubstitutor(newClass, anonymous, PsiSubstitutor.EMPTY);
    } else if (newClass != null) {
      substitutor = resolveResult.getSubstitutor();
    }
    else {
      return;
    }
    getExpectedTypesForConstructorCall(newClass, list, substitutor);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:ExpectedTypesProvider.java


示例19: unify

import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
@Nullable
private static PsiSubstitutor unify(@NotNull PsiSubstitutor substitutor, @NotNull PsiSubstitutor parentSubstitutor, @NotNull Project project) {
  Map<PsiTypeParameter,PsiType> newMap = new THashMap<PsiTypeParameter, PsiType>(substitutor.getSubstitutionMap());

  for (Map.Entry<PsiTypeParameter, PsiType> entry : substitutor.getSubstitutionMap().entrySet()) {
    PsiTypeParameter typeParameter = entry.getKey();
    PsiType type = entry.getValue();
    PsiClass resolved = PsiUtil.resolveClassInType(type);
    if (!parentSubstitutor.getSubstitutionMap().containsKey(typeParameter)) continue;
    PsiType parentType = parentSubstitutor.substitute(parentSubstitutor.substitute(typeParameter));

    if (resolved instanceof PsiTypeParameter) {
      PsiTypeParameter res = (PsiTypeParameter)resolved;
      newMap.put(res, parentType);
    }
    else if (!Comparing.equal(type, parentType)) {
      return null; // cannot unify
    }
  }
  return JavaPsiFacade.getElementFactory(project).createSubstitutor(newMap);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:SliceUtil.java


示例20: invoke

import com.intellij.psi.util.PsiUtil; //导入依赖的package包/类
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
  final PsiVariable refVariable = findPreviousVariable();
  if (refVariable == null) return;

  if (!CodeInsightUtil.preparePsiElementsForWrite(myVariable, refVariable)) return;

  final PsiExpression initializer = myVariable.getInitializer();
  if (initializer == null) {
    myVariable.delete();
    return;
  }

  PsiUtil.setModifierProperty(refVariable, PsiModifier.FINAL, false);
  final PsiElementFactory factory = JavaPsiFacade.getInstance(myVariable.getProject()).getElementFactory();
  final PsiElement statement = factory.createStatementFromText(myVariable.getName() + " = " + initializer.getText() + ";", null);
  myVariable.getParent().replace(statement);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ReuseVariableDeclarationFix.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AccessibleStateSet类代码示例发布时间:2022-05-21
下一篇:
Java AbstractHBaseTool类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap