Java 类com.intellij.psi.JavaCodeFragment 实例源码

项目:intellij-ce-playground    文件:ExtractMethodObject4DebuggerTest.java   
private void doTest(String evaluatedText,
                    String expectedCallSite,
                    String expectedClass,
                    boolean codeBlock) throws Exception {
  final String testName = getTestName(false);
  configureByFile("/refactoring/extractMethodObject4Debugger/" + testName + ".java");
  final int offset = getEditor().getCaretModel().getOffset();
  final PsiElement context = getFile().findElementAt(offset);
  final JavaCodeFragmentFactory fragmentFactory = JavaCodeFragmentFactory.getInstance(getProject());
  final JavaCodeFragment fragment = codeBlock ? fragmentFactory.createCodeBlockCodeFragment(evaluatedText, context, false) : fragmentFactory.createExpressionCodeFragment(evaluatedText, context, null, false);
  final ExtractLightMethodObjectHandler.ExtractedData extractedData =
    ExtractLightMethodObjectHandler.extractLightMethodObject(getProject(), getFile(), fragment, "test");
  assertNotNull(extractedData);
  assertEquals(expectedCallSite, extractedData.getGeneratedCallText());
  final PsiClass innerClass = extractedData.getGeneratedInnerClass();
  assertEquals(expectedClass, innerClass.getText());
}
项目:defrac-plugin-intellij    文件:DefracMainClassTextFieldWithBrowseButton.java   
public DefracMainClassTextFieldWithBrowseButton(@NotNull final Project project,
                                                @NotNull final ConfigurationModuleSelector moduleSelector) {
  super(project, true, new JavaCodeFragment.VisibilityChecker() {
    public Visibility isDeclarationVisible(PsiElement declaration, PsiElement place) {
      if(declaration instanceof PsiClass) {
        final PsiClass aClass = (PsiClass) declaration;

        if(isValidMainClass(aClass) || place.getParent() != null && isValidMainClass(moduleSelector.findClass(aClass.getQualifiedName()))) {
          return Visibility.VISIBLE;
        }
      }

      return Visibility.NOT_VISIBLE;
    }

    private boolean isValidMainClass(@Nullable final PsiClass cls) {
      return DefracRunUtil.isValidMainClass(moduleSelector.getModule(), cls);
    }
  });
}
项目:tools-idea    文件:TextWithImportsImpl.java   
public TextWithImportsImpl (PsiExpression expression) {
  myKind = CodeFragmentKind.EXPRESSION;
  final String text = expression.getText();
  PsiFile containingFile = expression.getContainingFile();
  if(containingFile instanceof PsiExpressionCodeFragment) {
    myText = text;
    myImports = ((JavaCodeFragment)containingFile).importsToString();
    myFileType = StdFileTypes.JAVA;
  }
  else {
    Trinity<String, String, FileType> trinity = parseExternalForm(text);
    myText = trinity.first;
    myImports = trinity.second;
    myFileType = trinity.third;
  }
}
项目:tools-idea    文件:CodeFragmentFactoryContextWrapper.java   
private PsiElement wrapContext(Project project, final PsiElement originalContext) {
  if (project.isDefault()) return originalContext;
  PsiElement context = originalContext;
  final DebugProcessImpl process = DebuggerManagerEx.getInstanceEx(project).getContext().getDebugProcess();
  if (process != null) {
    final Map<ObjectReference, ValueMarkup> markupMap = ValueDescriptorImpl.getMarkupMap(process);
    if (markupMap != null && markupMap.size() > 0) {
      final Pair<String, Map<String, ObjectReference>> markupVariables = createMarkupVariablesText(markupMap);
      int offset = markupVariables.getFirst().length() - 1;
      final TextWithImportsImpl textWithImports = new TextWithImportsImpl(CodeFragmentKind.CODE_BLOCK, markupVariables.getFirst(), "", myDelegate.getFileType());
      final JavaCodeFragment codeFragment = myDelegate.createCodeFragment(textWithImports, context, project);
      codeFragment.accept(new JavaRecursiveElementVisitor() {
        public void visitLocalVariable(PsiLocalVariable variable) {
          final String name = variable.getName();
          variable.putUserData(LABEL_VARIABLE_VALUE_KEY, markupVariables.getSecond().get(name));
        }
      });
      final PsiElement newContext = codeFragment.findElementAt(offset);
      if (newContext != null) {
        context = newContext;
      }
    }
  }
  return context;
}
项目:consulo-java    文件:JavaDebuggerEditorsProvider.java   
@Override
protected PsiFile createExpressionCodeFragment(@NotNull Project project, @NotNull XExpression expression, @Nullable PsiElement context, boolean isPhysical)
{
    TextWithImports text = TextWithImportsImpl.fromXExpression(expression);
    if(text != null && context != null)
    {
        CodeFragmentFactory factory = DebuggerUtilsEx.findAppropriateCodeFragmentFactory(text, context);
        JavaCodeFragment codeFragment = factory.createPresentationCodeFragment(text, context, project);
        codeFragment.forceResolveScope(GlobalSearchScope.allScope(project));

        final PsiClass contextClass = PsiTreeUtil.getNonStrictParentOfType(context, PsiClass.class);
        if(contextClass != null)
        {
            final PsiClassType contextType = JavaPsiFacade.getInstance(codeFragment.getProject()).getElementFactory().createType(contextClass);
            codeFragment.setThisType(contextType);
        }
        return codeFragment;
    }
    else
    {
        return super.createExpressionCodeFragment(project, expression, context, isPhysical);
    }
}
项目:consulo-java    文件:TextWithImportsImpl.java   
public TextWithImportsImpl(@NotNull PsiElement expression)
{
    myKind = CodeFragmentKind.EXPRESSION;
    final String text = expression.getText();
    PsiFile containingFile = expression.getContainingFile();
    if(containingFile instanceof PsiExpressionCodeFragment)
    {
        myText = text;
        myImports = ((JavaCodeFragment) containingFile).importsToString();
        myFileType = JavaFileType.INSTANCE;
    }
    else
    {
        Trinity<String, String, FileType> trinity = parseExternalForm(text);
        myText = trinity.first;
        myImports = trinity.second;
        myFileType = trinity.third;
    }
}
项目:consulo-java    文件:CompoundRendererConfigurable.java   
private ClassNameEditorWithBrowseButton(ActionListener browseActionListener, final Project project)
{
    super(browseActionListener, project, s ->
    {
        JavaCodeFragment fragment = new PsiTypeCodeFragmentImpl(project, true, "fragment.java", s, 0, null)
        {
            @Override
            public boolean importClass(PsiClass aClass)
            {
                return false;
            }
        };
        fragment.setVisibilityChecker(JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE);
        return PsiDocumentManager.getInstance(project).getDocument(fragment);
    }, "");
}
项目:livingdoc-intellij    文件:RunConfigurationEditor.java   
private void createUIComponents() {
    myMainClass = new LabeledComponent<>();
    myMainClass.setComponent(new EditorTextFieldWithBrowseButton(myProject, true, (declaration, place) -> {

        if (declaration instanceof PsiClass) {
            final PsiClass aClass = (PsiClass) declaration;
            if (ConfigurationUtil.MAIN_CLASS.value(aClass) && PsiMethodUtil.findMainMethod(aClass) != null) {
                return JavaCodeFragment.VisibilityChecker.Visibility.VISIBLE;
            }
        }
        return JavaCodeFragment.VisibilityChecker.Visibility.NOT_VISIBLE;
    }
    ));
}
项目:intellij-ce-playground    文件:CodeFragmentFactoryContextWrapper.java   
private PsiElement wrapContext(Project project, final PsiElement originalContext) {
  if (project.isDefault()) return originalContext;
  //TODO [egor] : does not work for anything other than java anyway, see IDEA-132677
  if (!(myDelegate instanceof DefaultCodeFragmentFactory)) {
    return originalContext;
  }
  PsiElement context = originalContext;
  XDebugSession session = XDebuggerManager.getInstance(project).getCurrentSession();
  if (session != null) {
    XValueMarkers<?, ?> markers = ((XDebugSessionImpl)session).getValueMarkers();
    Map<?, ValueMarkup> markupMap = markers != null ? markers.getAllMarkers() : null;
    //final Map<ObjectReference, ValueMarkup> markupMap = ValueDescriptorImpl.getMarkupMap(process);
    if (markupMap != null && markupMap.size() > 0) {
      final Pair<String, Map<String, ObjectReference>> markupVariables = createMarkupVariablesText(markupMap);
      int offset = markupVariables.getFirst().length() - 1;
      final TextWithImportsImpl textWithImports = new TextWithImportsImpl(CodeFragmentKind.CODE_BLOCK, markupVariables.getFirst(), "", myDelegate.getFileType());
      final JavaCodeFragment codeFragment = myDelegate.createCodeFragment(textWithImports, context, project);
      codeFragment.accept(new JavaRecursiveElementVisitor() {
        public void visitLocalVariable(PsiLocalVariable variable) {
          final String name = variable.getName();
          variable.putUserData(LABEL_VARIABLE_VALUE_KEY, markupVariables.getSecond().get(name));
        }
      });
      final PsiElement newContext = codeFragment.findElementAt(offset);
      if (newContext != null) {
        context = newContext;
      }
    }
  }
  return context;
}
项目:intellij-ce-playground    文件:ApplicationConfigurable.java   
private void createUIComponents() {
  myMainClass = new LabeledComponent<EditorTextFieldWithBrowseButton>();
  myMainClass.setComponent(new EditorTextFieldWithBrowseButton(myProject, true, new JavaCodeFragment.VisibilityChecker() {
    @Override
    public Visibility isDeclarationVisible(PsiElement declaration, PsiElement place) {
      if (declaration instanceof PsiClass) {
        final PsiClass aClass = (PsiClass)declaration;
        if (ConfigurationUtil.MAIN_CLASS.value(aClass) && PsiMethodUtil.findMainMethod(aClass) != null || place.getParent() != null && myModuleSelector.findClass(((PsiClass)declaration).getQualifiedName()) != null) {
          return Visibility.VISIBLE;
        }
      }
      return Visibility.NOT_VISIBLE;
    }
  }));
}
项目:embeddedlinux-jvmdebugger-intellij    文件:RunConfigurationEditor.java   
/**
 * Creates UI Components
 */
