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


Java PsiUtil.isAccessedForReading方法代码示例

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


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

示例1: getExpressionAccess

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public Access getExpressionAccess(final PsiElement expression) {
  if (!(expression instanceof PsiExpression)) return Access.Read;
  PsiExpression expr = (PsiExpression) expression;
  boolean readAccess = PsiUtil.isAccessedForReading(expr);
  boolean writeAccess = PsiUtil.isAccessedForWriting(expr);
  if (!writeAccess && expr instanceof PsiReferenceExpression) {
    //when searching usages of fields, should show all found setters as a "only write usage"
    PsiElement actualReferee = ((PsiReferenceExpression) expr).resolve();
    if (actualReferee instanceof PsiMethod && PropertyUtil.isSimplePropertySetter((PsiMethod)actualReferee)) {
      writeAccess = true;
      readAccess = false;
    }
  }
  if (writeAccess && readAccess) return Access.ReadWrite;
  return writeAccess ? Access.Write : Access.Read;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:JavaReadWriteAccessDetector.java

示例2: isReferencedForRead

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

示例3: visitReferenceExpression

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void visitReferenceExpression(PsiReferenceExpression expression) {
  if (read || written) {
    return;
  }
  final PsiElement target = expression.resolve();
  if (variable.equals(target)) {
    if (PsiUtil.isAccessedForWriting(expression)) {
      written  = true;
      return;
    }
    if (PsiUtil.isAccessedForReading(expression)) {
      reference = expression;
      read = true;
      return;
    }
  }
  super.visitReferenceExpression(expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:ConstantValueVariableUseInspection.java

示例4: visitMethod

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void visitMethod(PsiMethod method) {
  super.visitMethod(method);
  if (!PsiUtil.getLanguageLevel(method).isAtLeast(LanguageLevel.JDK_1_7)) return;
  if (AnnotationUtil.isAnnotated(method, "java.lang.SafeVarargs", false)) return;
  if (!method.isVarArgs()) return;

  final PsiParameter[] parameters = method.getParameterList().getParameters();
  final PsiParameter psiParameter = parameters[parameters.length - 1];
  if (!psiParameter.isVarArgs()) return;

  final PsiType type = psiParameter.getType();
  LOG.assertTrue(type instanceof PsiEllipsisType, "type: " + type.getCanonicalText() + "; param: " + psiParameter);

  final PsiType componentType = ((PsiEllipsisType)type).getComponentType();
  if (JavaGenericsUtil.isReifiableType(componentType)) {
    return;
  }
  for (PsiReference reference : ReferencesSearch.search(psiParameter)) {
    final PsiElement element = reference.getElement();
    if (element instanceof PsiExpression && !PsiUtil.isAccessedForReading((PsiExpression)element)) {
      return;
    }
  }
  final PsiIdentifier nameIdentifier = method.getNameIdentifier();
  if (nameIdentifier != null) {
    //if (method.hasModifierProperty(PsiModifier.ABSTRACT)) return;
    //final PsiClass containingClass = method.getContainingClass();
    //if (containingClass == null || containingClass.isInterface()) return; do not add
    registerProblem(method, nameIdentifier);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:PossibleHeapPollutionVarargsInspection.java

示例5: isEffectivelyFinal

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public static boolean isEffectivelyFinal(@NotNull PsiVariable variable, @NotNull PsiElement scope, @Nullable PsiJavaCodeReferenceElement context) {
  boolean effectivelyFinal;
  if (variable instanceof PsiParameter) {
    effectivelyFinal = notAccessedForWriting(variable, new LocalSearchScope(((PsiParameter)variable).getDeclarationScope()));
  }
  else {
    final ControlFlow controlFlow;
    try {
      PsiElement codeBlock = PsiUtil.getVariableCodeBlock(variable, context);
      if (codeBlock == null) return true;
      controlFlow = getControlFlow(codeBlock);
    }
    catch (AnalysisCanceledException e) {
      return true;
    }

    final List<PsiReferenceExpression> readBeforeWriteLocals = ControlFlowUtil.getReadBeforeWriteLocals(controlFlow);
    for (PsiReferenceExpression expression : readBeforeWriteLocals) {
      if (expression.resolve() == variable) {
        return PsiUtil.isAccessedForReading(expression);
      }
    }

    final Collection<ControlFlowUtil.VariableInfo> initializedTwice = ControlFlowUtil.getInitializedTwice(controlFlow);
    effectivelyFinal = !initializedTwice.contains(new ControlFlowUtil.VariableInfo(variable, null));
    if (effectivelyFinal) {
      effectivelyFinal = notAccessedForWriting(variable, new LocalSearchScope(scope));
    }
  }
  return effectivelyFinal;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:HighlightControlFlowUtil.java

示例6: createUsage

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Nullable
public EncapsulateFieldUsageInfo createUsage(@NotNull EncapsulateFieldsDescriptor descriptor,
                                             @NotNull FieldDescriptor fieldDescriptor,
                                             @NotNull PsiReference reference) {
  if (!(reference instanceof PsiReferenceExpression)) return null;

  boolean findSet = descriptor.isToEncapsulateSet();
  boolean findGet = descriptor.isToEncapsulateGet();
  PsiReferenceExpression ref = (PsiReferenceExpression)reference;
  // [Jeka] to avoid recursion in the field's accessors
  if (findGet && isUsedInExistingAccessor(descriptor.getTargetClass(), fieldDescriptor.getGetterPrototype(), ref)) return null;
  if (findSet && isUsedInExistingAccessor(descriptor.getTargetClass(), fieldDescriptor.getSetterPrototype(), ref)) return null;
  if (!findGet) {
    if (!PsiUtil.isAccessedForWriting(ref)) return null;
  }
  if (!findSet || fieldDescriptor.getField().hasModifierProperty(PsiModifier.FINAL)) {
    if (!PsiUtil.isAccessedForReading(ref)) return null;
  }
  if (!descriptor.isToUseAccessorsWhenAccessible()) {
    PsiModifierList newModifierList = createNewModifierList(descriptor);

    PsiClass accessObjectClass = null;
    PsiExpression qualifier = ref.getQualifierExpression();
    if (qualifier != null) {
      accessObjectClass = (PsiClass)PsiUtil.getAccessObjectClass(qualifier).getElement();
    }
    final PsiResolveHelper helper = JavaPsiFacade.getInstance(((PsiReferenceExpression)reference).getProject()).getResolveHelper();
    if (helper.isAccessible(fieldDescriptor.getField(), newModifierList, ref, accessObjectClass, null)) {
      return null;
    }
  }
  return new EncapsulateFieldUsageInfo(ref, fieldDescriptor);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:34,代码来源:JavaEncapsulateFieldHelper.java

示例7: visitReferenceExpression

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void visitReferenceExpression(
  PsiReferenceExpression expression) {
  super.visitReferenceExpression(expression);
  if (!alwaysNegated) {
    return;
  }
  final String referenceName = expression.getReferenceName();
  if (referenceName == null) {
    return;
  }
  if (!referenceName.equals(variable.getName())) {
    return;
  }
  final PsiElement target = expression.resolve();
  if (!variable.equals(target)) {
    return;
  }
  if (!PsiUtil.isAccessedForReading(expression)) {
    return;
  }
  read = true;
  PsiElement parent = expression.getParent();
  while (parent instanceof PsiParenthesizedExpression) {
    parent = parent.getParent();
  }
  if (!(parent instanceof PsiPrefixExpression)) {
    alwaysNegated = false;
    return;
  }
  final PsiPrefixExpression prefixExpression =
    (PsiPrefixExpression)parent;
  final IElementType tokenType =
    prefixExpression.getOperationTokenType();
  if (!JavaTokenType.EXCL.equals(tokenType)) {
    alwaysNegated = false;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:BooleanVariableAlwaysNegatedInspectionBase.java


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