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


Java Query.findFirst方法代码示例

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


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

示例1: getAssignmentToInline

import com.intellij.util.Query; //导入方法依赖的package包/类
private static Pair<PyStatement, Boolean> getAssignmentToInline(ScopeOwner containerBlock, PyReferenceExpression expr,
                                                                PyTargetExpression local, Project project) {
  if (expr != null) {
    try {
      final List<ReadWriteInstruction> candidates = PyDefUseUtil.getLatestDefs(containerBlock, local.getName(), expr, true);
      if (candidates.size() == 1) {
        final PyStatement expression = getAssignmentByLeftPart((PyElement)candidates.get(0).getElement());
        return Pair.create(expression, false);
      }
      return Pair.create(null, candidates.size() > 0);
    }
    catch (PyDefUseUtil.InstructionNotFoundException ignored) {
    }
  }
  final Query<PsiReference> query = ReferencesSearch.search(local, GlobalSearchScope.allScope(project), false);
  final PsiReference first = query.findFirst();

  final PyElement lValue = first != null ? (PyElement)first.resolve() : null;
  return lValue != null ? Pair.create(getAssignmentByLeftPart(lValue), false) : EMPTY_DEF_RESULT;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:PyInlineLocalHandler.java

示例2: buildFixes

import com.intellij.util.Query; //导入方法依赖的package包/类
@NotNull
@Override
protected InspectionGadgetsFix[] buildFixes(Object... infos) {
  final List<InspectionGadgetsFix> fixes = new ArrayList<InspectionGadgetsFix>();
  final PsiClass aClass = (PsiClass)infos[0];
  final PsiMethod constructor = getNullArgConstructor(aClass);
  if (constructor == null) {
    fixes.add(new CreateEmptyPrivateConstructor());
  }
  else {
    final Query<PsiReference> query = ReferencesSearch.search(constructor, constructor.getUseScope());
    final PsiReference reference = query.findFirst();
    if (reference == null) {
      fixes.add(new MakeConstructorPrivateFix());
    }
  }
  AddToIgnoreIfAnnotatedByListQuickFix.build(aClass, ignorableAnnotations, fixes);
  return fixes.toArray(new InspectionGadgetsFix[fixes.size()]);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:UtilityClassWithoutPrivateConstructorInspection.java

示例3: visitMethod

import com.intellij.util.Query; //导入方法依赖的package包/类
@Override
public void visitMethod(PsiMethod method) {
  super.visitMethod(method);
  if (!TestUtils.isJUnitTestMethod(method)) {
    return;
  }
  final PsiReferenceList throwsList = method.getThrowsList();
  final PsiJavaCodeReferenceElement[] referenceElements =
    throwsList.getReferenceElements();
  if (referenceElements.length < 2) {
    return;
  }

  final Query<PsiReference> query =
    MethodReferencesSearch.search(method);
  final PsiReference firstReference = query.findFirst();
  if (firstReference != null) {
    return;
  }
  registerError(throwsList);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:MultipleExceptionsDeclaredOnTestMethodInspection.java

示例4: visitMethod

import com.intellij.util.Query; //导入方法依赖的package包/类
@Override
public void visitMethod(@NotNull PsiMethod method) {
  final PsiParameterList parameterList = method.getParameterList();
  if (parameterList.getParametersCount() == 0) {
    return;
  }
  final Query<MethodSignatureBackedByPsiMethod> query =
    SuperMethodsSearch.search(
      method, method.getContainingClass(), true, false);
  final MethodSignatureBackedByPsiMethod methodSignature =
    query.findFirst();
  if (methodSignature == null) {
    return;
  }
  final PsiMethod superMethod = methodSignature.getMethod();
  final PsiParameter[] parameters = parameterList.getParameters();
  checkParameters(superMethod, parameters);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ParameterNameDiffersFromOverriddenParameterInspectionBase.java

示例5: isUnused

import com.intellij.util.Query; //导入方法依赖的package包/类
private static boolean isUnused(PsiElement obj, Query<PsiReference> query) {
    if (obj instanceof XsltParameter) {
        final Collection<PsiReference> references = query.findAll();
        int n = references.size();
        for (PsiReference reference : references) {
            final PsiElement element = reference.getElement();
            if (element instanceof XmlAttributeValue) {
                final XmlAttribute parent = (XmlAttribute)element.getParent();
                if ("name".equals(parent.getName())) {
                    final XmlTag tag = parent.getParent();
                    if (tag != null && "with-param".equals(tag.getLocalName())) {
                        n--;
                    }
                }
            }
        }
        return n == 0;
    } else {
        return query.findFirst() == null;
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:XsltValidator.java

示例6: findPackage

import com.intellij.util.Query; //导入方法依赖的package包/类
@Override
@Nullable
public PsiPackage findPackage(@NotNull String packageName) {
  Query<VirtualFile> dirs = myPackageIndex.getDirsByPackageName(packageName, true);
  if (dirs.findFirst() == null) return null;
  return new PsiPackageImpl(myManager, packageName);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:JavaFileManagerImpl.java

示例7: calculateResult

import com.intellij.util.Query; //导入方法依赖的package包/类
@Override
public Result calculateResult(@NotNull Expression[] expressions, ExpressionContext expressionContext) {
  final Query<PsiMember> psiMembers = findAnnotated(expressionContext, expressions);

  if (psiMembers != null) {
    final PsiMember member = psiMembers.findFirst();

    if (member != null) {
      return new TextResult(member instanceof PsiClass ? ((PsiClass)member).getQualifiedName():member.getName());
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:AnnotatedMacro.java

示例8: doRefactorImpl

import com.intellij.util.Query; //导入方法依赖的package包/类
@Override
protected void doRefactorImpl(@NotNull final Project project,
                              @NotNull final PyClass classUnderRefactoring,
                              @NotNull final PyMemberInfoStorage infoStorage,
                              @NotNull Editor editor) {

  //TODO: Move to presenter?
  final Query<PyClass> query = PyClassInheritorsSearch.search(classUnderRefactoring, false);
  if (query.findFirst() == null) {
    final String message = RefactoringBundle.message("class.0.does.not.have.inheritors", classUnderRefactoring.getName());
    CommonRefactoringUtil.showErrorHint(project, editor, message, getTitle(), getHelpId());
    return;
  }

  ViewPresenterUtils
    .linkViewWithPresenterAndLaunch(PyPushDownPresenter.class, PyPushDownView.class, new Creator<PyPushDownView, PyPushDownPresenter>() {
      @NotNull
      @Override
      public PyPushDownPresenter createPresenter(@NotNull PyPushDownView view) {
        return new PyPushDownPresenterImpl(project, view, classUnderRefactoring, infoStorage);
      }

      @NotNull
      @Override
      public PyPushDownView createView(@NotNull PyPushDownPresenter presenter) {
        return new PyPushDownViewSwingImpl(classUnderRefactoring, project, presenter);
      }
    });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:PyPushDownHandler.java

示例9: visitMethod

import com.intellij.util.Query; //导入方法依赖的package包/类
@Override
public void visitMethod(PsiMethod method) {
  super.visitMethod(method);
  final PsiCodeBlock body = method.getBody();
  if (body == null) {
    return;
  }
  if (method.getNameIdentifier() == null) {
    return;
  }
  final Query<MethodSignatureBackedByPsiMethod> superMethodQuery =
    SuperMethodsSearch.search(method, null, true, false);
  final MethodSignatureBackedByPsiMethod signature =
    superMethodQuery.findFirst();
  if (signature == null) {
    return;
  }
  final PsiMethod superMethod = signature.getMethod();
  final PsiCodeBlock superBody = superMethod.getBody();
  if (superBody == null) {
    return;
  }
  if (!modifierListsAreEquivalent(method.getModifierList(), superMethod.getModifierList())) {
    return;
  }
  final PsiType superReturnType = superMethod.getReturnType();
  if (superReturnType == null || !superReturnType.equals(method.getReturnType())) {
    return;
  }
  if (!EquivalenceChecker.codeBlocksAreEquivalent(body, superBody)) {
    return;
  }
  registerMethodError(method);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:RedundantMethodOverrideInspection.java

示例10: visitClass

import com.intellij.util.Query; //导入方法依赖的package包/类
@Override
public void visitClass(@NotNull PsiClass aClass) {
  // no call to super, so that it doesn't drill down to inner classes
  if (aClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
    return;
  }
  if (!UtilityClassUtil.isUtilityClass(aClass)) {
    return;
  }
  if (ignoreClassesWithOnlyMain && hasOnlyMain(aClass)) {
    return;
  }
  if (hasPrivateConstructor(aClass)) {
    return;
  }
  if (AnnotationUtil.isAnnotated(aClass, ignorableAnnotations)) {
    return;
  }
  if (aClass.hasModifierProperty(PsiModifier.PRIVATE) && aClass.getConstructors().length == 0) {
    return;
  }
  final SearchScope scope = GlobalSearchScope.projectScope(aClass.getProject());
  final Query<PsiClass> query = ClassInheritorsSearch.search(aClass, scope, true, true);
  final PsiClass subclass = query.findFirst();
  if (subclass != null) {
    return;
  }
  registerClassError(aClass, aClass);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:UtilityClassWithoutPrivateConstructorInspectionBase.java

示例11: visitMethod

import com.intellij.util.Query; //导入方法依赖的package包/类
@Override
public void visitMethod(PsiMethod method) {
  super.visitMethod(method);
  if (isOnTheFly() && !method.hasModifierProperty(PsiModifier.PRIVATE) && !ApplicationManager.getApplication().isUnitTestMode()) {
    // checking methods with greater visibility is too expensive.
    // for error checking in the editor
    return;
  }
  if (MethodUtils.hasSuper(method)) {
    // do not try to weaken methods with super methods
    return;
  }
  final Query<PsiMethod> overridingSearch = OverridingMethodsSearch.search(method);
  if (overridingSearch.findFirst() != null) {
    // do not try to weaken methods with overriding methods.
    return;
  }
  final Collection<PsiClass> weakestClasses =
    WeakestTypeFinder.calculateWeakestClassesNecessary(method,
                                                       useRighthandTypeAsWeakestTypeInAssignments,
                                                       useParameterizedTypeForCollectionMethods);
  if (doNotWeakenToJavaLangObject) {
    final Project project = method.getProject();
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
    final PsiClass javaLangObjectClass = facade.findClass(CommonClassNames.JAVA_LANG_OBJECT, method.getResolveScope());
    weakestClasses.remove(javaLangObjectClass);
  }
  if (onlyWeakentoInterface) {
    for (Iterator<PsiClass> iterator = weakestClasses.iterator(); iterator.hasNext(); ) {
      final PsiClass weakestClass = iterator.next();
      if (!weakestClass.isInterface()) {
        iterator.remove();
      }
    }
  }
  if (weakestClasses.isEmpty()) {
    return;
  }
  registerMethodError(method, method, weakestClasses);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:41,代码来源:TypeMayBeWeakenedInspection.java

示例12: isOverridden

import com.intellij.util.Query; //导入方法依赖的package包/类
public static boolean isOverridden(PsiMethod method) {
  if (method.isConstructor() || method.hasModifierProperty(PsiModifier.STATIC) || method.hasModifierProperty(PsiModifier.PRIVATE)) {
    return false;
  }
  final Query<PsiMethod> overridingMethodQuery = OverridingMethodsSearch.search(method);
  final PsiMethod result = overridingMethodQuery.findFirst();
  return result != null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:MethodUtils.java

示例13: visitMethodCallExpression

import com.intellij.util.Query; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(@NotNull PsiMethodCallExpression call) {
  super.visitMethodCallExpression(call);
  final PsiClass containingClass = ClassUtils.getContainingClass(call);
  if (containingClass == null) {
    return;
  }
  final PsiMethod method = call.resolveMethod();
  if (method == null) {
    return;
  }
  if (!containingClass.equals(method.getContainingClass())) {
    return;
  }
  final PsiReferenceExpression methodExpression = call.getMethodExpression();
  final PsiExpression qualifier = methodExpression.getQualifierExpression();
  if (qualifier != null && !(qualifier instanceof PsiThisExpression)) {
    if (ignoreGetterCallsOnOtherObjects) {
      return;
    }
    final PsiType type = qualifier.getType();
    if (!(type instanceof PsiClassType)) {
      return;
    }
    final PsiClassType classType = (PsiClassType)type;
    final PsiClass qualifierClass = classType.resolve();
    if (!containingClass.equals(qualifierClass)) {
      return;
    }
  }
  if (!PropertyUtil.isSimpleGetter(method)) {
    return;
  }
  if (onlyReportPrivateGetter && !method.hasModifierProperty(PsiModifier.PRIVATE)) {
    return;
  }
  final Query<PsiMethod> query = OverridingMethodsSearch.search(method, true);
  final PsiMethod overridingMethod = query.findFirst();
  if (overridingMethod != null) {
    return;
  }
  registerMethodCallError(call);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:44,代码来源:CallToSimpleGetterInClassInspectionBase.java

示例14: visitMethodCallExpression

import com.intellij.util.Query; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(@NotNull PsiMethodCallExpression call) {
  super.visitMethodCallExpression(call);
  final PsiClass containingClass = ClassUtils.getContainingClass(call);
  if (containingClass == null) {
    return;
  }
  final PsiMethod method = call.resolveMethod();
  if (method == null) {
    return;
  }
  if (!containingClass.equals(method.getContainingClass())) {
    return;
  }
  final PsiReferenceExpression methodExpression = call.getMethodExpression();
  final PsiExpression qualifier = methodExpression.getQualifierExpression();
  if (qualifier != null && !(qualifier instanceof PsiThisExpression)) {
    if (ignoreSetterCallsOnOtherObjects) {
      return;
    }
    final PsiType type = qualifier.getType();
    if (!(type instanceof PsiClassType)) {
      return;
    }
    final PsiClassType classType = (PsiClassType)type;
    final PsiClass qualifierClass = classType.resolve();
    if (!containingClass.equals(qualifierClass)) {
      return;
    }
  }
  if (!PropertyUtil.isSimpleSetter(method)) {
    return;
  }
  if (onlyReportPrivateSetter && !method.hasModifierProperty(PsiModifier.PRIVATE)) {
    return;
  }
  final Query<PsiMethod> query = OverridingMethodsSearch.search(method, true);
  final PsiMethod overridingMethod = query.findFirst();
  if (overridingMethod != null) {
    return;
  }
  registerMethodCallError(call);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:44,代码来源:CallToSimpleSetterInClassInspectionBase.java


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