Java 类com.intellij.psi.impl.source.DummyHolderFactory 实例源码

项目:intellij-ce-playground    文件:PsiJavaParserFacadeImpl.java   
@NotNull
@Override
public PsiComment createCommentFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
  final PsiJavaFile aFile = createDummyJavaFile(text);
  for (PsiElement aChildren : aFile.getChildren()) {
    if (aChildren instanceof PsiComment) {
      if (!aChildren.getText().equals(text)) {
        break;
      }
      final PsiComment comment = (PsiComment)aChildren;
      DummyHolderFactory.createHolder(myManager, (TreeElement)SourceTreeToPsiMap.psiElementToTree(comment), context);
      return comment;
    }
  }

  throw new IncorrectOperationException("Incorrect comment '" + text + "'");
}
项目:intellij-ce-playground    文件:PsiFileFactoryImpl.java   
@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();
}
项目:tools-idea    文件:PsiJavaParserFacadeImpl.java   
@NotNull
@Override
public PsiComment createCommentFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
  final PsiJavaFile aFile = createDummyJavaFile(text);
  for (PsiElement aChildren : aFile.getChildren()) {
    if (aChildren instanceof PsiComment) {
      if (!aChildren.getText().equals(text)) {
        break;
      }
      final PsiComment comment = (PsiComment)aChildren;
      DummyHolderFactory.createHolder(myManager, (TreeElement)SourceTreeToPsiMap.psiElementToTree(comment), context);
      return comment;
    }
  }

  throw new IncorrectOperationException("Incorrect comment \"" + text + "\".");
}
项目:tools-idea    文件:PsiFileFactoryImpl.java   
@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();
}
项目:consulo    文件:PsiFileFactoryImpl.java   
@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();
}
项目:consulo-java    文件:PsiElementFactoryImpl.java   
@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;
}
项目:consulo-java    文件:PsiJavaParserFacadeImpl.java   
@NotNull
@Override
public PsiComment createCommentFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException
{
    final PsiJavaFile aFile = createDummyJavaFile(text);
    for(PsiElement aChildren : aFile.getChildren())
    {
        if(aChildren instanceof PsiComment)
        {
            if(!aChildren.getText().equals(text))
            {
                break;
            }
            final PsiComment comment = (PsiComment) aChildren;
            DummyHolderFactory.createHolder(myManager, (TreeElement) SourceTreeToPsiMap.psiElementToTree(comment), context);
            return comment;
        }
    }

    throw new IncorrectOperationException("Incorrect comment '" + text + "'");
}
项目:intellij-csv-validator    文件:CsvStructureViewElement.java   
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();
}
项目:intellij-ce-playground    文件:JavaPsiFacadeImpl.java   
public JavaPsiFacadeImpl(Project project,
                         PsiManager psiManager,
                         JavaFileManager javaFileManager,
                         MessageBus bus) {
  myProject = project;
  myFileManager = javaFileManager;
  myConstantEvaluationHelper = new PsiConstantEvaluationHelperImpl();

  final PsiModificationTracker modificationTracker = psiManager.getModificationTracker();

  if (bus != null) {
    bus.connect().subscribe(PsiModificationTracker.TOPIC, new PsiModificationTracker.Listener() {
      private long lastTimeSeen = -1L;

      @Override
      public void modificationCountChanged() {
        myClassCache.clear();
        final long now = modificationTracker.getJavaStructureModificationCount();
        if (lastTimeSeen != now) {
          lastTimeSeen = now;
          myPackageCache.clear();
        }
      }
    });
  }

  DummyHolderFactory.setFactory(new JavaDummyHolderFactory());
}
项目:intellij-ce-playground    文件:PsiJavaParserFacadeImpl.java   
@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;
}
项目:intellij-ce-playground    文件:PsiJavaParserFacadeImpl.java   
@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;
}
项目:intellij-ce-playground    文件:PsiJavaParserFacadeImpl.java   
@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;
}
项目:intellij-ce-playground    文件:PsiJavaParserFacadeImpl.java   
@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;
}
项目:intellij-ce-playground    文件:PsiJavaParserFacadeImpl.java   
@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;
}
项目:intellij-ce-playground    文件:PsiJavaParserFacadeImpl.java   
@NotNull
@Override
public PsiTypeElement createTypeElementFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
  final LanguageLevel level = level(context);
  final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, TYPE, level), context);
  final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
  if (!(element instanceof PsiTypeElement)) {
    throw new IncorrectOperationException("Incorrect type '" + text + "' (" + level + ")");
  }
  return (PsiTypeElement)element;
}
项目:intellij-ce-playground    文件:PsiJavaParserFacadeImpl.java   
@NotNull
@Override
public PsiJavaCodeReferenceElement createReferenceFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
  final boolean isStaticImport = context instanceof PsiImportStaticStatement &&
                                 !((PsiImportStaticStatement)context).isOnDemand();
  final boolean mayHaveDiamonds = context instanceof PsiNewExpression &&
                                  PsiUtil.getLanguageLevel(context).isAtLeast(LanguageLevel.JDK_1_7);
  final JavaParserUtil.ParserWrapper wrapper = isStaticImport ? STATIC_IMPORT_REF : mayHaveDiamonds ? DIAMOND_REF : REFERENCE;
  final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, wrapper, level(context)), context);
  final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
  if (!(element instanceof PsiJavaCodeReferenceElement)) {
    throw new IncorrectOperationException("Incorrect reference '" + text + "'");
  }
  return (PsiJavaCodeReferenceElement)element;
}
项目:intellij-ce-playground    文件:PsiJavaParserFacadeImpl.java   
@NotNull
@Override
public PsiCodeBlock createCodeBlockFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
  final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, CODE_BLOCK, level(context), true), context);
  final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
  if (!(element instanceof PsiCodeBlock)) {
    throw new IncorrectOperationException("Incorrect code block '" + text + "'");
  }
  return (PsiCodeBlock)element;
}
项目:intellij-ce-playground    文件:PsiJavaParserFacadeImpl.java   
@NotNull
@Override
public PsiStatement createStatementFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
  final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, STATEMENT, level(context)), context);
  final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
  if (!(element instanceof PsiStatement)) {
    throw new IncorrectOperationException("Incorrect statement '" + text + "'");
  }
  return (PsiStatement)element;
}
项目:intellij-ce-playground    文件:PsiJavaParserFacadeImpl.java   
@NotNull
@Override
public PsiExpression createExpressionFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
  final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, EXPRESSION, level(context)), context);
  final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
  if (!(element instanceof PsiExpression)) {
    throw new IncorrectOperationException("Incorrect expression '" + text + "'");
  }
  return (PsiExpression)element;
}
项目:intellij-ce-playground    文件:PsiJavaParserFacadeImpl.java   
@NotNull
@Override
public PsiTypeParameter createTypeParameterFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
  final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, TYPE_PARAMETER, level(context)),
                                                             context);
  final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
  if (!(element instanceof PsiTypeParameter)) {
    throw new IncorrectOperationException("Incorrect type parameter '" + text + "'");
  }
  return (PsiTypeParameter)element;
}
项目:intellij-ce-playground    文件:PsiJavaParserFacadeImpl.java   
@NotNull
@Override
public PsiEnumConstant createEnumConstantFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
  final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, ENUM_CONSTANT, level(context)), context);
  final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
  if (!(element instanceof PsiEnumConstant)) {
    throw new IncorrectOperationException("Incorrect enum constant '" + text + "'");
  }
  return (PsiEnumConstant)element;
}
项目:intellij-ce-playground    文件:ClsParsingUtil.java   
public static PsiAnnotationMemberValue createMemberValueFromText(@NotNull String text,
                                                                 @NotNull PsiManager manager,
                                                                 @NotNull ClsElementImpl parent) {
  LanguageLevel level = PsiUtil.getLanguageLevel(parent);
  DummyHolder holder = DummyHolderFactory.createHolder(manager, new JavaDummyElement(text, ANNOTATION_VALUE, level), null);
  PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
  if (!(element instanceof PsiAnnotationMemberValue)) {
    LOG.error("Could not parse initializer:'" + text + "'");
    return null;
  }
  return getMemberValue(element, parent);
}
项目:intellij-ce-playground    文件:PsiParserFacadeImpl.java   
@Override
@NotNull
public PsiElement createWhiteSpaceFromText(@NotNull @NonNls String text) throws IncorrectOperationException {
  final FileElement holderElement = DummyHolderFactory.createHolder(myManager, null).getTreeElement();
  final LeafElement newElement = ASTFactory.leaf(TokenType.WHITE_SPACE, holderElement.getCharTable().intern(text));
  holderElement.rawAddChildren(newElement);
  GeneratedMarkerVisitor.markGenerated(newElement.getPsi());
  return newElement.getPsi();
}
项目:intellij-ce-playground    文件:PsiParserFacadeImpl.java   
private PsiComment findPsiCommentChild(PsiFile aFile) {
  PsiElement[] children = aFile.getChildren();
  for (PsiElement aChildren : children) {
    if (aChildren instanceof PsiComment) {
      PsiComment comment = (PsiComment)aChildren;
      DummyHolderFactory.createHolder(myManager, (TreeElement)SourceTreeToPsiMap.psiElementToTree(comment), null);
      return comment;
    }
  }
  throw new IncorrectOperationException("Incorrect comment \"" + aFile.getText() + "\".");
}
项目:intellij-ce-playground    文件:Factory.java   
@NotNull
public static LeafElement createSingleLeafElement(@NotNull IElementType type, CharSequence buffer, int startOffset, int endOffset, CharTable table, PsiManager manager, PsiFile originalFile) {
  DummyHolder dummyHolder = DummyHolderFactory.createHolder(manager, table, type.getLanguage());
  dummyHolder.setOriginalFile(originalFile);

  FileElement holderElement = dummyHolder.getTreeElement();

  LeafElement newElement = ASTFactory.leaf(type, holderElement.getCharTable().intern(
    buffer, startOffset, endOffset));
  holderElement.rawAddChildren(newElement);
  CodeEditUtil.setNodeGenerated(newElement, true);
  return newElement;
}
项目:intellij-ce-playground    文件:Factory.java   
@NotNull
public static LeafElement createSingleLeafElement(@NotNull IElementType type, CharSequence buffer, int startOffset, int endOffset, CharTable table, PsiManager manager, boolean generatedFlag) {
  final FileElement holderElement = DummyHolderFactory.createHolder(manager, table, type.getLanguage()).getTreeElement();
  final LeafElement newElement = ASTFactory.leaf(type, holderElement.getCharTable().intern(
    buffer, startOffset, endOffset));
  holderElement.rawAddChildren(newElement);
  if(generatedFlag) CodeEditUtil.setNodeGenerated(newElement, true);
  return newElement;
}
项目:intellij-ce-playground    文件:Factory.java   
@NotNull
public static CompositeElement createCompositeElement(@NotNull IElementType type,
                                                      final CharTable charTableByTree,
                                                      final PsiManager manager) {
  final FileElement treeElement = DummyHolderFactory.createHolder(manager, null, charTableByTree).getTreeElement();
  final CompositeElement composite = ASTFactory.composite(type);
  treeElement.rawAddChildren(composite);
  return composite;
}
项目:intellij-ce-playground    文件:ChangeUtil.java   
public static TreeElement copyElement(TreeElement original, final PsiElement context, CharTable table) {
  final TreeElement element = (TreeElement)original.clone();
  final PsiManager manager = original.getManager();
  DummyHolderFactory.createHolder(manager, element, context, table).getTreeElement();
  encodeInformation(element, original);
  TreeUtil.clearCaches(element);
  saveIndentationToCopy(original, element);
  return element;
}
项目:intellij-ce-playground    文件:ChangeUtil.java   
public static TreeElement copyToElement(PsiElement original) {
  final DummyHolder holder = DummyHolderFactory.createHolder(original.getManager(), null, original.getLanguage());
  final FileElement holderElement = holder.getTreeElement();
  final TreeElement treeElement = generateTreeElement(original, holderElement.getCharTable(), original.getManager());
  //  TreeElement treePrev = treeElement.getTreePrev(); // This is hack to support bug used in formater
  holderElement.rawAddChildren(treeElement);
  TreeUtil.clearCaches(holderElement);
  //  treeElement.setTreePrev(treePrev);
  saveIndentationToCopy((TreeElement)original.getNode(), treeElement);
  return treeElement;
}
项目:intellij-ce-playground    文件:XmlTokenManipulator.java   
@Override
public XmlToken handleContentChange(@NotNull XmlToken xmlToken, @NotNull TextRange range, String newContent) throws IncorrectOperationException {
  String oldText = xmlToken.getText();
  String newText = oldText.substring(0, range.getStartOffset()) + newContent + oldText.substring(range.getEndOffset());
  IElementType tokenType = xmlToken.getTokenType();

  FileElement holder = DummyHolderFactory.createHolder(xmlToken.getManager(), null).getTreeElement();
  LeafElement leaf = ASTFactory.leaf(tokenType, holder.getCharTable().intern(newText));
  holder.rawAddChildren(leaf);
  return (XmlToken)xmlToken.replace(leaf.getPsi());
}
项目:intellij-ce-playground    文件:CDATAOnAnyEncodedPolicy.java   
@SuppressWarnings({"HardCodedStringLiteral"})
public static FileElement createCDATAElement(final PsiManager manager, final CharTable charTableByTree, final String displayText) {
  final FileElement dummyParent = DummyHolderFactory.createHolder(manager, null, charTableByTree).getTreeElement();
  final CompositeElement cdata = ASTFactory.composite(XmlElementType.XML_CDATA);
  dummyParent.rawAddChildren(cdata);
  cdata.rawAddChildren(ASTFactory.leaf(XmlTokenType.XML_CDATA_START, "<![CDATA["));
  cdata.rawAddChildren(ASTFactory.leaf(XmlTokenType.XML_DATA_CHARACTERS, dummyParent.getCharTable().intern(displayText)));
  cdata.rawAddChildren(ASTFactory.leaf(XmlTokenType.XML_CDATA_END, "]]>"));
  dummyParent.acceptTree(new GeneratedMarkerVisitor());
  return dummyParent;
}
项目:tools-idea    文件:JavaPsiFacadeImpl.java   
public JavaPsiFacadeImpl(Project project,
                         PsiManagerImpl psiManager,
                         JavaFileManager javaFileManager,
                         MessageBus bus) {
  myProject = project;
  myFileManager = javaFileManager;
  myNameHelper = new PsiNameHelperImpl(this);
  myConstantEvaluationHelper = new PsiConstantEvaluationHelperImpl();

  final PsiModificationTracker modificationTracker = psiManager.getModificationTracker();

  if (bus != null) {
    bus.connect().subscribe(PsiModificationTracker.TOPIC, new PsiModificationTracker.Listener() {
      private long lastTimeSeen = -1L;

      @Override
      public void modificationCountChanged() {
        final long now = modificationTracker.getJavaStructureModificationCount();
        if (lastTimeSeen != now) {
          lastTimeSeen = now;
          myPackageCache = null;
        }
      }
    });
  }

  DummyHolderFactory.setFactory(new JavaDummyHolderFactory());
  JavaElementType.ANNOTATION.getIndex(); // Initialize stubs.
}
项目:tools-idea    文件:PsiJavaParserFacadeImpl.java   
@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;
}
项目:tools-idea    文件:PsiJavaParserFacadeImpl.java   
@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;
}
项目:tools-idea    文件:PsiJavaParserFacadeImpl.java   
@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;
}
项目:tools-idea    文件:PsiJavaParserFacadeImpl.java   
@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;
}
项目:tools-idea    文件:PsiJavaParserFacadeImpl.java   
@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;
}
项目:tools-idea    文件:PsiJavaParserFacadeImpl.java   
@NotNull
@Override
public PsiTypeElement createTypeElementFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
  final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, TYPE, level(context)), context);
  final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
  if (!(element instanceof PsiTypeElement)) {
    throw new IncorrectOperationException("Incorrect type \"" + text + "\".");
  }
  return (PsiTypeElement)element;
}
项目:tools-idea    文件:PsiJavaParserFacadeImpl.java   
@NotNull
@Override
public PsiJavaCodeReferenceElement createReferenceFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
  final boolean isStaticImport = context instanceof PsiImportStaticStatement &&
                                 !((PsiImportStaticStatement)context).isOnDemand();
  final boolean mayHaveDiamonds = context instanceof PsiNewExpression &&
                                  PsiUtil.getLanguageLevel(context).isAtLeast(LanguageLevel.JDK_1_7);
  final JavaParserUtil.ParserWrapper wrapper = isStaticImport ? STATIC_IMPORT_REF : mayHaveDiamonds ? DIAMOND_REF : REFERENCE;
  final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, wrapper, level(context)), context);
  final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
  if (!(element instanceof PsiJavaCodeReferenceElement)) {
    throw new IncorrectOperationException("Incorrect reference \"" + text + "\".");
  }
  return (PsiJavaCodeReferenceElement)element;
}
项目:tools-idea    文件:PsiJavaParserFacadeImpl.java   
@NotNull
@Override
public PsiCodeBlock createCodeBlockFromText(@NotNull final String text, @Nullable final PsiElement context) throws IncorrectOperationException {
  final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, CODE_BLOCK, level(context), true), context);
  final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
  if (!(element instanceof PsiCodeBlock)) {
    throw new IncorrectOperationException("Incorrect code block \"" + text + "\".");
  }
  return (PsiCodeBlock)element;
}