Search in sources :

Example 1 with ProblemDescriptorImpl

use of com.intellij.codeInspection.ex.ProblemDescriptorImpl in project google-cloud-intellij by GoogleCloudPlatform.

the class ConstructorInspectionTest method testQuickFix_noConstructor.

public void testQuickFix_noConstructor() {
    ProblemDescriptorImpl problemDescriptorMock = mock(ProblemDescriptorImpl.class);
    MockitoAnnotations.initMocks(this);
    PsiClass psiClass = JavaPsiFacade.getInstance(myFixture.getProject()).getElementFactory().createClass(getName());
    ConstructorInspection constructorInspection = new ConstructorInspection();
    ConstructorInspection.MyQuickFix myQuickFix = constructorInspection.new MyQuickFix(psiClass);
    myQuickFix.applyFix(myFixture.getProject(), problemDescriptorMock);
    Assert.assertEquals(1, psiClass.getConstructors().length);
    Assert.assertTrue(EndpointUtilities.isPublicNullaryConstructor(psiClass.getConstructors()[0]));
}
Also used : PsiClass(com.intellij.psi.PsiClass) ProblemDescriptorImpl(com.intellij.codeInspection.ex.ProblemDescriptorImpl)

Example 2 with ProblemDescriptorImpl

use of com.intellij.codeInspection.ex.ProblemDescriptorImpl in project intellij-community by JetBrains.

the class UnsupportedFeatures method createIntention.

@NotNull
private static IntentionAction createIntention(@NotNull PsiElement node, @Nullable TextRange range, @NotNull String message, @NotNull LocalQuickFix localQuickFix) {
    final LocalQuickFix[] quickFixes = { localQuickFix };
    final CommonProblemDescriptorImpl descr = new ProblemDescriptorImpl(node, node, message, quickFixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, true, range, true);
    return QuickFixWrapper.wrap((ProblemDescriptor) descr, 0);
}
Also used : CommonProblemDescriptorImpl(com.intellij.codeInspection.CommonProblemDescriptorImpl) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) CommonProblemDescriptorImpl(com.intellij.codeInspection.CommonProblemDescriptorImpl) ProblemDescriptorImpl(com.intellij.codeInspection.ex.ProblemDescriptorImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ProblemDescriptorImpl

use of com.intellij.codeInspection.ex.ProblemDescriptorImpl in project google-cloud-intellij by GoogleCloudPlatform.

the class ConstructorInspectionTest method testQuickFix_classWithNullaryConstructor.

public void testQuickFix_classWithNullaryConstructor() {
    ProblemDescriptorImpl problemDescriptorMock = mock(ProblemDescriptorImpl.class);
    MockitoAnnotations.initMocks(this);
    PsiElementFactory factory = JavaPsiFacade.getInstance(myFixture.getProject()).getElementFactory();
    PsiClass psiClass = factory.createClass(getName());
    PsiMethod nullaryConstructor = factory.createMethodFromText("public " + psiClass.getName() + "() { }", psiClass);
    psiClass.addAfter(nullaryConstructor, null);
    ConstructorInspection constructorInspection = new ConstructorInspection();
    ConstructorInspection.MyQuickFix myQuickFix = constructorInspection.new MyQuickFix(psiClass);
    myQuickFix.applyFix(myFixture.getProject(), problemDescriptorMock);
    Assert.assertEquals(1, psiClass.getConstructors().length);
    Assert.assertTrue(EndpointUtilities.isPublicNullaryConstructor(psiClass.getConstructors()[0]));
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiElementFactory(com.intellij.psi.PsiElementFactory) PsiClass(com.intellij.psi.PsiClass) ProblemDescriptorImpl(com.intellij.codeInspection.ex.ProblemDescriptorImpl)

Example 4 with ProblemDescriptorImpl

use of com.intellij.codeInspection.ex.ProblemDescriptorImpl in project google-cloud-intellij by GoogleCloudPlatform.

the class ConstructorInspectionTest method testQuickFix_classWithNonNullaryConstructor.

public void testQuickFix_classWithNonNullaryConstructor() {
    ProblemDescriptorImpl problemDescriptorMock = mock(ProblemDescriptorImpl.class);
    MockitoAnnotations.initMocks(this);
    PsiElementFactory factory = JavaPsiFacade.getInstance(myFixture.getProject()).getElementFactory();
    PsiClass psiClass = factory.createClass(getName());
    PsiMethod nullaryConstructor = factory.createMethodFromText("public " + psiClass.getName() + "(String param) { }", psiClass);
    psiClass.addAfter(nullaryConstructor, null);
    ConstructorInspection constructorInspection = new ConstructorInspection();
    ConstructorInspection.MyQuickFix myQuickFix = constructorInspection.new MyQuickFix(psiClass);
    myQuickFix.applyFix(myFixture.getProject(), problemDescriptorMock);
    Assert.assertEquals(2, psiClass.getConstructors().length);
    Assert.assertTrue(EndpointUtilities.isPublicNullaryConstructor(psiClass.getConstructors()[0]));
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiElementFactory(com.intellij.psi.PsiElementFactory) PsiClass(com.intellij.psi.PsiClass) ProblemDescriptorImpl(com.intellij.codeInspection.ex.ProblemDescriptorImpl)

Aggregations

ProblemDescriptorImpl (com.intellij.codeInspection.ex.ProblemDescriptorImpl)4 PsiClass (com.intellij.psi.PsiClass)3 PsiElementFactory (com.intellij.psi.PsiElementFactory)2 PsiMethod (com.intellij.psi.PsiMethod)2 CommonProblemDescriptorImpl (com.intellij.codeInspection.CommonProblemDescriptorImpl)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 NotNull (org.jetbrains.annotations.NotNull)1