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


Java PsiParameter.getModifierList方法代码示例

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


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

示例1: hasParameterName

import com.intellij.psi.PsiParameter; //导入方法依赖的package包/类
private boolean hasParameterName(PsiParameter psiParameter) {
  PsiModifierList modifierList = psiParameter.getModifierList();
  if (modifierList == null) {
    return false;
  }

  PsiAnnotation annotation = modifierList.findAnnotation("javax.inject.Named");
  if (annotation != null) {
    return true;
  }

  annotation = modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_NAMED);
  if (annotation != null) {
    return true;
  }

  return false;
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:19,代码来源:ApiParameterInspection.java

示例2: getNamedAnnotationValue

import com.intellij.psi.PsiParameter; //导入方法依赖的package包/类
/**
 * Returns the value for @Named if it exists for <code>psiParameter</code> or null if it does not
 * exist.
 *
 * @param psiParameter The parameter whose @Named value is to be returned.
 * @return The @Named value if it exists for <code>psiParameter</code> or null if it does not
 *     exist.
 */
@Nullable
public PsiAnnotationMemberValue getNamedAnnotationValue(PsiParameter psiParameter) {
  PsiModifierList modifierList = psiParameter.getModifierList();
  if (modifierList == null) {
    return null;
  }

  PsiAnnotation annotation = modifierList.findAnnotation("javax.inject.Named");
  if (annotation == null) {
    annotation = modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_NAMED);
    if (annotation == null) {
      return null;
    }
  }

  PsiNameValuePair[] nameValuePairs = annotation.getParameterList().getAttributes();
  if (nameValuePairs.length != 1) {
    return null;
  }

  if (nameValuePairs[0] == null) {
    return null;
  }

  return nameValuePairs[0].getValue();
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:35,代码来源:EndpointPsiElementVisitor.java

示例3: getPathParameter

import com.intellij.psi.PsiParameter; //导入方法依赖的package包/类
/**
 * Returns "/{}" for every parameter with a valid @Named annotation in {@code method} that does
 * not have @Nullable/@Default.
 */
private String getPathParameter(PsiMethod method) {
  StringBuilder path = new StringBuilder();
  EndpointPsiElementVisitor elementVisitor = new EndpointPsiElementVisitor();
  List<String> annotions =
      Arrays.asList(
          GctConstants.APP_ENGINE_ANNOTATION_NULLABLE,
          "javax.annotation.Nullable",
          GctConstants.APP_ENGINE_ANNOTATION_DEFAULT_VALUE);

  for (PsiParameter param : method.getParameterList().getParameters()) {
    // Check for @Nullable/@Default
    PsiModifierList modifierList = param.getModifierList();
    if (modifierList == null) {
      continue;
    }

    if (AnnotationUtil.isAnnotated(param, annotions)) {
      continue;
    }

    PsiAnnotationMemberValue namedValue = elementVisitor.getNamedAnnotationValue(param);
    if (namedValue != null) {
      path.append("/{}");
    }
  }

  return path.toString();
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:33,代码来源:RestSignatureInspection.java

示例4: applyFix

import com.intellij.psi.PsiParameter; //导入方法依赖的package包/类
/**
 * Add the {@link GctConstants.APP_ENGINE_ANNOTATION_NAMED} annotation to the {@link
 * PsiParameter} in <code>descriptor</code>. The query name in {@link
 * GctConstants.APP_ENGINE_ANNOTATION_NAMED} will be the name of the {@link PsiParameter} in
 * <code>descriptor</code>. If the {@link PsiElement} in <code>descriptor</code> is not of
 * {@link PsiParameter} type or if the {@link PsiParameter} in <code>descriptor</code> already
 * has {@link GctConstants.APP_ENGINE_ANNOTATION_NAMED} or javax.inject.Named, no annotation
 * will be added.
 */
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
  PsiElement element = descriptor.getPsiElement();
  if (element == null) {
    return;
  }

  if (!(element instanceof PsiParameter)) {
    return;
  }
  PsiParameter parameter = (PsiParameter) element;

  PsiModifierList modifierList = parameter.getModifierList();
  if (modifierList == null) {
    return;
  }

  if (modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_NAMED) != null) {
    return;
  }

  if (modifierList.findAnnotation("") != null) {
    return;
  }

  String annotationString = "@Named(\"" + parameter.getName() + "\")";
  PsiAnnotation annotation =
      JavaPsiFacade.getElementFactory(project)
          .createAnnotationFromText(annotationString, element);
  modifierList.add(annotation);

  PsiFile file = parameter.getContainingFile();
  if (file == null) {
    return;
  }

  if (!(file instanceof PsiJavaFile)) {
    return;
  }

  PsiAdapter.addImportStatement((PsiJavaFile) file, GctConstants.APP_ENGINE_ANNOTATION_NAMED);
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:52,代码来源:ApiParameterInspection.java

示例5: createSetterMethod

import com.intellij.psi.PsiParameter; //导入方法依赖的package包/类
@NotNull
public PsiMethod createSetterMethod(@NotNull PsiField psiField, @NotNull PsiClass psiClass, @NotNull String methodModifier) {
  final String fieldName = psiField.getName();
  final PsiType psiFieldType = psiField.getType();
  final PsiAnnotation setterAnnotation = PsiAnnotationSearchUtil.findAnnotation(psiField, Setter.class);

  final String methodName = getSetterName(psiField, PsiType.BOOLEAN.equals(psiFieldType));

  PsiType returnType = getReturnType(psiField);
  LombokLightMethodBuilder method = new LombokLightMethodBuilder(psiField.getManager(), methodName)
    .withMethodReturnType(returnType)
    .withContainingClass(psiClass)
    .withParameter(fieldName, psiFieldType)
    .withNavigationElement(psiField);
  if (StringUtil.isNotEmpty(methodModifier)) {
    method.withModifier(methodModifier);
  }
  boolean isStatic = psiField.hasModifierProperty(PsiModifier.STATIC);
  if (isStatic) {
    method.withModifier(PsiModifier.STATIC);
  }

  PsiParameter methodParameter = method.getParameterList().getParameters()[0];
  PsiModifierList methodParameterModifierList = methodParameter.getModifierList();
  if (null != methodParameterModifierList) {
    final Collection<String> annotationsToCopy = PsiAnnotationUtil.collectAnnotationsToCopy(psiField,
      LombokUtils.NON_NULL_PATTERN, LombokUtils.NULLABLE_PATTERN);
    for (String annotationFQN : annotationsToCopy) {
      methodParameterModifierList.addAnnotation(annotationFQN);
    }
    addOnXAnnotations(setterAnnotation, methodParameterModifierList, "onParam");
  }

  method.withBody(createCodeBlock(psiField, psiClass, returnType, isStatic, methodParameter));

  PsiModifierList methodModifierList = method.getModifierList();
  copyAnnotations(psiField, methodModifierList, LombokUtils.DEPRECATED_PATTERN);
  addOnXAnnotations(setterAnnotation, methodModifierList, "onMethod");

  return method;
}
 
开发者ID:mplushnikov,项目名称:lombok-intellij-plugin,代码行数:42,代码来源:SetterFieldProcessor.java


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