use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GroovyScriptRunConfiguration method checkConfiguration.
@Override
public void checkConfiguration() throws RuntimeConfigurationException {
super.checkConfiguration();
final String scriptPath = getScriptPath();
final VirtualFile script = ScriptFileUtil.findScriptFileByPath(scriptPath);
if (script == null)
throw new RuntimeConfigurationException("Cannot find script " + scriptPath);
final GroovyScriptRunner scriptRunner = getScriptRunner();
if (scriptRunner == null)
throw new RuntimeConfigurationException("Unknown script type " + scriptPath);
scriptRunner.ensureRunnerConfigured(this);
final PsiFile file = PsiManager.getInstance(getProject()).findFile(script);
final PsiClass toRun = GroovyRunnerPsiUtil.getRunningClass(file);
if (toRun == null) {
throw new RuntimeConfigurationWarning(GroovyBundle.message("class.does.not.exist"));
}
if (toRun instanceof GrTypeDefinition) {
if (!GroovyRunnerPsiUtil.canBeRunByGroovy(toRun)) {
throw new RuntimeConfigurationWarning(GroovyBundle.message("class.cannot.be.executed"));
}
} else {
throw new RuntimeConfigurationWarning(GroovyBundle.message("script.file.is.not.groovy.file"));
}
JavaParametersUtil.checkAlternativeJRE(this);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition 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
}
});
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GdslClosureCompleter method getParameterInfos.
@Override
protected List<ClosureParameterInfo> getParameterInfos(InsertionContext context, PsiMethod method, PsiSubstitutor substitutor, PsiElement place) {
final ArrayList<ClosureDescriptor> descriptors = new ArrayList<>();
GrReferenceExpression ref = (GrReferenceExpression) place;
PsiType qtype = PsiImplUtil.getQualifierType(ref);
if (qtype == null)
return null;
GrExpression qualifier = ref.getQualifier();
if (qualifier != null) {
PsiType type = qualifier.getType();
if (type == null)
return null;
processExecutors(qtype, ref, descriptors);
} else {
PsiElementFactory factory = JavaPsiFacade.getElementFactory(context.getProject());
for (PsiElement parent = ref.getParent(); parent != null; parent = parent.getParent()) {
if (parent instanceof GrClosableBlock) {
processExecutors(TypesUtil.createTypeByFQClassName(GroovyCommonClassNames.GROOVY_LANG_CLOSURE, ref), ref, descriptors);
} else if (parent instanceof GrTypeDefinition) {
processExecutors(factory.createType(((GrTypeDefinition) parent), PsiType.EMPTY_ARRAY), ref, descriptors);
}
}
}
for (ClosureDescriptor descriptor : descriptors) {
if (descriptor.isMethodApplicable(method, ref)) {
return descriptor.getParameters();
}
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class AbstractFolderNode method createFolderNode.
private AbstractFolderNode createFolderNode(PsiDirectory directory) {
PsiDirectory realDirectory = directory;
StringBuilder textBuilder = null;
if (getSettings().isHideEmptyMiddlePackages()) {
do {
if (realDirectory.getFiles().length > 0)
break;
PsiDirectory[] subdirectories = realDirectory.getSubdirectories();
if (subdirectories.length != 1)
break;
if (textBuilder == null) {
textBuilder = new StringBuilder();
textBuilder.append(realDirectory.getName());
}
realDirectory = subdirectories[0];
textBuilder.append('.').append(realDirectory.getName());
} while (true);
}
String presentableText = textBuilder == null ? directory.getName() : textBuilder.toString();
return new AbstractFolderNode(getModule(), realDirectory, presentableText, getSettings(), FOLDER) {
@Override
protected void processNotDirectoryFile(List<AbstractTreeNode> nodes, PsiFile file) {
AbstractFolderNode.this.processNotDirectoryFile(nodes, file);
}
@Override
protected AbstractTreeNode createClassNode(GrTypeDefinition typeDefinition) {
return AbstractFolderNode.this.createClassNode(typeDefinition);
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GrIntroduceFieldProcessor method insertField.
@NotNull
protected GrVariableDeclaration insertField(@NotNull PsiClass targetClass) {
GrVariableDeclaration declaration = createField(targetClass);
if (targetClass instanceof GrEnumTypeDefinition) {
final GrEnumConstantList enumConstants = ((GrEnumTypeDefinition) targetClass).getEnumConstantList();
return (GrVariableDeclaration) targetClass.addAfter(declaration, enumConstants);
}
if (targetClass instanceof GrTypeDefinition) {
PsiElement anchor = getAnchorForDeclaration((GrTypeDefinition) targetClass);
return (GrVariableDeclaration) targetClass.addAfter(declaration, anchor);
} else {
assert targetClass instanceof GroovyScriptClass;
final GroovyFile file = ((GroovyScriptClass) targetClass).getContainingFile();
PsiElement[] elements = file.getMethods();
if (elements.length == 0)
elements = file.getStatements();
final PsiElement anchor = ArrayUtil.getFirstElement(elements);
return (GrVariableDeclaration) file.addBefore(declaration, anchor);
}
}
Aggregations