use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class GrStubUtils method isGroovyStaticMemberStub.
public static boolean isGroovyStaticMemberStub(StubElement<?> stub) {
StubElement<?> modifierOwner = stub instanceof GrMethodStub ? stub : stub.getParentStub();
StubElement<GrModifierList> type = modifierOwner.findChildStubByType(GroovyElementTypes.MODIFIERS);
if (!(type instanceof GrModifierListStub)) {
return false;
}
int mask = ((GrModifierListStub) type).getModifiersFlags();
if (hasMaskModifier(mask, PsiModifier.PRIVATE)) {
return false;
}
if (hasMaskModifier(mask, PsiModifier.STATIC)) {
return true;
}
StubElement parent = modifierOwner.getParentStub();
StubElement classStub = parent == null ? null : parent.getParentStub();
if (classStub instanceof GrTypeDefinitionStub && (((GrTypeDefinitionStub) classStub).isAnnotationType() || ((GrTypeDefinitionStub) classStub).isInterface())) {
return true;
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class GrAnnotationCollector method collectAliasedAnnotationsFromAnnotationCollectorAnnotations.
private static void collectAliasedAnnotationsFromAnnotationCollectorAnnotations(@NotNull PsiModifierList modifierList, @NotNull Map<String, Map<String, PsiNameValuePair>> annotations) {
PsiElement parent = modifierList.getParent();
if (parent instanceof PsiClass && GroovyCommonClassNames.GROOVY_TRANSFORM_COMPILE_DYNAMIC.equals(((PsiClass) parent).getQualifiedName())) {
Map<String, PsiNameValuePair> params = ContainerUtil.newLinkedHashMap();
annotations.put(GroovyCommonClassNames.GROOVY_TRANSFORM_COMPILE_STATIC, params);
GrAnnotation annotation = GroovyPsiElementFactory.getInstance(modifierList.getProject()).createAnnotationFromText("@CompileStatic(TypeCheckingMode.SKIP)");
params.put("value", annotation.getParameterList().getAttributes()[0]);
return;
}
PsiAnnotation[] rawAnnotations = modifierList instanceof GrModifierList ? ((GrModifierList) modifierList).getRawAnnotations() : modifierList.getAnnotations();
for (PsiAnnotation annotation : rawAnnotations) {
final String qname = annotation.getQualifiedName();
if (qname == null || qname.equals(GroovyCommonClassNames.GROOVY_TRANSFORM_ANNOTATION_COLLECTOR))
continue;
final PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
for (PsiNameValuePair pair : attributes) {
Map<String, PsiNameValuePair> map = annotations.get(qname);
if (map == null) {
map = ContainerUtil.newLinkedHashMap();
annotations.put(qname, map);
}
map.put(pair.getName() != null ? pair.getName() : "value", pair);
}
if (attributes.length == 0 && !annotations.containsKey(qname)) {
annotations.put(qname, ContainerUtil.<String, PsiNameValuePair>newLinkedHashMap());
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class GroovyTreeGenerator method generateTreeFor.
@Override
public TreeElement generateTreeFor(@NotNull PsiElement original, @NotNull CharTable table, @NotNull PsiManager manager) {
if (original instanceof GrModifierList) {
final String text = original.getText();
assert text != null : "Text is null for " + original + "; " + original.getClass();
final GrModifierList modifierList = GroovyPsiElementFactory.getInstance(manager.getProject()).createModifierList(text);
return (TreeElement) modifierList.getNode();
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class ModifierListGenerator method writeModifiers.
public static boolean writeModifiers(StringBuilder builder, PsiModifierList modifierList, String[] modifiers, boolean writeAnnotations) {
boolean wasAddedModifiers = false;
if (writeAnnotations && modifierList instanceof GrModifierList) {
GrAnnotation[] annotations = ((GrModifierList) modifierList).getAnnotations();
AnnotationGenerator annotationGenerator = new AnnotationGenerator(builder, new ExpressionContext(modifierList.getProject(), GroovyFile.EMPTY_ARRAY));
wasAddedModifiers = annotations.length > 0;
for (GrAnnotation annotation : annotations) {
annotation.accept(annotationGenerator);
builder.append(' ');
}
}
for (String modifierType : modifiers) {
if (modifierList.hasModifierProperty(modifierType)) {
builder.append(modifierType);
builder.append(' ');
wasAddedModifiers = true;
}
}
return wasAddedModifiers;
}
Aggregations