Java 类com.intellij.psi.util.MethodSignature 实例源码

项目:intellij-ce-playground    文件:JavaOverridingMethodsSearcher.java   
@Nullable
private static PsiMethod findOverridingMethod(PsiClass inheritor, @NotNull PsiClass parentClass, PsiMethod method) {
  String name = method.getName();
  if (inheritor.findMethodsByName(name, false).length > 0) {
    PsiMethod found = MethodSignatureUtil.findMethodBySuperSignature(inheritor, getSuperSignature(inheritor, parentClass, method), false);
    if (found != null && isAcceptable(found, method)) {
      return found;
    }
  }

  if (parentClass.isInterface() && !inheritor.isInterface()) {  //check for sibling implementation
    final PsiClass superClass = inheritor.getSuperClass();
    if (superClass != null && !superClass.isInheritor(parentClass, true) && superClass.findMethodsByName(name, true).length > 0) {
      MethodSignature signature = getSuperSignature(inheritor, parentClass, method);
      PsiMethod derived = MethodSignatureUtil.findMethodInSuperClassBySignatureInDerived(inheritor, superClass, signature, true);
      if (derived != null && isAcceptable(derived, method)) {
        return derived;
      }
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:LambdaHighlightingUtil.java   
private static boolean checkReturnTypeApplicable(PsiClassType.ClassResolveResult resolveResult, final PsiClass aClass) {
  final MethodSignature methodSignature = LambdaUtil.getFunction(aClass);
  if (methodSignature == null) return false;

  for (PsiTypeParameter parameter : aClass.getTypeParameters()) {
    if (parameter.getExtendsListTypes().length == 0) continue;
    final PsiType substitution = resolveResult.getSubstitutor().substitute(parameter);
    if (substitution instanceof PsiWildcardType && !((PsiWildcardType)substitution).isBounded()) {
      boolean depends = false;
      for (PsiType paramType : methodSignature.getParameterTypes()) {
        if (LambdaUtil.depends(paramType, new LambdaUtil.TypeParamsChecker((PsiMethod)null, aClass) {
          @Override
          public boolean startedInference() {
            return true;
          }
        }, parameter)) {
          depends = true;
          break;
        }
      }
      if (!depends) return true;
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:OverrideImplementMethodAction.java   
private static boolean canImplementOverride(final MethodHierarchyNodeDescriptor descriptor, final MethodHierarchyBrowser methodHierarchyBrowser, final boolean toImplement) {
  final PsiElement psiElement = descriptor.getPsiClass();
  if (!(psiElement instanceof PsiClass)) return false;
  final PsiClass psiClass = (PsiClass)psiElement;
  if (psiClass instanceof PsiSyntheticClass) return false;
  final PsiMethod baseMethod = methodHierarchyBrowser.getBaseMethod();
  if (baseMethod == null) return false;
  final MethodSignature signature = baseMethod.getSignature(PsiSubstitutor.EMPTY);

  Collection<MethodSignature> allOriginalSignatures = toImplement
                                                      ? OverrideImplementUtil.getMethodSignaturesToImplement(psiClass)
                                                      : OverrideImplementUtil.getMethodSignaturesToOverride(psiClass);
  for (final MethodSignature originalSignature : allOriginalSignatures) {
    if (originalSignature.equals(signature)) {
      return true;
    }
  }

  return false;
}
项目:intellij-ce-playground    文件:RenameJavaMethodProcessor.java   
private static void findSubmemberHidesMemberCollisions(final PsiMethod method, final String newName, final List<UsageInfo> result) {
  final PsiClass containingClass = method.getContainingClass();
  if (containingClass == null) return;
  if (method.hasModifierProperty(PsiModifier.PRIVATE)) return;
  Collection<PsiClass> inheritors = ClassInheritorsSearch.search(containingClass, true).findAll();

  MethodSignature oldSignature = method.getSignature(PsiSubstitutor.EMPTY);
  MethodSignature newSignature = MethodSignatureUtil.createMethodSignature(newName, oldSignature.getParameterTypes(),
                                                                           oldSignature.getTypeParameters(),
                                                                           oldSignature.getSubstitutor(),
                                                                           method.isConstructor());
  for (PsiClass inheritor : inheritors) {
    PsiSubstitutor superSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(containingClass, inheritor, PsiSubstitutor.EMPTY);
    final PsiMethod[] methodsByName = inheritor.findMethodsByName(newName, false);
    for (PsiMethod conflictingMethod : methodsByName) {
      if (newSignature.equals(conflictingMethod.getSignature(superSubstitutor))) {
        result.add(new SubmemberHidesMemberUsageInfo(conflictingMethod, method));
        break;
      }
    }
  }
}
项目:intellij-ce-playground    文件:PullUpDialog.java   
@Override
public boolean isMemberEnabled(MemberInfo member) {
  final PsiClass currentSuperClass = getSuperClass();
  if(currentSuperClass == null) return true;
  if (myMemberInfoStorage.getDuplicatedMemberInfos(currentSuperClass).contains(member)) return false;
  if (myMemberInfoStorage.getExtending(currentSuperClass).contains(member.getMember())) return false;
  final boolean isInterface = currentSuperClass.isInterface();
  if (!isInterface) return true;

  PsiElement element = member.getMember();
  if (element instanceof PsiClass && ((PsiClass) element).isInterface()) return true;
  if (element instanceof PsiField) {
    return ((PsiModifierListOwner) element).hasModifierProperty(PsiModifier.STATIC);
  }
  if (element instanceof PsiMethod) {
    final PsiSubstitutor superSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(currentSuperClass, myClass, PsiSubstitutor.EMPTY);
    final MethodSignature signature = ((PsiMethod) element).getSignature(superSubstitutor);
    final PsiMethod superClassMethod = MethodSignatureUtil.findMethodBySignature(currentSuperClass, signature, false);
    if (superClassMethod != null && !PsiUtil.isLanguageLevel8OrHigher(currentSuperClass)) return false;
    return !((PsiModifierListOwner) element).hasModifierProperty(PsiModifier.STATIC) || PsiUtil.isLanguageLevel8OrHigher(currentSuperClass);
  }
  return true;
}
项目:intellij-ce-playground    文件:InterfaceMayBeAnnotatedFunctionalInspection.java   
@Override
public void visitClass(PsiClass aClass) {
  super.visitClass(aClass);
  if (!aClass.isInterface() || AnnotationUtil.isAnnotated(aClass, "java.lang.FunctionalInterface", false)) {
    return;
  }
  if (LambdaHighlightingUtil.checkInterfaceFunctional(aClass) != null) {
    return;
  }
  final List<HierarchicalMethodSignature> candidates = LambdaUtil.findFunctionCandidates(aClass);
  if (candidates == null || candidates.size() != 1) {
    return;
  }
  final MethodSignature signature = candidates.get(0);
  if (signature.getTypeParameters().length > 0) {
    return;
  }
  registerClassError(aClass, aClass);
}
项目:intellij-ce-playground    文件:UnnecessaryJavaDocLinkInspection.java   
public boolean isSuperMethod(PsiMethod superMethodCandidate,
                             PsiMethod derivedMethod) {
  final PsiClass superClassCandidate =
    superMethodCandidate.getContainingClass();
  final PsiClass derivedClass = derivedMethod.getContainingClass();
  if (derivedClass == null || superClassCandidate == null) {
    return false;
  }
  if (!derivedClass.isInheritor(superClassCandidate, false)) {
    return false;
  }
  final PsiSubstitutor superSubstitutor =
    TypeConversionUtil.getSuperClassSubstitutor(
      superClassCandidate, derivedClass,
      PsiSubstitutor.EMPTY);
  final MethodSignature superSignature =
    superMethodCandidate.getSignature(superSubstitutor);
  final MethodSignature derivedSignature =
    derivedMethod.getSignature(PsiSubstitutor.EMPTY);
  return MethodSignatureUtil.isSubsignature(superSignature,
                                            derivedSignature);
}
项目:intellij-ce-playground    文件:UninitializedReadCollector.java   
private boolean blockAssignsVariable(@Nullable PsiCodeBlock block, @NotNull PsiVariable variable,
                                     int stamp, @NotNull Set<MethodSignature> checkedMethods) {
  if (counter != stamp) {
    return true;
  }
  if (block == null) {
    return false;
  }
  final PsiStatement[] statements = block.getStatements();
  for (final PsiStatement statement : statements) {
    if (statementAssignsVariable(statement, variable, stamp, checkedMethods)) {
      return true;
    }
    if (counter != stamp) {
      return true;
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:UninitializedReadCollector.java   
private boolean tryStatementAssignsVariable(@NotNull PsiTryStatement tryStatement, @NotNull PsiVariable variable,
                                            int stamp, @NotNull Set<MethodSignature> checkedMethods) {
  final PsiResourceList resourceList = tryStatement.getResourceList();
  if (resourceList != null) {
    for (PsiResourceListElement resource : resourceList) {
      if (resource instanceof PsiResourceVariable) {
        final PsiExpression initializer = ((PsiResourceVariable)resource).getInitializer();
        if (expressionAssignsVariable(initializer, variable, stamp, checkedMethods)) {
          return true;
        }
      }
    }
  }
  final PsiCodeBlock tryBlock = tryStatement.getTryBlock();
  boolean initializedInTryOrCatch = blockAssignsVariable(tryBlock, variable, stamp, checkedMethods);
  final PsiCodeBlock[] catchBlocks = tryStatement.getCatchBlocks();
  for (final PsiCodeBlock catchBlock : catchBlocks) {
    initializedInTryOrCatch &= blockAssignsVariable(catchBlock, variable, stamp, checkedMethods);
  }
  if (initializedInTryOrCatch) {
    return true;
  }
  final PsiCodeBlock finallyBlock = tryStatement.getFinallyBlock();
  return blockAssignsVariable(finallyBlock, variable, stamp, checkedMethods);
}
项目:intellij-ce-playground    文件:UninitializedReadCollector.java   
private boolean forStatementAssignsVariable(@NotNull PsiForStatement forStatement, @NotNull PsiVariable variable,
                                            int stamp, @NotNull Set<MethodSignature> checkedMethods) {
  final PsiStatement initialization = forStatement.getInitialization();
  if (statementAssignsVariable(initialization, variable, stamp, checkedMethods)) {
    return true;
  }
  final PsiExpression condition = forStatement.getCondition();
  if (expressionAssignsVariable(condition, variable, stamp, checkedMethods)) {
    return true;
  }
  if (BoolUtils.isTrue(condition)) {
    final PsiStatement body = forStatement.getBody();
    if (statementAssignsVariable(body, variable, stamp, checkedMethods)) {
      return true;
    }
    final PsiStatement update = forStatement.getUpdate();
    if (statementAssignsVariable(update, variable, stamp, checkedMethods)) {
      return true;
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:UninitializedReadCollector.java   
private boolean assignmentExpressionAssignsVariable(@NotNull PsiAssignmentExpression assignment, @NotNull PsiVariable variable,
  int stamp, @NotNull Set<MethodSignature> checkedMethods) {
  final PsiExpression lhs = assignment.getLExpression();
  if (expressionAssignsVariable(lhs, variable, stamp, checkedMethods)) {
    return true;
  }
  final PsiExpression rhs = assignment.getRExpression();
  if (expressionAssignsVariable(rhs, variable, stamp, checkedMethods)) {
    return true;
  }
  if (lhs instanceof PsiReferenceExpression) {
    final PsiElement element = ((PsiReference)lhs).resolve();
    if (element != null && element.equals(variable)) {
      return true;
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:UninitializedReadCollector.java   
private boolean referenceExpressionAssignsVariable(@NotNull PsiReferenceExpression referenceExpression, @NotNull PsiVariable variable,
                                                   int stamp, @NotNull Set<MethodSignature> checkedMethods) {
  final PsiExpression qualifierExpression = referenceExpression.getQualifierExpression();
  if (expressionAssignsVariable(qualifierExpression, variable, stamp, checkedMethods)) {
    return true;
  }
  if (variable.equals(referenceExpression.resolve())) {
    final PsiElement parent = referenceExpression.getParent();
    if (parent instanceof PsiAssignmentExpression) {
      final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)parent;
      final PsiExpression rhs = assignmentExpression.getRExpression();
      if (rhs != null && rhs.equals(referenceExpression)) {
        checkReferenceExpression(referenceExpression, variable, qualifierExpression);
      }
    }
    else {
      checkReferenceExpression(referenceExpression, variable, qualifierExpression);
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:UninitializedReadCollector.java   
private boolean newExpressionAssignsVariable(@NotNull PsiNewExpression newExpression, @NotNull PsiVariable variable,
                                             int stamp, @NotNull Set<MethodSignature> checkedMethods) {
  final PsiExpressionList argumentList = newExpression.getArgumentList();
  if (argumentList != null) {
    final PsiExpression[] args = argumentList.getExpressions();
    for (final PsiExpression arg : args) {
      if (expressionAssignsVariable(arg, variable, stamp, checkedMethods)) {
        return true;
      }
    }
  }
  final PsiArrayInitializerExpression arrayInitializer = newExpression.getArrayInitializer();
  if (expressionAssignsVariable(arrayInitializer, variable, stamp, checkedMethods)) {
    return true;
  }
  final PsiExpression[] arrayDimensions = newExpression.getArrayDimensions();
  for (final PsiExpression dim : arrayDimensions) {
    if (expressionAssignsVariable(dim, variable, stamp, checkedMethods)) {
      return true;
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:InitializationUtils.java   
private static boolean blockAssignsVariableOrFails(@Nullable PsiCodeBlock block, @NotNull PsiVariable variable,
                                                   @NotNull Set<MethodSignature> checkedMethods, boolean strict) {
  if (block == null) {
    return false;
  }
  int assignmentCount = 0;
  for (final PsiStatement statement : block.getStatements()) {
    if (statementAssignsVariableOrFails(statement, variable, checkedMethods, strict)) {
      if (strict) {
        assignmentCount++;
      }
      else {
        return true;
      }
    }
  }
  return assignmentCount == 1;
}
项目:intellij-ce-playground    文件:InitializationUtils.java   
private static boolean tryStatementAssignsVariableOrFails(@NotNull PsiTryStatement tryStatement, PsiVariable variable,
                                                          @NotNull Set<MethodSignature> checkedMethods, boolean strict) {
  final PsiResourceList resourceList = tryStatement.getResourceList();
  if (resourceList != null) {
    for (PsiResourceListElement resource : resourceList) {
      if (resource instanceof PsiResourceVariable) {
        final PsiExpression initializer = ((PsiResourceVariable)resource).getInitializer();
        if (expressionAssignsVariableOrFails(initializer, variable, checkedMethods, strict)) {
          return true;
        }
      }
    }
  }
  boolean initializedInTryAndCatch = blockAssignsVariableOrFails(tryStatement.getTryBlock(), variable, checkedMethods, strict);
  final PsiCodeBlock[] catchBlocks = tryStatement.getCatchBlocks();
  for (final PsiCodeBlock catchBlock : catchBlocks) {
    if (strict) {
      initializedInTryAndCatch &= ExceptionUtils.blockThrowsException(catchBlock);
    }
    else {
      initializedInTryAndCatch &= blockAssignsVariableOrFails(catchBlock, variable, checkedMethods, strict);
    }
  }
  return initializedInTryAndCatch || blockAssignsVariableOrFails(tryStatement.getFinallyBlock(), variable, checkedMethods, strict);
}
项目:intellij-ce-playground    文件:InitializationUtils.java   
private static boolean ifStatementAssignsVariableOrFails(@NotNull PsiIfStatement ifStatement, PsiVariable variable,
                                                         @NotNull Set<MethodSignature> checkedMethods, boolean strict) {
  final PsiExpression condition = ifStatement.getCondition();
  if (expressionAssignsVariableOrFails(condition, variable, checkedMethods, strict)) {
    return true;
  }
  final PsiStatement thenBranch = ifStatement.getThenBranch();
  if (BoolUtils.isTrue(condition)) {
    return statementAssignsVariableOrFails(thenBranch, variable, checkedMethods, strict);
  }
  final PsiStatement elseBranch = ifStatement.getElseBranch();
  if (BoolUtils.isFalse(condition)) {
    return statementAssignsVariableOrFails(elseBranch, variable, checkedMethods, strict);
  }
  return statementAssignsVariableOrFails(thenBranch, variable, checkedMethods, strict) &&
         statementAssignsVariableOrFails(elseBranch, variable, checkedMethods, strict);
}
项目:intellij-ce-playground    文件:InitializationUtils.java   
private static boolean forStatementAssignsVariableOrFails(@NotNull PsiForStatement forStatement, PsiVariable variable,
                                                          @NotNull Set<MethodSignature> checkedMethods, boolean strict) {
  if (statementAssignsVariableOrFails(forStatement.getInitialization(), variable, checkedMethods, strict)) {
    return true;
  }
  final PsiExpression condition = forStatement.getCondition();
  if (expressionAssignsVariableOrFails(condition, variable, checkedMethods, strict)) {
    return true;
  }
  if (BoolUtils.isTrue(condition)) {
    if (statementAssignsVariableOrFails(forStatement.getBody(), variable, checkedMethods, strict)) {
      return true;
    }
    if (statementAssignsVariableOrFails(forStatement.getUpdate(), variable, checkedMethods, strict)) {
      return true;
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:InitializationUtils.java   
private static boolean newExpressionAssignsVariableOrFails(@NotNull PsiNewExpression newExpression, PsiVariable variable,
                                                           @NotNull Set<MethodSignature> checkedMethods, boolean strict) {
  final PsiExpressionList argumentList = newExpression.getArgumentList();
  if (argumentList != null) {
    for (final PsiExpression argument : argumentList.getExpressions()) {
      if (expressionAssignsVariableOrFails(argument, variable, checkedMethods, strict)) {
        return true;
      }
    }
  }
  if (expressionAssignsVariableOrFails(newExpression.getArrayInitializer(), variable, checkedMethods, strict)) {
    return true;
  }
  for (final PsiExpression dimension : newExpression.getArrayDimensions()) {
    if (expressionAssignsVariableOrFails(dimension, variable, checkedMethods, strict)) {
      return true;
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:DelegatedMethodsContributor.java   
@Override
public void collectMethods(@NotNull final GrTypeDefinition clazz, @NotNull Collection<PsiMethod> collector) {
  Set<PsiClass> processed = new HashSet<PsiClass>();

  if (!checkForDelegate(clazz)) return;

  Map<MethodSignature, PsiMethod> signatures = new THashMap<MethodSignature, PsiMethod>(MethodSignatureUtil.METHOD_PARAMETERS_ERASURE_EQUALITY);
  initializeSignatures(clazz, PsiSubstitutor.EMPTY, signatures, processed);

  List<PsiMethod> methods = new ArrayList<PsiMethod>();
  process(clazz, PsiSubstitutor.EMPTY, true, new HashSet<PsiClass>(), processed, methods, clazz, false);

  final Set<PsiMethod> result = new LinkedHashSet<PsiMethod>();
  for (PsiMethod method : methods) {
    addMethodChecked(signatures, method, PsiSubstitutor.EMPTY, result);
  }

  collector.addAll(result);
}
项目:intellij-ce-playground    文件:DelegatedMethodsContributor.java   
/**
 * Adds 'method' to 'signatures' if it doesn't yet contain any method with the same signature or replaces abstract methods
 */
private static void addMethodChecked(Map<MethodSignature, PsiMethod> signatures,
                                     PsiMethod method,
                                     PsiSubstitutor substitutor,
                                     @Nullable Set<PsiMethod> resultSet) {
  if (method.isConstructor()) return;
  if (method.hasModifierProperty(PsiModifier.STATIC)) return;

  final MethodSignature signature = method.getSignature(substitutor);
  final PsiMethod old = signatures.get(signature);

  if (old != null) {
    //if (method.hasModifierProperty(PsiModifier.ABSTRACT)) return;
    if (!old.hasModifierProperty(PsiModifier.ABSTRACT)) return;

    if (resultSet != null) resultSet.remove(old);
  }

  signatures.put(signature, method);
  if (resultSet != null) resultSet.add(method);
}
项目:intellij-ce-playground    文件:ClosureToSamConverter.java   
@Override
public Boolean isConvertible(@NotNull PsiType ltype, @NotNull PsiType rtype, @NotNull final GroovyPsiElement context) {
  if (rtype instanceof GrClosureType &&
      ltype instanceof PsiClassType &&
      isSamConversionAllowed(context) &&
      !TypesUtil.isClassType(ltype, GroovyCommonClassNames.GROOVY_LANG_CLOSURE)) {
    MethodSignature signature = findSAMSignature(ltype);
    if (signature != null) {
      final PsiType[] samParameterTypes = signature.getParameterTypes();

      GrSignature closureSignature = ((GrClosureType)rtype).getSignature();

      boolean raw = ((PsiClassType)ltype).isRaw();
      if (raw) return true;

      if (GrClosureSignatureUtil.isSignatureApplicable(closureSignature, samParameterTypes, context)) {
        return true;
      }
    }
  }

  return null;
}
项目:intellij-ce-playground    文件:FromAbstractTypeMethodsHintProcessor.java   
@NotNull
@Override
public List<PsiType[]> inferExpectedSignatures(@NotNull PsiMethod method,
                                               @NotNull PsiSubstitutor substitutor,
                                               @NotNull String[] options) {
  if (options.length != 1) return Collections.emptyList();

  String qname = options[0];
  PsiClass aClass = JavaPsiFacade.getInstance(method.getProject()).findClass(qname, method.getResolveScope());
  if (aClass == null) return Collections.emptyList();

  Collection<MethodSignature> abstractSignatures = OverrideImplementExploreUtil.getMethodSignaturesToImplement(aClass);
  return ContainerUtil.map(abstractSignatures, new Function<MethodSignature, PsiType[]>() {
    @Override
    public PsiType[] fun(MethodSignature signature) {
      return signature.getParameterTypes();
    }
  });
}
项目:intellij-ce-playground    文件:GrClosureSignatureUtil.java   
@NotNull
public static MultiMap<MethodSignature, PsiMethod> findRawMethodSignatures(@NotNull PsiMethod[] methods, @NotNull PsiClass clazz) {
  Map<PsiTypeParameter, PsiType> initialMap = ContainerUtil.newHashMap();

  for (PsiTypeParameter parameter : clazz.getTypeParameters()) {
    initialMap.put(parameter, null);
  }

  final PsiSubstitutor initialSubstitutor = PsiSubstitutorImpl.createSubstitutor(initialMap);

  MultiMap<MethodSignature, PsiMethod> result = new MultiMap<MethodSignature, PsiMethod>();
  for (PsiMethod method : methods) {
    final PsiMethod actual = method instanceof GrReflectedMethod ? ((GrReflectedMethod)method).getBaseMethod() : method;

    PsiSubstitutor substitutor = calcRawSubstitutor(initialMap, initialSubstitutor, actual);
    result.putValue(method.getSignature(substitutor), actual);
  }

  return result;
}
项目:intellij-ce-playground    文件:GrMethodConflictUtil.java   
private static void checkForMethodSignatureOverload(PsiClass clazz,
                                                    GrMethod prototype,
                                                    GrMethod refactoredMethod,
                                                    MultiMap<PsiElement, String> conflicts,
                                                    boolean excludeJavaConflicts,
                                                    List<MethodSignature> prototypeSignatures) {
  if (excludeJavaConflicts) {
    prototypeSignatures.remove(prototype.getSignature(PsiSubstitutor.EMPTY));
  }

  String newName = prototype.getName();
  PsiMethod[] methods = clazz.findMethodsByName(newName, false);
  MultiMap<MethodSignature, PsiMethod> signatures = GrClosureSignatureUtil.findRawMethodSignatures(methods, clazz);
  for (MethodSignature prototypeSignature : prototypeSignatures) {
    for (PsiMethod method : signatures.get(prototypeSignature)) {
      if (method != refactoredMethod) {
        String signaturePresentation = GroovyPresentationUtil.getSignaturePresentation(prototypeSignature);
        conflicts.putValue(method, GroovyRefactoringBundle.message("method.duplicate", signaturePresentation,
                                                                   RefactoringUIUtil.getDescription(clazz, false)));
        break;
      }
    }
  }
}
项目:intellij-ce-playground    文件:GrPullUpDialog.java   
@Override
public boolean isMemberEnabled(GrMemberInfo member) {
  PsiClass currentSuperClass = getSuperClass();
  if(currentSuperClass == null) return true;
  if (myMemberInfoStorage.getDuplicatedMemberInfos(currentSuperClass).contains(member)) return false;
  if (myMemberInfoStorage.getExtending(currentSuperClass).contains(member.getMember())) return false;
  if (!currentSuperClass.isInterface()) return true;

  PsiElement element = member.getMember();
  if (element instanceof PsiClass && ((PsiClass) element).isInterface()) return true;
  if (element instanceof PsiField) {
    return ((PsiModifierListOwner) element).hasModifierProperty(PsiModifier.STATIC);
  }
  if (element instanceof PsiMethod) {
    if (currentSuperClass.isInterface()) {
      final PsiSubstitutor superSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(currentSuperClass, myClass, PsiSubstitutor.EMPTY);
      final MethodSignature signature = ((PsiMethod)element).getSignature(superSubstitutor);
      final PsiMethod superClassMethod = MethodSignatureUtil.findMethodBySignature(currentSuperClass, signature, false);
      if (superClassMethod != null) return false;
    }
    return !((PsiModifierListOwner) element).hasModifierProperty(PsiModifier.STATIC);
  }
  return true;
}
项目:tools-idea    文件:JavaOverridingMethodsSearcher.java   
@Nullable
private static PsiMethod findOverridingMethod(PsiClass inheritor, @NotNull PsiClass parentClass, PsiMethod method) {
  PsiSubstitutor substitutor = inheritor.isInheritor(parentClass, true) ?
                               TypeConversionUtil.getSuperClassSubstitutor(parentClass, inheritor, PsiSubstitutor.EMPTY) :
                               PsiSubstitutor.EMPTY;
  MethodSignature signature = method.getSignature(substitutor);
  PsiMethod found = MethodSignatureUtil.findMethodBySuperSignature(inheritor, signature, false);
  if (found != null && isAcceptable(found, method)) {
    return found;
  }

  if (parentClass.isInterface() && !inheritor.isInterface()) {  //check for sibling implementation
    final PsiClass superClass = inheritor.getSuperClass();
    if (superClass != null && !superClass.isInheritor(parentClass, true)) {
      PsiMethod derived = MethodSignatureUtil.findMethodInSuperClassBySignatureInDerived(inheritor, superClass, signature, true);
      if (derived != null && isAcceptable(derived, method)) {
        return derived;
      }
    }
  }
  return null;
}
项目:tools-idea    文件:OverrideImplementExploreUtil.java   
@Override
public int compare(MethodSignature o1, MethodSignature o2) {
  if (o1 instanceof MethodSignatureBackedByPsiMethod && o2 instanceof MethodSignatureBackedByPsiMethod) {
    PsiMethod m1 = ((MethodSignatureBackedByPsiMethod)o1).getMethod();
    PsiMethod m2 = ((MethodSignatureBackedByPsiMethod)o2).getMethod();
    PsiClass c1 = m1.getContainingClass();
    PsiClass c2 = m2.getContainingClass();
    if (c1 != null && c2 != null) {
      if (c1 == c2) {
        final List<PsiMethod> methods = Arrays.asList(c1.getMethods());
        return methods.indexOf(m1) - methods.indexOf(m2);
      }

      if (c1.isInheritor(c2, true)) return -1;
      if (c2.isInheritor(c1, true)) return 1;

      return StringUtil.notNullize(c1.getName()).compareTo(StringUtil.notNullize(c2.getName()));
    }
    return m1.getTextOffset() - m2.getTextOffset();
  }
  return 0;
}
项目:tools-idea    文件:LambdaHighlightingUtil.java   
private static boolean checkReturnTypeApplicable(PsiClassType.ClassResolveResult resolveResult, final PsiClass aClass) {
  final MethodSignature methodSignature = LambdaUtil.getFunction(aClass);
  if (methodSignature == null) return false;

  for (PsiTypeParameter parameter : aClass.getTypeParameters()) {
    if (parameter.getExtendsListTypes().length == 0) continue;
    boolean depends = false;
    final PsiType substitution = resolveResult.getSubstitutor().substitute(parameter);
    if (substitution instanceof PsiWildcardType && !((PsiWildcardType)substitution).isBounded()) {
      for (PsiType paramType : methodSignature.getParameterTypes()) {
        if (LambdaUtil.depends(paramType, new LambdaUtil.TypeParamsChecker((PsiMethod)null, aClass) {
          @Override
          public boolean startedInference() {
            return true;
          }
        }, parameter)) {
          depends = true;
          break;
        }
      }
      if (!depends) return true;
    }
  }
  return false;
}
项目:tools-idea    文件:OverrideImplementMethodAction.java   
private static boolean canImplementOverride(final MethodHierarchyNodeDescriptor descriptor, final MethodHierarchyBrowser methodHierarchyBrowser, final boolean toImplement) {
  final PsiClass psiClass = descriptor.getPsiClass();
  if (psiClass == null || psiClass instanceof JspClass) return false;
  final PsiMethod baseMethod = methodHierarchyBrowser.getBaseMethod();
  if (baseMethod == null) return false;
  final MethodSignature signature = baseMethod.getSignature(PsiSubstitutor.EMPTY);

  Collection<MethodSignature> allOriginalSignatures = toImplement
                                                      ? OverrideImplementUtil.getMethodSignaturesToImplement(psiClass)
                                                      : OverrideImplementUtil.getMethodSignaturesToOverride(psiClass);
  for (final MethodSignature originalSignature : allOriginalSignatures) {
    if (originalSignature.equals(signature)) {
      return true;
    }
  }

  return false;
}
项目:tools-idea    文件:RenameJavaMethodProcessor.java   
private static void findSubmemberHidesMemberCollisions(final PsiMethod method, final String newName, final List<UsageInfo> result) {
  final PsiClass containingClass = method.getContainingClass();
  if (containingClass == null) return;
  if (method.hasModifierProperty(PsiModifier.PRIVATE)) return;
  Collection<PsiClass> inheritors = ClassInheritorsSearch.search(containingClass, true).findAll();

  MethodSignature oldSignature = method.getSignature(PsiSubstitutor.EMPTY);
  MethodSignature newSignature = MethodSignatureUtil.createMethodSignature(newName, oldSignature.getParameterTypes(),
                                                                           oldSignature.getTypeParameters(),
                                                                           oldSignature.getSubstitutor(),
                                                                           method.isConstructor());
  for (PsiClass inheritor : inheritors) {
    PsiSubstitutor superSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(containingClass, inheritor, PsiSubstitutor.EMPTY);
    final PsiMethod[] methodsByName = inheritor.findMethodsByName(newName, false);
    for (PsiMethod conflictingMethod : methodsByName) {
      if (newSignature.equals(conflictingMethod.getSignature(superSubstitutor))) {
        result.add(new SubmemberHidesMemberUsageInfo(conflictingMethod, method));
        break;
      }
    }
  }
}
项目:tools-idea    文件:PullUpDialog.java   
public boolean isMemberEnabled(MemberInfo member) {
  PsiClass currentSuperClass = getSuperClass();
  if(currentSuperClass == null) return true;
  if (myMemberInfoStorage.getDuplicatedMemberInfos(currentSuperClass).contains(member)) return false;
  if (myMemberInfoStorage.getExtending(currentSuperClass).contains(member.getMember())) return false;
  if (!currentSuperClass.isInterface()) return true;

  PsiElement element = member.getMember();
  if (element instanceof PsiClass && ((PsiClass) element).isInterface()) return true;
  if (element instanceof PsiField) {
    return ((PsiModifierListOwner) element).hasModifierProperty(PsiModifier.STATIC);
  }
  if (element instanceof PsiMethod) {
    if (currentSuperClass.isInterface()) {
      final PsiSubstitutor superSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(currentSuperClass, myClass, PsiSubstitutor.EMPTY);
      final MethodSignature signature = ((PsiMethod) element).getSignature(superSubstitutor);
      final PsiMethod superClassMethod = MethodSignatureUtil.findMethodBySignature(currentSuperClass, signature, false);
      if (superClassMethod != null) return false;
    }
    return !((PsiModifierListOwner) element).hasModifierProperty(PsiModifier.STATIC);
  }
  return true;
}
项目:tools-idea    文件:UnnecessaryJavaDocLinkInspection.java   
public boolean isSuperMethod(PsiMethod superMethodCandidate,
                             PsiMethod derivedMethod) {
  final PsiClass superClassCandidate =
    superMethodCandidate.getContainingClass();
  final PsiClass derivedClass = derivedMethod.getContainingClass();
  if (derivedClass == null || superClassCandidate == null) {
    return false;
  }
  if (!derivedClass.isInheritor(superClassCandidate, false)) {
    return false;
  }
  final PsiSubstitutor superSubstitutor =
    TypeConversionUtil.getSuperClassSubstitutor(
      superClassCandidate, derivedClass,
      PsiSubstitutor.EMPTY);
  final MethodSignature superSignature =
    superMethodCandidate.getSignature(superSubstitutor);
  final MethodSignature derivedSignature =
    derivedMethod.getSignature(PsiSubstitutor.EMPTY);
  return MethodSignatureUtil.isSubsignature(superSignature,
                                            derivedSignature);
}
项目:tools-idea    文件:UninitializedReadCollector.java   
private boolean blockAssignsVariable(@Nullable PsiCodeBlock block, @NotNull PsiVariable variable,
                                     int stamp, @NotNull Set<MethodSignature> checkedMethods) {
  if (counter != stamp) {
    return true;
  }
  if (block == null) {
    return false;
  }
  final PsiStatement[] statements = block.getStatements();
  for (final PsiStatement statement : statements) {
    if (statementAssignsVariable(statement, variable, stamp, checkedMethods)) {
      return true;
    }
    if (counter != stamp) {
      return true;
    }
  }
  return false;
}
项目:tools-idea    文件:UninitializedReadCollector.java   
private boolean tryStatementAssignsVariable(@NotNull PsiTryStatement tryStatement, @NotNull PsiVariable variable,
                                            int stamp, @NotNull Set<MethodSignature> checkedMethods) {
  final PsiResourceList resourceList = tryStatement.getResourceList();
  if (resourceList != null) {
    final List<PsiResourceVariable> resourceVariables = resourceList.getResourceVariables();
    for (PsiResourceVariable resourceVariable : resourceVariables) {
      final PsiExpression initializer = resourceVariable.getInitializer();
      if (expressionAssignsVariable(initializer, variable, stamp, checkedMethods)) {
        return true;
      }
    }
  }
  final PsiCodeBlock tryBlock = tryStatement.getTryBlock();
  boolean initializedInTryOrCatch = blockAssignsVariable(tryBlock, variable, stamp, checkedMethods);
  final PsiCodeBlock[] catchBlocks = tryStatement.getCatchBlocks();
  for (final PsiCodeBlock catchBlock : catchBlocks) {
    initializedInTryOrCatch &= blockAssignsVariable(catchBlock, variable, stamp, checkedMethods);
  }
  if (initializedInTryOrCatch) {
    return true;
  }
  final PsiCodeBlock finallyBlock = tryStatement.getFinallyBlock();
  return blockAssignsVariable(finallyBlock, variable, stamp, checkedMethods);
}
项目:tools-idea    文件:UninitializedReadCollector.java   
private boolean forStatementAssignsVariable(@NotNull PsiForStatement forStatement, @NotNull PsiVariable variable,
                                            int stamp, @NotNull Set<MethodSignature> checkedMethods) {
  final PsiStatement initialization = forStatement.getInitialization();
  if (statementAssignsVariable(initialization, variable, stamp, checkedMethods)) {
    return true;
  }
  final PsiExpression condition = forStatement.getCondition();
  if (expressionAssignsVariable(condition, variable, stamp, checkedMethods)) {
    return true;
  }
  if (BoolUtils.isTrue(condition)) {
    final PsiStatement body = forStatement.getBody();
    if (statementAssignsVariable(body, variable, stamp, checkedMethods)) {
      return true;
    }
    final PsiStatement update = forStatement.getUpdate();
    if (statementAssignsVariable(update, variable, stamp, checkedMethods)) {
      return true;
    }
  }
  return false;
}
项目:tools-idea    文件:UninitializedReadCollector.java   
private boolean assignmentExpressionAssignsVariable(@NotNull PsiAssignmentExpression assignment, @NotNull PsiVariable variable,
  int stamp, @NotNull Set<MethodSignature> checkedMethods) {
  final PsiExpression lhs = assignment.getLExpression();
  if (expressionAssignsVariable(lhs, variable, stamp, checkedMethods)) {
    return true;
  }
  final PsiExpression rhs = assignment.getRExpression();
  if (expressionAssignsVariable(rhs, variable, stamp, checkedMethods)) {
    return true;
  }
  if (lhs instanceof PsiReferenceExpression) {
    final PsiElement element = ((PsiReference)lhs).resolve();
    if (element != null && element.equals(variable)) {
      return true;
    }
  }
  return false;
}
项目:tools-idea    文件:UninitializedReadCollector.java   
private boolean referenceExpressionAssignsVariable(@NotNull PsiReferenceExpression referenceExpression, @NotNull PsiVariable variable,
                                                   int stamp, @NotNull Set<MethodSignature> checkedMethods) {
  final PsiExpression qualifierExpression = referenceExpression.getQualifierExpression();
  if (expressionAssignsVariable(qualifierExpression, variable, stamp, checkedMethods)) {
    return true;
  }
  if (variable.equals(referenceExpression.resolve())) {
    final PsiElement parent = referenceExpression.getParent();
    if (parent instanceof PsiAssignmentExpression) {
      final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)parent;
      final PsiExpression rhs = assignmentExpression.getRExpression();
      if (rhs != null && rhs.equals(referenceExpression)) {
        checkReferenceExpression(referenceExpression, variable, qualifierExpression);
      }
    }
    else {
      checkReferenceExpression(referenceExpression, variable, qualifierExpression);
    }
  }
  return false;
}
项目:tools-idea    文件:UninitializedReadCollector.java   
private boolean newExpressionAssignsVariable(@NotNull PsiNewExpression newExpression, @NotNull PsiVariable variable,
                                             int stamp, @NotNull Set<MethodSignature> checkedMethods) {
  final PsiExpressionList argumentList = newExpression.getArgumentList();
  if (argumentList != null) {
    final PsiExpression[] args = argumentList.getExpressions();
    for (final PsiExpression arg : args) {
      if (expressionAssignsVariable(arg, variable, stamp, checkedMethods)) {
        return true;
      }
    }
  }
  final PsiArrayInitializerExpression arrayInitializer = newExpression.getArrayInitializer();
  if (expressionAssignsVariable(arrayInitializer, variable, stamp, checkedMethods)) {
    return true;
  }
  final PsiExpression[] arrayDimensions = newExpression.getArrayDimensions();
  for (final PsiExpression dim : arrayDimensions) {
    if (expressionAssignsVariable(dim, variable, stamp, checkedMethods)) {
      return true;
    }
  }
  return false;
}
项目:tools-idea    文件:InitializationUtils.java   
private static boolean blockAssignsVariableOrFails(
  @Nullable PsiCodeBlock block, @NotNull PsiVariable variable,
  @NotNull Set<MethodSignature> checkedMethods, boolean strict) {
  if (block == null) {
    return false;
  }
  final PsiStatement[] statements = block.getStatements();
  int assignmentCount = 0;
  for (final PsiStatement statement : statements) {
    if (statementAssignsVariableOrFails(statement, variable,
                                        checkedMethods, strict)) {
      if (strict) {
        assignmentCount++;
      }
      else {
        return true;
      }
    }
  }
  return assignmentCount == 1;
}
项目:tools-idea    文件:InitializationUtils.java   
private static boolean declarationStatementAssignsVariableOrFails(
  PsiDeclarationStatement declarationStatement, PsiVariable variable,
  Set<MethodSignature> checkedMethods, boolean strict) {
  final PsiElement[] elements =
    declarationStatement.getDeclaredElements();
  for (PsiElement element : elements) {
    if (element instanceof PsiVariable) {
      final PsiVariable declaredVariable = (PsiVariable)element;
      final PsiExpression initializer =
        declaredVariable.getInitializer();
      if (expressionAssignsVariableOrFails(initializer, variable,
                                           checkedMethods, strict)) {
        return true;
      }
    }
  }
  return false;
}