use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class GroovyShortNamesCache method getScriptClassesByFQName.
public List<PsiClass> getScriptClassesByFQName(final String name, final GlobalSearchScope scope, final boolean srcOnly) {
GlobalSearchScope actualScope = srcOnly ? new GrSourceFilterScope(scope) : scope;
final Collection<GroovyFile> files = StubIndex.getElements(GrFullScriptNameIndex.KEY, name.hashCode(), myProject, actualScope, GroovyFile.class);
if (files.isEmpty()) {
return Collections.emptyList();
}
final ArrayList<PsiClass> result = new ArrayList<>();
for (GroovyFile file : files) {
if (file.isScript()) {
final PsiClass scriptClass = file.getScriptClass();
if (scriptClass != null && name.equals(scriptClass.getQualifiedName())) {
result.add(scriptClass);
}
}
}
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class ResolveUtil method isScriptField.
public static boolean isScriptField(GrVariable var) {
GrModifierList list = var.getModifierList();
if (list == null)
return false;
PsiFile containingFile = var.getContainingFile();
if (!(containingFile instanceof GroovyFile) || !((GroovyFile) containingFile).isScript())
return false;
GrMember member = PsiTreeUtil.getParentOfType(var, GrTypeDefinition.class, GrMethod.class);
if (member != null)
return false;
for (GrAnnotation annotation : list.getAnnotations()) {
String qualifiedName = annotation.getQualifiedName();
if (qualifiedName == null)
continue;
if (qualifiedName.equals(GroovyCommonClassNames.GROOVY_TRANSFORM_FIELD))
return true;
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class ResolveUtil method findDuplicate.
public static PsiNamedElement findDuplicate(@NotNull GrVariable variable) {
if (isScriptField(variable)) {
final String name = variable.getName();
final GroovyScriptClass script = (GroovyScriptClass) ((GroovyFile) variable.getContainingFile()).getScriptClass();
assert script != null;
List<GrField> duplicates = ContainerUtil.filter(script.getFields(), (GrField f) -> {
if (!(f instanceof GrScriptField))
return false;
if (!name.equals(f.getName()))
return false;
if (((GrScriptField) f).getOriginalVariable() == variable)
return false;
return true;
});
return duplicates.size() > 0 ? duplicates.get(0) : null;
} else {
PsiNamedElement duplicate = resolveExistingElement(variable, new DuplicateVariablesProcessor(variable), GrVariable.class);
final PsiElement context1 = variable.getContext();
if (duplicate == null && variable instanceof GrParameter && context1 != null) {
final PsiElement context = context1.getContext();
if (context instanceof GrClosableBlock || context instanceof GrMethod && !(context.getParent() instanceof GroovyFile) || context instanceof GrTryCatchStatement) {
duplicate = resolveExistingElement(context.getParent(), new DuplicateVariablesProcessor(variable), GrVariable.class);
}
}
if (duplicate instanceof GrLightParameter && "args".equals(duplicate.getName())) {
return null;
} else {
return duplicate;
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class NewGroovyClassAction method doCreate.
@Override
protected final GrTypeDefinition doCreate(PsiDirectory dir, String className, String templateName) throws IncorrectOperationException {
final String fileName = className + NewGroovyActionBase.GROOVY_EXTENSION;
final PsiFile fromTemplate = GroovyTemplatesFactory.createFromTemplate(dir, className, fileName, templateName, true);
if (fromTemplate instanceof GroovyFile) {
CodeStyleManager.getInstance(fromTemplate.getManager()).reformat(fromTemplate);
return ((GroovyFile) fromTemplate).getTypeDefinitions()[0];
}
final String description = fromTemplate.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 android by JetBrains.
the class GradleDslFile method parse.
public void parse() {
ApplicationManager.getApplication().assertReadAccessAllowed();
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(myFile);
GroovyFile myPsiFile = null;
if (psiFile instanceof GroovyFile) {
myPsiFile = (GroovyFile) psiFile;
}
if (myPsiFile == null) {
return;
}
setPsiElement(myPsiFile);
parse(myPsiFile);
}
Aggregations