com.intellij.psi.PsiModifierListOwner Java Examples

The following examples show how to use com.intellij.psi.PsiModifierListOwner. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnnotationDetector.java    From here-be-dragons with MIT License 7 votes vote down vote up
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;
}
 
Example #2
Source File: PsiConsultantImpl.java    From dagger-intellij-plugin with Apache License 2.0 6 votes vote down vote up
public static Set<String> getQualifierAnnotations(PsiElement element) {
  Set<String> qualifiedClasses = new HashSet<String>();

  if (element instanceof PsiModifierListOwner) {
    PsiModifierListOwner listOwner = (PsiModifierListOwner) element;
    PsiModifierList modifierList = listOwner.getModifierList();

    if (modifierList != null) {
      for (PsiAnnotation psiAnnotation : modifierList.getAnnotations()) {
        if (psiAnnotation != null && psiAnnotation.getQualifiedName() != null) {
          JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(element.getProject());
          PsiClass psiClass = psiFacade.findClass(psiAnnotation.getQualifiedName(),
              GlobalSearchScope.projectScope(element.getProject()));

          if (hasAnnotation(psiClass, CLASS_QUALIFIER)) {
            qualifiedClasses.add(psiAnnotation.getQualifiedName());
          }
        }
      }
    }
  }

  return qualifiedClasses;
}
 
Example #3
Source File: PropertiesManager.java    From intellij-quarkus with Eclipse Public License 2.0 6 votes vote down vote up
public MicroProfileProjectInfo getMicroProfileProjectInfo(Module module,
                                                          List<MicroProfilePropertiesScope> scopes, ClasspathKind classpathKind, IPsiUtils utils,
                                                          DocumentFormat documentFormat) {
    MicroProfileProjectInfo info = createInfo(module, classpathKind);
    long startTime = System.currentTimeMillis();
    boolean excludeTestCode = classpathKind == ClasspathKind.SRC;
    PropertiesCollector collector = new PropertiesCollector(info, scopes);
    SearchScope scope = createSearchScope(module, scopes, classpathKind == ClasspathKind.TEST);
    SearchContext context = new SearchContext(module, scope, collector, utils, documentFormat);
    DumbService.getInstance(module.getProject()).runReadActionInSmartMode(() -> {
        Query<PsiModifierListOwner> query = createSearchQuery(context);
        beginSearch(context);
        query.forEach((Consumer<? super PsiModifierListOwner>) psiMember -> collectProperties(psiMember, context));
        endSearch(context);
    });
    LOGGER.info("End computing MicroProfile properties for '" + info.getProjectURI() + "' in "
            + (System.currentTimeMillis() - startTime) + "ms.");
    return info;
}
 
Example #4
Source File: QuarkusConfigRootProvider.java    From intellij-quarkus with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Process Quarkus ConfigRoot annotation from the given
 * <code>psiElement</code>.
 * 
 * @param psiElement          the class, field element which have a Quarkus
 *                             ConfigRoot annotations
 * @param configRootAnnotation the Quarkus ConfigRoot annotation
 * @param javadocCache         the documentation cache
 * @param collector            the properties to fill
 */
private void processConfigRoot(PsiModifierListOwner psiElement, PsiAnnotation configRootAnnotation,
		Map<VirtualFile, Properties> javadocCache, IPropertiesCollector collector) {
	ConfigPhase configPhase = getConfigPhase(configRootAnnotation);
	String configRootAnnotationName = getConfigRootName(configRootAnnotation);
	String extension = getExtensionName(getSimpleName(psiElement), configRootAnnotationName, configPhase);
	if (extension == null) {
		return;
	}
	// Location (JAR, src)
	VirtualFile packageRoot = PsiTypeUtils.getRootDirectory(PsiTreeUtil.getParentOfType(psiElement, PsiFile.class));
	String location = PsiTypeUtils.getLocation(psiElement.getProject(), packageRoot);
	// Quarkus Extension name
	String extensionName = PsiQuarkusUtils.getExtensionName(location);

	String baseKey = extension.isEmpty() ? QuarkusConstants.QUARKUS_PREFIX
			: QuarkusConstants.QUARKUS_PREFIX + '.' + extension;
	processConfigGroup(extensionName, psiElement, baseKey, configPhase, javadocCache, collector);
}
 
