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