use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class RenameAliasedUsagesUtil method filterAliasedRefs.
public static Collection<PsiReference> filterAliasedRefs(Collection<PsiReference> refs, PsiElement element) {
Map<GroovyFile, String> aliases = new HashMap<>();
ArrayList<PsiReference> result = new ArrayList<>();
for (PsiReference ref : refs) {
final PsiElement e = ref.getElement();
if (e == null)
continue;
if (skipReference(element, aliases, e))
continue;
result.add(ref);
}
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class RenameGroovyScriptProcessor method findExistingNameConflicts.
@Override
public void findExistingNameConflicts(PsiElement element, String newName, MultiMap<PsiElement, String> conflicts) {
final String scriptName = FileUtil.getNameWithoutExtension(newName);
if (!StringUtil.isJavaIdentifier(scriptName)) {
final PsiClass script = ((GroovyFile) element).getScriptClass();
conflicts.putValue(script, GroovyRefactoringBundle.message("cannot.rename.script.class.to.0", script.getName(), scriptName));
}
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class MoveGroovyClassHandler method generateNewScript.
private static GroovyFile generateNewScript(GroovyFile file, PsiPackage newPackage) {
for (GrImportStatement importStatement : file.getImportStatements()) {
importStatement.delete();
}
final GroovyFile newFile = GroovyPsiElementFactory.getInstance(file.getProject()).createGroovyFile("", true, null);
newFile.addRange(file.getFirstChild(), file.getLastChild());
final PsiClass[] newFileClasses = newFile.getClasses();
for (PsiClass psiClass : newFileClasses) {
if (psiClass instanceof GroovyScriptClass)
continue;
final GrDocComment docComment = GrDocCommentUtil.findDocComment((GrDocCommentOwner) psiClass);
if (docComment != null)
docComment.delete();
psiClass.delete();
}
final GrPackageDefinition packageDefinition = newFile.getPackageDefinition();
if (packageDefinition != null)
packageDefinition.delete();
PsiElement cur = newFile.getFirstChild();
while (cur != null && PsiImplUtil.isWhiteSpaceOrNls(cur)) {
cur = cur.getNextSibling();
}
if (cur != null && cur != newFile.getFirstChild()) {
cur = cur.getPrevSibling();
newFile.deleteChildRange(newFile.getFirstChild(), cur);
}
cur = newFile.getLastChild();
while (cur != null && PsiImplUtil.isWhiteSpaceOrNls(cur)) {
cur = cur.getPrevSibling();
}
if (cur != null && cur != newFile.getLastChild()) {
cur = cur.getNextSibling();
newFile.deleteChildRange(cur, newFile.getLastChild());
}
newFile.setName(file.getName());
setPackageDefinition(file, newFile, newPackage.getQualifiedName());
GroovyChangeContextUtil.decodeContextInfo(newFile, null, null);
return newFile;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class MoveGroovyFileHandler method prepareMovedFile.
@Override
public void prepareMovedFile(PsiFile file, PsiDirectory moveDestination, Map<PsiElement, PsiElement> oldToNewMap) {
final GroovyFile groovyFile = (GroovyFile) file;
GroovyChangeContextUtil.encodeContextInfo(groovyFile);
for (PsiClass psiClass : groovyFile.getClasses()) {
oldToNewMap.put(psiClass, MoveClassesOrPackagesUtil.doMoveClass(psiClass, moveDestination));
}
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class CompleteReferenceExpression method getBindings.
private void getBindings() {
final PsiClass containingClass = PsiTreeUtil.getParentOfType(myRefExpr, PsiClass.class);
if (containingClass != null)
return;
final PsiFile file = FileContextUtil.getContextFile(myRefExpr);
if (file instanceof GroovyFile) {
((GroovyFile) file).accept(new GroovyRecursiveElementVisitor() {
@Override
public void visitAssignmentExpression(@NotNull GrAssignmentExpression expression) {
super.visitAssignmentExpression(expression);
final GrExpression value = expression.getLValue();
if (value instanceof GrReferenceExpression && !((GrReferenceExpression) value).isQualified()) {
final PsiElement resolved = ((GrReferenceExpression) value).resolve();
if (resolved instanceof GrBindingVariable) {
myProcessor.execute(resolved, ResolveState.initial());
} else if (resolved == null) {
myProcessor.execute(new GrBindingVariable((GroovyFile) file, ((GrReferenceExpression) value).getReferenceName(), true), ResolveState.initial());
}
}
}
@Override
public void visitTypeDefinition(@NotNull GrTypeDefinition typeDefinition) {
//don't go into classes
}
});
}
}
Aggregations