use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class GrReferenceExpressionImpl method bindToElementViaStaticImport.
@Override
public GrReferenceExpression bindToElementViaStaticImport(@NotNull PsiMember member) {
if (getQualifier() != null) {
throw new IncorrectOperationException("Reference has qualifier");
}
if (StringUtil.isEmpty(getReferenceName())) {
throw new IncorrectOperationException("Reference has empty name");
}
PsiClass containingClass = member.getContainingClass();
if (containingClass == null) {
throw new IncorrectOperationException("Member has no containing class");
}
final PsiFile file = getContainingFile();
if (file instanceof GroovyFile) {
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(getProject());
String text = "import static " + containingClass.getQualifiedName() + "." + member.getName();
final GrImportStatement statement = factory.createImportStatementFromText(text);
((GroovyFile) file).addImport(statement);
}
return this;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class GrTypeDefinitionImpl method isRenameFileOnClassRenaming.
private boolean isRenameFileOnClassRenaming() {
final PsiFile file = getContainingFile();
if (!(file instanceof GroovyFile))
return false;
final GroovyFile groovyFile = (GroovyFile) file;
if (groovyFile.isScript())
return false;
final String name = getName();
final VirtualFile vFile = groovyFile.getVirtualFile();
return vFile != null && name != null && name.equals(vFile.getNameWithoutExtension());
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class GrTypeDefinitionImpl method getQualifiedName.
@Nullable
@Override
public String getQualifiedName() {
final GrTypeDefinitionStub stub = getStub();
if (stub != null) {
return stub.getQualifiedName();
}
PsiElement parent = getParent();
if (parent instanceof GroovyFile) {
String packageName = ((GroovyFile) parent).getPackageName();
return !packageName.isEmpty() ? packageName + "." + getName() : getName();
}
final PsiClass containingClass = getContainingClass();
if (containingClass != null && containingClass.getQualifiedName() != null) {
return containingClass.getQualifiedName() + "." + getName();
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class GrClosableBlockImpl method getOwner.
private PsiVariable getOwner() {
return CachedValuesManager.getCachedValue(this, () -> {
final GroovyPsiElement context = PsiTreeUtil.getParentOfType(this, GrTypeDefinition.class, GrClosableBlock.class, GroovyFile.class);
final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
PsiType type = null;
if (context instanceof GrTypeDefinition) {
type = factory.createType((PsiClass) context);
} else if (context instanceof GrClosableBlock) {
type = GrClosureType.create((GrClosableBlock) context, true);
} else if (context instanceof GroovyFile) {
final PsiClass scriptClass = ((GroovyFile) context).getScriptClass();
if (scriptClass != null && GroovyNamesUtil.isIdentifier(scriptClass.getName()))
type = factory.createType(scriptClass);
}
if (type == null) {
type = TypesUtil.getJavaLangObject(this);
}
PsiVariable owner = new GrLightVariable(getManager(), OWNER_NAME, type, this);
return CachedValueProvider.Result.create(owner, PsiModificationTracker.MODIFICATION_COUNT);
});
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class GrStubUtils method getAliasMapping.
@NotNull
private static Map<String, String> getAliasMapping(@Nullable PsiFile file) {
if (!(file instanceof GroovyFile))
return Collections.emptyMap();
return CachedValuesManager.getCachedValue(file, () -> {
Map<String, String> mapping = ContainerUtil.newHashMap();
for (GrImportStatement importStatement : ((GroovyFile) file).getImportStatements()) {
if (importStatement.getImportReference() != null && !importStatement.isStatic() && importStatement.isAliasedImport()) {
String importName = importStatement.getImportReference().getClassNameText();
String importedName = importStatement.getImportedName();
if (importedName != null) {
mapping.put(importedName, importName);
}
}
}
return CachedValueProvider.Result.create(mapping, file);
});
}
Aggregations