本文整理汇总了Java中com.intellij.psi.PsiAnnotationMemberValue类的典型用法代码示例。如果您正苦于以下问题:Java PsiAnnotationMemberValue类的具体用法?Java PsiAnnotationMemberValue怎么用?Java PsiAnnotationMemberValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PsiAnnotationMemberValue类属于com.intellij.psi包,在下文中一共展示了PsiAnnotationMemberValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toStringImpl
import com.intellij.psi.PsiAnnotationMemberValue; //导入依赖的package包/类
/**
* Implementation of dynamicProxy.toString()
*/
private String toStringImpl() {
StringBuilder result = new StringBuilder(128);
result.append('@');
result.append(type.getName());
result.append('(');
boolean firstMember = true;
PsiNameValuePair[] attributes = myAnnotation.getParameterList().getAttributes();
for (PsiNameValuePair e : attributes) {
if (firstMember) {
firstMember = false;
}
else {
result.append(", ");
}
result.append(e.getName());
result.append('=');
PsiAnnotationMemberValue value = e.getValue();
result.append(value == null ? "null" : value.getText());
}
result.append(')');
return result.toString();
}
示例2: checkArgumentList
import com.intellij.psi.PsiAnnotationMemberValue; //导入依赖的package包/类
@Override
public boolean checkArgumentList(@NotNull AnnotationHolder holder, @NotNull GrAnnotation annotation) {
if (!GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO.equals(annotation.getQualifiedName())) return false;
final PsiAnnotationMemberValue valueAttribute = annotation.findAttributeValue("value");
if (valueAttribute == null) {
final PsiAnnotationOwner owner = annotation.getOwner();
if (owner instanceof GrModifierList) {
final PsiElement parent1 = ((GrModifierList)owner).getParent();
if (parent1 instanceof GrParameter) {
final PsiElement parent = parent1.getParent();
if (parent instanceof GrParameterList) {
for (GrParameter parameter : ((GrParameterList)parent).getParameters()) {
if (parameter.getModifierList().findAnnotation(GroovyCommonClassNames.GROOVY_LANG_DELEGATES_TO_TARGET) != null) {
return true;
}
}
}
}
}
}
return false;
}
示例3: addOwnerDomainAttribute
import com.intellij.psi.PsiAnnotationMemberValue; //导入依赖的package包/类
private void addOwnerDomainAttribute(
@NotNull final Project project, final PsiAnnotation annotation) {
new WriteCommandAction(project, annotation.getContainingFile()) {
@Override
protected void run(final Result result) throws Throwable {
// @A(ownerDomain = "your-company.com")
PsiAnnotationMemberValue newMemberValue =
JavaPsiFacade.getInstance(project)
.getElementFactory()
.createAnnotationFromText(
"@A("
+ API_NAMESPACE_DOMAIN_ATTRIBUTE
+ " = \""
+ SUGGESTED_DOMAIN_ATTRIBUTE
+ "\")",
null)
.findDeclaredAttributeValue(API_NAMESPACE_DOMAIN_ATTRIBUTE);
annotation.setDeclaredAttributeValue(API_NAMESPACE_DOMAIN_ATTRIBUTE, newMemberValue);
}
}.execute();
}
示例4: addOwnerNameAttribute
import com.intellij.psi.PsiAnnotationMemberValue; //导入依赖的package包/类
private void addOwnerNameAttribute(
@NotNull final Project project, final PsiAnnotation annotation) {
new WriteCommandAction(project, annotation.getContainingFile()) {
@Override
protected void run(final Result result) throws Throwable {
// @A(ownerName = "YourCo")
PsiAnnotationMemberValue newMemberValue =
JavaPsiFacade.getInstance(project)
.getElementFactory()
.createAnnotationFromText(
"@A("
+ API_NAMESPACE_NAME_ATTRIBUTE
+ " = \""
+ SUGGESTED_OWNER_ATTRIBUTE
+ "\")",
null)
.findDeclaredAttributeValue(API_NAMESPACE_NAME_ATTRIBUTE);
annotation.setDeclaredAttributeValue(API_NAMESPACE_NAME_ATTRIBUTE, newMemberValue);
}
}.execute();
}
示例5: getAttributeFromAnnotation
import com.intellij.psi.PsiAnnotationMemberValue; //导入依赖的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);
}
}
示例6: initializePsiMethod
import com.intellij.psi.PsiAnnotationMemberValue; //导入依赖的package包/类
private void initializePsiMethod(String methodName, String httpMethodValue, String pathValue) {
PsiAnnotationMemberValue mockAnnotationMemberValue1 = mock(PsiAnnotationMemberValue.class);
when(mockAnnotationMemberValue1.getText()).thenReturn(httpMethodValue);
PsiAnnotationMemberValue mockAnnotationMemberValue2 = mock(PsiAnnotationMemberValue.class);
when(mockAnnotationMemberValue2.getText()).thenReturn(pathValue);
PsiAnnotation mockAnnotation = mock(PsiAnnotation.class);
when(mockAnnotation.getQualifiedName())
.thenReturn(GctConstants.APP_ENGINE_ANNOTATION_API_METHOD);
when(mockAnnotation.findAttributeValue("httpMethod")).thenReturn(mockAnnotationMemberValue1);
when(mockAnnotation.findAttributeValue("path")).thenReturn(mockAnnotationMemberValue2);
PsiAnnotation[] mockAnnotationsArray = {mockAnnotation};
PsiModifierList mockModifierList = mock(PsiModifierList.class);
when(mockModifierList.getAnnotations()).thenReturn(mockAnnotationsArray);
mockPsiMethod = mock(PsiMethod.class);
when(mockPsiMethod.getModifierList()).thenReturn(mockModifierList);
when(mockPsiMethod.getName()).thenReturn(methodName);
when(mockPsiMethod.getContainingClass()).thenReturn(mockPsiClass);
PsiParameterList mockParameterList = mock(PsiParameterList.class);
when(mockParameterList.getParameters()).thenReturn(new PsiParameter[0]);
when(mockPsiMethod.getParameterList()).thenReturn(mockParameterList);
}
示例7: initializePsiClass
import com.intellij.psi.PsiAnnotationMemberValue; //导入依赖的package包/类
private void initializePsiClass(String apiResource, String apiClassResource) {
PsiAnnotationMemberValue mockAnnotationMemberValue1 = mock(PsiAnnotationMemberValue.class);
when(mockAnnotationMemberValue1.getText()).thenReturn(apiResource);
PsiAnnotationMemberValue mockAnnotationMemberValue2 = mock(PsiAnnotationMemberValue.class);
when(mockAnnotationMemberValue2.getText()).thenReturn(apiClassResource);
// Mock @Api(resource = "")
PsiAnnotation mockAnnotation1 = mock(PsiAnnotation.class);
when(mockAnnotation1.getQualifiedName()).thenReturn(GctConstants.APP_ENGINE_ANNOTATION_API);
when(mockAnnotation1.findAttributeValue("resource")).thenReturn(mockAnnotationMemberValue1);
// Mock @ApiClass(resource = "")
PsiAnnotation mockAnnotation2 = mock(PsiAnnotation.class);
when(mockAnnotation2.getQualifiedName())
.thenReturn(GctConstants.APP_ENGINE_ANNOTATION_API_CLASS);
when(mockAnnotation2.findAttributeValue("resource")).thenReturn(mockAnnotationMemberValue2);
PsiAnnotation[] mockAnnotationsArray = {mockAnnotation1, mockAnnotation2};
PsiModifierList mockModifierList = mock(PsiModifierList.class);
when(mockModifierList.getAnnotations()).thenReturn(mockAnnotationsArray);
mockPsiClass = mock(PsiClass.class);
when(mockPsiClass.getModifierList()).thenReturn(mockModifierList);
}
示例8: getAttributeValue
import com.intellij.psi.PsiAnnotationMemberValue; //导入依赖的package包/类
public static String getAttributeValue(PsiAnnotation annotation, String attributeName, DefaultPolicy policy) {
final PsiAnnotationMemberValue value = getAnnotationMemberValue(annotation, attributeName);
if (value != null) {
if (value instanceof PsiClassObjectAccessExpression) {
final PsiType type = ((PsiClassObjectAccessExpression) value).getType();
if (type == null) {
return null;
}
return type.getCanonicalText();
}
else {
final String text = value.getText();
return text.substring(1, text.length() - 1);
}
}
if (policy == DefaultPolicy.OWNER_IDENTIFIER_NAME) {
return PsiUtil.getName(getImmediateOwnerElement(annotation));
}
else {
return null;
}
}
示例9: shouldShow
import com.intellij.psi.PsiAnnotationMemberValue; //导入依赖的package包/类
@Override public boolean shouldShow(UsageTarget target, Usage usage) {
PsiElement element = ((UsageInfo2UsageAdapter) usage).getElement();
PsiMethod psimethod = PsiConsultantImpl.findMethod(element);
PsiAnnotationMemberValue attribValue = PsiConsultantImpl
.findTypeAttributeOfProvidesAnnotation(psimethod);
// Is it a @Provides method?
return psimethod != null
// Ensure it has an @Provides.
&& PsiConsultantImpl.hasAnnotation(psimethod, CLASS_PROVIDES)
// Check for Qualifier annotations.
&& PsiConsultantImpl.hasQuailifierAnnotations(psimethod, qualifierAnnotations)
// Right return type.
&& PsiConsultantImpl.getReturnClassFromMethod(psimethod, false)
.getName()
.equals(target.getName())
// Right type parameters.
&& PsiConsultantImpl.hasTypeParameters(psimethod, typeParameters)
// @Provides(type=SET)
&& attribValue != null
&& attribValue.textMatches(SET_TYPE);
}
示例10: getParameterizedLocation
import com.intellij.psi.PsiAnnotationMemberValue; //导入依赖的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;
}
示例11: extractNullityFromWhenValue
import com.intellij.psi.PsiAnnotationMemberValue; //导入依赖的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;
}
示例12: findTargetFeature
import com.intellij.psi.PsiAnnotationMemberValue; //导入依赖的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;
}
示例13: RemoveAnnotationValueFix
import com.intellij.psi.PsiAnnotationMemberValue; //导入依赖的package包/类
private RemoveAnnotationValueFix( @NotNull PsiAnnotationMemberValue annotationValueToRemove,
@NotNull PsiJavaCodeReferenceElement sideEffectClassReference )
{
super( message( "side.effects.annotation.declared.correctly.fix.remove.class.reference",
sideEffectClassReference.getQualifiedName() ) );
this.annotationValueToRemove = annotationValueToRemove;
}
示例14: RemoveInvalidConcernClassReferenceFix
import com.intellij.psi.PsiAnnotationMemberValue; //导入依赖的package包/类
public RemoveInvalidConcernClassReferenceFix( @NotNull PsiAnnotationMemberValue annotationValueToRemove,
@NotNull PsiJavaCodeReferenceElement concernClassReference )
{
super( message( "concerns.annotation.declared.correctly.fix.remove.concern.class.reference",
concernClassReference.getQualifiedName() ) );
this.concernClassAnnotationValue = annotationValueToRemove;
}
示例15: createProblemDescriptor
import com.intellij.psi.PsiAnnotationMemberValue; //导入依赖的package包/类
private ProblemDescriptor createProblemDescriptor( @NotNull InspectionManager manager,
@NotNull PsiAnnotationMemberValue mixinAnnotationValue,
@NotNull PsiJavaCodeReferenceElement mixinClassReference,
@NotNull String message )
{
RemoveInvalidMixinClassReferenceFix fix = new RemoveInvalidMixinClassReferenceFix(
mixinAnnotationValue, mixinClassReference
);
return manager.createProblemDescriptor( mixinAnnotationValue, message, fix, GENERIC_ERROR_OR_WARNING );
}