Example #5
Source File: MicroProfileFaultToleranceProvider.java    From intellij-quarkus with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void processAnnotation(PsiModifierListOwner javaElement, PsiAnnotation mpftAnnotation, String annotationName,
								 SearchContext context) {
	if (!(javaElement instanceof PsiMember)) {
		return;
	}
	// The java element is method or a class
	MicroProfileFaultToleranceContext mpftContext = getMicroProfileFaultToleranceContext(context);
	AnnotationInfo info = mpftContext.getAnnotationInfo(annotationName);
	if (info != null) {
		// 1. Collect properties for <annotation>/<list of parameters>
		collectProperties(context.getCollector(), info, null, null, mpftContext);
		mpftContext.addFaultToleranceProperties(context.getCollector());
		// 2. Collect properties for <classname>/<annotation>/<list of parameters>
		if (javaElement instanceof PsiMethod) {
			PsiMethod annotatedMethod = (PsiMethod) javaElement;
			PsiClass classType = annotatedMethod.getContainingClass();
			PsiAnnotation mpftAnnotationForClass = getAnnotation(classType, annotationName);
			collectProperties(context.getCollector(), info, classType, mpftAnnotationForClass, mpftContext);
		}
		// 3. Collect properties for <classname>/<annotation>/<list of parameters> or
		// <classname>/<methodname>/<annotation>/<list of parameters>
		collectProperties(context.getCollector(), info, (PsiMember) javaElement, mpftAnnotation, mpftContext);
	}
}
 
Example #6
Source File: AbstractTypeDeclarationPropertiesProvider.java    From intellij-quarkus with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void collectProperties(PsiModifierListOwner match, SearchContext context) {
	if (match instanceof PsiClass) {
		PsiClass type = (PsiClass) match;
		String className = type.getQualifiedName();
		String[] names = getTypeNames();
		for (String name : names) {
			if (name.equals(className)) {
				try {
					// Collect properties from the class name and stop the loop.
					processClass(type, className, context);
					break;
				} catch (Exception e) {
					LOGGER.error("Cannot compute MicroProfile properties for the Java class '" + className + "'.",
							e);
				}
			}
		}
	}
}
 
Example #7
Source File: DeprecatedLombokAnnotationInspection.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void checkFor(String deprecatedAnnotationFQN, String newAnnotationFQN, PsiAnnotation psiAnnotation) {
  final String annotationQualifiedName = psiAnnotation.getQualifiedName();
  if (Objects.equals(deprecatedAnnotationFQN, annotationQualifiedName)) {
    final PsiModifierListOwner listOwner = PsiTreeUtil.getParentOfType(psiAnnotation, PsiModifierListOwner.class, false);
    if (null != listOwner) {

      holder.registerProblem(psiAnnotation,
        "Lombok annotation '" + deprecatedAnnotationFQN + "' is deprecated and " +
          "not supported by lombok-plugin any more. Use '" + newAnnotationFQN + "' instead.",
        ProblemHighlightType.ERROR,
        new AddAnnotationFix(newAnnotationFQN,
          listOwner,
          psiAnnotation.getParameterList().getAttributes(),
          deprecatedAnnotationFQN));
    }
  }
}
 
Example #8
Source File: AbstractPropertiesProvider.java    From intellij-quarkus with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Return an instance of search pattern.
 */
