Search in sources :

Example 1 with GrLightField

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightField in project intellij-community by JetBrains.

the class GrTraitUtil method createTraitField.

private static GrLightField createTraitField(TraitFieldDescriptor descriptor, PsiClass trait) {
    GrLightField field = new GrLightField(trait, descriptor.name, descriptor.typeString);
    if ((descriptor.flags & TraitFieldDescriptor.STATIC) != 0)
        field.getModifierList().addModifier(STATIC_MASK);
    field.getModifierList().addModifier((descriptor.flags & TraitFieldDescriptor.PUBLIC) != 0 ? PUBLIC_MASK : PRIVATE_MASK);
    return field;
}
Also used : GrLightField(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightField)

Example 2 with GrLightField

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightField in project intellij-community by JetBrains.

the class LoggingContributor method applyTransformation.

@Override
public void applyTransformation(@NotNull TransformationContext context) {
    GrModifierList modifierList = context.getCodeClass().getModifierList();
    if (modifierList == null)
        return;
    for (GrAnnotation annotation : modifierList.getAnnotations()) {
        String qname = annotation.getQualifiedName();
        String logger = ourLoggers.get(qname);
        if (logger != null) {
            String fieldName = PsiUtil.getAnnoAttributeValue(annotation, "value", "log");
            GrLightField field = new GrLightField(fieldName, logger, context.getCodeClass());
            field.setNavigationElement(annotation);
            field.getModifierList().setModifiers(PsiModifier.PRIVATE, PsiModifier.FINAL, PsiModifier.STATIC);
            field.setOriginInfo("created by @" + annotation.getShortName());
            context.addField(field);
        }
    }
}
Also used : GrModifierList(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList) GrAnnotation(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation) GrLightField(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightField)

Example 3 with GrLightField

use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightField in project intellij-community by JetBrains.

the class GebUtil method calculateContentElements.

private static Map<String, PsiField> calculateContentElements(@NotNull PsiClass pageOrModuleClass) {
    PsiField contentField = pageOrModuleClass.findFieldByName("content", false);
    if (!(contentField instanceof GrField))
        return Collections.emptyMap();
    GrExpression initializer = ((GrField) contentField).getInitializerGroovy();
    if (!(initializer instanceof GrClosableBlock))
        return Collections.emptyMap();
    Map<String, PsiField> res = new HashMap<>();
    PsiType objectType = PsiType.getJavaLangObject(pageOrModuleClass.getManager(), pageOrModuleClass.getResolveScope());
    for (PsiElement e = initializer.getFirstChild(); e != null; e = e.getNextSibling()) {
        if (e instanceof GrMethodCall) {
            GrMethodCall methodCall = (GrMethodCall) e;
            GrExpression invokedExpression = methodCall.getInvokedExpression();
            if (!(invokedExpression instanceof GrReferenceExpression))
                continue;
            if (((GrReferenceExpression) invokedExpression).isQualified())
                continue;
            GrExpression[] arguments = PsiUtil.getAllArguments((GrCall) e);
            if (arguments.length == 0)
                continue;
            final GrClosableBlock block;
            if (arguments.length == 1 && arguments[0] instanceof GrClosableBlock) {
                block = (GrClosableBlock) arguments[0];
            } else if (arguments.length == 2 && arguments[0] == null && arguments[1] instanceof GrClosableBlock) {
                block = (GrClosableBlock) arguments[1];
            } else {
                continue;
            }
            GrLightField field = new GrLightField(pageOrModuleClass, ((GrReferenceExpression) invokedExpression).getReferenceName(), objectType, invokedExpression) {

                @Override
                public PsiType getTypeGroovy() {
                    return block.getReturnType();
                }

                @Override
                public PsiType getDeclaredType() {
                    return null;
                }
            };
            field.getModifierList().addModifier(GrModifierFlags.STATIC_MASK);
            res.put(field.getName(), field);
        }
    }
    return res;
}
Also used : GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) HashMap(java.util.HashMap) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) GrLightField(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightField)

Aggregations

GrLightField (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightField)3 HashMap (java.util.HashMap)1 GrModifierList (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList)1 GrAnnotation (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation)1 GrField (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField)1 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)1 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)1 GrMethodCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall)1 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)1