use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class GroovyAnnotator method visitForInClause.
@Override
public void visitForInClause(@NotNull GrForInClause forInClause) {
final GrVariable var = forInClause.getDeclaredVariable();
if (var == null)
return;
final GrModifierList modifierList = var.getModifierList();
if (modifierList == null)
return;
final PsiElement[] modifiers = modifierList.getModifiers();
for (PsiElement modifier : modifiers) {
if (modifier instanceof PsiAnnotation)
continue;
final String modifierText = modifier.getText();
if (PsiModifier.FINAL.equals(modifierText))
continue;
if (GrModifier.DEF.equals(modifierText))
continue;
myHolder.createErrorAnnotation(modifier, GroovyBundle.message("not.allowed.modifier.in.forin", modifierText));
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class GroovyAnnotator method visitVariableDeclaration.
@Override
public void visitVariableDeclaration(@NotNull GrVariableDeclaration variableDeclaration) {
if (variableDeclaration.isTuple()) {
final GrModifierList list = variableDeclaration.getModifierList();
final PsiElement last = PsiUtil.skipWhitespacesAndComments(list.getLastChild(), false);
if (last != null) {
final IElementType type = last.getNode().getElementType();
if (type != GroovyTokenTypes.kDEF) {
myHolder.createErrorAnnotation(list, GroovyBundle.message("tuple.declaration.should.end.with.def.modifier"));
}
} else {
myHolder.createErrorAnnotation(list, GroovyBundle.message("tuple.declaration.should.end.with.def.modifier"));
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class GrMethodBaseImpl method insertPlaceHolderToModifierList.
private void insertPlaceHolderToModifierList() {
final GrModifierList list = getModifierList();
PsiImplUtil.insertPlaceHolderToModifierListAtEndIfNeeded(list);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.
the class ConvertClosureToMethodIntention method execute.
private static void execute(final GrField field, final Collection<PsiElement> fieldUsages) {
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(field.getProject());
final StringBuilder builder = new StringBuilder(field.getTextLength());
final GrClosableBlock block = (GrClosableBlock) field.getInitializerGroovy();
final GrModifierList modifierList = field.getModifierList();
if (modifierList.getModifiers().length > 0 || modifierList.getAnnotations().length > 0) {
builder.append(modifierList.getText());
} else {
builder.append(GrModifier.DEF);
}
builder.append(' ').append(field.getName());
builder.append('(');
if (block.hasParametersSection()) {
builder.append(block.getParameterList().getText());
} else {
builder.append("def it = null");
}
builder.append(") {");
ApplicationManager.getApplication().runWriteAction(() -> {
block.getParameterList().delete();
block.getLBrace().delete();
final PsiElement psiElement = PsiUtil.skipWhitespacesAndComments(block.getFirstChild(), true);
if (psiElement != null && "->".equals(psiElement.getText())) {
psiElement.delete();
}
builder.append(block.getText());
final GrMethod method = GroovyPsiElementFactory.getInstance(field.getProject()).createMethodFromText(builder.toString());
field.getParent().replace(method);
for (PsiElement usage : fieldUsages) {
if (usage instanceof GrReferenceExpression) {
final PsiElement parent = usage.getParent();
StringBuilder newRefText = new StringBuilder();
if (parent instanceof GrReferenceExpression && usage == ((GrReferenceExpression) parent).getQualifier() && "call".equals(((GrReferenceExpression) parent).getReferenceName())) {
newRefText.append(usage.getText());
usage = parent;
} else {
PsiElement qualifier = ((GrReferenceExpression) usage).getQualifier();
if (qualifier == null) {
if (parent instanceof GrReferenceExpression && ((GrReferenceExpression) parent).getQualifier() != null && usage != ((GrReferenceExpression) parent).getQualifier()) {
qualifier = ((GrReferenceExpression) parent).getQualifier();
usage = parent;
}
}
if (qualifier != null) {
newRefText.append(qualifier.getText()).append('.');
((GrReferenceExpression) usage).setQualifier(null);
} else {
newRefText.append("this.");
}
newRefText.append('&').append(usage.getText());
}
usage.replace(factory.createReferenceExpressionFromText(newRefText.toString()));
}
}
});
}
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());
}
}
}
Aggregations