public Query<PsiModifierListOwner> createSearchPattern(SearchContext context) {
	Query<PsiModifierListOwner> query = null;
	String[] patterns = getPatterns();
	if (patterns == null) {
		return null;
	}

	for (String pattern : patterns) {
		if (query == null) {
			query = createSearchPattern(context, pattern);
		} else {
			Query<PsiModifierListOwner> rightQuery = createSearchPattern(context, pattern);
			if (rightQuery != null) {
				query = new MergeQuery<>(query, rightQuery);
			}
		}
	}
	return query;
}
 
Example #9
Source File: PsiAnnotationProxyUtils.java    From litho with Apache License 2.0 6 votes vote down vote up
@Nullable
public static <T extends Annotation> T findAnnotationInHierarchy(
    PsiModifierListOwner listOwner, Class<T> annotationClass) {
  T basicProxy = AnnotationUtil.findAnnotationInHierarchy(listOwner, annotationClass);
  if (basicProxy == null) {
    return null;
  }

  T biggerProxy =
      (T)
          Proxy.newProxyInstance(
              annotationClass.getClassLoader(),
              new Class[] {annotationClass},
              new AnnotationProxyInvocationHandler(basicProxy, listOwner, annotationClass));

  return biggerProxy;
}
 
Example #10
Source File: AbstractAnnotationTypeReferencePropertiesProvider.java    From intellij-quarkus with Eclipse Public License 2.0 6 votes vote down vote up
protected void processAnnotation(PsiModifierListOwner psiElement, SearchContext context) {
	try {
		String[] names = getAnnotationNames();
		PsiAnnotation[] annotations = psiElement.getAnnotations();
		for (PsiAnnotation annotation : annotations) {
			for (String annotationName : names) {
				if (isMatchAnnotation(annotation, annotationName)) {
					processAnnotation(psiElement, annotation, annotationName, context);
					break;
				}
			}
		}
	} catch (Exception e) {
			LOGGER.error("Cannot compute MicroProfile properties for the Java element '"
					+ psiElement + "'.", e);
	}
}
 
Example #11
Source File: MicroProfileConfigPropertyProvider.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void processAnnotation(PsiModifierListOwner psiElement, PsiAnnotation configPropertyAnnotation,
								 String annotationName, SearchContext context) {
	if (psiElement instanceof PsiField || psiElement instanceof PsiMethod || psiElement instanceof PsiParameter) {
		IPropertiesCollector collector = context.getCollector();
		String name = AnnotationUtils.getAnnotationMemberValue(configPropertyAnnotation,
				QuarkusConstants.CONFIG_PROPERTY_ANNOTATION_NAME);
		if (StringUtils.isNotEmpty(name)) {
			String propertyTypeName = "";
			if (psiElement instanceof PsiField) {
				propertyTypeName = PsiTypeUtils.getResolvedTypeName((PsiField) psiElement);
			} else if (psiElement instanceof PsiMethod) {
				propertyTypeName = PsiTypeUtils.getResolvedResultTypeName((PsiMethod) psiElement);
			} else if (psiElement instanceof PsiVariable) {
				propertyTypeName = PsiTypeUtils.getResolvedTypeName((PsiVariable) psiElement);
			}
			PsiClass fieldClass = JavaPsiFacade.getInstance(psiElement.getProject()).findClass(propertyTypeName, GlobalSearchScope.allScope(psiElement.getProject()));

			String type = PsiTypeUtils.getPropertyType(fieldClass, propertyTypeName);
			String description = null;
			String sourceType = PsiTypeUtils.getSourceType(psiElement);
			String sourceField = null;
			String sourceMethod = null;
			if (psiElement instanceof PsiField || psiElement instanceof PsiMethod) {
				sourceField = PsiTypeUtils.getSourceField((PsiMember) psiElement);
			} else if (psiElement instanceof PsiParameter) {
				PsiMethod method = (PsiMethod) ((PsiParameter)psiElement).getDeclarationScope();
					sourceMethod = PsiTypeUtils.getSourceMethod(method);
			}
			String defaultValue = AnnotationUtils.getAnnotationMemberValue(configPropertyAnnotation,
					QuarkusConstants.CONFIG_PROPERTY_ANNOTATION_DEFAULT_VALUE);
			String extensionName = null;

			super.updateHint(collector, fieldClass);

			addItemMetadata(collector, name, type, description, sourceType, sourceField, sourceMethod, defaultValue,
					extensionName, PsiTypeUtils.isBinary(psiElement));
		}
	}
}
 
