Search in sources :

Example 76 with PsiClass

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;
}
Also used : TreeClassChooser(com.intellij.ide.util.TreeClassChooser) JavaExceptionBreakpointProperties(org.jetbrains.java.debugger.breakpoints.properties.JavaExceptionBreakpointProperties) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) PsiClass(com.intellij.psi.PsiClass) Nullable(org.jetbrains.annotations.Nullable)

Example 77 with PsiClass

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;
}
Also used : SourcePosition(com.intellij.debugger.SourcePosition) PsiClass(com.intellij.psi.PsiClass)

Example 78 with PsiClass

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);
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) PsiClass(com.intellij.psi.PsiClass) Nullable(org.jetbrains.annotations.Nullable)

Example 79 with PsiClass

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());
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass) PsiClass(com.intellij.psi.PsiClass)

Example 80 with PsiClass

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));
}
Also used : SmaliFile(org.jf.smalidea.psi.impl.SmaliFile) SmaliClass(org.jf.smalidea.psi.impl.SmaliClass) PsiClassType(com.intellij.psi.PsiClassType) PsiElementFactory(com.intellij.psi.PsiElementFactory) PsiClass(com.intellij.psi.PsiClass)

Aggregations

PsiClass (com.intellij.psi.PsiClass)598 PsiElement (com.intellij.psi.PsiElement)113 PsiMethod (com.intellij.psi.PsiMethod)97 Nullable (org.jetbrains.annotations.Nullable)75 NotNull (org.jetbrains.annotations.NotNull)60 Project (com.intellij.openapi.project.Project)59 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)57 Module (com.intellij.openapi.module.Module)55 PsiFile (com.intellij.psi.PsiFile)49 VirtualFile (com.intellij.openapi.vfs.VirtualFile)47 ArrayList (java.util.ArrayList)37 PsiField (com.intellij.psi.PsiField)36 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)25 Location (com.intellij.execution.Location)20 File (java.io.File)16 HashSet (java.util.HashSet)16 PsiClassType (com.intellij.psi.PsiClassType)15 PsiPackage (com.intellij.psi.PsiPackage)15 List (java.util.List)15 PsiType (com.intellij.psi.PsiType)13