use of com.intellij.psi.PsiAnnotation in project google-cloud-intellij by GoogleCloudPlatform.
the class RestSignatureInspectionTest method initializePsiClass.
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);
}
use of com.intellij.psi.PsiAnnotation in project component-runtime by Talend.
the class SuggestionServiceImpl method fromComponent.
private Stream<Suggestion> fromComponent(final PsiClass clazz, final String defaultFamily) {
final PsiAnnotation componentAnnotation = AnnotationUtil.findAnnotation(clazz, PARTITION_MAPPER, PROCESSOR, EMITTER);
final PsiAnnotationMemberValue name = componentAnnotation.findAttributeValue("name");
if (name == null || "\"\"".equals(name.getText())) {
return Stream.empty();
}
final PsiAnnotationMemberValue familyValue = componentAnnotation.findAttributeValue("family");
final String componentFamily = (familyValue == null || removeQuotes(familyValue.getText()).isEmpty()) ? null : removeQuotes(familyValue.getText());
final String family = ofNullable(componentFamily).orElseGet(() -> ofNullable(defaultFamily).orElse(null));
if (family == null) {
return Stream.empty();
}
return Stream.of(new Suggestion(family + "." + DISPLAY_NAME, Suggestion.Type.Family), new Suggestion(family + "." + removeQuotes(name.getText()) + "." + DISPLAY_NAME, Suggestion.Type.Component));
}
use of com.intellij.psi.PsiAnnotation in project azure-tools-for-java by Microsoft.
the class FunctionUtils method getUserDefinedBinding.
private static Binding getUserDefinedBinding(final Project project, PsiAnnotation annotation) throws AzureExecutionException {
final PsiJavaCodeReferenceElement referenceElement = annotation.getNameReferenceElement();
if (referenceElement == null) {
return null;
}
final PsiAnnotation customBindingAnnotation = AnnotationUtil.findAnnotation((PsiModifierListOwner) referenceElement.resolve(), AZURE_FUNCTION_CUSTOM_BINDING_CLASS);
if (customBindingAnnotation == null) {
return null;
}
final Map<String, Object> annotationProperties = AnnotationHelper.evaluateAnnotationProperties(project, annotation, CUSTOM_BINDING_RESERVED_PROPERTIES);
final Map<String, Object> customBindingProperties = AnnotationHelper.evaluateAnnotationProperties(project, customBindingAnnotation, null);
final Map<String, Object> mergedMap = new HashMap<>(annotationProperties);
customBindingProperties.forEach(mergedMap::putIfAbsent);
final Binding extendBinding = new Binding(BindingEnum.CustomBinding) {
public String getName() {
return (String) mergedMap.get("name");
}
public String getDirection() {
return (String) mergedMap.get("direction");
}
public String getType() {
return (String) mergedMap.get("type");
}
};
annotationProperties.forEach((name, value) -> {
if (!CUSTOM_BINDING_RESERVED_PROPERTIES.contains(name)) {
extendBinding.setAttribute(name, value);
}
});
return extendBinding;
}
use of com.intellij.psi.PsiAnnotation in project qi4j-sdk by Qi4j.
the class Qi4jServiceAnnotationUtil method isValidServiceAnnotationDeclaration.
/**
* Validates whether the variable has {@code @Service} annotation declared correctly.
*
* @param variable variable to check.
* @return Look at {@link ServiceAnnotationDeclarationValidationResult}.
* @since 0.1
*/
@NotNull
public static ServiceAnnotationDeclarationValidationResult isValidServiceAnnotationDeclaration(@NotNull PsiVariable variable) {
PsiAnnotation serviceAnnotation = getServiceAnnotation(variable);
if (serviceAnnotation == null) {
return invalidServiceAnnotationNotDeclared;
}
PsiModifierList modifierList = variable.getModifierList();
if (modifierList != null) {
if (modifierList.hasModifierProperty(STATIC)) {
return invalidDeclaredOnStaticVariable;
}
}
// Can't be type that is injected by @Structure
if (isInjecteableByStructureAnnotation(variable)) {
return invalidTypeIsInjectedViaStructureAnnotation;
}
return valid;
}
use of com.intellij.psi.PsiAnnotation in project qi4j-sdk by Qi4j.
the class SideEffectsAnnotationDeclaredCorrectlyInspection method checkClass.
@Override
public final ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
// If class does not have @SideEffects, ignore
PsiAnnotation sideEffectsAnnotation = getSideEffectsAnnotation(psiClass);
if (sideEffectsAnnotation == null) {
return null;
}
// If @SideEffects declared in class, suggest remove @SideEffects annotation
if (!psiClass.isInterface()) {
String message = message("side.effects.annotation.declared.correctly.error.annotation.declared.in.class");
RemoveSideEffectsAnnotationFix fix = new RemoveSideEffectsAnnotationFix(sideEffectsAnnotation);
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(sideEffectsAnnotation, message, fix, GENERIC_ERROR_OR_WARNING);
return new ProblemDescriptor[] { problemDescriptor };
}
// If @SideEffects annotation is empty, ignore
List<PsiAnnotationMemberValue> sideEffectsAnnotationValue = getSideEffectsAnnotationValue(sideEffectsAnnotation);
if (sideEffectsAnnotationValue.isEmpty()) {
return null;
}
// If SideEffectOf is not resolved, ignore
Project project = psiClass.getProject();
GlobalSearchScope searchScope = determineSearchScope(psiClass);
PsiClass sideEffectOfClass = Qi4jSideEffectUtil.getGenericSideEffectClass(project, searchScope);
if (sideEffectOfClass == null) {
return null;
}
List<ProblemDescriptor> problems = new LinkedList<ProblemDescriptor>();
for (PsiAnnotationMemberValue sideEffectClassReferenceWrapper : sideEffectsAnnotationValue) {
PsiJavaCodeReferenceElement sideEffectClassReference = getSideEffectClassReference(sideEffectClassReferenceWrapper);
// If it's not a class reference, ignore
if (sideEffectClassReference == null) {
continue;
}
// If class reference can't be resolved, ignore
PsiClass sideEffectClass = (PsiClass) sideEffectClassReference.resolve();
if (sideEffectClass == null) {
continue;
}
// If side effect class does not inherit SideEffectOf class, suggest remove that reference.
if (!sideEffectClass.isInheritor(sideEffectOfClass, true)) {
String message = Qi4jResourceBundle.message("side.effects.annotation.declared.correctly.error.side.effect.does.not.extend.side.effect.of", sideEffectClass.getQualifiedName());
RemoveAnnotationValueFix fix = new RemoveAnnotationValueFix(sideEffectClassReferenceWrapper, sideEffectClassReference);
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(sideEffectClassReferenceWrapper, message, fix, GENERIC_ERROR_OR_WARNING);
problems.add(problemDescriptor);
} else {
// TODO: Test whether it is a generic side effect
// TODO: Test whether it is a specific side effect
}
}
return problems.toArray(new ProblemDescriptor[problems.size()]);
}
Aggregations