Example #12
Source File: PropertiesManager.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
private Query<PsiModifierListOwner> createSearchQuery(SearchContext context) {
    Query<PsiModifierListOwner> query = null;

    for(IPropertiesProvider provider : IPropertiesProvider.EP_NAME.getExtensions()) {
      Query<PsiModifierListOwner> providerQuery = provider.createSearchPattern(context);
      if (providerQuery != null) {
          if (query == null) {
              query = providerQuery;
          } else {
              query = new MergeQuery<>(query, providerQuery);
          }
      }
    }
    return query;
}
 
Example #13
Source File: PsiTypeUtils.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
public static String getSourceType(PsiModifierListOwner psiElement) {
    if (psiElement instanceof PsiField || psiElement instanceof PsiMethod) {
        return ClassUtil.getJVMClassName(((PsiMember)psiElement).getContainingClass());
    } else if (psiElement instanceof PsiParameter) {
        return ClassUtil.getJVMClassName(((PsiMethod)((PsiParameter)psiElement).getDeclarationScope()).getContainingClass());
    }
    return null;
}
 
Example #14
Source File: LithoPluginUtils.java    From litho with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static boolean hasAnnotation(
    PsiModifierListOwner modifierListOwner, Predicate<String> nameFilter) {
  return Optional.of(modifierListOwner)
      .map(PsiModifierListOwner::getAnnotations)
      .map(
          annotations ->
              Stream.of(annotations)
                  .map(PsiAnnotation::getQualifiedName)
                  .filter(Objects::nonNull)
                  .anyMatch(nameFilter))
      .orElse(false);
}
 
Example #15
Source File: LithoPluginUtilsTest.java    From litho with Apache License 2.0 5 votes vote down vote up
private static <T extends PsiModifierListOwner> T createWithAnnotation(
    Class<T> cls, String annotationName) {
  T withAnnotation = Mockito.mock(cls);
  PsiAnnotation annotation = createPsiAnnotation(annotationName);
  Mockito.when(withAnnotation.getAnnotations()).thenReturn(new PsiAnnotation[] {annotation});
  return withAnnotation;
}
 
Example #16
Source File: LombokHighlightErrorFilter.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void processHook(@NotNull PsiElement highlightedElement, @NotNull HighlightInfo highlightInfo) {
  PsiElement importantParent = PsiTreeUtil.getParentOfType(highlightedElement,
    PsiMethod.class, PsiLambdaExpression.class, PsiMethodReferenceExpression.class, PsiClassInitializer.class
  );

  // applicable only for methods
  if (importantParent instanceof PsiMethod) {
    AddAnnotationFix fix = new AddAnnotationFix(SneakyThrows.class.getCanonicalName(), (PsiModifierListOwner) importantParent);
    highlightInfo.registerFix(fix, null, null, null, null);
  }
}
 
