本文整理汇总了Java中com.intellij.psi.PsiAnnotationMemberValue.getText方法的典型用法代码示例。如果您正苦于以下问题:Java PsiAnnotationMemberValue.getText方法的具体用法?Java PsiAnnotationMemberValue.getText怎么用?Java PsiAnnotationMemberValue.getText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.PsiAnnotationMemberValue
的用法示例。
在下文中一共展示了PsiAnnotationMemberValue.getText方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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;
}
}
示例3: buildVisitor
import com.intellij.psi.PsiAnnotationMemberValue; //导入方法依赖的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());
}
}
};
}
示例4: applyFix
import com.intellij.psi.PsiAnnotationMemberValue; //导入方法依赖的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);
}
示例5: getStringValue
import com.intellij.psi.PsiAnnotationMemberValue; //导入方法依赖的package包/类
public String getStringValue() {
final PsiClass value = getValue();
if (value != null) return value.getQualifiedName();
final PsiAnnotationMemberValue psi = getPsiElement();
if (psi == null) return null;
final String text = psi.getText();
if (text != null && text.endsWith(".class")) return text.substring(0, text.length() - ".class".length());
return null;
}
示例6: buildVisitor
import com.intellij.psi.PsiAnnotationMemberValue; //导入方法依赖的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());
}
}
};
}
示例7: applyFix
import com.intellij.psi.PsiAnnotationMemberValue; //导入方法依赖的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);
}
}
示例8: buildVisitor
import com.intellij.psi.PsiAnnotationMemberValue; //导入方法依赖的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());
}
}
};
}