private void createUIComponents() {
    myMainClass = new LabeledComponent<>();
    myMainClass.setComponent(new EditorTextFieldWithBrowseButton(myProject, true, (declaration, place) -> {
        if (declaration instanceof PsiClass) {
            final PsiClass aClass = (PsiClass)declaration;
            if (ConfigurationUtil.MAIN_CLASS.value(aClass) && PsiMethodUtil.findMainMethod(aClass) != null || place.getParent() != null && myModuleSelector.findClass(((PsiClass)declaration).getQualifiedName()) != null) {
                return JavaCodeFragment.VisibilityChecker.Visibility.VISIBLE;
            }
        }
        return JavaCodeFragment.VisibilityChecker.Visibility.NOT_VISIBLE;
    }));
}
项目:tools-idea    文件:ApplicationConfigurable.java   
private void createUIComponents() {
  myMainClass = new LabeledComponent<EditorTextFieldWithBrowseButton>();
  myMainClass.setComponent(new EditorTextFieldWithBrowseButton(myProject, true, new JavaCodeFragment.VisibilityChecker() {
    @Override
    public Visibility isDeclarationVisible(PsiElement declaration, PsiElement place) {
      if (declaration instanceof PsiClass) {
        final PsiClass aClass = (PsiClass)declaration;
        if (ConfigurationUtil.MAIN_CLASS.value(aClass) && PsiMethodUtil.findMainMethod(aClass) != null) {
          return Visibility.VISIBLE;
        }
      }
      return Visibility.NOT_VISIBLE;
    }
  }));
}
项目:consulo-java    文件:JavaReferenceEditorUtil.java   
@Nullable
@RequiredReadAction
public static Document createDocument(final String text, Project project, boolean isClassesAccepted) {
  final PsiJavaPackage defaultPackage = JavaPsiFacade.getInstance(project).findPackage("");
  final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(project);
  final JavaCodeFragment fragment = factory.createReferenceCodeFragment(text, defaultPackage, true, isClassesAccepted);
  fragment.setVisibilityChecker(JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE);
  return PsiDocumentManager.getInstance(project).getDocument(fragment);
}
项目:consulo-java    文件:JavaReferenceEditorUtil.java   
@Nullable
@RequiredReadAction
public static Document createTypeDocument(final String text, Project project) {
  final PsiJavaPackage defaultPackage = JavaPsiFacade.getInstance(project).findPackage("");
  final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(project);
  final JavaCodeFragment fragment = factory.createTypeCodeFragment(text, defaultPackage, true);
  fragment.setVisibilityChecker(JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE);
  return PsiDocumentManager.getInstance(project).getDocument(fragment);
}
项目:consulo-java    文件:EditorTextFieldWithBrowseButton.java   
private static EditorTextField createEditorTextField(Project project,
                                                     boolean isClassAccepted,
                                                     JavaCodeFragment.VisibilityChecker visibilityChecker,
                                                     final FileType fileType) {
  if (project.isDefault()) return new EditorTextField();
  return new EditorTextField(createDocument("", project, isClassAccepted,
                                           visibilityChecker), project, fileType);
}
项目:consulo-java    文件:EditorTextFieldWithBrowseButton.java   
private static Document createDocument(final String text,
                                       Project project,
                                       boolean isClassesAccepted,
                                       JavaCodeFragment.VisibilityChecker visibilityChecker) {
  PsiElement defaultPackage = JavaPsiFacade.getInstance(project).findPackage("");
  final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(project);
  final JavaCodeFragment fragment = factory.createReferenceCodeFragment(text, defaultPackage, true, isClassesAccepted);
  fragment.setVisibilityChecker(visibilityChecker);
  return PsiDocumentManager.getInstance(project).getDocument(fragment);
}
项目:consulo-java    文件:ReferenceEditorComboWithBrowseButton.java   
public ReferenceEditorComboWithBrowseButton(final ActionListener browseActionListener,
                                            final String text,
                                            @NotNull final Project project,
                                            boolean toAcceptClasses,
                                            final JavaCodeFragment.VisibilityChecker visibilityChecker, final String recentsKey) {
  super(new EditorComboBox(createDocument(StringUtil.isEmpty(text) ? "" : text, project, toAcceptClasses, visibilityChecker), project, JavaFileType.INSTANCE),
        browseActionListener);
  final List<String> recentEntries = RecentsManager.getInstance(project).getRecentEntries(recentsKey);
  if (recentEntries != null) {
    setHistory(ArrayUtil.toStringArray(recentEntries));
  }
  if (text != null && text.length() > 0) {
    prependItem(text);
  }
}
项目:consulo-java    文件:ReferenceEditorComboWithBrowseButton.java   
private static Document createDocument(final String text,
                                       Project project,
                                       boolean isClassesAccepted, 
                                       final JavaCodeFragment.VisibilityChecker visibilityChecker) {
  PsiJavaPackage defaultPackage = JavaPsiFacade.getInstance(project).findPackage("");
  final JavaCodeFragment fragment = JavaCodeFragmentFactory.getInstance(project).createReferenceCodeFragment(text, defaultPackage, true, isClassesAccepted);
  fragment.setVisibilityChecker(visibilityChecker);
  return PsiDocumentManager.getInstance(project).getDocument(fragment);
}
项目:consulo-java    文件:JavaDebuggerEditorsProvider.java   
@NotNull
@Override
public XExpression createExpression(@NotNull Project project, @NotNull Document document, @Nullable Language language, @NotNull EvaluationMode mode)
{
    PsiDocumentManager.getInstance(project).commitDocument(document);
    PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
    if(psiFile != null)
    {
        return new XExpressionImpl(psiFile.getText(), language, ((JavaCodeFragment) psiFile).importsToString(), mode);
    }
    return super.createExpression(project, document, language, mode);
}
项目:consulo-java    文件:CodeFragmentFactoryContextWrapper.java   
private PsiElement wrapContext(Project project, final PsiElement originalContext)
{
    if(project.isDefault())
    {
        return originalContext;
    }
    PsiElement context = originalContext;
    final DebugProcessImpl process = DebuggerManagerEx.getInstanceEx(project).getContext().getDebugProcess();
    if(process != null)
    {
        final Map<ObjectReference, ValueMarkup> markupMap = ValueDescriptorImpl.getMarkupMap(process);
        if(markupMap != null && markupMap.size() > 0)
        {
            final Pair<String, Map<String, ObjectReference>> markupVariables = createMarkupVariablesText(markupMap);
            int offset = markupVariables.getFirst().length() - 1;
            final TextWithImportsImpl textWithImports = new TextWithImportsImpl(CodeFragmentKind.CODE_BLOCK, markupVariables.getFirst(), "", myDelegate.getFileType());
            final JavaCodeFragment codeFragment = myDelegate.createCodeFragment(textWithImports, context, project);
            codeFragment.accept(new JavaRecursiveElementVisitor()
            {
                @Override
                public void visitLocalVariable(PsiLocalVariable variable)
                {
                    final String name = variable.getName();
                    variable.putUserData(LABEL_VARIABLE_VALUE_KEY, markupVariables.getSecond().get(name));
                }
            });
            final PsiElement newContext = codeFragment.findElementAt(offset);
            if(newContext != null)
            {
                context = newContext;
            }
        }
    }
    return context;
}
项目:consulo-java    文件:CachedEvaluator.java   
protected Cache initEvaluatorAndChildrenExpression(final Project project)
{
    final Cache cache = new Cache();
    try
    {
        Pair<PsiElement, PsiType> psiClassAndType = DebuggerUtilsImpl.getPsiClassAndType(getClassName(), project);
        PsiElement context = psiClassAndType.first;
        if(context == null)
        {
            throw EvaluateExceptionUtil.CANNOT_FIND_SOURCE_CLASS;
        }
        CodeFragmentFactory factory = DebuggerUtilsEx.findAppropriateCodeFragmentFactory(myReferenceExpression, context);
        JavaCodeFragment codeFragment = factory.createCodeFragment(myReferenceExpression, overrideContext(context), project);
        codeFragment.setThisType(psiClassAndType.second);
        DebuggerUtils.checkSyntax(codeFragment);
        cache.myPsiChildrenExpression = codeFragment instanceof PsiExpressionCodeFragment ? ((PsiExpressionCodeFragment) codeFragment).getExpression() : null;

        try
        {
            cache.myEvaluator = factory.getEvaluatorBuilder().build(codeFragment, null);
        }
        catch(UnsupportedExpressionException ex)
        {
            ExpressionEvaluator eval = CompilingEvaluatorImpl.create(project, context, element -> codeFragment);
            if(eval != null)
            {
                cache.myEvaluator = eval;
            }
            throw ex;
        }
    }
    catch(EvaluateException e)
    {
        cache.myException = e;
    }

    myCache = new SoftReference<>(cache);
    return cache;
}
项目:consulo-java    文件:UserExpressionDescriptorImpl.java   
protected PsiCodeFragment getEvaluationCode(final StackFrameContext context) throws EvaluateException
{
    Pair<PsiElement, PsiType> psiClassAndType = DebuggerUtilsImpl.getPsiClassAndType(myTypeName, myProject);
    if(psiClassAndType.first == null)
    {
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.invalid.type.name", myTypeName));
    }
    PsiCodeFragment fragment = createCodeFragment(psiClassAndType.first);
    if(fragment instanceof JavaCodeFragment)
    {
        ((JavaCodeFragment) fragment).setThisType(psiClassAndType.second);
    }
    return fragment;
}
项目:intellij-ce-playground    文件:CodeFragmentFactoryContextWrapper.java   
public JavaCodeFragment createCodeFragment(TextWithImports item, PsiElement context, Project project) {
  return myDelegate.createCodeFragment(item, wrapContext(project, context), project);
}
项目:intellij-ce-playground    文件:CodeFragmentFactoryContextWrapper.java   
public JavaCodeFragment createPresentationCodeFragment(TextWithImports item, PsiElement context, Project project) {
  return myDelegate.createPresentationCodeFragment(item, wrapContext(project, context), project);
}
项目:PageObjectEvaluator    文件:PageObjectConfigurable.java   
private void createClassTextField() {
    myClass = new LabeledComponent<EditorTextFieldWithBrowseButton>();
    EditorTextFieldWithBrowseButton myClassBrowseTextField = new EditorTextFieldWithBrowseButton(project, true, JavaCodeFragment.VisibilityChecker.PROJECT_SCOPE_VISIBLE);
    myClass.setComponent(myClassBrowseTextField);
}
项目:tools-idea    文件:CodeFragmentFactoryContextWrapper.java   
public JavaCodeFragment createCodeFragment(TextWithImports item, PsiElement context, Project project) {
  return myDelegate.createCodeFragment(item, wrapContext(project, context), project);
}
项目:tools-idea    文件:CodeFragmentFactoryContextWrapper.java   
public JavaCodeFragment createPresentationCodeFragment(TextWithImports item, PsiElement context, Project project) {
  return myDelegate.createPresentationCodeFragment(item, wrapContext(project, context), project);
}
项目:consulo-java    文件:EditorTextFieldWithBrowseButton.java   
public EditorTextFieldWithBrowseButton(Project project, boolean isClassAccepted) {
  this(project, isClassAccepted, JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE);
}
项目:consulo-java    文件:EditorTextFieldWithBrowseButton.java   
public EditorTextFieldWithBrowseButton(Project project,
                                       boolean isClassAccepted,
                                       final JavaCodeFragment.VisibilityChecker visibilityChecker) {
  super(createEditorTextField(project, isClassAccepted, visibilityChecker), null);
}
项目:consulo-java    文件:EditorTextFieldWithBrowseButton.java   
public EditorTextFieldWithBrowseButton(Project project,
                                       boolean isClassAccepted,
                                       final JavaCodeFragment.VisibilityChecker visibilityChecker,
                                       FileType fileType) {
  super(createEditorTextField(project, isClassAccepted, visibilityChecker, fileType), null);
}
项目:consulo-java    文件:EditorTextFieldWithBrowseButton.java   
private static EditorTextField createEditorTextField(Project project,
                                                     boolean isClassAccepted,
                                                     JavaCodeFragment.VisibilityChecker visibilityChecker) {
  return createEditorTextField(project, isClassAccepted, visibilityChecker, JavaFileType.INSTANCE);
}
项目:consulo-java    文件:ReferenceEditorComboWithBrowseButton.java   
public ReferenceEditorComboWithBrowseButton(final ActionListener browseActionListener,
                                            final String text,
                                            @NotNull final Project project,
                                            boolean toAcceptClasses, final String recentsKey) {
  this(browseActionListener, text, project, toAcceptClasses, JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE, recentsKey);
}
项目:consulo-java    文件:JavaCodeFragmentFactoryImpl.java   
@NotNull
@Override
public JavaCodeFragment createCodeBlockCodeFragment(@NotNull final String text, @Nullable final PsiElement context, final boolean isPhysical)
{
    return new PsiCodeFragmentImpl(myProject, JavaElementType.STATEMENTS, isPhysical, "fragment.java", text, context);
}
项目:consulo-java    文件:EditMigrationEntryDialog.java   
@Override
protected JComponent createNorthPanel()
{
    JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints gbConstraints = new GridBagConstraints();
    gbConstraints.insets = JBUI.insets(4);
    gbConstraints.weighty = 0;

    gbConstraints.gridwidth = GridBagConstraints.RELATIVE;
    gbConstraints.fill = GridBagConstraints.BOTH;
    gbConstraints.weightx = 0;
    myRbPackage = new JRadioButton(RefactoringBundle.message("migration.entry.package"));
    panel.add(myRbPackage, gbConstraints);

    gbConstraints.gridwidth = GridBagConstraints.RELATIVE;
    gbConstraints.fill = GridBagConstraints.BOTH;
    gbConstraints.weightx = 0;
    myRbClass = new JRadioButton(RefactoringBundle.message("migration.entry.class"));
    panel.add(myRbClass, gbConstraints);

    gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gbConstraints.fill = GridBagConstraints.BOTH;
    gbConstraints.weightx = 1;
    panel.add(new JPanel(), gbConstraints);

    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(myRbPackage);
    buttonGroup.add(myRbClass);

    gbConstraints.weightx = 0;
    gbConstraints.gridwidth = GridBagConstraints.RELATIVE;
    gbConstraints.fill = GridBagConstraints.NONE;
    JLabel oldNamePrompt = new JLabel(RefactoringBundle.message("migration.entry.old.name"));
    panel.add(oldNamePrompt, gbConstraints);

    gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gbConstraints.fill = GridBagConstraints.HORIZONTAL;
    gbConstraints.weightx = 1;
    final LanguageTextField.DocumentCreator documentCreator = new LanguageTextField.DocumentCreator()
    {
        @Override
        public Document createDocument(String value, @Nullable Language language, Project project)
        {
            PsiPackage defaultPackage = JavaPsiFacade.getInstance(project).findPackage("");
            final JavaCodeFragment fragment = JavaCodeFragmentFactory.getInstance(project).createReferenceCodeFragment("", defaultPackage, true, true);
            return PsiDocumentManager.getInstance(project).getDocument(fragment);
        }
    };
    myOldNameField = new LanguageTextField(JavaLanguage.INSTANCE, myProject, "", documentCreator);
    panel.add(myOldNameField, gbConstraints);

    gbConstraints.weightx = 0;
    gbConstraints.gridwidth = GridBagConstraints.RELATIVE;
    gbConstraints.fill = GridBagConstraints.NONE;
    JLabel newNamePrompt = new JLabel(RefactoringBundle.message("migration.entry.new.name"));
    panel.add(newNamePrompt, gbConstraints);

    gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gbConstraints.fill = GridBagConstraints.HORIZONTAL;
    gbConstraints.weightx = 1;
    myNewNameField = new LanguageTextField(JavaLanguage.INSTANCE, myProject, "", documentCreator);
    panel.setPreferredSize(new Dimension(300, panel.getPreferredSize().height));
    panel.add(myNewNameField, gbConstraints);

    final DocumentListener documentAdapter = new DocumentListener()
    {
        @Override
        public void documentChanged(DocumentEvent e)
        {
            validateOKButton();
        }
    };
    myOldNameField.getDocument().addDocumentListener(documentAdapter);
    myNewNameField.getDocument().addDocumentListener(documentAdapter);
    return panel;
}
项目:consulo-java    文件:CodeFragmentFactoryContextWrapper.java   
public JavaCodeFragment createCodeFragment(TextWithImports item, PsiElement context, Project project)
{
    return myDelegate.createCodeFragment(item, wrapContext(project, context), project);
}
项目:consulo-java    文件:CodeFragmentFactoryContextWrapper.java   
public JavaCodeFragment createPresentationCodeFragment(TextWithImports item, PsiElement context, Project project)
{
    return myDelegate.createPresentationCodeFragment(item, wrapContext(project, context), project);
}
项目:consulo-java    文件:DefaultCodeFragmentFactory.java   
@Override
public JavaCodeFragment createPresentationCodeFragment(final TextWithImports item, final PsiElement context, final Project project)
{
    return createCodeFragment(item, context, project);
}
项目:consulo-java    文件:DefaultCodeFragmentFactory.java   
@Override
public JavaCodeFragment createCodeFragment(TextWithImports item, PsiElement context, final Project project)
{
    final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(project);
    final String text = item.getText();

    final JavaCodeFragment fragment;
    if(CodeFragmentKind.EXPRESSION == item.getKind())
    {
        final String expressionText = StringUtil.endsWithChar(text, ';') ? text.substring(0, text.length() - 1) : text;
        fragment = factory.createExpressionCodeFragment(expressionText, context, null, true);
    }
    else /*if (CodeFragmentKind.CODE_BLOCK == item.getKind())*/
    {
        fragment = factory.createCodeBlockCodeFragment(text, context, true);
    }

    if(item.getImports().length() > 0)
    {
        fragment.addImportsFromString(item.getImports());
    }
    fragment.setVisibilityChecker(JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE);
    //noinspection HardCodedStringLiteral
    fragment.putUserData(KEY, "DebuggerComboBoxEditor.IS_DEBUGGER_EDITOR");
    fragment.putCopyableUserData(JavaCompletionUtilCore.DYNAMIC_TYPE_EVALUATOR, new PairFunction<PsiExpression, CompletionParameters, PsiType>()
    {
        @Override
        public PsiType fun(PsiExpression expression, CompletionParameters parameters)
        {
            if(!RuntimeTypeEvaluator.isSubtypeable(expression))
            {
                return null;
            }

            if(parameters.getInvocationCount() <= 1 && JavaCompletionUtilCore.mayHaveSideEffects(expression))
            {
                final CompletionService service = CompletionService.getCompletionService();
                if(parameters.getInvocationCount() < 2)
                {
                    service.setAdvertisementText("Invoke completion once more to see runtime type variants");
                }
                return null;
            }

            final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(project).getContext();
            DebuggerSession debuggerSession = debuggerContext.getDebuggerSession();
            if(debuggerSession != null && debuggerContext.getSuspendContext() != null)
            {
                final Semaphore semaphore = new Semaphore();
                semaphore.down();
                final AtomicReference<PsiType> nameRef = new AtomicReference<PsiType>();
                final RuntimeTypeEvaluator worker = new RuntimeTypeEvaluator(null, expression, debuggerContext, ProgressManager.getInstance().getProgressIndicator())
                {
                    @Override
                    protected void typeCalculationFinished(@Nullable PsiType type)
                    {
                        nameRef.set(type);
                        semaphore.up();
                    }
                };
                debuggerSession.getProcess().getManagerThread().invoke(worker);
                for(int i = 0; i < 50; i++)
                {
                    ProgressManager.checkCanceled();
                    if(semaphore.waitFor(20))
                    {
                        break;
                    }
                }
                return nameRef.get();
            }
            return null;
        }
    });

    return fragment;
}
项目:intellij-ce-playground    文件:CodeFragmentFactory.java   
public abstract JavaCodeFragment createCodeFragment(TextWithImports item, PsiElement context, Project project);
项目:intellij-ce-playground    文件:CodeFragmentFactory.java   
public abstract JavaCodeFragment createPresentationCodeFragment(TextWithImports item, PsiElement context, Project project);