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('}');
}
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();
}
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));
}
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());
}
}
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();
}
Aggregations