Java 类com.intellij.psi.PsiModifierListOwner 实例源码

项目:nullability-annotations-inspection    文件:NullabilityAnnotationsInspection.java   
private void createProblemDescriptorWithQuickFixes(PsiModifierListOwner owner,
                                                   InspectionManager manager,
                                                   Collection<ProblemDescriptor> problemDescriptors,
                                                   PsiElement element) {
    if (element.isPhysical()) {
        LocalQuickFix[] localQuickFixes = createQuickFixes(owner, isRemoveRedundantAnnotations());
        ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(
                element,
                MISSING_NULLABLE_NONNULL_ANNOTATION,
                localQuickFixes,
                GENERIC_ERROR_OR_WARNING,
                true,
                false);
        problemDescriptors.add(problemDescriptor);
    }
}
项目:nullability-annotations-inspection    文件:NullabilityAnnotationsWithTypeQualifierDefault.java   
static List<String> findAnnotations(PsiModifierListOwner element, boolean nullable) {
    if (overridesSuper(element)) {
        return Collections.emptyList();
    }

    List<String> annotations = new ArrayList<>();
    Project project = element.getProject();
    PsiModifierList modifierList = element.getModifierList();
    List<String> nullabilityAnnotations = nullable
            ? NullableNotNullManager.getInstance(project).getNullables()
            : NullableNotNullManager.getInstance(project).getNotNulls();
    for (String notNullAnnotationFqn : nullabilityAnnotations) {
        PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
        PsiAnnotation annotation = factory.createAnnotationFromText("@" + notNullAnnotationFqn, null);
        PsiAnnotation.TargetType[] targetTypes = getTargetsForLocation(modifierList);
        if (isNullabilityAnnotationForTypeQualifierDefault(annotation, nullable, targetTypes)) {
            annotations.add(annotation.getQualifiedName());
        }
    }
    return annotations;
}
项目:manifold-ij    文件:ManGotoDeclarationHandler.java   
public static PsiElement find( PsiModifierListOwner resolve, ManifoldPsiClass facade )
{
  PsiModifierList modifierList = resolve.getModifierList();
  if( modifierList == null )
  {
    return null;
  }

  PsiAnnotation[] annotations = modifierList.getAnnotations();
  if( annotations.length > 0 &&
      Objects.equals( annotations[0].getQualifiedName(), SourcePosition.class.getName() ) )
  {
    return findTargetFeature( annotations[0], facade );
  }

  if( !facade.getRawFiles().isEmpty() &&
      DarkJavaTypeManifold.FILE_EXTENSIONS.stream()
        .anyMatch( ext -> ext.equalsIgnoreCase( facade.getRawFiles().get( 0 ).getVirtualFile().getExtension() ) ) )
  {
    // DarkJava is Java
    return facade.getRawFiles().get( 0 ).findElementAt( resolve.getTextOffset() );
  }

  return null;
}
项目:manifold-ij    文件:ResourceToManifoldUtil.java   
private static boolean isJavaElementForType( PsiModifierListOwner modifierListOwner, PsiClass psiClass )
{
  PsiAnnotation annotation = modifierListOwner.getModifierList().findAnnotation( TypeReference.class.getName() );
  if( annotation != null )
  {
    PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
    for( PsiNameValuePair pair : attributes )
    {
      String fqn = pair.getLiteralValue();
      if( psiClass.getQualifiedName().contains( fqn ) )
      {
        return true;
      }
    }
  }
  return false;
}
项目:here-be-dragons    文件:AnnotationDetector.java   
static PsiAnnotation findAnnotation(PsiElement element, String annotationName) {
    if (element instanceof PsiModifierListOwner) {
        PsiModifierListOwner listOwner = (PsiModifierListOwner) element;
        PsiModifierList modifierList = listOwner.getModifierList();

        if (modifierList != null) {
            for (PsiAnnotation psiAnnotation : modifierList.getAnnotations()) {
                if (annotationName.equals(psiAnnotation.getQualifiedName())) {
                    return psiAnnotation;
                }
            }
        }

    }
    return null;
}
项目:intellij-ce-playground    文件:ToggleSourceInferredAnnotations.java   
@Override
public boolean isAvailable(@NotNull final Project project, Editor editor, PsiFile file) {
  final PsiElement leaf = file.findElementAt(editor.getCaretModel().getOffset());
  final PsiModifierListOwner owner = getAnnotationOwner(leaf);
  if (owner != null && isSourceCode(owner)) {
    boolean hasSrcInferredAnnotation = ContainerUtil.or(findSignatureNonCodeAnnotations(owner, true), new Condition<PsiAnnotation>() {
      @Override
      public boolean value(PsiAnnotation annotation) {
        return AnnotationUtil.isInferredAnnotation(annotation);
      }
    });
    if (hasSrcInferredAnnotation) {
      setText((CodeInsightSettings.getInstance().SHOW_SOURCE_INFERRED_ANNOTATIONS ? "Hide" : "Show") + " annotations inferred from source code");
      return true;
    }
  }

  return false;
}
项目:intellij-ce-playground    文件:LiteralExpressionTokenizer.java   
@Override
public void tokenize(@NotNull PsiLiteralExpression element, TokenConsumer consumer) {
  PsiLiteralExpressionImpl literalExpression = (PsiLiteralExpressionImpl)element;
  if (literalExpression.getLiteralElementType() != JavaTokenType.STRING_LITERAL) return;  // not a string literal

  String text = literalExpression.getInnerText();
  if (StringUtil.isEmpty(text) || text.length() <= 2) { // optimisation to avoid expensive injection check
    return;
  }
  if (InjectedLanguageUtil.hasInjections(literalExpression)) return;

  final PsiModifierListOwner listOwner = PsiTreeUtil.getParentOfType(element, PsiModifierListOwner.class);
  if (listOwner != null && AnnotationUtil.isAnnotated(listOwner, Collections.singleton(AnnotationUtil.NON_NLS), false, false)) {
    return;
  }

  if (!text.contains("\\")) {
    consumer.consumeToken(element, PlainTextSplitter.getInstance());
  }
  else {
    processTextWithEscapeSequences(element, text, consumer);
  }
}
项目:intellij-ce-playground    文件:CompilerIconLayerProvider.java   
@Override
public Icon getLayerIcon(@NotNull Iconable element, boolean isLocked) {
  VirtualFile vFile = null;
  Project project = null;
  if (element instanceof PsiModifierListOwner) {
    project = ((PsiModifierListOwner) element).getProject();
    final PsiFile containingFile = ((PsiModifierListOwner) element).getContainingFile();
    vFile = containingFile == null ? null : containingFile.getVirtualFile();
  }
  else if (element instanceof PsiDirectory) {
    project = ((PsiDirectory) element).getProject();
    vFile = ((PsiDirectory) element).getVirtualFile();
  }
  if (vFile != null && isExcluded(vFile, project)) {
    return PlatformIcons.EXCLUDED_FROM_COMPILE_ICON;
  }
  return null;
}
项目:tools-idea    文件:CompilerIconLayerProvider.java   
@Override
public Icon getLayerIcon(@NotNull Iconable element, boolean isLocked) {
  VirtualFile vFile = null;
  Project project = null;
  if (element instanceof PsiModifierListOwner) {
    project = ((PsiModifierListOwner) element).getProject();
    final PsiFile containingFile = ((PsiModifierListOwner) element).getContainingFile();
    vFile = containingFile == null ? null : containingFile.getVirtualFile();
  }
  else if (element instanceof PsiDirectory) {
    project = ((PsiDirectory) element).getProject();
    vFile = ((PsiDirectory) element).getVirtualFile();
  }
  if (vFile != null && isExcluded(vFile, project)) {
    return PlatformIcons.EXCLUDED_FROM_COMPILE_ICON;
  }
  return null;
}
项目:tools-idea    文件:LiteralExpressionTokenizer.java   
@Override
public void tokenize(@NotNull PsiLiteralExpression element, TokenConsumer consumer) {
  PsiLiteralExpressionImpl literalExpression = (PsiLiteralExpressionImpl) element;
  if (literalExpression.getLiteralElementType() != JavaTokenType.STRING_LITERAL) {
    return;  // not a string literal
  }

  final PsiModifierListOwner listOwner = PsiTreeUtil.getParentOfType(element, PsiModifierListOwner.class);
  if (listOwner != null && AnnotationUtil.isAnnotated(listOwner, Collections.singleton(AnnotationUtil.NON_NLS), false, false)) {
    return;
  }

  String text = literalExpression.getInnerText();
  if (text == null) {
    return;
  }
  if (!text.contains("\\")) {
    consumer.consumeToken(element, PlainTextSplitter.getInstance());
  }
  else {
    processTextWithEscapeSequences(element, text, consumer);
  }
}
项目:consulo-java    文件:MetaAnnotationUtil.java   
/**
 * Check if listOwner is annotated with annotations or listOwner's annotations contain given annotations
 */
