use of com.intellij.psi.PsiElementFactory in project intellij-community by JetBrains.
the class ConvertToJBColorQuickFix 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 newJBColor = String.format("new %s(%s, new java.awt.Color())", JBColor.class.getName(), element.getText());
final PsiExpression expression = factory.createExpressionFromText(newJBColor, element.getContext());
final PsiElement newElement = element.replace(expression);
final PsiElement el = JavaCodeStyleManager.getInstance(project).shortenClassReferences(newElement);
final int offset = el.getTextOffset() + el.getText().length() - 2;
final Editor editor = PsiUtilBase.findEditor(el);
if (editor != null) {
editor.getCaretModel().moveToOffset(offset);
}
}
use of com.intellij.psi.PsiElementFactory in project intellij-community by JetBrains.
the class ChangeToPairCreateQuickFix method applyFix.
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement element = descriptor.getPsiElement();
if (element == null) {
return;
}
String text = element.getText();
String newText = "com.intellij.openapi.util.Pair.create(" + text.substring(text.indexOf('(') + 1);
PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
PsiExpression expression = factory.createExpressionFromText(newText, element.getContext());
PsiElement newElement = element.replace(expression);
JavaCodeStyleManager.getInstance(project).shortenClassReferences(newElement);
}
use of com.intellij.psi.PsiElementFactory in project intellij-community by JetBrains.
the class GrDocMethodParamsImpl method getParameterTypes.
@Override
public PsiType[] getParameterTypes() {
ArrayList<PsiType> types = new ArrayList<>();
PsiManagerEx manager = getManager();
GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
for (GrDocMethodParameter parameter : getParameters()) {
GrDocReferenceElement typeElement = parameter.getTypeElement();
try {
PsiType type = factory.createTypeFromText(typeElement.getText(), this);
type = TypesUtil.boxPrimitiveType(type, manager, scope);
types.add(type);
} catch (IncorrectOperationException e) {
LOG.info(e);
types.add(null);
}
}
return types.toArray(PsiType.createArray(types.size()));
}
use of com.intellij.psi.PsiElementFactory in project GsonFormat by zzz40500.
the class DataWriter method run.
@Override
protected void run() {
if (targetClass == null) {
return;
}
generateClassList.clear();
new ClassProcessor(factory, cls).generate(targetClass, new IProcessor() {
@Override
public void onStarProcess(ClassEntity classEntity, PsiElementFactory factory, PsiClass cls) {
generateClassList.add(cls.getQualifiedName());
}
@Override
public void onEndProcess(ClassEntity classEntity, PsiElementFactory factory, PsiClass cls) {
}
@Override
public void onStartGenerateClass(PsiElementFactory factory, ClassEntity classEntity, PsiClass parentClass) {
}
@Override
public void onEndGenerateClass(PsiElementFactory factory, ClassEntity classEntity, PsiClass parentClass, PsiClass generateClass) {
generateClassList.add(generateClass.getQualifiedName());
}
});
}
use of com.intellij.psi.PsiElementFactory in project intellij-community by JetBrains.
the class ConvertToGrayQuickFix 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 PsiExpression expression = factory.createExpressionFromText("com.intellij.ui.Gray._" + myNum, element.getContext());
final PsiElement newElement = element.replace(expression);
JavaCodeStyleManager.getInstance(project).shortenClassReferences(newElement);
}
Aggregations