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);
}
}
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();
}
}
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()]);
}
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));
}
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");
}
}
}
Aggregations