use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GrClassBodyFixer method apply.
@Override
public void apply(@NotNull Editor editor, @NotNull GroovySmartEnterProcessor processor, @NotNull PsiElement element) throws IncorrectOperationException {
if (element instanceof GrTypeDefinition && ((GrTypeDefinition) element).getBody() == null) {
final Document doc = editor.getDocument();
doc.insertString(element.getTextRange().getEndOffset(), "{\n}");
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GrMoveClassToCorrectPlaceFix method processIntention.
@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
final GrTypeDefinition containingClass = PsiTreeUtil.getParentOfType(myClass, GrTypeDefinition.class);
if (containingClass != null) {
containingClass.add(myClass);
} else {
final PsiFile containingFile = myClass.getContainingFile();
final PsiElement added = containingFile.add(myClass);
final PsiElement prevSibling = added.getPrevSibling();
if (prevSibling != null && prevSibling.getNode().getElementType() != GroovyTokenTypes.mNLS) {
containingFile.getNode().addLeaf(GroovyTokenTypes.mNLS, "\n", added.getNode());
}
}
myClass.delete();
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class ClashingTraitMethodsInspectionBase method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitTypeDefinition(@NotNull GrTypeDefinition typeDefinition) {
super.visitTypeDefinition(typeDefinition);
List<PsiClass> superTraits = collectImplementedTraits(typeDefinition);
if (superTraits.size() < 2)
return;
List<ClashingMethod> clashingMethods = collectClassingMethods(typeDefinition);
for (ClashingMethod clashing : clashingMethods) {
registerError(typeDefinition.getNameIdentifierGroovy(), buildWarning(clashing), new LocalQuickFix[] { getFix() }, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
}
@NotNull
private String buildWarning(@NotNull ClashingMethod entry) {
return "Traits " + buildTraitString(entry) + " contain clashing methods with signature " + buildSignatureString(entry);
}
@NotNull
private String buildSignatureString(@NotNull ClashingMethod entry) {
HierarchicalMethodSignature signature = entry.getSignature();
return PsiFormatUtil.formatMethod(signature.getMethod(), signature.getSubstitutor(), PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE);
}
@NotNull
private String buildTraitString(@NotNull ClashingMethod entry) {
return StringUtil.join(entry.getSuperTraits(), tr -> tr.getName(), ", ");
}
};
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GroovyConstructorUsagesSearcher method processConstructorUsages.
static void processConstructorUsages(final PsiMethod constructor, final SearchScope searchScope, final Processor<PsiReference> consumer, final SearchRequestCollector collector, final boolean includeOverloads) {
if (!constructor.isConstructor())
return;
final PsiClass clazz = constructor.getContainingClass();
if (clazz == null)
return;
SearchScope onlyGroovy = GroovyScopeUtil.restrictScopeToGroovyFiles(searchScope, GroovyScopeUtil.getEffectiveScope(constructor));
Set<PsiClass> processed = collector.getSearchSession().getUserData(LITERALLY_CONSTRUCTED_CLASSES);
if (processed == null) {
collector.getSearchSession().putUserData(LITERALLY_CONSTRUCTED_CLASSES, processed = ContainerUtil.newConcurrentSet());
}
if (!processed.add(clazz))
return;
if (clazz.isEnum() && clazz instanceof GroovyPsiElement) {
for (PsiField field : clazz.getFields()) {
if (field instanceof GrEnumConstant) {
final PsiReference ref = field.getReference();
if (ref != null && ref.isReferenceTo(constructor)) {
if (!consumer.process(ref))
return;
}
}
}
}
final LiteralConstructorSearcher literalProcessor = new LiteralConstructorSearcher(constructor, consumer, includeOverloads);
final Processor<GrNewExpression> newExpressionProcessor = grNewExpression -> {
final PsiMethod resolvedConstructor = grNewExpression.resolveMethod();
if (includeOverloads || constructor.getManager().areElementsEquivalent(resolvedConstructor, constructor)) {
return consumer.process(grNewExpression.getReferenceElement());
}
return true;
};
processGroovyClassUsages(clazz, searchScope, collector, newExpressionProcessor, literalProcessor);
//this()
if (clazz instanceof GrTypeDefinition) {
if (!processConstructors(constructor, consumer, clazz, true)) {
return;
}
}
//super()
DirectClassInheritorsSearch.search(clazz, onlyGroovy).forEach(new ReadActionProcessor<PsiClass>() {
@Override
public boolean processInReadAction(PsiClass inheritor) {
if (inheritor instanceof GrTypeDefinition) {
if (!processConstructors(constructor, consumer, inheritor, false))
return false;
}
return true;
}
});
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GroovyDslDefaultMembers method delegatesTo.
/**
* **********************************************************************************
* Methods and properties of the GroovyDSL language
* **********************************************************************************
*/
public void delegatesTo(@Nullable PsiElement elem, GdslMembersHolderConsumer consumer) {
if (elem instanceof PsiClass) {
final PsiClass clazz = (PsiClass) elem;
final NonCodeMembersHolder holder = new NonCodeMembersHolder();
if (clazz instanceof GrTypeDefinition) {
final PsiClassType type = JavaPsiFacade.getElementFactory(consumer.getProject()).createType(clazz);
final ResolverProcessor processor = CompletionProcessor.createPropertyCompletionProcessor(clazz);
final GroovyPsiElement context = (GroovyPsiElement) clazz;
ResolveUtil.processAllDeclarations(type, processor, ResolveState.initial(), context);
for (GroovyResolveResult result : processor.getCandidates()) {
final PsiElement element = result.getElement();
if (element instanceof PsiMethod && !((PsiMethod) element).isConstructor() || element instanceof PsiField) {
holder.addDeclaration(element);
}
}
} else {
for (PsiMethod method : clazz.getAllMethods()) {
if (!method.isConstructor())
holder.addDeclaration(method);
}
for (PsiField field : clazz.getAllFields()) {
holder.addDeclaration(field);
}
}
consumer.addMemberHolder(holder);
} else if (elem instanceof GrExpression) {
GrExpression expr = (GrExpression) elem;
final PsiType type = expr.getType();
if (type instanceof PsiClassType) {
PsiClassType ctype = (PsiClassType) type;
delegatesTo(ctype.resolve(), consumer);
}
}
}
Aggregations