use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass in project intellij-community by JetBrains.
the class UpdateGroovyCopyrightsProvider method createInstance.
@Override
public UpdateCopyright createInstance(Project project, Module module, VirtualFile file, FileType base, CopyrightProfile options) {
return new UpdateJavaFileCopyright(project, module, file, options) {
@Override
protected boolean accept() {
return getFile() instanceof GroovyFile;
}
@Override
protected PsiElement[] getImportsList() {
return ((GroovyFile) getFile()).getImportStatements();
}
@Override
protected PsiElement getPackageStatement() {
return ((GroovyFile) getFile()).getPackageDefinition();
}
@Override
protected void checkCommentsForTopClass(PsiClass topclass, int location, List<PsiComment> comments) {
if (!(topclass instanceof GroovyScriptClass)) {
super.checkCommentsForTopClass(topclass, location, comments);
return;
}
final GroovyFile containingFile = (GroovyFile) topclass.getContainingFile();
PsiElement last = containingFile.getFirstChild();
while (last != null && !(last instanceof GrStatement)) {
last = last.getNextSibling();
}
checkComments(last, location == JavaOptions.LOCATION_BEFORE_CLASS, comments);
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass in project intellij-community by JetBrains.
the class GrIntroduceFieldProcessor method createField.
@NotNull
private GrVariableDeclaration createField(@NotNull PsiClass targetClass) {
final String name = mySettings.getName();
final PsiType type = mySettings.getSelectedType();
final String modifier = mySettings.getVisibilityModifier();
List<String> modifiers = new ArrayList<>();
if (targetClass instanceof GroovyScriptClass) {
modifiers.add("@" + GroovyCommonClassNames.GROOVY_TRANSFORM_FIELD);
}
if (mySettings.isStatic())
modifiers.add(PsiModifier.STATIC);
if (!PsiModifier.PACKAGE_LOCAL.equals(modifier))
modifiers.add(modifier);
if (mySettings.declareFinal())
modifiers.add(PsiModifier.FINAL);
final String[] arr_modifiers = ArrayUtil.toStringArray(modifiers);
final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(myContext.getProject());
if (targetClass instanceof GroovyScriptClass) {
return factory.createVariableDeclaration(arr_modifiers, ((GrExpression) null), type, name);
} else {
return factory.createFieldDeclaration(arr_modifiers, name, null, type);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass in project intellij-community by JetBrains.
the class GrIntroduceFieldProcessor method generateConstructor.
@NotNull
private PsiMethod generateConstructor(@NotNull PsiClass scope) {
final String name = scope.getName();
LOG.assertTrue(name != null, scope.getText());
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(myContext.getProject());
final GrMethod constructor = factory.createConstructorFromText(name, ArrayUtil.EMPTY_STRING_ARRAY, ArrayUtil.EMPTY_STRING_ARRAY, "{}", scope);
if (scope instanceof GroovyScriptClass)
constructor.getModifierList().setModifierProperty(GrModifier.DEF, true);
return (PsiMethod) scope.add(constructor);
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass in project intellij-community by JetBrains.
the class GrIntroduceHandlerBase method collectVariableUsages.
public static PsiElement[] collectVariableUsages(GrVariable variable, PsiElement scope) {
final List<PsiElement> list = Collections.synchronizedList(new ArrayList<PsiElement>());
if (scope instanceof GroovyScriptClass) {
scope = scope.getContainingFile();
}
ReferencesSearch.search(variable, new LocalSearchScope(scope)).forEach(psiReference -> {
final PsiElement element = psiReference.getElement();
if (element != null) {
list.add(element);
}
return true;
});
return list.toArray(new PsiElement[list.size()]);
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass in project intellij-community by JetBrains.
the class StubGenerator method collectMethods.
@Override
public Collection<PsiMethod> collectMethods(PsiClass typeDefinition) {
List<PsiMethod> methods = new ArrayList<>();
for (PsiMethod method : typeDefinition.getMethods()) {
if (method instanceof DelegatedMethod) {
PsiMethod prototype = ((DelegatedMethod) method).getPrototype();
PsiClass aClass = prototype.getContainingClass();
if (prototype.hasModifierProperty(PsiModifier.FINAL) && aClass != null && typeDefinition.isInheritor(aClass, true)) {
//skip final super methods
continue;
}
}
methods.add(method);
}
boolean isClass = !typeDefinition.isInterface() && !typeDefinition.isAnnotationType() && !typeDefinition.isEnum() && !(typeDefinition instanceof GroovyScriptClass);
if (isClass) {
final Collection<MethodSignature> toOverride = OverrideImplementExploreUtil.getMethodSignaturesToOverride(typeDefinition);
for (MethodSignature signature : toOverride) {
if (!(signature instanceof MethodSignatureBackedByPsiMethod))
continue;
final PsiMethod method = ((MethodSignatureBackedByPsiMethod) signature).getMethod();
final PsiClass baseClass = method.getContainingClass();
if (baseClass == null)
continue;
final String qname = baseClass.getQualifiedName();
if (GroovyCommonClassNames.GROOVY_OBJECT.equals(qname) || GroovyCommonClassNames.GROOVY_OBJECT_SUPPORT.equals(qname) || method.hasModifierProperty(PsiModifier.ABSTRACT) && typeDefinition.isInheritor(baseClass, true)) {
if (method.isConstructor())
continue;
methods.add(mirrorMethod(typeDefinition, method, baseClass, signature.getSubstitutor()));
}
}
final Collection<MethodSignature> toImplement = OverrideImplementExploreUtil.getMethodSignaturesToImplement(typeDefinition);
for (MethodSignature signature : toImplement) {
if (!(signature instanceof MethodSignatureBackedByPsiMethod))
continue;
final PsiMethod resolved = ((MethodSignatureBackedByPsiMethod) signature).getMethod();
final PsiClass baseClass = resolved.getContainingClass();
if (baseClass == null)
continue;
if (!GroovyCommonClassNames.GROOVY_OBJECT.equals(baseClass.getQualifiedName()))
continue;
methods.add(mirrorMethod(typeDefinition, resolved, baseClass, signature.getSubstitutor()));
}
}
return methods;
}
Aggregations