Search in sources :

Example 6 with PsiElementFactory

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);
    }
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiElementFactory(com.intellij.psi.PsiElementFactory) JBColor(com.intellij.ui.JBColor) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement)

Example 7 with PsiElementFactory

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);
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiElementFactory(com.intellij.psi.PsiElementFactory) PsiElement(com.intellij.psi.PsiElement)

Example 8 with PsiElementFactory

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()));
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) GrDocReferenceElement(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocReferenceElement) ArrayList(java.util.ArrayList) PsiElementFactory(com.intellij.psi.PsiElementFactory) IncorrectOperationException(com.intellij.util.IncorrectOperationException) GrDocMethodParameter(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocMethodParameter) PsiType(com.intellij.psi.PsiType) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx)

Example 9 with PsiElementFactory

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());
        }
    });
}
Also used : ClassEntity(org.gsonformat.intellij.entity.ClassEntity) ClassProcessor(org.gsonformat.intellij.process.ClassProcessor) PsiElementFactory(com.intellij.psi.PsiElementFactory) PsiClass(com.intellij.psi.PsiClass) IProcessor(org.gsonformat.intellij.process.IProcessor)

Example 10 with PsiElementFactory

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);
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiElementFactory(com.intellij.psi.PsiElementFactory) 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