Search in sources :

Example 1 with PsiAnonymousClass

use of com.intellij.psi.PsiAnonymousClass in project kotlin by JetBrains.

the class ViewConstructorDetector method checkClass.

@Override
public void checkClass(@NonNull JavaContext context, @NonNull UClass declaration) {
    // Only applies to concrete classes
    JavaEvaluator evaluator = context.getEvaluator();
    if (evaluator.isAbstract(declaration) || declaration instanceof PsiAnonymousClass) {
        // Ignore abstract classes
        return;
    }
    if (declaration.getContainingClass() != null && !evaluator.isStatic(declaration)) {
        // anyway since we'd need the outer instance
        return;
    }
    boolean found = false;
    for (PsiMethod constructor : declaration.getConstructors()) {
        if (isXmlConstructor(evaluator, constructor)) {
            found = true;
            break;
        }
    }
    if (!found) {
        String message = String.format("Custom view `%1$s` is missing constructor used by tools: " + "`(Context)` or `(Context,AttributeSet)` " + "or `(Context,AttributeSet,int)`", declaration.getName());
        Location location = context.getUastNameLocation(declaration);
        context.reportUast(ISSUE, declaration, location, message);
    }
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiAnonymousClass(com.intellij.psi.PsiAnonymousClass) JavaEvaluator(com.android.tools.klint.client.api.JavaEvaluator) Location(com.android.tools.klint.detector.api.Location)

Example 2 with PsiAnonymousClass

use of com.intellij.psi.PsiAnonymousClass in project intellij-community by JetBrains.

the class TurnRefsToSuperHandler method invoke.

@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
    int offset = editor.getCaretModel().getOffset();
    editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
    PsiElement element = file.findElementAt(offset);
    while (true) {
        if (element == null || element instanceof PsiFile) {
            String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.class"));
            CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.TURN_REFS_TO_SUPER);
            return;
        }
        if (element instanceof PsiClass && !(element instanceof PsiAnonymousClass)) {
            invoke(project, new PsiElement[] { element }, dataContext);
            return;
        }
        element = element.getParent();
    }
}
Also used : PsiClass(com.intellij.psi.PsiClass) PsiAnonymousClass(com.intellij.psi.PsiAnonymousClass) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 3 with PsiAnonymousClass

use of com.intellij.psi.PsiAnonymousClass in project intellij-community by JetBrains.

the class SubtypesHierarchyTreeStructure method buildChildren.

@NotNull
protected final Object[] buildChildren(@NotNull final HierarchyNodeDescriptor descriptor) {
    final Object element = ((TypeHierarchyNodeDescriptor) descriptor).getPsiClass();
    if (!(element instanceof PsiClass))
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    final PsiClass psiClass = (PsiClass) element;
    if (CommonClassNames.JAVA_LANG_OBJECT.equals(psiClass.getQualifiedName())) {
        return new Object[] { IdeBundle.message("node.hierarchy.java.lang.object") };
    }
    if (psiClass instanceof PsiAnonymousClass)
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    if (psiClass.hasModifierProperty(PsiModifier.FINAL))
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    final SearchScope searchScope = psiClass.getUseScope().intersectWith(getSearchScope(myCurrentScopeType, psiClass));
    final List<PsiClass> classes = new ArrayList<>(searchInheritors(psiClass, searchScope));
    final List<HierarchyNodeDescriptor> descriptors = new ArrayList<>(classes.size());
    for (PsiClass aClass : classes) {
        descriptors.add(new TypeHierarchyNodeDescriptor(myProject, descriptor, aClass, false));
    }
    FunctionalExpressionSearch.search(psiClass, searchScope).forEach(expression -> {
        descriptors.add(new TypeHierarchyNodeDescriptor(myProject, descriptor, expression, false));
        return true;
    });
    return descriptors.toArray(new HierarchyNodeDescriptor[descriptors.size()]);
}
Also used : PsiClass(com.intellij.psi.PsiClass) SearchScope(com.intellij.psi.search.SearchScope) ArrayList(java.util.ArrayList) PsiAnonymousClass(com.intellij.psi.PsiAnonymousClass) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with PsiAnonymousClass

use of com.intellij.psi.PsiAnonymousClass in project intellij-community by JetBrains.

the class JavaAnonymousClassesHelperTest method doTest.

@SuppressWarnings("ConstantConditions")
private void doTest(int num) {
    final PsiElement element = PsiUtilBase.getElementAtCaret(myFixture.getEditor()).getParent().getParent();
    assert element instanceof PsiAnonymousClass : "There should be anonymous class at caret but " + element + " found";
    assertEquals("$" + num, JavaAnonymousClassesHelper.getName((PsiAnonymousClass) element));
}
Also used : PsiAnonymousClass(com.intellij.psi.PsiAnonymousClass) PsiElement(com.intellij.psi.PsiElement)

Example 5 with PsiAnonymousClass

use of com.intellij.psi.PsiAnonymousClass in project intellij-community by JetBrains.

the class NonSerializableWithSerializationMethodsInspection method buildErrorString.

@Override
@NotNull
public String buildErrorString(Object... infos) {
    final boolean hasReadObject = ((Boolean) infos[0]).booleanValue();
    final boolean hasWriteObject = ((Boolean) infos[1]).booleanValue();
    final PsiClass aClass = (PsiClass) infos[2];
    if (aClass instanceof PsiAnonymousClass) {
        if (hasReadObject && hasWriteObject) {
            return InspectionGadgetsBundle.message("non.serializable.anonymous.with.readwriteobject.problem.descriptor.both");
        } else if (hasWriteObject) {
            return InspectionGadgetsBundle.message("non.serializable.anonymous.with.readwriteobject.problem.descriptor.write");
        } else {
            return InspectionGadgetsBundle.message("non.serializable.anonymous.with.readwriteobject.problem.descriptor.read");
        }
    } else {
        if (hasReadObject && hasWriteObject) {
            return InspectionGadgetsBundle.message("non.serializable.class.with.readwriteobject.problem.descriptor.both");
        } else if (hasWriteObject) {
            return InspectionGadgetsBundle.message("non.serializable.class.with.readwriteobject.problem.descriptor.write");
        } else {
            return InspectionGadgetsBundle.message("non.serializable.class.with.readwriteobject.problem.descriptor.read");
        }
    }
}
Also used : PsiClass(com.intellij.psi.PsiClass) PsiAnonymousClass(com.intellij.psi.PsiAnonymousClass) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiAnonymousClass (com.intellij.psi.PsiAnonymousClass)6 PsiClass (com.intellij.psi.PsiClass)3 PsiElement (com.intellij.psi.PsiElement)2 PsiMethod (com.intellij.psi.PsiMethod)2 NotNull (org.jetbrains.annotations.NotNull)2 JavaEvaluator (com.android.tools.klint.client.api.JavaEvaluator)1 Location (com.android.tools.klint.detector.api.Location)1 GenerateEqualsWizard (com.intellij.codeInsight.generation.ui.GenerateEqualsWizard)1 HierarchyNodeDescriptor (com.intellij.ide.hierarchy.HierarchyNodeDescriptor)1 PsiFile (com.intellij.psi.PsiFile)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 SearchScope (com.intellij.psi.search.SearchScope)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 ArrayList (java.util.ArrayList)1 Nullable (org.jetbrains.annotations.Nullable)1