Search in sources :

Example 1 with PsiElementFactory

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

the class MorphAction method updateBoundFieldType.

private static void updateBoundFieldType(final GuiEditor editor, final RadComponent oldComponent, final ComponentItem targetItem) {
    PsiField oldBoundField = BindingProperty.findBoundField(editor.getRootContainer(), oldComponent.getBinding());
    if (oldBoundField != null) {
        final PsiElementFactory factory = JavaPsiFacade.getInstance(editor.getProject()).getElementFactory();
        try {
            PsiType componentType = factory.createTypeFromText(targetItem.getClassName().replace('$', '.'), null);
            new ChangeFieldTypeFix(editor, oldBoundField, componentType).run();
        } catch (IncorrectOperationException e) {
            LOG.error(e);
        }
    }
}
Also used : PsiField(com.intellij.psi.PsiField) PsiElementFactory(com.intellij.psi.PsiElementFactory) ChangeFieldTypeFix(com.intellij.uiDesigner.quickFixes.ChangeFieldTypeFix) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PsiType(com.intellij.psi.PsiType)

Example 2 with PsiElementFactory

use of com.intellij.psi.PsiElementFactory 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)

Example 3 with PsiElementFactory

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

the class FieldDescriptorImpl method getDescriptorEvaluation.

@Override
public PsiExpression getDescriptorEvaluation(DebuggerContext context) throws EvaluateException {
    PsiElementFactory elementFactory = JavaPsiFacade.getInstance(myProject).getElementFactory();
    String fieldName;
    if (isStatic()) {
        String typeName = myField.declaringType().name().replace('$', '.');
        typeName = DebuggerTreeNodeExpression.normalize(typeName, PositionUtil.getContextElement(context), myProject);
        fieldName = typeName + "." + getName();
    } else {
        //noinspection HardCodedStringLiteral
        fieldName = isOuterLocalVariableValue() ? StringUtil.trimStart(getName(), OUTER_LOCAL_VAR_FIELD_PREFIX) : "this." + getName();
    }
    try {
        return elementFactory.createExpressionFromText(fieldName, null);
    } catch (IncorrectOperationException e) {
        throw new EvaluateException(DebuggerBundle.message("error.invalid.field.name", getName()), e);
    }
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) PsiElementFactory(com.intellij.psi.PsiElementFactory) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 4 with PsiElementFactory

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

the class JavaIntroduceVariableTest method doTest.

protected static void doTest(String expression, VariableKind kind, PsiType type, String... results) throws Exception {
    final PsiElementFactory factory = JavaPsiFacade.getElementFactory(getProject());
    final PsiExpression expr = factory.createExpressionFromText(expression, null);
    final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(getProject());
    final SuggestedNameInfo info = codeStyleManager.suggestVariableName(kind, null, expr, type);
    assert info.names.length >= results.length : msg("Can't find some variants", info.names, results);
    for (int i = 0; i < results.length; i++) {
        if (!results[i].equals(info.names[i])) {
            throw new Exception(msg("", info.names, results));
        }
    }
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) JavaCodeStyleManager(com.intellij.psi.codeStyle.JavaCodeStyleManager) PsiElementFactory(com.intellij.psi.PsiElementFactory) SuggestedNameInfo(com.intellij.psi.codeStyle.SuggestedNameInfo)

Example 5 with PsiElementFactory

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

the class ConvertToJBColorConstantQuickFix method applyFix.

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    final PsiElement element = descriptor.getPsiElement();
    final PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
    final String jbColorConstant = String.format("%s.%s", JBColor.class.getName(), myConstantName);
    final PsiExpression expression = factory.createExpressionFromText(jbColorConstant, element.getContext());
    final PsiElement newElement = element.replace(expression);
    JavaCodeStyleManager.getInstance(project).shortenClassReferences(newElement);
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiElementFactory(com.intellij.psi.PsiElementFactory) JBColor(com.intellij.ui.JBColor) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiElementFactory (com.intellij.psi.PsiElementFactory)20 PsiClass (com.intellij.psi.PsiClass)6 PsiElement (com.intellij.psi.PsiElement)6 PsiExpression (com.intellij.psi.PsiExpression)5 IncorrectOperationException (com.intellij.util.IncorrectOperationException)5 ProblemDescriptorImpl (com.intellij.codeInspection.ex.ProblemDescriptorImpl)2 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)2 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)2 PsiComment (com.intellij.psi.PsiComment)2 PsiMethod (com.intellij.psi.PsiMethod)2 PsiType (com.intellij.psi.PsiType)2 JBColor (com.intellij.ui.JBColor)2 ArrayList (java.util.ArrayList)2 ArrayElementDescriptorImpl (com.intellij.debugger.ui.impl.watch.ArrayElementDescriptorImpl)1 Editor (com.intellij.openapi.editor.Editor)1 Project (com.intellij.openapi.project.Project)1 LanguageLevel (com.intellij.pom.java.LanguageLevel)1 PsiClassType (com.intellij.psi.PsiClassType)1 PsiField (com.intellij.psi.PsiField)1 JavaCodeStyleManager (com.intellij.psi.codeStyle.JavaCodeStyleManager)1