use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class JavaExceptionBreakpointType method addBreakpoint.
//public Key<ExceptionBreakpoint> getBreakpointCategory() {
// return ExceptionBreakpoint.CATEGORY;
//}
@Nullable
@Override
public XBreakpoint<JavaExceptionBreakpointProperties> addBreakpoint(final Project project, JComponent parentComponent) {
final PsiClass throwableClass = JavaPsiFacade.getInstance(project).findClass(CommonClassNames.JAVA_LANG_THROWABLE, GlobalSearchScope.allScope(project));
TreeClassChooser chooser = TreeClassChooserFactory.getInstance(project).createInheritanceClassChooser(DebuggerBundle.message("add.exception.breakpoint.classchooser.title"), GlobalSearchScope.allScope(project), throwableClass, true, true, null);
chooser.showDialog();
final PsiClass selectedClass = chooser.getSelected();
final String qName = selectedClass == null ? null : JVMNameUtil.getNonAnonymousClassName(selectedClass);
if (qName != null && qName.length() > 0) {
return ApplicationManager.getApplication().runWriteAction(new Computable<XBreakpoint<JavaExceptionBreakpointProperties>>() {
@Override
public XBreakpoint<JavaExceptionBreakpointProperties> compute() {
return XDebuggerManager.getInstance(project).getBreakpointManager().addBreakpoint(JavaExceptionBreakpointType.this, new JavaExceptionBreakpointProperties(qName, ((PsiClassOwner) selectedClass.getContainingFile()).getPackageName()));
}
});
}
return null;
}
use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class JumpToObjectAction method calcPosition.
private static SourcePosition calcPosition(final ValueDescriptor descriptor, final DebugProcessImpl debugProcess) throws ClassNotLoadedException {
Type type = descriptor.getType();
if (type == null) {
return null;
}
try {
if (type instanceof ArrayType) {
type = ((ArrayType) type).componentType();
}
if (type instanceof ClassType) {
ClassType clsType = (ClassType) type;
Method lambdaMethod = MethodBytecodeUtil.getLambdaMethod(clsType, debugProcess.getVirtualMachineProxy());
Location location = lambdaMethod != null ? ContainerUtil.getFirstItem(DebuggerUtilsEx.allLineLocations(lambdaMethod)) : null;
if (location == null) {
location = ContainerUtil.getFirstItem(clsType.allLineLocations());
}
if (location != null) {
SourcePosition position = debugProcess.getPositionManager().getSourcePosition(location);
return ApplicationManager.getApplication().runReadAction(new Computable<SourcePosition>() {
@Override
public SourcePosition compute() {
// adjust position for non-anonymous classes
if (clsType.name().indexOf('$') < 0) {
PsiClass classAt = JVMNameUtil.getClassAt(position);
if (classAt != null) {
SourcePosition classPosition = SourcePosition.createFromElement(classAt);
if (classPosition != null) {
return classPosition;
}
}
}
return position;
}
});
}
}
} catch (ClassNotPreparedException | AbsentInformationException e) {
LOG.debug(e);
}
return null;
}
use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class TargetType method create.
@Nullable
public static TargetType create(final PsiClassType classType) {
final PsiClassType.ClassResolveResult resolvedGenerics = classType.resolveGenerics();
final PsiClass resolvedClass = resolvedGenerics.getElement();
if (resolvedClass == null) {
return null;
}
final String classQName = resolvedClass.getQualifiedName();
if (classQName == null) {
return null;
}
if (resolvedClass.hasTypeParameters()) {
return null;
}
return new TargetType(classQName, false, classType);
}
use of com.intellij.psi.PsiClass in project smali by JesusFreke.
the class SmaliClassTest method testGetSuperclass.
public void testGetSuperclass() {
myFixture.addFileToProject("base.smali", ".class public interface Lbase; .super Ljava/lang/Object;");
myFixture.addFileToProject("iface.smali", ".class public interface Liface; .super Ljava/lang/Object;");
SmaliFile file = (SmaliFile) myFixture.addFileToProject("blah.smali", ".class public Lblah; .super Lbase; .implements Liface;");
SmaliClass smaliClass = file.getPsiClass();
Assert.assertEquals("blah", smaliClass.getQualifiedName());
PsiClass superClass = smaliClass.getSuperClass();
Assert.assertNotNull(superClass);
Assert.assertEquals("base", smaliClass.getSuperClass().getQualifiedName());
Assert.assertEquals(2, smaliClass.getSupers().length);
Assert.assertEquals("base", smaliClass.getSupers()[0].getQualifiedName());
Assert.assertEquals("iface", smaliClass.getSupers()[1].getQualifiedName());
Assert.assertEquals(2, smaliClass.getSuperTypes().length);
Assert.assertEquals("base", smaliClass.getSuperTypes()[0].getCanonicalText());
Assert.assertEquals("iface", smaliClass.getSuperTypes()[1].getCanonicalText());
Assert.assertEquals(1, smaliClass.getInterfaces().length);
Assert.assertEquals("iface", smaliClass.getInterfaces()[0].getQualifiedName());
}
use of com.intellij.psi.PsiClass in project smali by JesusFreke.
the class SmaliClassTest method testIsInheritor.
public void testIsInheritor() {
SmaliFile file = (SmaliFile) myFixture.addFileToProject("blah.smali", ".class public Lblah; .super Ljava/lang/Exception;");
SmaliClass smaliClass = file.getPsiClass();
Assert.assertEquals("blah", smaliClass.getQualifiedName());
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
PsiClassType throwableType = factory.createTypeByFQClassName("java.lang.Throwable", file.getResolveScope());
PsiClass throwableClass = throwableType.resolve();
Assert.assertNotNull(throwableClass);
PsiClassType exceptionType = factory.createTypeByFQClassName("java.lang.Exception", file.getResolveScope());
PsiClass exceptionClass = exceptionType.resolve();
Assert.assertNotNull(exceptionClass);
PsiClassType objectType = factory.createTypeByFQClassName("java.lang.Object", file.getResolveScope());
PsiClass objectClass = objectType.resolve();
Assert.assertNotNull(objectClass);
Assert.assertTrue(smaliClass.isInheritor(exceptionClass, true));
Assert.assertTrue(smaliClass.isInheritor(throwableClass, true));
Assert.assertTrue(smaliClass.isInheritor(objectClass, true));
Assert.assertTrue(smaliClass.isInheritorDeep(exceptionClass, null));
Assert.assertTrue(smaliClass.isInheritorDeep(throwableClass, null));
Assert.assertTrue(smaliClass.isInheritorDeep(objectClass, null));
Assert.assertTrue(smaliClass.isInheritor(exceptionClass, false));
Assert.assertFalse(smaliClass.isInheritor(throwableClass, false));
Assert.assertFalse(smaliClass.isInheritor(objectClass, false));
}
Aggregations