use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationMemberValue in project intellij-community by JetBrains.
the class ClassItemGeneratorImpl method writeMethod.
@Override
public void writeMethod(StringBuilder builder, PsiMethod method) {
if (method == null)
return;
GenerationUtil.writeDocComment(builder, method, true);
String name = method.getName();
boolean isAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT);
PsiModifierList modifierList = method.getModifierList();
final PsiClass containingClass = method.getContainingClass();
if (method.isConstructor() && containingClass != null && containingClass.isEnum()) {
ModifierListGenerator.writeModifiers(builder, modifierList, ModifierListGenerator.ENUM_CONSTRUCTOR_MODIFIERS);
} else {
ModifierListGenerator.writeModifiers(builder, modifierList);
}
if (method.hasTypeParameters()) {
GenerationUtil.writeTypeParameters(builder, method, classNameProvider);
builder.append(' ');
}
//append return type
if (!method.isConstructor()) {
PsiType retType = context.typeProvider.getReturnType(method);
TypeWriter.writeType(builder, retType, method, classNameProvider);
builder.append(' ');
}
builder.append(name);
if (method instanceof GroovyPsiElement) {
context.searchForLocalVarsToWrap((GroovyPsiElement) method);
}
GenerationUtil.writeParameterList(builder, method.getParameterList().getParameters(), classNameProvider, context);
if (method instanceof GrAnnotationMethod) {
GrAnnotationMemberValue defaultValue = ((GrAnnotationMethod) method).getDefaultValue();
if (defaultValue != null) {
builder.append("default ");
defaultValue.accept(new AnnotationGenerator(builder, context));
}
}
GenerationUtil.writeThrowsList(builder, method.getThrowsList(), getMethodExceptions(method), classNameProvider);
if (!isAbstract) {
/* ************ body ********* */
if (method instanceof GrMethod) {
if (method instanceof GrReflectedMethod && ((GrReflectedMethod) method).getSkippedParameters().length > 0) {
builder.append("{\n").append(generateDelegateCall((GrReflectedMethod) method)).append("\n}\n");
} else {
new CodeBlockGenerator(builder, context.extend()).generateMethodBody((GrMethod) method);
}
} else if (method instanceof GrAccessorMethod) {
writeAccessorBody(builder, method);
} else if (method instanceof LightMethodBuilder && containingClass instanceof GroovyScriptClass) {
if ("main".equals(method.getName())) {
writeMainScriptMethodBody(builder, method);
} else if ("run".equals(method.getName())) {
writeRunScriptMethodBody(builder, method);
}
} else {
builder.append("{//todo\n}");
}
} else {
builder.append(';');
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationMemberValue in project intellij-community by JetBrains.
the class CustomAnnotationChecker method checkAnnotationValueByType.
public static void checkAnnotationValueByType(@NotNull AnnotationHolder holder, @NotNull GrAnnotationMemberValue value, @Nullable PsiType ltype, boolean skipArrays) {
final GlobalSearchScope resolveScope = value.getResolveScope();
final PsiManager manager = value.getManager();
if (value instanceof GrExpression) {
final PsiType rtype;
if (value instanceof GrClosableBlock) {
rtype = PsiType.getJavaLangClass(manager, resolveScope);
} else {
rtype = ((GrExpression) value).getType();
}
if (rtype != null && !checkAnnoTypeAssignable(ltype, rtype, value, skipArrays)) {
holder.createErrorAnnotation(value, GroovyBundle.message("cannot.assign", rtype.getPresentableText(), ltype.getPresentableText()));
}
} else if (value instanceof GrAnnotation) {
final PsiElement resolved = ((GrAnnotation) value).getClassReference().resolve();
if (resolved instanceof PsiClass) {
final PsiClassType rtype = JavaPsiFacade.getElementFactory(value.getProject()).createType((PsiClass) resolved, PsiSubstitutor.EMPTY);
if (!checkAnnoTypeAssignable(ltype, rtype, value, skipArrays)) {
holder.createErrorAnnotation(value, GroovyBundle.message("cannot.assign", rtype.getPresentableText(), ltype.getPresentableText()));
}
}
} else if (value instanceof GrAnnotationArrayInitializer) {
if (ltype instanceof PsiArrayType) {
final PsiType componentType = ((PsiArrayType) ltype).getComponentType();
final GrAnnotationMemberValue[] initializers = ((GrAnnotationArrayInitializer) value).getInitializers();
for (GrAnnotationMemberValue initializer : initializers) {
checkAnnotationValueByType(holder, initializer, componentType, false);
}
} else {
final PsiType rtype = TypesUtil.getTupleByAnnotationArrayInitializer((GrAnnotationArrayInitializer) value);
if (!checkAnnoTypeAssignable(ltype, rtype, value, skipArrays)) {
holder.createErrorAnnotation(value, GroovyBundle.message("cannot.assign", rtype.getPresentableText(), ltype.getPresentableText()));
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationMemberValue in project intellij-community by JetBrains.
the class GroovySuppressableInspectionTool method getInspectionIdsSuppressedInAnnotation.
@NotNull
private static Collection<String> getInspectionIdsSuppressedInAnnotation(final GrModifierList modifierList) {
if (modifierList == null) {
return Collections.emptyList();
}
PsiAnnotation annotation = modifierList.findAnnotation(BatchSuppressManager.SUPPRESS_INSPECTIONS_ANNOTATION_NAME);
if (annotation == null) {
return Collections.emptyList();
}
final GrAnnotationMemberValue attributeValue = (GrAnnotationMemberValue) annotation.findAttributeValue(null);
Collection<String> result = new ArrayList<>();
if (attributeValue instanceof GrAnnotationArrayInitializer) {
for (GrAnnotationMemberValue annotationMemberValue : ((GrAnnotationArrayInitializer) attributeValue).getInitializers()) {
final String id = getInspectionIdSuppressedInAnnotationAttribute(annotationMemberValue);
if (id != null) {
result.add(id);
}
}
} else {
final String id = getInspectionIdSuppressedInAnnotationAttribute(attributeValue);
if (id != null) {
result.add(id);
}
}
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationMemberValue in project intellij-community by JetBrains.
the class GrLightAnnotation method addAttribute.
public void addAttribute(PsiNameValuePair pair) {
if (pair instanceof GrAnnotationNameValuePair) {
myAnnotationArgList.addAttribute((GrAnnotationNameValuePair) pair);
} else {
GrAnnotationMemberValue newValue = new AnnotationArgConverter().convert(pair.getValue());
if (newValue == null)
return;
String name = pair.getName();
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(pair.getProject());
String annotationText;
annotationText = name != null ? "@A(" + name + "=" + newValue.getText() + ")" : "@A(" + newValue.getText() + ")";
GrAnnotation annotation = factory.createAnnotationFromText(annotationText);
myAnnotationArgList.addAttribute(annotation.getParameterList().getAttributes()[0]);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationMemberValue in project intellij-community by JetBrains.
the class GrNameValuePairElementType method createStub.
@NotNull
@Override
public GrNameValuePairStub createStub(@NotNull GrAnnotationNameValuePair psi, StubElement parentStub) {
String name = psi.getName();
GrAnnotationMemberValue value = psi.getValue();
return new GrNameValuePairStub(parentStub, name, value == null ? null : value.getText());
}
Aggregations