Example #17
Source File: ValueModifierProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void transformModifiers(@NotNull PsiModifierList modifierList, @NotNull final Set<String> modifiers) {
  if (modifiers.contains(PsiModifier.STATIC)) {
    return; // skip static fields
  }

  final PsiModifierListOwner parentElement = PsiTreeUtil.getParentOfType(modifierList, PsiModifierListOwner.class, false);
  if (null != parentElement) {

    // FINAL
    if (!PsiAnnotationSearchUtil.isAnnotatedWith(parentElement, lombok.experimental.NonFinal.class)) {
      modifiers.add(PsiModifier.FINAL);
    }

    // PRIVATE
    if (modifierList.getParent() instanceof PsiField &&
      // Visibility is only changed for package private fields
      hasPackagePrivateModifier(modifierList) &&
      // except they are annotated with @PackagePrivate
      !PsiAnnotationSearchUtil.isAnnotatedWith(parentElement, lombok.experimental.PackagePrivate.class)) {
      modifiers.add(PsiModifier.PRIVATE);

      // IDEA _right now_ checks if other modifiers are set, and ignores PACKAGE_LOCAL but may as well clean it up
      modifiers.remove(PsiModifier.PACKAGE_LOCAL);
    }
  }
}
 
Example #18
Source File: SneakyThrowsExceptionHandler.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean isExceptionHandled(@NotNull PsiModifierListOwner psiModifierListOwner, PsiClassType exceptionClassType) {
  final PsiAnnotation psiAnnotation = PsiAnnotationSearchUtil.findAnnotation(psiModifierListOwner, SneakyThrows.class);
  if (psiAnnotation == null) {
    return false;
  }

  final Collection<PsiType> sneakedExceptionTypes = PsiAnnotationUtil.getAnnotationValues(psiAnnotation, PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME, PsiType.class);
  //Default SneakyThrows handles all exceptions
  return sneakedExceptionTypes.isEmpty()
    || sneakedExceptionTypes.iterator().next().equalsToText(JAVA_LANG_THROWABLE)
    || isExceptionHandled(exceptionClassType, sneakedExceptionTypes);
}
 
Example #19
Source File: PsiAnnotationSearchUtil.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
public static PsiAnnotation findAnnotation(@NotNull PsiModifierListOwner psiModifierListOwner, @NotNull final Class<? extends Annotation>... annotationTypes) {
  if (annotationTypes.length == 1) {
    return findAnnotation(psiModifierListOwner, annotationTypes[0]);
  }

  final String[] qualifiedNames = new String[annotationTypes.length];
  for (int i = 0; i < annotationTypes.length; i++) {
    qualifiedNames[i] = annotationTypes[i].getName();
  }
  return findAnnotationQuick(psiModifierListOwner.getModifierList(), qualifiedNames);
}
 
Example #20
Source File: PsiAnnotationSearchUtil.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static boolean isAnnotatedWith(@NotNull PsiModifierListOwner psiModifierListOwner, @NotNull final Pattern annotationPattern) {
  final PsiModifierList psiModifierList = psiModifierListOwner.getModifierList();
  if (psiModifierList != null) {
    for (PsiAnnotation psiAnnotation : psiModifierList.getAnnotations()) {
      final String suspect = getSimpleNameOf(psiAnnotation);
      if (annotationPattern.matcher(suspect).matches()) {
        return true;
      }
    }
  }
  return false;
}
 
Example #21
Source File: PsiAnnotationSearchUtil.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static boolean checkAnnotationsSimpleNameExistsIn(@NotNull PsiModifierListOwner modifierListOwner, @NotNull Collection<String> annotationNames) {
  final PsiModifierList modifierList = modifierListOwner.getModifierList();
  if (null != modifierList) {
    for (PsiAnnotation psiAnnotation : modifierList.getAnnotations()) {
      final String simpleName = getSimpleNameOf(psiAnnotation);
      if (annotationNames.contains(simpleName)) {
        return true;
      }
    }
  }
  return false;
}
 
Example #22
Source File: LombokProcessorUtil.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
public static PsiAnnotation createAnnotationWithAccessLevel(@NotNull Class<? extends Annotation> annotationClass, @NotNull PsiModifierListOwner psiModifierListOwner) {
  String value = "";
  final PsiModifierList modifierList = psiModifierListOwner.getModifierList();
  if (null != modifierList) {
    final int accessLevelCode = PsiUtil.getAccessLevel(modifierList);

    final AccessLevel accessLevel = ACCESS_LEVEL_MAP.get(accessLevelCode);
    if (null != accessLevel && !AccessLevel.PUBLIC.equals(accessLevel)) {
      value = AccessLevel.class.getName() + "." + accessLevel;
    }
  }

  return PsiAnnotationUtil.createPsiAnnotation(psiModifierListOwner, annotationClass, value);
}
 
