Search in sources :

Example 11 with PsiElementFactory

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

the class CompoundTypeRenderer method getChildValueExpression.

protected final PsiElement getChildValueExpression(String text, DebuggerTreeNode node, DebuggerContext context) {
    Project project = node.getProject();
    PsiElementFactory elementFactory = JavaPsiFacade.getInstance(project).getElementFactory();
    return elementFactory.createExpressionFromText(text, getContext(project, context));
}
Also used : Project(com.intellij.openapi.project.Project) PsiElementFactory(com.intellij.psi.PsiElementFactory)

Example 12 with PsiElementFactory

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

the class ArrayRenderer method getChildValueExpression.

public PsiExpression getChildValueExpression(DebuggerTreeNode node, DebuggerContext context) {
    LOG.assertTrue(node.getDescriptor() instanceof ArrayElementDescriptorImpl, node.getDescriptor().getClass().getName());
    ArrayElementDescriptorImpl descriptor = (ArrayElementDescriptorImpl) node.getDescriptor();
    PsiElementFactory elementFactory = JavaPsiFacade.getInstance(node.getProject()).getElementFactory();
    try {
        LanguageLevel languageLevel = LanguageLevelProjectExtension.getInstance(node.getProject()).getLanguageLevel();
        return elementFactory.createExpressionFromText("this[" + descriptor.getIndex() + "]", elementFactory.getArrayClass(languageLevel));
    } catch (IncorrectOperationException e) {
        LOG.error(e);
        return null;
    }
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) PsiElementFactory(com.intellij.psi.PsiElementFactory) IncorrectOperationException(com.intellij.util.IncorrectOperationException) ArrayElementDescriptorImpl(com.intellij.debugger.ui.impl.watch.ArrayElementDescriptorImpl)

Example 13 with PsiElementFactory

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

the class ClassRenderer method getChildValueExpression.

@Override
public PsiElement getChildValueExpression(DebuggerTreeNode node, DebuggerContext context) throws EvaluateException {
    FieldDescriptor fieldDescriptor = (FieldDescriptor) node.getDescriptor();
    PsiElementFactory elementFactory = JavaPsiFacade.getInstance(node.getProject()).getElementFactory();
    try {
        return elementFactory.createExpressionFromText("this." + fieldDescriptor.getField().name(), DebuggerUtils.findClass(fieldDescriptor.getObject().referenceType().name(), context.getProject(), context.getDebugProcess().getSearchScope()));
    } catch (IncorrectOperationException e) {
        throw new EvaluateException(DebuggerBundle.message("error.invalid.field.name", fieldDescriptor.getField().name()), null);
    }
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) PsiElementFactory(com.intellij.psi.PsiElementFactory) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 14 with PsiElementFactory

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

the class PsiUtilTest method createClass.

private static PsiClass createClass(String text) throws IncorrectOperationException {
    final PsiElementFactory factory = JavaPsiFacade.getInstance(ourProject).getElementFactory();
    final PsiClass classA = factory.createClassFromText(text, null).getInnerClasses()[0];
    return classA;
}
Also used : PsiElementFactory(com.intellij.psi.PsiElementFactory) PsiClass(com.intellij.psi.PsiClass)

Example 15 with PsiElementFactory

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

the class ChangeToEndOfLineCommentIntention method processIntention.

@Override
public void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
    final PsiComment comment = (PsiComment) element;
    final JavaPsiFacade manager = JavaPsiFacade.getInstance(comment.getProject());
    final PsiElement parent = comment.getParent();
    assert parent != null;
    final PsiElementFactory factory = manager.getElementFactory();
    final String commentText = comment.getText();
    final PsiElement whitespace = comment.getNextSibling();
    final String text = commentText.substring(2, commentText.length() - 2);
    final String[] lines = text.split("\n");
    for (int i = lines.length - 1; i >= 1; i--) {
        final PsiComment nextComment = factory.createCommentFromText("//" + lines[i].trim() + '\n', parent);
        parent.addAfter(nextComment, comment);
    /* if (whitespace != null) {
      final PsiElement newWhiteSpace =
          factory.createWhiteSpaceFromText(whitespace.getText());
      parent.addAfter(newWhiteSpace, comment);
    }  */
    }
    final PsiComment newComment = factory.createCommentFromText("//" + lines[0], parent);
    comment.replace(newComment);
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) PsiComment(com.intellij.psi.PsiComment) 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