本文整理汇总了Java中com.intellij.psi.impl.source.DummyHolder类的典型用法代码示例。如果您正苦于以下问题:Java DummyHolder类的具体用法?Java DummyHolder怎么用?Java DummyHolder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DummyHolder类属于com.intellij.psi.impl.source包,在下文中一共展示了DummyHolder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findCodeFragment
import com.intellij.psi.impl.source.DummyHolder; //导入依赖的package包/类
@NotNull
public static PsiElement findCodeFragment(@NotNull PsiElement element) {
PsiElement codeFragment = element;
PsiElement parent = codeFragment.getParent();
while (parent != null) {
if (parent instanceof PsiDirectory
|| parent instanceof PsiMethod
|| parent instanceof PsiField || parent instanceof PsiClassInitializer
|| parent instanceof DummyHolder
|| parent instanceof PsiLambdaExpression) {
break;
}
codeFragment = parent;
parent = parent.getParent();
}
return codeFragment;
}
示例2: testMergeWhenEmptyElementAfterWhitespaceIsLastChild
import com.intellij.psi.impl.source.DummyHolder; //导入依赖的package包/类
public void testMergeWhenEmptyElementAfterWhitespaceIsLastChild() throws Throwable {
myBuilder = createBuilder(" foo bar");
parseWhenEmptyElementAfterWhitespaceIsLastChild();
final ASTNode tree = myBuilder.getTreeBuilt();
new DummyHolder(getPsiManager(), (TreeElement)tree, null);
myBuilder = createBuilder(" bar", tree);
parseWhenEmptyElementAfterWhitespaceIsLastChild();
DebugUtil.startPsiModification(null);
try {
myBuilder.getTreeBuilt();
fail();
}
catch (BlockSupport.ReparsedSuccessfullyException e) {
e.getDiffLog().performActualPsiChange(tree.getPsi().getContainingFile());
}
finally {
DebugUtil.finishPsiModification();
}
assertEquals(" bar", tree.getText());
}
示例3: createElementFromText
import com.intellij.psi.impl.source.DummyHolder; //导入依赖的package包/类
@Nullable
public PsiElement createElementFromText(@Nullable final String text,
@NotNull final Language language,
@NotNull final IElementType type,
@Nullable final PsiElement context) {
if (text == null) return null;
final DummyHolder result = DummyHolderFactory.createHolder(myManager, language, context);
final FileElement holder = result.getTreeElement();
final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
if (parserDefinition == null) {
throw new AssertionError("No parser definition for " + language);
}
final Project project = myManager.getProject();
final Lexer lexer = parserDefinition.createLexer(project);
final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, holder, lexer, language, text);
final ASTNode node = parserDefinition.createParser(project).parse(type, builder);
holder.rawAddChildren((TreeElement)node);
markGenerated(result);
return node.getPsi();
}
示例4: loadTree
import com.intellij.psi.impl.source.DummyHolder; //导入依赖的package包/类
@NotNull
static PsiElement loadTree(@NotNull PsiElement host, @NotNull PsiFile containingFile) {
if (containingFile instanceof DummyHolder) {
PsiElement context = containingFile.getContext();
if (context != null) {
PsiFile topFile = context.getContainingFile();
topFile.getNode(); //load tree
TextRange textRange = host.getTextRange().shiftRight(context.getTextRange().getStartOffset());
PsiElement inLoadedTree =
PsiTreeUtil.findElementOfClassAtRange(topFile, textRange.getStartOffset(), textRange.getEndOffset(), host.getClass());
if (inLoadedTree != null) {
host = inLoadedTree;
}
}
}
return host;
}
示例5: findCodeFragment
import com.intellij.psi.impl.source.DummyHolder; //导入依赖的package包/类
public static PsiElement findCodeFragment(PsiElement element) {
PsiElement codeFragment = element;
PsiElement parent = codeFragment.getParent();
while (parent != null) {
if (parent instanceof PsiDirectory
|| parent instanceof PsiMethod
|| parent instanceof PsiField || parent instanceof PsiClassInitializer
|| parent instanceof DummyHolder
|| parent instanceof PsiLambdaExpression) {
break;
}
codeFragment = parent;
parent = parent.getParent();
}
return codeFragment;
}
示例6: testMergeWhenEmptyElementAfterWhitespaceIsLastChild
import com.intellij.psi.impl.source.DummyHolder; //导入依赖的package包/类
public void testMergeWhenEmptyElementAfterWhitespaceIsLastChild() throws Throwable {
myBuilder = createBuilder(" foo bar");
parseWhenEmptyElementAfterWhitespaceIsLastChild();
final ASTNode tree = myBuilder.getTreeBuilt();
new DummyHolder(getPsiManager(), (TreeElement)tree, null);
myBuilder = createBuilder(" bar", tree);
parseWhenEmptyElementAfterWhitespaceIsLastChild();
try {
myBuilder.getTreeBuilt();
fail();
}
catch (BlockSupport.ReparsedSuccessfullyException e) {
e.getDiffLog().performActualPsiChange(tree.getPsi().getContainingFile());
}
assertEquals(" bar", tree.getText());
}
示例7: createElementFromText
import com.intellij.psi.impl.source.DummyHolder; //导入依赖的package包/类
@Nullable
public PsiElement createElementFromText(@Nullable final String text,
@Nonnull final Language language,
@Nonnull final LanguageVersion languageVersion,
@Nonnull final IElementType type,
@Nullable final PsiElement context) {
if (text == null) return null;
final DummyHolder result = DummyHolderFactory.createHolder(myManager, language, context);
final FileElement holder = result.getTreeElement();
final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
if (parserDefinition == null) {
throw new AssertionError("No parser definition for " + language);
}
final Project project = myManager.getProject();
final Lexer lexer = parserDefinition.createLexer(languageVersion);
final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, holder, lexer, language, languageVersion, text);
final ASTNode node = parserDefinition.createParser(languageVersion).parse(type, builder, languageVersion);
holder.rawAddChildren((TreeElement)node);
markGenerated(result);
return node.getPsi();
}
示例8: loadTree
import com.intellij.psi.impl.source.DummyHolder; //导入依赖的package包/类
@Nonnull
static PsiElement loadTree(@Nonnull PsiElement host, @Nonnull PsiFile containingFile) {
if (containingFile instanceof DummyHolder) {
PsiElement context = containingFile.getContext();
if (context != null) {
PsiFile topFile = context.getContainingFile();
topFile.getNode(); //load tree
TextRange textRange = host.getTextRange().shiftRight(context.getTextRange().getStartOffset());
PsiElement inLoadedTree =
PsiTreeUtil.findElementOfClassAtRange(topFile, textRange.getStartOffset(), textRange.getEndOffset(), host.getClass());
if (inLoadedTree != null) {
host = inLoadedTree;
}
}
}
return host;
}
示例9: createCatchSection
import com.intellij.psi.impl.source.DummyHolder; //导入依赖的package包/类
@NotNull
@Override
public PsiCatchSection createCatchSection(@NotNull final PsiType exceptionType, @NotNull final String exceptionName, @Nullable final PsiElement context) throws IncorrectOperationException
{
if(!(exceptionType instanceof PsiClassType || exceptionType instanceof PsiDisjunctionType))
{
throw new IncorrectOperationException("Unexpected type:" + exceptionType);
}
@NonNls final String text = "catch (" + exceptionType.getCanonicalText(true) + " " + exceptionName + ") {}";
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, CATCH_SECTION, level(context)), context);
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
if(!(element instanceof PsiCatchSection))
{
throw new IncorrectOperationException("Incorrect catch section '" + text + "'. Parsed element: " + element);
}
final Project project = myManager.getProject();
final JavaPsiImplementationHelper helper = JavaPsiImplementationHelper.getInstance(project);
helper.setupCatchBlock(exceptionName, context, (PsiCatchSection) element);
final CodeStyleManager styleManager = CodeStyleManager.getInstance(project);
final PsiCatchSection catchSection = (PsiCatchSection) styleManager.reformat(element);
GeneratedMarkerVisitor.markGenerated(catchSection);
return catchSection;
}
示例10: createEmptyPsiField
import com.intellij.psi.impl.source.DummyHolder; //导入依赖的package包/类
protected PsiElement createEmptyPsiField() {
final String text = "<undefined>";
final IElementType type = CsvTypes.FIELD;
final Project project = this.element.getProject();
final PsiManager psiManager = PsiManager.getInstance(project);
final DummyHolder dummyHolder = DummyHolderFactory.createHolder(psiManager, null);
final FileElement fileElement = dummyHolder.getTreeElement();
final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(CsvLanguage.INSTANCE);
final Lexer lexer = parserDefinition.createLexer(project);
final PsiBuilder psiBuilder = PsiBuilderFactory.getInstance().createBuilder(project, fileElement, lexer, CsvLanguage.INSTANCE, text);
final ASTNode node = parserDefinition.createParser(project).parse(type, psiBuilder);
fileElement.rawAddChildren((com.intellij.psi.impl.source.tree.TreeElement)node);
return node.getPsi();
}
示例11: createAnnotationFromText
import com.intellij.psi.impl.source.DummyHolder; //导入依赖的package包/类
@NotNull
@Override
public PsiAnnotation createAnnotationFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, ANNOTATION, level(context)), context);
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
if (!(element instanceof PsiAnnotation)) {
throw new IncorrectOperationException("Incorrect annotation '" + text + "'");
}
return (PsiAnnotation)element;
}
示例12: createFieldFromText
import com.intellij.psi.impl.source.DummyHolder; //导入依赖的package包/类
@NotNull
@Override
public PsiField createFieldFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, DECLARATION, level(context)), context);
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
if (!(element instanceof PsiField)) {
throw new IncorrectOperationException("Incorrect field '" + text + "'");
}
return (PsiField)element;
}
示例13: createMethodFromText
import com.intellij.psi.impl.source.DummyHolder; //导入依赖的package包/类
@NotNull
@Override
public PsiMethod createMethodFromText(@NotNull final String text, @Nullable final PsiElement context, final LanguageLevel level) throws IncorrectOperationException {
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, DECLARATION, level), context);
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
if (!(element instanceof PsiMethod)) {
throw newException("Incorrect method '" + text + "'", holder);
}
return (PsiMethod)element;
}
示例14: createParameterFromText
import com.intellij.psi.impl.source.DummyHolder; //导入依赖的package包/类
@NotNull
@Override
public PsiParameter createParameterFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, PARAMETER, level(context)), context);
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
if (!(element instanceof PsiParameter)) {
throw new IncorrectOperationException("Incorrect parameter '" + text + "'");
}
return (PsiParameter)element;
}
示例15: createResourceFromText
import com.intellij.psi.impl.source.DummyHolder; //导入依赖的package包/类
@NotNull
@Override
public PsiResourceVariable createResourceFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, RESOURCE, level(context)), context);
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
if (!(element instanceof PsiResourceVariable)) {
throw new IncorrectOperationException("Incorrect resource '" + text + "'");
}
return (PsiResourceVariable)element;
}