Example #23
Source File: PsiConsultantImpl.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #24
Source File: ElementUtils.java    From aircon with MIT License 5 votes vote down vote up
public static boolean hasAnnotation(final PsiModifierListOwner field, Class<? extends Annotation> annotationClass) {
	for (PsiAnnotation psiAnnotation : field.getAnnotations()) {
		if (isOfType(psiAnnotation, annotationClass)) {
			return true;
		}
	}
	return false;
}
 
Example #25
Source File: ElementUtils.java    From aircon with MIT License 5 votes vote down vote up
public static boolean hasOneOfAnnotations(final PsiModifierListOwner field, Class<? extends Annotation>... annotationClasses) {
	for (PsiAnnotation psiAnnotation : field.getAnnotations()) {
		if (isOneOfTypes(psiAnnotation, annotationClasses)) {
			return true;
		}
	}
	return false;
}
 
Example #26
Source File: QuarkusConfigPropertiesProvider.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void processAnnotation(PsiModifierListOwner psiElement, PsiAnnotation annotation, String annotationName,
								 SearchContext context) {
	ConfigPropertiesContext configPropertiesContext = (ConfigPropertiesContext) context
			.get(CONFIG_PROPERTIES_CONTEXT_KEY);
	processConfigProperties(psiElement, annotation, configPropertiesContext, context.getCollector());
}
 
Example #27
Source File: AbstractPropertiesProvider.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Create a search pattern for the given <code>annotationName</code> annotation
 * name.
 * 
 * @param annotationName the annotation name to search.
 * @return a search pattern for the given <code>annotationName</code> annotation
 *         name.
 */
protected static Query<PsiModifierListOwner> createAnnotationTypeReferenceSearchPattern(SearchContext context, String annotationName) {
	PsiClass annotationClass = context.getUtils().findClass(context.getModule(), annotationName);
	if (annotationClass != null) {
		return AnnotatedElementsSearch.searchElements(annotationClass, context.getScope(), PsiModifierListOwner.class);
	} else {
		return new EmptyQuery<>();
	}
}
 
Example #28
Source File: AbstractPropertiesProvider.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Create a search pattern for the given <code>className</code> class name.
 * 
 * @param annotationName the class name to search.
 * @return a search pattern for the given <code>className</code> class name.
 */
protected static Query<PsiModifierListOwner> createAnnotationTypeDeclarationSearchPattern(SearchContext context, String annotationName) {
	JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(context.getModule().getProject());
	PsiClass annotationClass = javaPsiFacade.findClass(annotationName, GlobalSearchScope.allScope(context.getModule().getProject()));
	if (annotationClass != null) {
		return new ArrayQuery<>(annotationClass);
	} else {
		return new EmptyQuery<>();
	}
}
 
Example #29
Source File: QuarkusConfigRootProvider.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void processAnnotation(PsiModifierListOwner psiElement, PsiAnnotation annotation, String annotationName,
								 SearchContext context) {
	Map<VirtualFile, Properties> javadocCache = (Map<VirtualFile, Properties>) context
			.get(JAVADOC_CACHE_KEY);
	processConfigRoot(psiElement, annotation, javadocCache, context.getCollector());
}
 