public static boolean isMetaAnnotated(@NotNull PsiModifierListOwner listOwner, @NotNull final Collection<String> annotations)
{
    if(AnnotationUtil.isAnnotated(listOwner, annotations, false))
    {
        return true;
    }

    final List<PsiClass> resolvedAnnotations = getResolvedClassesInAnnotationsList(listOwner);
    for(String annotationFQN : annotations)
    {
        for(PsiClass resolvedAnnotation : resolvedAnnotations)
        {
            if(metaAnnotationCached(resolvedAnnotation, annotationFQN) != null)
            {
                return true;
            }
        }
    }

    return false;
}
项目:lombok-intellij-plugin    文件:DelegateHandler.java   
public boolean validate(@NotNull PsiModifierListOwner psiModifierListOwner, @NotNull PsiType psiType, @NotNull PsiAnnotation psiAnnotation, @NotNull ProblemBuilder builder) {
  boolean result = true;

  if (psiModifierListOwner.hasModifierProperty(PsiModifier.STATIC)) {
    builder.addError("@Delegate is legal only on instance fields or no-argument instance methods.");
    result = false;
  }

  final Collection<PsiType> types = collectDelegateTypes(psiAnnotation, psiType);
  result &= validateTypes(types, builder);

  final Collection<PsiType> excludes = collectExcludeTypes(psiAnnotation);
  result &= validateTypes(excludes, builder);

  return result;
}
项目:consulo-java    文件:ExternalAnnotationsLineMarkerProvider.java   
@Nullable
static PsiModifierListOwner getAnnotationOwner(@Nullable PsiElement element)
{
    if(element == null)
    {
        return null;
    }

    PsiElement owner = element.getParent();
    if(!(owner instanceof PsiModifierListOwner) || !(owner instanceof PsiNameIdentifierOwner))
    {
        return null;
    }
    if(owner instanceof PsiParameter || owner instanceof PsiLocalVariable)
    {
        return null;
    }

    // support non-Java languages where getNameIdentifier may return non-physical psi with the same range
    PsiElement nameIdentifier = ((PsiNameIdentifierOwner) owner).getNameIdentifier();
    if(nameIdentifier == null || !nameIdentifier.getTextRange().equals(element.getTextRange()))
    {
        return null;
    }
    return (PsiModifierListOwner) owner;
}
项目:consulo-java    文件:ToggleSourceInferredAnnotations.java   
@Override
public boolean isAvailable(@NotNull final Project project, Editor editor, PsiFile file)
{
    final PsiElement leaf = file.findElementAt(editor.getCaretModel().getOffset());
    final PsiModifierListOwner owner = getAnnotationOwner(leaf);
    if(owner != null)
    {
        boolean hasSrcInferredAnnotation = ContainerUtil.exists(AnnotationDocGenerator.getAnnotationsToShow(owner), AnnotationDocGenerator::isInferredFromSource);
        if(hasSrcInferredAnnotation)
        {
            setText((JavaCodeInsightSettings.getInstance().SHOW_SOURCE_INFERRED_ANNOTATIONS ? "Hide" : "Show") + " annotations inferred from source code");
            return true;
        }
    }

    return false;
}
项目:consulo-java    文件:MakeInferredAnnotationExplicit.java   
@Override
public boolean isAvailable(@NotNull final Project project, Editor editor, PsiFile file)
{
    final PsiElement leaf = file.findElementAt(editor.getCaretModel().getOffset());
    final PsiModifierListOwner owner = ExternalAnnotationsLineMarkerProvider.getAnnotationOwner(leaf);
    if(owner != null && owner.getLanguage().isKindOf(JavaLanguage.INSTANCE) && isWritable(owner) && ModuleUtilCore.findModuleForPsiElement(file) != null && PsiUtil.getLanguageLevel(file)
            .isAtLeast(LanguageLevel.JDK_1_5))
    {
        final PsiAnnotation[] annotations = InferredAnnotationsManager.getInstance(project).findInferredAnnotations(owner);
        if(annotations.length > 0)
        {
            final String annos = StringUtil.join(annotations, annotation ->
            {
                final PsiJavaCodeReferenceElement nameRef = correctAnnotation(annotation).getNameReferenceElement();
                final String name = nameRef != null ? nameRef.getReferenceName() : annotation.getQualifiedName();
                return "@" + name + annotation.getParameterList().getText();
            }, " ");
            setText("Insert '" + annos + "'");
            return true;
        }
    }

    return false;
}
项目:consulo-java    文件:MakeExternalAnnotationExplicit.java   
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file)
{
    final PsiElement leaf = file.findElementAt(editor.getCaretModel().getOffset());
    final PsiModifierListOwner owner = ExternalAnnotationsLineMarkerProvider.getAnnotationOwner(leaf);
    if(owner != null && owner.getLanguage().isKindOf(JavaLanguage.INSTANCE) && isWritable(owner) && ModuleUtilCore.findModuleForPsiElement(file) != null && PsiUtil.getLanguageLevel(file)
            .isAtLeast(LanguageLevel.JDK_1_5))
    {
        final PsiAnnotation[] annotations = getAnnotations(project, owner);
        if(annotations.length > 0)
        {
            final String annos = StringUtil.join(annotations, annotation ->
            {
                final PsiJavaCodeReferenceElement nameRef = annotation.getNameReferenceElement();
                final String name = nameRef != null ? nameRef.getReferenceName() : annotation.getQualifiedName();
                return "@" + name + annotation.getParameterList().getText();
            }, " ");
            setText("Insert '" + annos + "'");
            return true;
        }
    }

    return false;
}
项目:lombok-intellij-plugin    文件:BaseLombokHandler.java   
private void addAnnotation(@NotNull PsiModifierListOwner targetElement, @NotNull PsiAnnotation newPsiAnnotation,
                           @NotNull Class<? extends Annotation> annotationClass) {
  final PsiAnnotation presentAnnotation = PsiAnnotationSearchUtil.findAnnotation(targetElement, annotationClass);

  final Project project = targetElement.getProject();
  final JavaCodeStyleManager javaCodeStyleManager = JavaCodeStyleManager.getInstance(project);
  javaCodeStyleManager.shortenClassReferences(newPsiAnnotation);

  if (null == presentAnnotation) {
    PsiModifierList modifierList = targetElement.getModifierList();
    if (null != modifierList) {
      modifierList.addAfter(newPsiAnnotation, null);
    }
  } else {
    presentAnnotation.setDeclaredAttributeValue(PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME,
      newPsiAnnotation.findDeclaredAttributeValue(PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME));
  }
}
项目:consulo-java    文件:MakeExternalAnnotationExplicit.java   
@NotNull
private PsiAnnotation[] getAnnotations(@NotNull Project project, PsiModifierListOwner owner)
{
    PsiAnnotation[] annotations = ExternalAnnotationsManager.getInstance(project).findExternalAnnotations(owner);
    if(annotations == null)
    {
        return PsiAnnotation.EMPTY_ARRAY;
    }
    else
    {
        JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
        return Arrays.stream(annotations).filter(anno ->
        {
            String qualifiedName = anno.getQualifiedName();
            return qualifiedName != null && facade.findClass(qualifiedName, owner.getResolveScope()) != null;
        }).toArray(PsiAnnotation[]::new);
    }
}
项目:guards    文件:PsiGuard.java   
@Nullable
public static PsiGuard of(@Nullable PsiAnnotation annotation) {
    if ( annotation == null ) {
        return null;
    }
    PsiGuardType psiGuardType = PsiGuardType.ofPsiAnnotation(annotation);
    if ( psiGuardType == null ) {
        return null;
    }
    if ( !(annotation.getOwner() instanceof PsiModifierListOwner) ) {
        return null;
    }
    PsiGuardTarget target = PsiGuardTarget.get((PsiModifierListOwner)annotation.getOwner());
    if ( target == null ) {
        return null;
    }
    return new PsiGuard(annotation, psiGuardType, target);
}
项目:consulo-javaee    文件:JamAnnotationMeta.java   
public <T extends PsiModifierListOwner> void registerTopLevelSem(SemRegistrar registrar, final ElementPattern<? extends T> parentPattern, final JamMemberMeta<T,?> parentMeta) {
  final boolean isPackage = parentMeta instanceof JamPackageMeta;
  final PsiAnnotationPattern annoPattern = myAnnoNamePattern.withSuperParent(
      2, isPackage ? PACKAGE_STATEMENT.with(new PatternCondition<PsiPackageStatement>("package") {
      @Override
      public boolean accepts(@NotNull PsiPackageStatement psiPackageStatement, ProcessingContext context) {
        return parentPattern.accepts(psiPackageStatement.getPackageReference().resolve(), context);
      }
    }) : parentPattern);
  registrar.registerSemElementProvider(myMetaKey, annoPattern, annotation -> {
    final PsiElement parent = annotation.getParent().getParent();
    final T element = (isPackage && parent instanceof PsiPackageStatement? (T)((PsiPackageStatement)parent).getPackageReference().resolve() : (T)parent);
    if (element != null && SemService.getSemService(annotation.getProject()).getSemElement(parentMeta.getMetaKey(), element) == parentMeta) {
      return this;
    }
    return null;
  });

  registerChildren(registrar, annoPattern);
}
项目:consulo-java    文件:LiteralExpressionTokenizer.java   
@Override
public void tokenize(@NotNull PsiLiteralExpression element, TokenConsumer consumer) {
  PsiLiteralExpressionImpl literalExpression = (PsiLiteralExpressionImpl) element;
  if (literalExpression.getLiteralElementType() != JavaTokenType.STRING_LITERAL) {
    return;  // not a string literal
  }

  final PsiModifierListOwner listOwner = PsiTreeUtil.getParentOfType(element, PsiModifierListOwner.class);
  if (listOwner != null && AnnotationUtil.isAnnotated(listOwner, Collections.singleton(AnnotationUtil.NON_NLS), false, false)) {
    return;
  }

  String text = literalExpression.getInnerText();
  if (text == null) {
    return;
  }
  if (!text.contains("\\")) {
    consumer.consumeToken(element, PlainTextSplitter.getInstance());
  }
  else {
    processTextWithEscapeSequences(element, text, consumer);
  }
}
项目:consulo-google-guice    文件:GoogleGuiceAnnotationUtil.java   
@RequiredReadAction
public static Collection<String> getInjectAnnotations(@NotNull PsiModifierListOwner element)
{
    GoogleGuiceModuleExtension extension = ModuleUtilCore.getExtension(element, GoogleGuiceModuleExtension.class);
    if(extension == null)
    {
        return Collections.emptyList();
    }

    List<String> anno = new ArrayList<>(2);
    if(extension.isUseJSR330())
    {
        anno.add(JSR330_INJECT);
    }
    anno.add(GUICE_INJECT);
    return anno;
}
项目:consulo-google-guice    文件:GoogleGuiceAnnotationUtil.java   
@RequiredReadAction
public static Collection<String> getSingletonAnnotations(@NotNull PsiModifierListOwner element)
{
    GoogleGuiceModuleExtension extension = ModuleUtilCore.getExtension(element, GoogleGuiceModuleExtension.class);
    if(extension == null)
    {
        return Collections.emptyList();
    }

    List<String> anno = new ArrayList<>(2);
    if(extension.isUseJSR330())
    {
        anno.add(JSR330_SINGLETON);
    }
    anno.add(GUICE_SINGLETON);
    return anno;
}
项目:consulo-java    文件:BaseExternalAnnotationsManager.java   
@NotNull
private List<AnnotationData> collectExternalAnnotations(@NotNull PsiModifierListOwner listOwner)
{
    if(!hasAnyAnnotationsRoots())
    {
        return Collections.emptyList();
    }

    List<AnnotationData> cached;
    while(true)
    {
        cached = (List<AnnotationData>) cache.get(listOwner);
        if(cached == NO_DATA || !cached.isEmpty())
        {
            return cached;
        }
        List<AnnotationData> computed = doCollect(listOwner, false);
        if(cache.replace(listOwner, cached, computed))
        {
            cached = computed;
            break;
        }
    }
    return cached;
}
项目:consulo-java    文件:ExternalAnnotationsLineMarkerProvider.java   
@Nullable
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element)
{
    PsiModifierListOwner owner = getAnnotationOwner(element);
    if(owner == null)
    {
        return null;
    }

    boolean includeSourceInferred = JavaCodeInsightSettings.getInstance().SHOW_SOURCE_INFERRED_ANNOTATIONS;
    boolean hasAnnotationsToShow = ContainerUtil.exists(NonCodeAnnotationGenerator.getSignatureNonCodeAnnotations(owner).values(), a -> includeSourceInferred || !a.isInferredFromSource());
    if(!hasAnnotationsToShow)
    {
        return null;
    }

    return new LineMarkerInfo<>(element, element.getTextRange(), JavaIcons.Gutter.ExtAnnotation, Pass.LINE_MARKERS, ourTooltipProvider, MyIconGutterHandler.INSTANCE, GutterIconRenderer.Alignment
            .RIGHT);
}
项目:consulo-java    文件:ProjectBytecodeAnalysis.java   
@Nullable
public PsiAnnotation findInferredAnnotation(@NotNull PsiModifierListOwner listOwner, @NotNull String annotationFQN)
{
    if(!(listOwner instanceof PsiCompiledElement))
    {
        return null;
    }
    if(annotationFQN.equals(AnnotationUtil.NOT_NULL) || annotationFQN.equals(AnnotationUtil.NULLABLE) || annotationFQN.equals(ControlFlowAnalyzer.ORG_JETBRAINS_ANNOTATIONS_CONTRACT))
    {
        PsiAnnotation[] annotations = findInferredAnnotations(listOwner);
        for(PsiAnnotation annotation : annotations)
        {
            if(annotationFQN.equals(annotation.getQualifiedName()))
            {
                return annotation;
            }
        }
        return null;
    }
    else
    {
        return null;
    }
}
项目:consulo-java    文件:ProjectBytecodeAnalysis.java   
@NotNull
public PsiAnnotation[] findInferredAnnotations(@NotNull final PsiModifierListOwner listOwner)
{
    if(!(listOwner instanceof PsiCompiledElement))
    {
        return PsiAnnotation.EMPTY_ARRAY;
    }
    return CachedValuesManager.getCachedValue(listOwner, new CachedValueProvider<PsiAnnotation[]>()
    {
        @Nullable
        @Override
        public Result<PsiAnnotation[]> compute()
        {
            return CachedValueProvider.Result.create(ProjectBytecodeAnalysis.this.collectInferredAnnotations(listOwner), listOwner);
        }
    });
}
项目:consulo-java    文件:ProjectBytecodeAnalysis.java   
@Nullable
public static HKey getKey(@NotNull PsiModifierListOwner owner, MessageDigest md)
{
    LOG.assertTrue(owner instanceof PsiCompiledElement, owner);
    if(owner instanceof PsiMethod)
    {
        return BytecodeAnalysisConverter.psiKey((PsiMethod) owner, Out, md);
    }
    if(owner instanceof PsiParameter)
    {
        PsiElement parent = owner.getParent();
        if(parent instanceof PsiParameterList)
        {
            PsiElement gParent = parent.getParent();
            if(gParent instanceof PsiMethod)
            {
                final int index = ((PsiParameterList) parent).getParameterIndex((PsiParameter) owner);
                return BytecodeAnalysisConverter.psiKey((PsiMethod) gParent, new In(index, In.NOT_NULL_MASK), md);
            }
        }
    }
    return null;
}
项目:consulo-java    文件:AddNullableNotNullAnnotationFix.java   
@Override
public boolean isAvailable(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement)
{
    if(!super.isAvailable(project, file, startElement, endElement))
    {
        return false;
    }
    PsiModifierListOwner owner = getContainer(file, startElement.getTextRange().getStartOffset());
    if(owner == null || AnnotationUtil.isAnnotated(owner, getAnnotationsToRemove()[0], false, false))
    {
        return false;
    }
    if(owner instanceof PsiMethod)
    {
        PsiType returnType = ((PsiMethod) owner).getReturnType();

        return returnType != null && !(returnType instanceof PsiPrimitiveType);
    }
    return true;
}
项目:nullability-annotations-inspection    文件:QuickFixFactory.java   
static LocalQuickFix[] createQuickFixes(PsiModifierListOwner owner, boolean removeRedundantAnnotations) {
    List<LocalQuickFix> quickFixes = new ArrayList<>();

    NullabilityAnnotationsWithTypeQualifierDefault.findAnnotations(owner, false)
            .forEach(defaultAnnotation -> quickFixes.add(new AddPackageInfoWithNullabilityDefaultsFix(owner,
                    defaultAnnotation,
                    false,
                    removeRedundantAnnotations)));

    NullabilityAnnotationsWithTypeQualifierDefault.findAnnotations(owner, true)
            .forEach(defaultAnnotation -> quickFixes.add(new AddPackageInfoWithNullabilityDefaultsFix(owner,
                    defaultAnnotation,
                    true,
                    removeRedundantAnnotations)));

    quickFixes.add(new AddNotNullAnnotationFix(owner) {
        @Override
        protected boolean isAvailable() {
            return true;
        }
    });

    quickFixes.add(new AddNullableAnnotationFix(owner) {
        @Override
        protected boolean isAvailable() {
            return true;
        }
    });

    return quickFixes.toArray(new LocalQuickFix[0]);
}
项目:nullability-annotations-inspection    文件:AddPackageInfoWithNullabilityDefaultsFix.java   
AddPackageInfoWithNullabilityDefaultsFix(PsiModifierListOwner element,
                                         String annotationForTypeQualifierFqn,
                                         boolean nullable,
                                         boolean removeRedundantAnnotations) {
    super(element);

    this.annotationForTypeQualifierFqn = annotationForTypeQualifierFqn;
    this.nullable = nullable;
    this.removeRedundantAnnotations = removeRedundantAnnotations;
}
项目:nullability-annotations-inspection    文件:AddPackageInfoWithNullabilityDefaultsFix.java   
private void removeRedundantAnnotations(PsiModifierListOwner element,
                                        List<String> redundantAnnotations,
                                        Set<PsiAnnotation.TargetType> targetsForDefaultAnnotation) {
    PsiAnnotation.TargetType[] targetTypes = getTargetsForLocation(element.getModifierList());
    boolean isTargeted = targetsForDefaultAnnotation.isEmpty()
            || ContainerUtil.intersects(targetsForDefaultAnnotation, Arrays.asList(targetTypes));
    if (isTargeted) {
        removePhysicalAnnotations(element, ArrayUtil.toStringArray(redundantAnnotations));
    }
}
项目:nullability-annotations-inspection    文件:NullabilityAnnotationsWithTypeQualifierDefault.java   
private static boolean overridesSuper(PsiModifierListOwner element) {
    if (element instanceof PsiParameter) {
        PsiMethod method = (PsiMethod) element.getParent().getParent();
        return !superMethods(method).isEmpty();
    } else if (element instanceof PsiMethod) {
        return !superMethods((PsiMethod) element).isEmpty();
    }
    return false;
}
项目:intellij-plugin    文件:CoffigResolver.java   
Optional<PsiAnnotation> getConfigAnnotation(@NotNull PsiModifierListOwner psiModifierListOwner) {
    return Optional.ofNullable(psiModifierListOwner.getModifierList())
            .map(PsiAnnotationOwner::getAnnotations)
            .map(Arrays::stream)
            .map(stream -> stream.filter(annotation -> Optional.ofNullable(annotation.getNameReferenceElement())
                    .map(PsiReference::resolve)
                    .map(psiElement -> psiElement == configAnnotationClass)
                    .orElse(false)
            ))
            .flatMap(Stream::findFirst);
}
项目:intellij-plugin    文件:ResourceNode.java   
private PsiAnnotation getPathAnnotation(PsiClass pathAnnotationClass, @NotNull PsiModifierListOwner psiModifierListOwner) {
    return Optional.ofNullable(psiModifierListOwner.getModifierList())
            .map(PsiAnnotationOwner::getAnnotations)
            .map(Arrays::stream)
            .map(stream -> stream.filter(annotation -> Optional.ofNullable(annotation.getNameReferenceElement())
                    .map(PsiReference::resolve)
                    .map(psiElement -> psiElement == pathAnnotationClass)
                    .orElse(false)
            ))
            .flatMap(Stream::findFirst)
            .orElse(null);
}
项目:manifold-ij    文件:ManGotoDeclarationHandler.java   
public static PsiElement find( PsiElement resolve )
{
  PsiFile file = resolve.getContainingFile();
  if( file != null )
  {
    ManifoldPsiClass facade = resolve instanceof ManifoldPsiClass ? (ManifoldPsiClass)resolve : file.getUserData( ManifoldPsiClass.KEY_MANIFOLD_PSI_CLASS );
    if( facade != null )
    {
      PsiElement annotations = find( (PsiModifierListOwner)resolve, facade );
      if( annotations != null ) return annotations;
    }
  }
  return null;
}
项目:manifold-ij    文件:ResourceToManifoldUtil.java   
private static boolean isJavaElementFor( PsiModifierListOwner modifierListOwner, PsiElement element )
{
  PsiAnnotation annotation = modifierListOwner.getModifierList().findAnnotation( SourcePosition.class.getName() );
  if( annotation != null )
  {
    int textOffset = element.getTextOffset();
    int textLength = element instanceof PsiNamedElement ? ((PsiNamedElement)element).getName().length() : element.getTextLength();
    PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
    int offset = -1;
    for( PsiNameValuePair pair : attributes )
    {
      if( pair.getNameIdentifier().getText().equals( SourcePosition.OFFSET ) )
      {
        String literalValue = pair.getLiteralValue();
        if( literalValue == null )
        {
          return false;
        }
        offset = Integer.parseInt( literalValue );
        break;
      }
    }
    if( offset >= textOffset && offset <= textOffset + textLength )
    {
      return true;
    }
  }
  return false;
}
项目:manifold-ij    文件:StubBuilder.java   
private void addAnnotations( SrcAnnotated<?> srcAnnotated, PsiModifierListOwner annotated )
{
  for( PsiAnnotation psiAnno : annotated.getModifierList().getAnnotations() )
  {
    SrcAnnotationExpression annoExpr = new SrcAnnotationExpression( psiAnno.getQualifiedName() );
    for( PsiNameValuePair value : psiAnno.getParameterList().getAttributes() )
    {
      SrcArgument srcArg = new SrcArgument( new SrcRawExpression( value.getLiteralValue() ) );
      annoExpr.addArgument( srcArg ).name( value.getName() );
    }
    srcAnnotated.addAnnotation( annoExpr );
  }
}
项目:intellij-ce-playground    文件:EntryPointsManagerBase.java   
@Override
public boolean isEntryPoint(@NotNull PsiElement element) {
  if (!(element instanceof PsiModifierListOwner)) return false;
  PsiModifierListOwner owner = (PsiModifierListOwner)element;
  if (!ADDITIONAL_ANNOTATIONS.isEmpty() && ADDITIONAL_ANNOTATIONS.contains(Deprecated.class.getName()) &&
      element instanceof PsiDocCommentOwner && ((PsiDocCommentOwner)element).isDeprecated()) {
    return true;
  }

  return AnnotationUtil.checkAnnotatedUsingPatterns(owner, ADDITIONAL_ANNOTATIONS) ||
         AnnotationUtil.checkAnnotatedUsingPatterns(owner, getAdditionalAnnotations());
}
项目:intellij-ce-playground    文件:SpecialAnnotationsUtilBase.java   
public static void createAddToSpecialAnnotationFixes(@NotNull PsiModifierListOwner owner, @NotNull Processor<String> processor) {
  final PsiModifierList modifierList = owner.getModifierList();
  if (modifierList != null) {
    final PsiAnnotation[] psiAnnotations = modifierList.getAnnotations();
    for (PsiAnnotation psiAnnotation : psiAnnotations) {
      @NonNls final String name = psiAnnotation.getQualifiedName();
      if (name == null) continue;
      if (name.startsWith("java.") || name.startsWith("javax.") ||
          name.startsWith("org.jetbrains.") && AnnotationUtil.isJetbrainsAnnotation(StringUtil.getShortName(name))) continue;
      if (!processor.process(name)) break;
    }
  }
}