當前位置: 首頁>>代碼示例>>Java>>正文


Java PsiMethod.getContainingClass方法代碼示例

本文整理匯總了Java中com.intellij.psi.PsiMethod.getContainingClass方法的典型用法代碼示例。如果您正苦於以下問題:Java PsiMethod.getContainingClass方法的具體用法?Java PsiMethod.getContainingClass怎麽用?Java PsiMethod.getContainingClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.psi.PsiMethod的用法示例。


在下文中一共展示了PsiMethod.getContainingClass方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getWritablePropertyType

import com.intellij.psi.PsiMethod; //導入方法依賴的package包/類
@Nullable
public static PsiType getWritablePropertyType(@Nullable PsiClass containingClass,
    @Nullable PsiElement declaration) {
  if (declaration instanceof PsiField) {
    return getWrappedPropertyType((PsiField) declaration, JavaFxCommonNames.ourWritableMap);
  }
  if (declaration instanceof PsiMethod) {
    final PsiMethod method = (PsiMethod) declaration;
    if (method.getParameterList().getParametersCount() != 0) {
      return getSetterArgumentType(method);
    }
    final String propertyName = PropertyUtil.getPropertyName(method);
    final PsiClass psiClass =
        containingClass != null ? containingClass : method.getContainingClass();
    if (propertyName != null && containingClass != null) {
      final PsiMethod setter = findInstancePropertySetter(psiClass, propertyName);
      if (setter != null) {
        final PsiType setterArgumentType = getSetterArgumentType(setter);
        if (setterArgumentType != null)
          return setterArgumentType;
      }
    }
    return getGetterReturnType(method);
  }
  return null;
}
 
開發者ID:1tontech,項目名稱:intellij-spring-assistant,代碼行數:27,代碼來源:PsiUtil.java

示例2: createMethodFilter

import com.intellij.psi.PsiMethod; //導入方法依賴的package包/類
/**
 * Override in case if your JVMNames slightly different then it can be provided by getJvmSignature method.
 *
 * @param stepTarget
 * @return SmartStepFilter
 */