Example #30
Source File: MicroProfileRegisterRestClientProvider.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void processAnnotation(PsiModifierListOwner psiElement, PsiAnnotation registerRestClientAnnotation,
								 String annotationName, SearchContext context) {
	if (psiElement instanceof PsiClass) {

		IPropertiesCollector collector = context.getCollector();
		if (context.get(MP_REST_ADDED) == null) {

			// FIXME: move this dynamic properties declaration on MicroProfile LS side.
			// /mp-rest/url
			String docs = "The base URL to use for this service, the equivalent of the `baseUrl` method.\r\n"
					+ "This property (or */mp-rest/uri) is considered required, however implementations may have other ways to define these URLs/URIs.";
			super.addItemMetadata(collector, MP_REST_CLIENT_CLASS_REFERENCE_TYPE + "/mp-rest/url",
					"java.lang.String", docs, null, null, null, null, null, false);

			// /mp-rest/uri
			docs = "The base URI to use for this service, the equivalent of the baseUri method.\r\n"
					+ "This property (or */mp-rest/url) is considered required, however implementations may have other ways to define these URLs/URIs."
					+ "This property will override any `baseUri` value specified in the `@RegisterRestClient` annotation.";
			super.addItemMetadata(collector, MP_REST_CLIENT_CLASS_REFERENCE_TYPE + "/mp-rest/uri",
					"java.lang.String", docs, null, null, null, null, null, false);

			// /mp-rest/scope
			docs = "The fully qualified classname to a CDI scope to use for injection, defaults to "
					+ "`javax.enterprise.context.Dependent`.";
			super.addItemMetadata(collector, MP_REST_CLIENT_CLASS_REFERENCE_TYPE + "/mp-rest/scope",
					"java.lang.String", docs, null, null, null, null, null, false);

			// /mp-rest/providers
			docs = "A comma separated list of fully-qualified provider classnames to include in the client, "
					+ "the equivalent of the `register` method or the `@RegisterProvider` annotation.";
			super.addItemMetadata(collector, MP_REST_CLIENT_CLASS_REFERENCE_TYPE + "/mp-rest/providers",
					"java.lang.String", docs, null, null, null, null, null, false);

			// TODO : provider is managed as mapped property (with {*}). It should be
			// improved to have
			// completion on all providers implementation
			docs = "Override the priority of the provider for the given interface.";
			super.addItemMetadata(collector,
					MP_REST_CLIENT_CLASS_REFERENCE_TYPE + "/mp-rest/providers/{*}/priority", "int", docs, null,
					null, null, null, null, false);

			// /mp-rest/connectTimeout
			docs = "Timeout specified in milliseconds to wait to connect to the remote endpoint.";
			super.addItemMetadata(collector, MP_REST_CLIENT_CLASS_REFERENCE_TYPE + "/mp-rest/connectTimeout",
					"long", docs, null, null, null, null, null, false);

			// /mp-rest/readTimeout
			docs = "Timeout specified in milliseconds to wait for a response from the remote endpoint.";
			super.addItemMetadata(collector, MP_REST_CLIENT_CLASS_REFERENCE_TYPE + "/mp-rest/readTimeout", "long",
					docs, null, null, null, null, null, false);

			context.put(MP_REST_ADDED, Boolean.TRUE);
		}

		PsiClass type = (PsiClass) psiElement;
		ItemHint itemHint = collector.getItemHint(MP_REST_CLIENT_CLASS_REFERENCE_TYPE);
		if (!PsiTypeUtils.isBinary(type)) {
			itemHint.setSource(Boolean.TRUE);
		}

		// Add class annotated with @RegisterRestClient in the "hints" values with name
		// '${mp.register.rest.client.class}'
		ValueHint value = new ValueHint();
		String classOrConfigKey = AnnotationUtils.getAnnotationMemberValue(registerRestClientAnnotation,
				REGISTER_REST_CLIENT_ANNOTATION_CONFIG_KEY);
		if (classOrConfigKey == null) {
			classOrConfigKey = type.getQualifiedName();
		}
		value.setValue(classOrConfigKey);
		value.setSourceType(type.getQualifiedName());
		itemHint.getValues().add(value);
	}
}