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


Java PsiMethod類代碼示例

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


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

示例1: checkNestedStringFormat

import com.intellij.psi.PsiMethod; //導入依賴的package包/類
private static void checkNestedStringFormat(JavaContext context, UCallExpression call) {
  UElement current = call;
  while (true) {
    current = LintUtils.skipParentheses(current.getUastParent());
    if (current == null || current instanceof UMethod) {
      // Reached AST root or code block node; String.format not inside Timber.X(..).
      return;
    }
    if (current instanceof UCallExpression) {
      UCallExpression maybeTimberLogCall = (UCallExpression) current;
      JavaEvaluator evaluator = context.getEvaluator();
      PsiMethod psiMethod = maybeTimberLogCall.resolve();
      if (Pattern.matches(TIMBER_TREE_LOG_METHOD_REGEXP, psiMethod.getName())
          && evaluator.isMemberInClass(psiMethod, "timber.log.Timber")) {
        LintFix fix = quickFixIssueFormat(call);
        context.report(ISSUE_FORMAT, call, context.getLocation(call),
            "Using 'String#format' inside of 'Timber'", fix);
        return;
      }
    }
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:WrongTimberUsageDetector.java

示例2: 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

示例3: hasGetAndSet

import com.intellij.psi.PsiMethod; //導入依賴的package包/類
private static boolean hasGetAndSet(@NonNull String getPrefix, @NonNull String setPrefix, @NonNull PsiClass cls, @NonNull PsiField field) {
    boolean isPublic = field.hasModifierProperty(PsiModifier.PUBLIC);
    if (isPublic) return true;

    String fieldName = captureName(field.getName());
    String getMethodName = getPrefix + fieldName;
    String setMethodName = setPrefix + fieldName;
    PsiMethod[] gets = cls.findMethodsByName(getMethodName, true);
    PsiMethod[] sets = cls.findMethodsByName(setMethodName, true);

    boolean hasGet = gets.length > 0;
    boolean hasSet = sets.length > 0;

    return hasGet && hasSet;

}
 
開發者ID:jessie345,項目名稱:CustomLintRules,代碼行數:17,代碼來源:Utils.java

示例4: visitMethod

import com.intellij.psi.PsiMethod; //導入依賴的package包/類
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable JavaElementVisitor visitor,
                        @NonNull PsiMethodCallExpression node, @NonNull PsiMethod method) {

    boolean isLayoutInflaterCall = isLayoutInflaterCall(context, node, method);
    boolean isViewInflateCall = isInViewCall(context, node, method);

    String name = method.getName();
    boolean fromMethod = LAYOUTINFLATER_FROM.equals(name);
    boolean viewInflateMethod = VIEW_INFLATE.equals(name);

    if (isLayoutInflaterCall && fromMethod) {

        context.report(ISSUE_LAYOUTINFLATER, node, context.getLocation(node),
                "error use system LayoutInflater,should use LayoutInflaterWrapper.");
        return;
    }

    if (viewInflateMethod && isViewInflateCall) {

        context.report(ISSUE_VIEW_INFLATE, node, context.getLocation(node),
                "error use View.inflate(),should use LayoutInflaterWrapper.inflate.");
        return;
    }

}
 
開發者ID:jessie345,項目名稱:CustomLintRules,代碼行數:27,代碼來源:AutoPointLayoutInflaterDetector.java

示例5: visitMethod

import com.intellij.psi.PsiMethod; //導入依賴的package包/類
@Override
public void visitMethod(JavaContext context, JavaElementVisitor visitor,
    PsiMethodCallExpression call, PsiMethod method) {
  JavaEvaluator evaluator = context.getEvaluator();
  if (evaluator.getParameterCount(method) == 0) {
    PsiMethod parent = PsiTreeUtil.getParentOfType(call, PsiMethod.class);
    if (parent != null) {
      if (evaluator.isMemberInClass(method, CLASS_DIRECTOR) &&
          evaluator.isMemberInSubClassOf(parent, CLASS_DIRECTOR_BACK_HANDLER, false)) {
        context.report(ISSUE, call, context.getLocation(call),
            "Can't call Stage.handleBack() in Stage.BackHandler.handleBack()");
      } else if (evaluator.isMemberInClass(method, CLASS_STAGE) &&
          evaluator.isMemberInSubClassOf(parent, CLASS_STAGE_BACK_HANDLER, false)) {
        context.report(ISSUE, call, context.getLocation(call),
            "Can't call Director.handleBack() in Director.BackHandler.handleBack()");
      }
    }
  }
}
 
開發者ID:seven332,項目名稱:Stage,代碼行數:20,代碼來源:BackHandlerDetector.java

示例6: checkMethodSignature

import com.intellij.psi.PsiMethod; //導入依賴的package包/類
private boolean checkMethodSignature(PsiMethod method) {
    // subscribe() calls that have no return type are custom Observers whose error handling we cannot check
    if (PsiType.VOID.equals(method.getReturnType())) {
        return false;
    }
    int argCount = method.getParameterList().getParametersCount();
    // when more than one argument is given, there is usually one error callback included
    if (argCount > 1) {
        return false;
    }
    // no arguments, no error handling
    if (argCount == 0) {
        return true;
    }
    // if we have only one argument, check that it's not a BiConsumer
    PsiParameter parameter = method.getParameterList().getParameters()[0];
    return !"io.reactivex.functions.BiConsumer".equals(parameter.getType().getCanonicalText());
}
 
開發者ID:IlyaGulya,項目名稱:rxlint,代碼行數:19,代碼來源:RxJava2SubscriberCheck.java

示例7: visitMethod

import com.intellij.psi.PsiMethod; //導入依賴的package包/類
@Override
public void visitMethod(JavaContext context, JavaElementVisitor visitor, PsiMethodCallExpression call, PsiMethod method) {
    super.visitMethod(context, visitor, call, method);
    if (isRxSubscribeableClass(method.getContainingClass()) && !PsiType.VOID.equals(method.getReturnType())) {
        PsiElement element = LintUtils.skipParentheses(call.getParent());
        if (element instanceof PsiExpressionStatement) {
            String message;
            if (isRx2(method.getContainingClass())) {
                message = "No reference to the disposable is kept";
            } else {
                message = "No reference to the subscription is kept";
            }
            context.report(ISSUE, call, context.getLocation(call), message);
        }
    }
}
 
開發者ID:IlyaGulya,項目名稱:rxlint,代碼行數:17,代碼來源:DanglingSubscriptionDetector.java

示例8: canProcessElement

import com.intellij.psi.PsiMethod; //導入依賴的package包/類
@Override
public boolean canProcessElement( @NotNull PsiElement elem )
{
  PsiElement[] element = new PsiElement[]{elem};
  List<PsiElement> javaElems = findJavaElements( element );
  if( javaElems.isEmpty() )
  {
    return false;
  }

  for( PsiElement javaElem : javaElems )
  {
    if( !(javaElem instanceof PsiMethod) &&
        !(javaElem instanceof PsiField) &&
        !(javaElem instanceof PsiClass) )
    {
      return false;
    }
  }

  return true;
}
 
開發者ID:manifold-systems,項目名稱:manifold-ij,代碼行數:23,代碼來源:RenameResourceElementProcessor.java

示例9: makePsiMethod

import com.intellij.psi.PsiMethod; //導入依賴的package包/類
private PsiMethod makePsiMethod( AbstractSrcMethod method, PsiClass psiClass )
{
  PsiElementFactory elementFactory = JavaPsiFacade.getInstance( psiClass.getProject() ).getElementFactory();
  StringBuilder sb = new StringBuilder();
  method.render( sb, 0 );
  try
  {
    return elementFactory.createMethodFromText( sb.toString(), psiClass );
  }
  catch( IncorrectOperationException ioe )
  {
    // the text of the method does not conform to method grammar, probably being edited in an IJ editor,
    // ignore these since the editor provides error information
    return null;
  }
}
 
開發者ID:manifold-systems,項目名稱:manifold-ij,代碼行數:17,代碼來源:ManAugmentProvider.java

示例10: findExtensionMethodNavigationElement

import com.intellij.psi.PsiMethod; //導入依賴的package包/類
private PsiElement findExtensionMethodNavigationElement( PsiClass extClass, PsiMethod plantedMethod )
{
  PsiMethod[] found = extClass.findMethodsByName( plantedMethod.getName(), false );
  outer:
  for( PsiMethod m : found )
  {
    PsiParameter[] extParams = m.getParameterList().getParameters();
    PsiParameter[] plantedParams = plantedMethod.getParameterList().getParameters();
    if( extParams.length - 1 == plantedParams.length )
    {
      for( int i = 1; i < extParams.length; i++ )
      {
        PsiParameter extParam = extParams[i];
        PsiParameter plantedParam = plantedParams[i - 1];
        PsiType extErased = TypeConversionUtil.erasure( extParam.getType() );
        PsiType plantedErased = TypeConversionUtil.erasure( plantedParam.getType() );
        if( !extErased.toString().equals( plantedErased.toString() ) )
        {
          continue outer;
        }
      }
      return m.getNavigationElement();
    }
  }
  return null;
}
 
開發者ID:manifold-systems,項目名稱:manifold-ij,代碼行數:27,代碼來源:ManAugmentProvider.java

示例11: makeSrcClass

import com.intellij.psi.PsiMethod; //導入依賴的package包/類
public SrcClass makeSrcClass( String fqn, PsiClass psiClass, ManModule module )
{
  SrcClass srcClass = new SrcClass( fqn, getKind( psiClass ) )
    .modifiers( getModifiers( psiClass.getModifierList() ) );
  for( PsiTypeParameter typeVar : psiClass.getTypeParameters() )
  {
    srcClass.addTypeVar( new SrcType( makeTypeVar( typeVar ) ) );
  }
  setSuperTypes( srcClass, psiClass );
  for( PsiMethod psiMethod : psiClass.getMethods() )
  {
    addMethod( srcClass, psiMethod );
  }
  for( PsiField psiField : psiClass.getFields() )
  {
    addField( srcClass, psiField );
  }
  for( PsiClass psiInnerClass : psiClass.getInnerClasses() )
  {
    addInnerClass( srcClass, psiInnerClass, module );
  }
  return srcClass;
}
 
開發者ID:manifold-systems,項目名稱:manifold-ij,代碼行數:24,代碼來源:StubBuilder.java

示例12: check

import com.intellij.psi.PsiMethod; //導入依賴的package包/類
void check(@NonNull PsiMethod method) {
    if (mClass != null &&
            !mClassFields.isEmpty()) {

        // メソッド引數に boolean のパラメータがある場合のみ対象とする
        Map<String, PsiParameter> parameters = new HashMap<>();
        PsiParameter[] params = method.getParameterList().getParameters();
        for (PsiParameter param : params) {
            if (param.getType() != PsiType.BOOLEAN) continue;
            parameters.put(param.getName(), param);
        }
        if (parameters.isEmpty()) return;

        mMethod = method;
        mFlagMethodParameters.clear();
        mFlagMethodParameters.putAll(parameters);
        mFlagLogic = null;
    }
}
 
開發者ID:cch-robo,項目名稱:Android_Lint_SRP_Practice_Example,代碼行數:20,代碼來源:MultiFunctionFlagStructureDetector.java

示例13: check

import com.intellij.psi.PsiMethod; //導入依賴的package包/類
void check(@NonNull PsiMethod method) {
    if (mClass == null) return;
    Debug.checkedMethod(mClass, method);

    if (!mUnusedMethods.remove(method)) {
        // クラス內のインナークラスや匿名クラスに無名クラスのメソッドは、対象としていません。
        return;
    }
    if (method.isConstructor()) return;

    // メソッドを関數とフィールド変數変更メソッドに分離
    WriteFieldGroupMethod writeFieldGroup = new WriteFieldGroupMethod(method, mClassFields);
    if (writeFieldGroup.hasWriteFields()) {
        mWriteFieldGroupMethods.add(writeFieldGroup);
    } else {
        mFunctions.add(writeFieldGroup);
    }

    if (mUnusedMethods.isEmpty()) {
        Debug.methodTypes(mClass, mWriteFieldGroupMethods, mFunctions);

        // フィールド変數変更メソッドのグループ分け開始
        parse();
        clean();
    }
}
 
開發者ID:cch-robo,項目名稱:Android_Lint_SRP_Practice_Example,代碼行數:27,代碼來源:SharingGroupClassificationDetector.java

示例14: applyTestMethodConfiguration

import com.intellij.psi.PsiMethod; //導入依賴的package包/類
private static boolean applyTestMethodConfiguration(@NotNull ExternalSystemRunConfiguration configuration,
                                                    @NotNull ConfigurationContext context,
                                                    @NotNull PsiMethod psiMethod,
                                                    @NotNull PsiClass... containingClasses) {
  if (!StringUtil.equals(
    context.getModule().getOptionValue(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY),
    GradleConstants.SYSTEM_ID.toString())) {
    return false;
  }

  configuration.getSettings().setExternalProjectPath(context.getModule().getOptionValue(ExternalSystemConstants.LINKED_PROJECT_PATH_KEY));
  configuration.getSettings().setTaskNames(TASKS_TO_RUN);

  StringBuilder buf = new StringBuilder();
  for (PsiClass aClass : containingClasses) {
    buf.append(creatTestFilter(aClass, psiMethod));
  }

  configuration.getSettings().setScriptParameters(buf.toString().trim());
  configuration.setName(psiMethod.getName());
  return true;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:23,代碼來源:TestMethodGradleConfigurationProducer.java

示例15: visitMethod

import com.intellij.psi.PsiMethod; //導入依賴的package包/類
@Override
public void visitMethod(@NotNull PsiMethod method) {
  //no call to super, so we don't drill into anonymous classes
  if (method.isConstructor()) {
    return;
  }
  if (method.hasModifierProperty(PsiModifier.SYNCHRONIZED)) {
    return;
  }
  if (method.getNameIdentifier() == null) {
    return;
  }
  final PsiMethod[] superMethods = method.findSuperMethods();
  for (final PsiMethod superMethod : superMethods) {
    if (superMethod.hasModifierProperty(PsiModifier.SYNCHRONIZED)) {
      registerMethodError(method);
      return;
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:21,代碼來源:NonSynchronizedMethodOverridesSynchronizedMethodVisitor.java


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