@Nullable
protected MethodFilter createMethodFilter(SmartStepTarget stepTarget) {
  if (stepTarget instanceof MethodSmartStepTarget) {
    final PsiMethod method = ((MethodSmartStepTarget)stepTarget).getMethod();
    if (stepTarget.needsBreakpointRequest()) {
      return Registry.is("debugger.async.smart.step.into") && method.getContainingClass() instanceof PsiAnonymousClass
             ? new ClassInstanceMethodFilter(method, stepTarget.getCallingExpressionLines())
             : new AnonymousClassMethodFilter(method, stepTarget.getCallingExpressionLines());
    }
    else {
      return new BasicStepMethodFilter(method, stepTarget.getCallingExpressionLines());
    }
  }
  if (stepTarget instanceof LambdaSmartStepTarget) {
    final LambdaSmartStepTarget lambdaTarget = (LambdaSmartStepTarget)stepTarget;
    return new LambdaMethodFilter(lambdaTarget.getLambda(), lambdaTarget.getOrdinal(), stepTarget.getCallingExpressionLines());
  }
  return null;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:26,代碼來源:JvmSmartStepIntoHandler.java

示例3: visitMethod

import com.intellij.psi.PsiMethod; //導入方法依賴的package包/類
@Override
public void visitMethod(@NotNull PsiMethod method) {
  // no call to super, so it doesn't drill down into inner classes
  if (method.isConstructor()) {
    return;
  }
  final String methodName = method.getName();
  final PsiClass containingClass = method.getContainingClass();
  if (containingClass == null) {
    return;
  }
  final String className = containingClass.getName();
  if (className == null) {
    return;
  }
  if (!methodName.equals(className)) {
    return;
  }
  registerMethodError(method, Boolean.valueOf(isOnTheFly()));
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:21,代碼來源:MethodNameSameAsClassNameInspectionBase.java

示例4: checkSuperMethod

import com.intellij.psi.PsiMethod; //導入方法依賴的package包/類
public static PsiMethod checkSuperMethod(@NotNull PsiMethod method, @NotNull String actionString) {
  PsiClass aClass = method.getContainingClass();
  if (aClass == null) return method;

  PsiMethod superMethod = method.findDeepestSuperMethod();
  if (superMethod == null) return method;

  if (ApplicationManager.getApplication().isUnitTestMode()) return superMethod;

  PsiClass containingClass = superMethod.getContainingClass();

  SuperMethodWarningDialog dialog =
      new SuperMethodWarningDialog(
          method.getProject(),
          DescriptiveNameUtil.getDescriptiveName(method), actionString, containingClass.isInterface() || superMethod.hasModifierProperty(PsiModifier.ABSTRACT),
          containingClass.isInterface(), aClass.isInterface(), containingClass.getQualifiedName()
      );
  dialog.show();

  if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) return superMethod;
  if (dialog.getExitCode() == SuperMethodWarningDialog.NO_EXIT_CODE) return method;

  return null;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:25,代碼來源:SuperMethodWarningUtil.java

示例5: isRunFinalizersOnExit

import com.intellij.psi.PsiMethod; //導入方法依賴的package包/類
private static boolean isRunFinalizersOnExit(
  PsiMethodCallExpression expression) {
  final PsiReferenceExpression methodExpression =
    expression.getMethodExpression();
  final String methodName = methodExpression.getReferenceName();
  @NonNls final String runFinalizers = "runFinalizersOnExit";
  if (!runFinalizers.equals(methodName)) {
    return false;
  }
  final PsiMethod method = expression.resolveMethod();
  if (method == null) {
    return false;
  }
  final PsiClass aClass = method.getContainingClass();
  if (aClass == null) {
    return false;
  }
  final String className = aClass.getQualifiedName();
  if (className == null) {
    return false;
  }
  return "java.lang.System".equals(className);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:24,代碼來源:SystemRunFinalizersOnExitInspection.java

示例6: processQuery

import com.intellij.psi.PsiMethod; //導入方法依賴的package包/類
@Override
public void processQuery(@NotNull MethodReferencesSearch.SearchParameters p, @NotNull Processor<PsiReference> consumer) {
  final PsiMethod method = p.getMethod();
  final PsiClass aClass = method.getContainingClass();
  if (aClass == null) return;

  final String name = method.getName();
  if (StringUtil.isEmpty(name)) return;

  final boolean strictSignatureSearch = p.isStrictSignatureSearch();
  final PsiMethod[] methods = strictSignatureSearch ? new PsiMethod[]{method} : aClass.findMethodsByName(name, false);

  SearchScope accessScope = GroovyScopeUtil.getEffectiveScope(methods);
  final SearchScope restrictedByAccess = GroovyScopeUtil.restrictScopeToGroovyFiles(p.getEffectiveSearchScope(), accessScope);

  final String textToSearch = findLongestWord(name);

  p.getOptimizer().searchWord(textToSearch, restrictedByAccess, UsageSearchContext.IN_STRINGS, true, method,
                              new MethodTextOccurrenceProcessor(aClass, strictSignatureSearch, methods));
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:21,代碼來源:GrLiteralMethodSearcher.java

示例7: isThreadYield

import com.intellij.psi.PsiMethod; //導入方法依賴的package包/類
private static boolean isThreadYield(
  PsiMethodCallExpression expression) {
  final PsiReferenceExpression methodExpression =
    expression.getMethodExpression();
  @NonNls final String methodName =
    methodExpression.getReferenceName();
  if (!"yield".equals(methodName)) {
    return false;
  }
  final PsiMethod method = expression.resolveMethod();
  if (method == null) {
    return false;
  }
  final PsiClass aClass = method.getContainingClass();
  if (aClass == null) {
    return false;
  }
  final String className = aClass.getQualifiedName();
  if (className == null) {
    return false;
  }
  return "java.lang.Thread".equals(className);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:24,代碼來源:ThreadYieldInspection.java

示例8: visitMethod

import com.intellij.psi.PsiMethod; //導入方法依賴的package包/類
@Override
public void visitMethod(@NotNull PsiMethod method) {
  // no call to super, so it doesn't drill down
  final PsiClass aClass = method.getContainingClass();
  if (aClass == null) {
    return;
  }
  if (aClass.isInterface() || aClass.isAnnotationType()) {
    return;
  }
  if (method.hasModifierProperty(PsiModifier.PRIVATE)) {
    return;
  }
  if (!SerializationUtils.isReadObject(method) &&
      !SerializationUtils.isWriteObject(method)) {
    return;
  }
  if (!SerializationUtils.isSerializable(aClass)) {
    return;
  }
  registerMethodError(method);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:23,代碼來源:ReadObjectAndWriteObjectPrivateInspection.java

示例9: afterCheckClass

import com.intellij.psi.PsiMethod; //導入方法依賴的package包/類
public void afterCheckClass(Context context) {

        if (mMethods.size() == 0) return;

        JavaContext javaContext = (JavaContext) context;
        JavaEvaluator evaluator = javaContext.getEvaluator();
        if (evaluator == null) return;

        StringBuilder sb = new StringBuilder();

        boolean methodInDataAdapter = false;
        for (PsiMethod method : mMethods) {
            PsiClass pc = method.getContainingClass();
            boolean isSubclass = evaluator.implementsInterface(pc, CLASS_DATA_ADAPTER, false);

            methodInDataAdapter = methodInDataAdapter || isSubclass;

            if (!isSubclass) {
                sb.append(method.getName())
                        .append(",");
            }
        }

        if (!methodInDataAdapter) {
            context.report(ISSUE_VIEW_GROUP, Location.create(context.file), "the Custom ViewGroup with data bind should extend DataAdapter,method names:" + sb.toString());
        }
    }
 
開發者ID:jessie345,項目名稱:CustomLintRules,代碼行數:28,代碼來源:AutoPointCustomViewGroupDetector.java

示例10: visitNewExpression

import com.intellij.psi.PsiMethod; //導入方法依賴的package包/類
@Override
public void visitNewExpression(PsiNewExpression expression) {
    super.visitNewExpression(expression);

    PsiMethod constructor = expression.resolveConstructor();
    if (constructor == null) return;

    JavaEvaluator evaluator = mContext.getEvaluator();
    PsiClass cls = constructor.getContainingClass();
    boolean isView = evaluator.extendsClass(cls, CLASS_VIEW, true);
    if (!isView) return;

    Location location = this.mContext.getLocation(expression);

    PsiElement psiElement = expression.getParent();

    //創建的變量沒有賦值給本地變量,無法指定注解
    if (!(psiElement instanceof PsiLocalVariable)) {
        this.mContext.report(DynamicNewViewDetector.ISSUE, expression, location, "檢測到動態創建view操作,new 操作的結果需要賦值給本地變量");
        return;
    }

    PsiLocalVariable localVariable = (PsiLocalVariable) psiElement;
    PsiModifierList modifierList = localVariable.getModifierList();
    if (modifierList == null) {
        this.mContext.report(DynamicNewViewDetector.ISSUE, expression, location, "檢測到動態創建view操作,確認是否為view指定了唯一標識");
        return;
    }

    PsiAnnotation[] annotations = modifierList.getAnnotations();
    for (PsiAnnotation annotation : annotations) {
        String fullName = annotation.getQualifiedName();
        if (IDENTIFIER_ANNOTATION.equals(fullName)) {
            return;
        }
    }

    this.mContext.report(DynamicNewViewDetector.ISSUE, expression, location, "檢測到動態創建view操作,確認是否為view指定了唯一標識");
}
 
開發者ID:jessie345,項目名稱:CustomLintRules,代碼行數:40,代碼來源:DynamicNewViewDetector.java

示例11: isMissingOnError

import com.intellij.psi.PsiMethod; //導入方法依賴的package包/類
@Override
public boolean isMissingOnError(PsiMethod method) {
    PsiClass clz = method.getContainingClass();
    String type = clz.getQualifiedName();
    if ("io.reactivex.Observable".equals(type) ||
          "io.reactivex.Flowable".equals(type) ||
          "io.reactivex.Completable".equals(type) ||
          "io.reactivex.Single".equals(type) ||
          "io.reactivex.Maybe".equals(type)) {
        return checkMethodSignature(method);
    }
    return false;
}
 
開發者ID:IlyaGulya,項目名稱:rxlint,代碼行數:14,代碼來源:RxJava2SubscriberCheck.java

示例12: isMissingOnError

import com.intellij.psi.PsiMethod; //導入方法依賴的package包/類
@Override
public boolean isMissingOnError(PsiMethod method) {
    PsiClass clz = method.getContainingClass();
    if ("rx.Observable".equals(clz.getQualifiedName()) || "rx.Single".equals(clz.getQualifiedName())) {
        return method.getParameterList().getParametersCount() == 1 &&
                method.getParameterList().getParameters()[0].getType().equalsToText("rx.functions.Action1");
    } else if ("rx.Completable".equals(clz.getQualifiedName())) {
        // only a completion callback
        return method.getParameterList().getParametersCount() == 1 && method.getParameterList().getParameters()[0].getType().equalsToText("rx.functions.Action0");
    }
    return false;
}
 
開發者ID:IlyaGulya,項目名稱:rxlint,代碼行數:13,代碼來源:RxJavaSubscriberCheck.java

示例13: getLanguagesToInject

import com.intellij.psi.PsiMethod; //導入方法依賴的package包/類
@Override
public void getLanguagesToInject(
    @NotNull final PsiLanguageInjectionHost host,
    @NotNull final InjectedLanguagePlaces injectionPlacesRegistrar
) {
    final PsiElement hostParent = host.getParent();
    if (host instanceof ImpexStringImpl) {
        final String hostString = StringUtil.unquoteString(host.getText()).toLowerCase();
        if (StringUtil.trim(hostString).startsWith("select ")) {
            registerInjectionPlace(injectionPlacesRegistrar, host);
        }
    }

    if (hostParent != null) {
        if (hostParent.getParent() instanceof PsiMethodCallExpressionImpl) {
            final PsiMethodCallExpressionImpl callExpression = (PsiMethodCallExpressionImpl) hostParent.getParent();
            final PsiMethod method = callExpression.resolveMethod();
            if (method != null) {
                final PsiClass containingClass = method.getContainingClass();
                if (containingClass != null
                    && "FlexibleSearchService".equals(containingClass.getName())
                    && "search".equals(method.getName())) {

                    registerInjectionPlace(injectionPlacesRegistrar, host);
                }
            }
        }
    }
}
 
開發者ID:AlexanderBartash,項目名稱:hybris-integration-intellij-idea-plugin,代碼行數:30,代碼來源:FlexibleSearchInjector.java

示例14: matches

import com.intellij.psi.PsiMethod; //導入方法依賴的package包/類
public static boolean matches(SmcMethodLikeElement methodLikeElement, PsiMethod method) {
    PsiClass containingClass = method.getContainingClass();
    SmcFile containingFile = (SmcFile) methodLikeElement.getContainingFile();
    PsiClass fsmClass = containingFile.getFsmClass();
    if (fsmClass == null || containingClass == null) {
        return false;
    }
    if (!containingClass.isEquivalentTo(fsmClass) && !containingClass.isInheritor(fsmClass, true)) {
        return false;
    }

    return method.getName().equals(methodLikeElement.getName()) &&
            method.getParameterList().getParametersCount() == methodLikeElement.getArgumentCount();
}
 
開發者ID:menshele,項目名稱:smcplugin,代碼行數:15,代碼來源:SmcPsiImplUtil.java

示例15: visitMethod

import com.intellij.psi.PsiMethod; //導入方法依賴的package包/類
@Override
public void visitMethod(@NotNull PsiMethod method) {
  final PsiClass aClass = method.getContainingClass();
  if (aClass == null) {
    return;
  }
  if (method.getNameIdentifier() == null) {
    return;
  }
  final String methodName = method.getName();
  final MethodSignature signature = method.getSignature(PsiSubstitutor.EMPTY);
  PsiClass ancestorClass = aClass.getSuperClass();
  final Set<PsiClass> visitedClasses = new HashSet<PsiClass>();
  while (ancestorClass != null) {
    if (!visitedClasses.add(ancestorClass)) {
      return;
    }
    final PsiMethod[] methods =
      ancestorClass.findMethodsByName(methodName, false);
    for (final PsiMethod testMethod : methods) {
      final MethodSignature testSignature = testMethod.getSignature(PsiSubstitutor.EMPTY);
      if (!signature.equals(testSignature)) {
        continue;
      }
      if (testMethod.hasModifierProperty(PsiModifier.STATIC) &&
          !testMethod.hasModifierProperty(PsiModifier.PRIVATE)) {
        registerMethodError(method);
        return;
      }
    }
    ancestorClass = ancestorClass.getSuperClass();
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:34,代碼來源:MethodOverridesStaticMethodInspectionBase.java


注:本文中的com.intellij.psi.PsiMethod.getContainingClass方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。