use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GrNavBarModelExtension method adjustElement.
@Override
public PsiElement adjustElement(PsiElement psiElement) {
final ProjectFileIndex index = ProjectRootManager.getInstance(psiElement.getProject()).getFileIndex();
final PsiFile containingFile = psiElement.getContainingFile();
if (containingFile instanceof GroovyFileBase) {
final VirtualFile file = containingFile.getVirtualFile();
if (file != null && (index.isUnderSourceRootOfType(file, JavaModuleSourceRootTypes.SOURCES) || index.isInLibraryClasses(file) || index.isInLibrarySource(file))) {
if (psiElement instanceof GroovyFileBase) {
final GroovyFileBase grFile = (GroovyFileBase) psiElement;
if (grFile.getViewProvider().getBaseLanguage().equals(GroovyLanguage.INSTANCE)) {
final PsiClass[] psiClasses = grFile.getClasses();
if (psiClasses.length == 1 && !grFile.isScript()) {
return psiClasses[0];
}
}
} else if (psiElement instanceof GrTypeDefinition) {
return psiElement;
}
}
return containingFile;
}
return psiElement;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GroovyImplementMethodsHandler method invoke.
@Override
public void invoke(@NotNull final Project project, @NotNull Editor editor, @NotNull PsiFile file) {
if (!EditorModificationUtil.checkModificationAllowed(editor))
return;
PsiClass aClass = OverrideImplementUtil.getContextClass(project, editor, file, true);
if (aClass instanceof GrTypeDefinition) {
GrTypeDefinition typeDefinition = (GrTypeDefinition) aClass;
if (GroovyOverrideImplementExploreUtil.getMethodSignaturesToImplement(typeDefinition).isEmpty()) {
HintManager.getInstance().showErrorHint(editor, "No methods to implement have been found");
return;
}
GroovyOverrideImplementUtil.chooseAndImplementMethods(project, editor, typeDefinition);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class ClassNode method getChildrenImpl.
@Override
@Nullable
protected Collection<AbstractTreeNode> getChildrenImpl() {
final List<AbstractTreeNode> children = new ArrayList<>();
final Module module = getModule();
final GrTypeDefinition grTypeDefinition = extractPsiFromValue();
assert grTypeDefinition != null;
buildChildren(module, grTypeDefinition, children);
return children.isEmpty() ? null : children;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class GroovyRangeTypeCheckInspection method buildFix.
@Override
protected GroovyFix buildFix(@NotNull PsiElement location) {
final GrRangeExpression range = (GrRangeExpression) location;
final PsiType type = range.getType();
final List<GroovyFix> fixes = new ArrayList<>(3);
if (type instanceof GrRangeType) {
PsiType iterationType = ((GrRangeType) type).getIterationType();
if (!(iterationType instanceof PsiClassType))
return null;
final PsiClass psiClass = ((PsiClassType) iterationType).resolve();
if (!(psiClass instanceof GrTypeDefinition))
return null;
final GroovyResolveResult[] nexts = ResolveUtil.getMethodCandidates(iterationType, "next", range);
final GroovyResolveResult[] previouses = ResolveUtil.getMethodCandidates(iterationType, "previous", range);
final GroovyResolveResult[] compareTos = ResolveUtil.getMethodCandidates(iterationType, "compareTo", range, iterationType);
if (countImplementations(psiClass, nexts) == 0) {
fixes.add(GroovyQuickFixFactory.getInstance().createAddMethodFix("next", (GrTypeDefinition) psiClass));
}
if (countImplementations(psiClass, previouses) == 0) {
fixes.add(GroovyQuickFixFactory.getInstance().createAddMethodFix("previous", (GrTypeDefinition) psiClass));
}
if (!InheritanceUtil.isInheritor(iterationType, CommonClassNames.JAVA_LANG_COMPARABLE) || countImplementations(psiClass, compareTos) == 0) {
fixes.add(GroovyQuickFixFactory.getInstance().createAddClassToExtendsFix((GrTypeDefinition) psiClass, CommonClassNames.JAVA_LANG_COMPARABLE));
}
return new GroovyFix() {
@Override
protected void doFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) throws IncorrectOperationException {
for (GroovyFix fix : fixes) {
fix.applyFix(project, descriptor);
}
}
@NotNull
@Override
public String getName() {
return GroovyInspectionBundle.message("fix.class", psiClass.getName());
}
@Nls
@NotNull
@Override
public String getFamilyName() {
return "Fix range class";
}
};
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.
the class NewInstanceOfSingletonInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitNewExpression(@NotNull GrNewExpression newExpression) {
if (newExpression.getArrayDeclaration() != null)
return;
GrCodeReferenceElement refElement = newExpression.getReferenceElement();
if (refElement == null)
return;
PsiElement resolved = refElement.resolve();
if (!(resolved instanceof GrTypeDefinition))
return;
PsiAnnotation annotation = AnnotationUtil.findAnnotation((GrTypeDefinition) resolved, GROOVY_LANG_SINGLETON);
if (annotation == null)
return;
registerError(newExpression, GroovyInspectionBundle.message("new.instance.of.singleton"), ContainerUtil.ar(new ReplaceWithInstanceAccessFix()), ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
};
}
Aggregations