Search in sources :

Example 66 with GroovyFile

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

the class ClassGenerator method writeTypeDefinition.

public void writeTypeDefinition(StringBuilder text, @NotNull final PsiClass typeDefinition, boolean toplevel, boolean insertPackageSmst) {
    final boolean isScript = typeDefinition instanceof GroovyScriptClass;
    final GroovyFile containingFile = (GroovyFile) typeDefinition.getContainingFile();
    if (insertPackageSmst) {
        writePackageStatement(text, containingFile.getPackageDefinition());
    }
    GenerationUtil.writeDocComment(text, typeDefinition, true);
    boolean isEnum = typeDefinition.isEnum();
    boolean isAnnotationType = typeDefinition.isAnnotationType();
    boolean isInterface = typeDefinition.isInterface();
    ModifierListGenerator.writeClassModifiers(text, typeDefinition.getModifierList(), typeDefinition.isInterface(), typeDefinition.isEnum(), toplevel, classItemGenerator.generateAnnotations());
    if (isAnnotationType) {
        text.append('@');
    }
    if (isInterface) {
        text.append("interface");
    } else if (isEnum) {
        text.append("enum");
    } else {
        text.append("class");
    }
    text.append(' ').append(typeDefinition.getName());
    GenerationUtil.writeTypeParameters(text, typeDefinition, classNameProvider);
    text.append(' ');
    if (isScript) {
        text.append("extends ").append(GroovyCommonClassNames.GROOVY_LANG_SCRIPT).append(' ');
    } else if (!isEnum && !isAnnotationType) {
        classItemGenerator.writeExtendsList(text, typeDefinition);
        classItemGenerator.writeImplementsList(text, typeDefinition);
    }
    text.append("{\n");
    writeMembers(text, typeDefinition);
    text.append('}');
}
Also used : GroovyScriptClass(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile)

Example 67 with GroovyFile

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

the class ConvertToJavaHandler method invokeInner.

private static void invokeInner(Project project, PsiElement[] elements, Editor editor) {
    Set<GroovyFile> files = ContainerUtil.newHashSet();
    for (PsiElement element : elements) {
        if (!(element instanceof PsiFile)) {
            element = element.getContainingFile();
        }
        if (element instanceof GroovyFile) {
            files.add((GroovyFile) element);
        } else {
            if (!ApplicationManager.getApplication().isUnitTestMode()) {
                CommonRefactoringUtil.showErrorHint(project, editor, GroovyRefactoringBundle.message("convert.to.java.can.work.only.with.groovy"), REFACTORING_NAME, null);
                return;
            }
        }
    }
    new ConvertToJavaProcessor(project, files.toArray(new GroovyFile[files.size()])).run();
}
Also used : PsiFile(com.intellij.psi.PsiFile) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) PsiElement(com.intellij.psi.PsiElement)

Example 68 with GroovyFile

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

the class NewScriptAction method doCreate.

@Override
@NotNull
protected GroovyFile doCreate(PsiDirectory directory, String newName, String templateName) throws IncorrectOperationException {
    String fileName = newName + "." + extractExtension(templateName);
    PsiFile file = GroovyTemplatesFactory.createFromTemplate(directory, newName, fileName, templateName, true);
    if (file instanceof GroovyFile)
        return (GroovyFile) file;
    final String description = file.getFileType().getDescription();
    throw new IncorrectOperationException(GroovyBundle.message("groovy.file.extension.is.not.mapped.to.groovy.file.type", description));
}
Also used : PsiFile(com.intellij.psi.PsiFile) IncorrectOperationException(com.intellij.util.IncorrectOperationException) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) NotNull(org.jetbrains.annotations.NotNull)

Example 69 with GroovyFile

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

the class DumpGroovyControlFlowAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
    if (editor == null)
        return;
    final PsiFile psiFile = HandlerUtils.getPsiFile(editor, e.getDataContext());
    if (!(psiFile instanceof GroovyFile))
        return;
    int offset = editor.getCaretModel().getOffset();
    final List<GrControlFlowOwner> controlFlowOwners = collectControlFlowOwners(psiFile, editor, offset);
    if (controlFlowOwners.isEmpty())
        return;
    if (controlFlowOwners.size() == 1) {
        passInner(controlFlowOwners.get(0));
    } else {
        IntroduceTargetChooser.showChooser(editor, controlFlowOwners, new Pass<GrControlFlowOwner>() {

            @Override
            public void pass(GrControlFlowOwner grExpression) {
                passInner(grExpression);
            }
        }, flowOwner -> flowOwner.getText());
    }
}
Also used : GrControlFlowOwner(org.jetbrains.plugins.groovy.lang.psi.GrControlFlowOwner) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile)

Example 70 with GroovyFile

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

the class GroovyValidationUtil method validateNewParameterName.

public static boolean validateNewParameterName(GrParameter variable, MultiMap<PsiElement, String> conflicts, @NotNull String varName) {
    GrParameterList list = PsiTreeUtil.getParentOfType(variable, GrParameterList.class);
    GrParametersOwner owner = PsiTreeUtil.getParentOfType(variable, GrParametersOwner.class);
    assert owner != null;
    for (GrParameter parameter : list.getParameters()) {
        if (parameter.equals(variable))
            continue;
        validateVariableOccurrencesDownImpl(parameter, conflicts, varName);
    }
    validateVariableOccurrencesDown(owner, list, conflicts, varName);
    PsiElement parent = owner.getParent();
    validateVariableOccurrencesUp(parent, owner, conflicts, varName, parent instanceof GroovyFile);
    return conflicts.isEmpty();
}
Also used : GrParameterList(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) PsiElement(com.intellij.psi.PsiElement) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile)

Aggregations

GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)91 PsiFile (com.intellij.psi.PsiFile)26 PsiElement (com.intellij.psi.PsiElement)21 NotNull (org.jetbrains.annotations.NotNull)17 GrImportStatement (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement)17 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 Project (com.intellij.openapi.project.Project)10 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)10 PsiClass (com.intellij.psi.PsiClass)9 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)9 Nullable (org.jetbrains.annotations.Nullable)8 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)8 GroovyScriptClass (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass)8 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)7 Module (com.intellij.openapi.module.Module)6 IncorrectOperationException (com.intellij.util.IncorrectOperationException)6 GrReferenceElement (org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement)6 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)6 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)6 ASTNode (com.intellij.lang.ASTNode)5