本文整理汇总了Java中com.intellij.psi.PsiModifierList.findAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java PsiModifierList.findAnnotation方法的具体用法?Java PsiModifierList.findAnnotation怎么用?Java PsiModifierList.findAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.PsiModifierList
的用法示例。
在下文中一共展示了PsiModifierList.findAnnotation方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitClass
import com.intellij.psi.PsiModifierList; //导入方法依赖的package包/类
@Override
public void visitClass(UClass uClass) {
//only check interface
if(!uClass.isInterface()){
return;
}
Set<PropInfo> infos = getPropInfoWithSupers(uClass);
if(infos.isEmpty()){
return;
}
//check method is relative of any field
for(UMethod method: uClass.getMethods()){
PsiModifierList list = method.getModifierList();
PsiAnnotation pa_keep = list.findAnnotation(NAME_KEEP);
PsiAnnotation pa_impl = list.findAnnotation(NAME_IMPL_METHOD);
if (pa_keep == null && pa_impl == null) {
if(!hasPropInfo(infos, method.getName())){
report(method);
}
}
}
}
示例2: errrantThisOrExtension
import com.intellij.psi.PsiModifierList; //导入方法依赖的package包/类
private void errrantThisOrExtension( PsiElement element, AnnotationHolder holder )
{
if( element instanceof PsiModifierList )
{
PsiModifierList mods = (PsiModifierList)element;
PsiAnnotation annotation;
if( (annotation = mods.findAnnotation( Extension.class.getName() )) != null ||
(annotation = mods.findAnnotation( This.class.getName() )) != null)
{
TextRange range = new TextRange( annotation.getTextRange().getStartOffset(),
annotation.getTextRange().getEndOffset() );
//noinspection ConstantConditions
holder.createErrorAnnotation( range, ExtIssueMsg.MSG_NOT_IN_EXTENSION_CLASS.get( ClassUtil.extractClassName( annotation.getQualifiedName() ) ) );
}
}
}
示例3: hasParameterName
import com.intellij.psi.PsiModifierList; //导入方法依赖的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;
}
示例4: findAnnotation
import com.intellij.psi.PsiModifierList; //导入方法依赖的package包/类
@Override
public PsiAnnotation findAnnotation(@NotNull final String qualifiedName) {
for (PsiModifierList sublist : mySublists) {
final PsiAnnotation annotation = sublist.findAnnotation(qualifiedName);
if (annotation != null) return annotation;
}
return null;
}
示例5: isAutoFactoryClass
import com.intellij.psi.PsiModifierList; //导入方法依赖的package包/类
static boolean isAutoFactoryClass(PsiElement element) {
PsiClass psiClass = getPsiClass(element);
if (psiClass == null || !psiClass.hasModifierProperty(PsiModifier.PUBLIC)) {
return false;
}
PsiModifierList modifiers = psiClass.getModifierList();
return modifiers != null && modifiers.findAnnotation(AUTO_FACTORY_ANNOTATION) != null;
}
示例6: hasAnnotation
import com.intellij.psi.PsiModifierList; //导入方法依赖的package包/类
private static boolean hasAnnotation(PsiField field) {
PsiModifierList modifiers = field.getModifierList();
if (modifiers == null) {
return false;
}
return modifiers.findAnnotation(JSR_330_INJECT_ANNOTATION) != null
|| modifiers.findAnnotation(GUICE_INJECT_ANNOTATION) != null;
}
示例7: hasTransformer
import com.intellij.psi.PsiModifierList; //导入方法依赖的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;
}
示例8: getNamedAnnotationValue
import com.intellij.psi.PsiModifierList; //导入方法依赖的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();
}
示例9: applyFix
import com.intellij.psi.PsiModifierList; //导入方法依赖的package包/类
/** Remove @Default and @Nullable from the method parameter if they exist. */
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement element = descriptor.getPsiElement();
if (element == null) {
return;
}
if (!(element instanceof PsiParameter)) {
return;
}
PsiModifierList modifierList = ((PsiParameter) element).getModifierList();
PsiAnnotation gaeNullableAnnotation =
modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_NULLABLE);
if (gaeNullableAnnotation != null) {
gaeNullableAnnotation.delete();
}
PsiAnnotation javaxNullableAnnotation =
modifierList.findAnnotation("javax.annotation.Nullable");
if (javaxNullableAnnotation != null) {
javaxNullableAnnotation.delete();
}
PsiAnnotation defaultValueAnnotation =
modifierList.findAnnotation(GctConstants.APP_ENGINE_ANNOTATION_DEFAULT_VALUE);
if (defaultValueAnnotation != null) {
defaultValueAnnotation.delete();
}
}
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:32,代码来源:InvalidParameterAnnotationsInspection.java
示例10: substituteClass
import com.intellij.psi.PsiModifierList; //导入方法依赖的package包/类
@Override
public GrClassSubstitution substituteClass(@NotNull PsiClass base) {
final PsiModifierList modifierList = base.getModifierList();
if (modifierList != null && modifierList.findAnnotation("groovy.lang.Trait") != null) {
return new TraitClass(base);
}
return null;
}
示例11: applyFix
import com.intellij.psi.PsiModifierList; //导入方法依赖的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);
}
示例12: insert
import com.intellij.psi.PsiModifierList; //导入方法依赖的package包/类
@Override
public void insert(@NotNull final PsiClass aClass, @Nullable PsiElement anchor, boolean before) throws IncorrectOperationException
{
final PsiMember existingMember;
if(myMember instanceof PsiField)
{
existingMember = aClass.findFieldByName(myMember.getName(), false);
}
else if(myMember instanceof PsiMethod)
{
existingMember = aClass.findMethodBySignature((PsiMethod) myMember, false);
}
else
{
existingMember = null;
}
if(existingMember == null || !myMergeIfExists)
{
PsiElement newMember = GenerateMembersUtil.insert(aClass, myMember, anchor, before);
myMember = (T) JavaCodeStyleManager.getInstance(aClass.getProject()).shortenClassReferences(newMember);
LOG.assertTrue(myMember.isValid(), myMember);
}
else
{
final PsiModifierList modifierList = myMember.getModifierList();
final PsiModifierList existingModifierList = existingMember.getModifierList();
if(modifierList != null && existingModifierList != null)
{
final PsiAnnotation[] psiAnnotations = modifierList.getAnnotations();
PsiElement annoAnchor = existingModifierList.getAnnotations().length > 0 ? existingModifierList.getAnnotations()[0] : existingModifierList.getFirstChild();
if(psiAnnotations.length > 0)
{
for(PsiAnnotation annotation : psiAnnotations)
{
final PsiAnnotation existingAnno = existingModifierList.findAnnotation(annotation.getQualifiedName());
if(existingAnno != null)
{
annoAnchor = existingAnno.replace(annotation);
}
else
{
existingModifierList.addBefore(annotation, annoAnchor);
}
}
}
}
myMember = (T) existingMember;
if(!myMember.isValid())
{
LOG.error("invalid member: " + myMember +
" existing member: " + existingMember.isValid() +
" self modified list: " + modifierList +
" existing modified list: " + existingModifierList);
}
}
}
示例13: addCapturePointIfNeeded
import com.intellij.psi.PsiModifierList; //导入方法依赖的package包/类
private static void addCapturePointIfNeeded(PsiModifierListOwner psiElement,
PsiMethod psiMethod,
String annotationName,
String defaultExpression,
boolean capture,
List<CapturePoint> capturePointsFromAnnotations)
{
CapturePoint capturePoint = new CapturePoint();
capturePoint.myEnabled = false;
if(capture)
{
capturePoint.myClassName = JVMNameUtil.getNonAnonymousClassName(psiMethod.getContainingClass());
capturePoint.myMethodName = JVMNameUtil.getJVMMethodName(psiMethod);
}
else
{
capturePoint.myInsertClassName = JVMNameUtil.getNonAnonymousClassName(psiMethod.getContainingClass());
capturePoint.myInsertMethodName = JVMNameUtil.getJVMMethodName(psiMethod);
}
PsiModifierList modifierList = psiElement.getModifierList();
if(modifierList != null)
{
PsiAnnotation annotation = modifierList.findAnnotation(annotationName);
if(annotation != null)
{
PsiAnnotationMemberValue keyExpressionValue = annotation.findAttributeValue("keyExpression");
String keyExpression = keyExpressionValue != null ? StringUtil.unquoteString(keyExpressionValue.getText()) : null;
if(StringUtil.isEmpty(keyExpression))
{
keyExpression = defaultExpression;
}
if(capture)
{
capturePoint.myCaptureKeyExpression = keyExpression;
}
else
{
capturePoint.myInsertKeyExpression = keyExpression;
}
PsiAnnotationMemberValue groupValue = annotation.findAttributeValue("group");
String group = groupValue != null ? StringUtil.unquoteString(groupValue.getText()) : null;
if(!StringUtil.isEmpty(group))
{
for(CapturePoint capturePointsFromAnnotation : capturePointsFromAnnotations)
{
if(StringUtil.startsWith(group, capturePointsFromAnnotation.myClassName) && StringUtil.endsWith(group, capturePointsFromAnnotation.myMethodName))
{
capturePointsFromAnnotation.myInsertClassName = capturePoint.myInsertClassName;
capturePointsFromAnnotation.myInsertMethodName = capturePoint.myInsertMethodName;
capturePointsFromAnnotation.myInsertKeyExpression = capturePoint.myInsertKeyExpression;
return;
}
}
}
}
}
capturePointsFromAnnotations.add(capturePoint);
}