本文整理汇总了Java中com.intellij.psi.JavaCodeFragment类的典型用法代码示例。如果您正苦于以下问题:Java JavaCodeFragment类的具体用法?Java JavaCodeFragment怎么用?Java JavaCodeFragment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JavaCodeFragment类属于com.intellij.psi包,在下文中一共展示了JavaCodeFragment类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: doTest
import com.intellij.psi.JavaCodeFragment; //导入依赖的package包/类
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());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:ExtractMethodObject4DebuggerTest.java
示例2: DefracMainClassTextFieldWithBrowseButton
import com.intellij.psi.JavaCodeFragment; //导入依赖的package包/类
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);
}
});
}
开发者ID:defrac,项目名称:defrac-plugin-intellij,代码行数:21,代码来源:DefracMainClassTextFieldWithBrowseButton.java
示例3: TextWithImportsImpl
import com.intellij.psi.JavaCodeFragment; //导入依赖的package包/类
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;
}
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:17,代码来源:TextWithImportsImpl.java
示例4: wrapContext
import com.intellij.psi.JavaCodeFragment; //导入依赖的package包/类
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;
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:26,代码来源:CodeFragmentFactoryContextWrapper.java
示例5: createExpressionCodeFragment
import com.intellij.psi.JavaCodeFragment; //导入依赖的package包/类
@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);
}
}
开发者ID:consulo,项目名称:consulo-java,代码行数:24,代码来源:JavaDebuggerEditorsProvider.java
示例6: TextWithImportsImpl
import com.intellij.psi.JavaCodeFragment; //导入依赖的package包/类
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;
}
}
开发者ID:consulo,项目名称:consulo-java,代码行数:20,代码来源:TextWithImportsImpl.java
示例7: ClassNameEditorWithBrowseButton
import com.intellij.psi.JavaCodeFragment; //导入依赖的package包/类
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);
}, "");
}
开发者ID:consulo,项目名称:consulo-java,代码行数:17,代码来源:CompoundRendererConfigurable.java
示例8: createUIComponents
import com.intellij.psi.JavaCodeFragment; //导入依赖的package包/类
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;
}
));
}
开发者ID:testIT-LivingDoc,项目名称:livingdoc-intellij,代码行数:15,代码来源:RunConfigurationEditor.java
示例9: wrapContext
import com.intellij.psi.JavaCodeFragment; //导入依赖的package包/类
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;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:CodeFragmentFactoryContextWrapper.java
示例10: createUIComponents
import com.intellij.psi.JavaCodeFragment; //导入依赖的package包/类
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;
}
}));
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:ApplicationConfigurable.java
示例11: createUIComponents
import com.intellij.psi.JavaCodeFragment; //导入依赖的package包/类
/**
* 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;
}));
}
开发者ID:asebak,项目名称:embeddedlinux-jvmdebugger-intellij,代码行数:16,代码来源:RunConfigurationEditor.java
示例12: createUIComponents
import com.intellij.psi.JavaCodeFragment; //导入依赖的package包/类
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;
}
}));
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:16,代码来源:ApplicationConfigurable.java
示例13: createDocument
import com.intellij.psi.JavaCodeFragment; //导入依赖的package包/类
@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);
}
开发者ID:consulo,项目名称:consulo-java,代码行数:10,代码来源:JavaReferenceEditorUtil.java
示例14: createTypeDocument
import com.intellij.psi.JavaCodeFragment; //导入依赖的package包/类
@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);
}
开发者ID:consulo,项目名称:consulo-java,代码行数:10,代码来源:JavaReferenceEditorUtil.java
示例15: createEditorTextField
import com.intellij.psi.JavaCodeFragment; //导入依赖的package包/类
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);
}
开发者ID:consulo,项目名称:consulo-java,代码行数:9,代码来源:EditorTextFieldWithBrowseButton.java
示例16: createDocument
import com.intellij.psi.JavaCodeFragment; //导入依赖的package包/类
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);
}
开发者ID:consulo,项目名称:consulo-java,代码行数:11,代码来源:EditorTextFieldWithBrowseButton.java
示例17: ReferenceEditorComboWithBrowseButton
import com.intellij.psi.JavaCodeFragment; //导入依赖的package包/类
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);
}
}
开发者ID:consulo,项目名称:consulo-java,代码行数:16,代码来源:ReferenceEditorComboWithBrowseButton.java
示例18: createDocument
import com.intellij.psi.JavaCodeFragment; //导入依赖的package包/类
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);
}
开发者ID:consulo,项目名称:consulo-java,代码行数:10,代码来源:ReferenceEditorComboWithBrowseButton.java
示例19: createExpression
import com.intellij.psi.JavaCodeFragment; //导入依赖的package包/类
@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);
}
开发者ID:consulo,项目名称:consulo-java,代码行数:13,代码来源:JavaDebuggerEditorsProvider.java
示例20: wrapContext
import com.intellij.psi.JavaCodeFragment; //导入依赖的package包/类
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;
}
开发者ID:consulo,项目名称:consulo-java,代码行数:36,代码来源:CodeFragmentFactoryContextWrapper.java
注:本文中的com.intellij.psi.JavaCodeFragment类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论