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


Java PsiAnnotation.findAttributeValue方法代码示例

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


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

示例1: getAttributeFromAnnotation

import com.intellij.psi.PsiAnnotation; //导入方法依赖的package包/类
private String getAttributeFromAnnotation(
    PsiAnnotation annotation, String annotationType, final String attribute)
    throws InvalidAnnotationException, MissingAttributeException {

  String annotationQualifiedName = annotation.getQualifiedName();
  if (annotationQualifiedName == null) {
    throw new InvalidAnnotationException(annotation, annotationType);
  }

  if (annotationQualifiedName.equals(annotationType)) {
    PsiAnnotationMemberValue annotationMemberValue = annotation.findAttributeValue(attribute);
    if (annotationMemberValue == null) {
      throw new MissingAttributeException(annotation, attribute);
    }

    String httpMethodWithQuotes = annotationMemberValue.getText();
    return httpMethodWithQuotes.substring(1, httpMethodWithQuotes.length() - 1);
  } else {
    throw new InvalidAnnotationException(annotation, annotationType);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:22,代码来源:RestSignatureInspection.java

示例2: getParameterizedLocation

import com.intellij.psi.PsiAnnotation; //导入方法依赖的package包/类
public static Location getParameterizedLocation(PsiClass psiClass, String paramSetName, String parameterizedClassName)
{
	final PsiAnnotation annotation = AnnotationUtil.findAnnotationInHierarchy(psiClass, Collections.singleton(JUnitUtil.RUN_WITH));
	if(annotation != null)
	{
		final PsiAnnotationMemberValue attributeValue = annotation.findAttributeValue("value");
		if(attributeValue instanceof PsiClassObjectAccessExpression)
		{
			final PsiTypeElement operand = ((PsiClassObjectAccessExpression) attributeValue).getOperand();
			if(InheritanceUtil.isInheritor(operand.getType(), parameterizedClassName))
			{
				return new PsiMemberParameterizedLocation(psiClass.getProject(), psiClass, null, paramSetName);
			}
		}
	}
	return null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:18,代码来源:PsiMemberParameterizedLocation.java

示例3: extractNullityFromWhenValue

import com.intellij.psi.PsiAnnotation; //导入方法依赖的package包/类
@NotNull
private static Nullness extractNullityFromWhenValue(PsiAnnotation nonNull)
{
	PsiAnnotationMemberValue when = nonNull.findAttributeValue("when");
	if(when instanceof PsiReferenceExpression)
	{
		String refName = ((PsiReferenceExpression) when).getReferenceName();
		if("ALWAYS".equals(refName))
		{
			return Nullness.NOT_NULL;
		}
		if("MAYBE".equals(refName) || "NEVER".equals(refName))
		{
			return Nullness.NULLABLE;
		}
	}
	return Nullness.UNKNOWN;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:19,代码来源:NullableNotNullManagerImpl.java

示例4: findTargetFeature

import com.intellij.psi.PsiAnnotation; //导入方法依赖的package包/类
private static PsiElement findTargetFeature( PsiAnnotation psiAnnotation, ManifoldPsiClass facade )
  {
    PsiAnnotationMemberValue value = psiAnnotation.findAttributeValue( SourcePosition.FEATURE );
    String featureName = StringUtil.unquoteString( value.getText() );
//    value = psiAnnotation.findAttributeValue( SourcePosition.TYPE );
//    if( value != null )
//    {
//      String ownersType = StringUtil.unquoteString( value.getText() );
//      if( ownersType != null )
//      {
//        PsiElement target = findIndirectTarget( ownersType, featureName, facade.getRawFile().getProject() );
//        if( target != null )
//        {
//          return target;
//        }
//      }
//    }

    int iOffset = Integer.parseInt( psiAnnotation.findAttributeValue( SourcePosition.OFFSET ).getText() );
    int iLength = Integer.parseInt( psiAnnotation.findAttributeValue( SourcePosition.LENGTH ).getText() );

    List<PsiFile> sourceFiles = facade.getRawFiles();
    if( iOffset >= 0 )
    {
      //PsiElement target = sourceFile.findElementAt( iOffset );
      //## todo: handle multiple files
      return new FakeTargetElement( sourceFiles.get( 0 ), iOffset, iLength >= 0 ? iLength : 1, featureName );
    }
    return facade;
  }
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:31,代码来源:ManGotoDeclarationHandler.java

示例5: buildVisitor

import com.intellij.psi.PsiAnnotation; //导入方法依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
  return new EndpointPsiElementVisitor() {
    @Override
    public void visitAnnotation(PsiAnnotation annotation) {
      if (!EndpointUtilities.isEndpointClass(annotation)) {
        return;
      }

      if (!GctConstants.APP_ENGINE_ANNOTATION_API_METHOD.equals(annotation.getQualifiedName())) {
        return;
      }

      PsiAnnotationMemberValue memberValue = annotation.findAttributeValue(API_NAME_ATTRIBUTE);
      if (memberValue == null) {
        return;
      }

      String nameValueWithQuotes = memberValue.getText();
      String nameValue = EndpointUtilities.removeBeginningAndEndingQuotes(nameValueWithQuotes);
      if (nameValue.isEmpty()) {
        return;
      }

      if (!API_NAME_PATTERN
          .matcher(EndpointUtilities.collapseSequenceOfDots(nameValue))
          .matches()) {
        holder.registerProblem(
            memberValue,
            "Invalid method name: letters, digits, underscores and dots are acceptable "
                + "characters. Leading and trailing dots are prohibited.",
            new MyQuickFix());
      }
    }
  };
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:38,代码来源:MethodNameInspection.java

示例6: hasTransformer

import com.intellij.psi.PsiAnnotation; //导入方法依赖的package包/类
/**
 * Returns true if the class containing <code>psiElement</code> has a transformer specified by
 * using the @ApiTransformer annotation on a class or by using the transformer attribute of the
 *
 * @return True if the class containing <code>psiElement</code> has a transformer and false
 *     otherwise. @Api annotation. Returns false otherwise.
 */
public boolean hasTransformer(PsiElement psiElement) {
  PsiClass psiClass = PsiUtils.findClass(psiElement);
  if (psiClass == null) {
    return false;
  }

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

  // Check if class has @ApiTransformer to specify a transformer
  PsiAnnotation apiTransformerAnnotation =
      modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_API_TRANSFORMER);
  if (apiTransformerAnnotation != null) {
    return true;
  }

  // Check if class utilizes the transformer attribute of the @Api annotation
  // to specify its transformer
  PsiAnnotation apiAnnotation =
      modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_API);
  if (apiAnnotation != null) {
    PsiAnnotationMemberValue transformerMember =
        apiAnnotation.findAttributeValue(API_TRANSFORMER_ATTRIBUTE);
    if (transformerMember != null && !transformerMember.getText().equals("{}")) {
      return true;
    }
  }

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

示例7: applyFix

import com.intellij.psi.PsiAnnotation; //导入方法依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
  PsiElement element = descriptor.getPsiElement();
  if (!(element instanceof PsiAnnotation)) {
    return;
  }

  PsiAnnotation annotation = (PsiAnnotation) element;
  if (!GctConstants.APP_ENGINE_ANNOTATION_API_METHOD.equals(annotation.getQualifiedName())) {
    return;
  }

  PsiAnnotationMemberValue apiMethodNameAttribute =
      annotation.findAttributeValue(API_METHOD_NAME_ATTRIBUTE);
  if (apiMethodNameAttribute == null) {
    return;
  }

  // Get name
  String nameValueWithQuotes = apiMethodNameAttribute.getText();
  String nameValue = EndpointUtilities.removeBeginningAndEndingQuotes(nameValueWithQuotes);

  // @A(name = "someName")
  PsiAnnotationMemberValue newMemberValue =
      JavaPsiFacade.getInstance(project)
          .getElementFactory()
          .createAnnotationFromText(
              "@A(" + API_METHOD_NAME_ATTRIBUTE + " = \"" + nameValue + "_1\")", null)
          .findDeclaredAttributeValue(API_METHOD_NAME_ATTRIBUTE);

  apiMethodNameAttribute.replace(newMemberValue);
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:33,代码来源:FullMethodNameInspection.java

示例8: inferStringAttribute

import com.intellij.psi.PsiAnnotation; //导入方法依赖的package包/类
@Nullable
public static String inferStringAttribute(@NotNull PsiAnnotation annotation, @NotNull String attributeName) {
  final PsiAnnotationMemberValue targetValue = annotation.findAttributeValue(attributeName);
  if (targetValue instanceof PsiLiteral) {
    final Object value = ((PsiLiteral)targetValue).getValue();
    if (value instanceof String) return (String)value;
  }
  return null;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:10,代码来源:GrAnnotationUtil.java

示例9: inferIntegerAttribute

import com.intellij.psi.PsiAnnotation; //导入方法依赖的package包/类
@Nullable
public static Integer inferIntegerAttribute(@NotNull PsiAnnotation annotation, @NotNull String attributeName) {
  final PsiAnnotationMemberValue targetValue = annotation.findAttributeValue(attributeName);
  if (targetValue instanceof PsiLiteral) {
    final Object value = ((PsiLiteral)targetValue).getValue();
    if (value instanceof Integer) return (Integer)value;
  }
  return null;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:10,代码来源:GrAnnotationUtil.java

示例10: getOnX

import com.intellij.psi.PsiAnnotation; //导入方法依赖的package包/类
@NotNull
public static Collection<String> getOnX(@NotNull PsiAnnotation psiAnnotation, @NotNull String parameterName) {
  PsiAnnotationMemberValue onXValue = psiAnnotation.findAttributeValue(parameterName);
  if (!(onXValue instanceof PsiAnnotation)) {
    return Collections.emptyList();
  }
  Collection<PsiAnnotation> annotations = PsiAnnotationUtil.getAnnotationValues((PsiAnnotation) onXValue, "value", PsiAnnotation.class);
  Collection<String> annotationStrings = new ArrayList<String>();
  for (PsiAnnotation annotation : annotations) {
    PsiAnnotationParameterList params = annotation.getParameterList();
    annotationStrings.add(PsiAnnotationSearchUtil.getSimpleNameOf(annotation) + params.getText());
  }
  return annotationStrings;
}
 
开发者ID:mplushnikov,项目名称:lombok-intellij-plugin,代码行数:15,代码来源:LombokProcessorUtil.java

示例11: findTypeAttributeOfProvidesAnnotation

import com.intellij.psi.PsiAnnotation; //导入方法依赖的package包/类
public static PsiAnnotationMemberValue findTypeAttributeOfProvidesAnnotation(
    PsiElement element ) {
  PsiAnnotation annotation = findAnnotation(element, CLASS_PROVIDES);
  if (annotation != null) {
    return annotation.findAttributeValue(ATTRIBUTE_TYPE);
  }
  return null;
}
 
开发者ID:square,项目名称:dagger-intellij-plugin,代码行数:9,代码来源:PsiConsultantImpl.java

示例12: buildVisitor

import com.intellij.psi.PsiAnnotation; //导入方法依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(
    @NotNull final com.intellij.codeInspection.ProblemsHolder holder, boolean isOnTheFly) {
  return new EndpointPsiElementVisitor() {

    /**
     * Flags @ApiNamespace that have one or more attributes specified where both the OwnerName and
     * OwnerDomain attributes are not specified.
     */
    @Override
    public void visitAnnotation(PsiAnnotation annotation) {
      if (!EndpointUtilities.isEndpointClass(annotation)) {
        return;
      }

      if (!GctConstants.APP_ENGINE_ANNOTATION_API_NAMESPACE.equals(
          annotation.getQualifiedName())) {
        return;
      }

      PsiAnnotationMemberValue ownerDomainMember =
          annotation.findAttributeValue(API_NAMESPACE_DOMAIN_ATTRIBUTE);
      if (ownerDomainMember == null) {
        return;
      }
      String ownerDomainWithQuotes = ownerDomainMember.getText();

      PsiAnnotationMemberValue ownerNameMember =
          annotation.findAttributeValue(API_NAMESPACE_NAME_ATTRIBUTE);
      if (ownerNameMember == null) {
        return;
      }
      String ownerNameWithQuotes = ownerNameMember.getText();

      String ownerDomain =
          EndpointUtilities.removeBeginningAndEndingQuotes(ownerDomainWithQuotes);
      String ownerName = EndpointUtilities.removeBeginningAndEndingQuotes(ownerNameWithQuotes);
      // Package Path has a default value of ""
      String packagePath =
          EndpointUtilities.removeBeginningAndEndingQuotes(
              annotation.findAttributeValue(API_NAMESPACE_PACKAGE_PATH_ATTRIBUTE).getText());

      boolean allUnspecified =
          ownerDomain.isEmpty() && ownerName.isEmpty() && packagePath.isEmpty();
      boolean ownerFullySpecified = !ownerDomain.isEmpty() && !ownerName.isEmpty();

      // Either everything must be fully unspecified or owner domain/name must both be specified.
      if (!allUnspecified && !ownerFullySpecified) {
        holder.registerProblem(
            annotation,
            "Invalid namespace configuration. If a namespace is set,"
                + " make sure to set an Owner Domain and Name. Package Path is optional.",
            new MyQuickFix());
      }
    }
  };
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:59,代码来源:ApiNamespaceInspection.java

示例13: applyFix

import com.intellij.psi.PsiAnnotation; //导入方法依赖的package包/类
/**
 * Provides a default value for OwnerName and OwnerDomain attributes in @ApiNamespace when they
 * are not provided.
 */
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
  PsiElement psiElement = descriptor.getPsiElement();
  if (psiElement == null) {
    return;
  }

  if (!(psiElement instanceof PsiAnnotation)) {
    return;
  }

  PsiAnnotation annotation = (PsiAnnotation) psiElement;
  if (!GctConstants.APP_ENGINE_ANNOTATION_API_NAMESPACE.equals(annotation.getQualifiedName())) {
    return;
  }

  PsiAnnotationMemberValue ownerDomainMember =
      annotation.findAttributeValue(API_NAMESPACE_DOMAIN_ATTRIBUTE);
  if (ownerDomainMember == null) {
    return;
  }
  String ownerDomainWithQuotes = ownerDomainMember.getText();

  PsiAnnotationMemberValue ownerNameMember =
      annotation.findAttributeValue(API_NAMESPACE_NAME_ATTRIBUTE);
  if (ownerNameMember == null) {
    return;
  }
  String ownerNameWithQuotes = ownerNameMember.getText();

  String ownerDomain = EndpointUtilities.removeBeginningAndEndingQuotes(ownerDomainWithQuotes);
  String ownerName = EndpointUtilities.removeBeginningAndEndingQuotes(ownerNameWithQuotes);

  if (ownerDomain.isEmpty() && ownerName.isEmpty()) {
    addOwnerDomainAndNameAttributes(project, annotation);
  } else if (ownerDomain.isEmpty() && !ownerName.isEmpty()) {
    addOwnerDomainAttribute(project, annotation);
  } else if (!ownerDomain.isEmpty() && ownerName.isEmpty()) {
    addOwnerNameAttribute(project, annotation);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:46,代码来源:ApiNamespaceInspection.java

示例14: buildVisitor

import com.intellij.psi.PsiAnnotation; //导入方法依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(
    @NotNull final com.intellij.codeInspection.ProblemsHolder holder, boolean isOnTheFly) {
  return new EndpointPsiElementVisitor() {

    @Override
    public void visitAnnotation(PsiAnnotation annotation) {
      if (annotation == null) {
        return;
      }

      if (!GctConstants.APP_ENGINE_ANNOTATION_API.equals(annotation.getQualifiedName())) {
        return;
      }

      // Need to check for user added attributes because default values are used when not
      // specified by user and we are only interested in the user specified values
      PsiAnnotationParameterList parameterList = annotation.getParameterList();
      if (parameterList.getAttributes().length == 0) {
        return;
      }

      PsiAnnotationMemberValue annotationMemberValue =
          annotation.findAttributeValue(API_NAME_ATTRIBUTE);
      if (annotationMemberValue == null) {
        return;
      }

      String nameValueWithQuotes = annotationMemberValue.getText();
      String nameValue = EndpointUtilities.removeBeginningAndEndingQuotes(nameValueWithQuotes);

      // Empty API name is valid
      if (nameValue.isEmpty()) {
        return;
      }

      if (!API_NAME_PATTERN.matcher(nameValue).matches()) {
        holder.registerProblem(
            annotationMemberValue,
            "Invalid api name: it must start with a lower case letter and consists only of "
                + "letter and digits",
            new MyQuickFix());
      }
    }
  };
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:48,代码来源:ApiNameInspection.java

示例15: getBooleanAnnotationValue

import com.intellij.psi.PsiAnnotation; //导入方法依赖的package包/类
public static boolean getBooleanAnnotationValue(@NotNull PsiAnnotation psiAnnotation, @NotNull String parameter, boolean defaultValue) {
  PsiAnnotationMemberValue attrValue = psiAnnotation.findAttributeValue(parameter);
  final Boolean result = null != attrValue ? resolveElementValue(attrValue, Boolean.class) : null;
  return result == null ? defaultValue : result;
}
 
开发者ID:mplushnikov,项目名称:lombok-intellij-plugin,代码行数:6,代码来源:PsiAnnotationUtil.java


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