Package com.intellij.psi

Examples of com.intellij.psi.PsiElementFactory


  @Nullable
  public static PsiTypeParameterList createTypeParameterList(@NotNull PsiTypeParameterList psiTypeParameterList) {
    PsiTypeParameter[] psiTypeParameters = psiTypeParameterList.getTypeParameters();
    if (psiTypeParameters.length > 0) {

      final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(psiTypeParameterList.getProject()).getElementFactory();

      final StringBuilder builder = new StringBuilder("public <");

      for (PsiTypeParameter psiTypeParameter : psiTypeParameters) {
        builder.append(psiTypeParameter.getName());

        PsiClassType[] superTypes = psiTypeParameter.getExtendsListTypes();
        if (superTypes.length > 1 || superTypes.length == 1 && !superTypes[0].equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) {
          builder.append(" extends ");
          for (PsiClassType type : superTypes) {
            if (type.equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) {
              continue;
            }
            builder.append(type.getCanonicalText()).append('&');
          }
          builder.deleteCharAt(builder.length() - 1);
        }
        builder.append(',');
      }
      builder.deleteCharAt(builder.length() - 1);

      builder.append("> void foo(){}");

      PsiMethod methodFromText = elementFactory.createMethodFromText(builder.toString(), null);
      return methodFromText.getTypeParameterList();
    }
    return null;
  }
View Full Code Here


        builder.deleteCharAt(builder.length() - 1);
      }
      builder.append(')');
      builder.append('{').append("  ").append('}');

      PsiElementFactory elementFactory = JavaPsiFacade.getInstance(getManager().getProject()).getElementFactory();
      return elementFactory.createMethodFromText(builder.toString(), getContainingClass());
    } finally {
      StringBuilderSpinAllocator.dispose(builder);
    }
  }
View Full Code Here

            String relativePathToContainingFile = FileUtil.getRelativePath(pathToContainingFile, newFilePath, File.separatorChar);
            if (null == relativePathToContainingFile) {
                return null;
            }

            PsiElementFactory factory = new PsiElementFactoryImpl(getManager());
            /*
            // The parser has a problem with parsing just simple string literals in that they don't fall into any of the
            // element patterns it expects.  With no context, the string literal falls through to an error handler and
            // gets marked with an error annotation.
            // To make a long story short, it's easier "for now" to construct a full import statement and replace the
            // import declaration element than to fix the parser.
            // - TC
            PsiElement newEl = factory.createDummyHolder(("\"" + relativePathToContainingFile + "\""), elementType, getContext());
            return this.replace(newEl);
            */

            PsiElement newEl = factory.createDummyHolder(("import \"" + relativePathToContainingFile + "\";"), PbElementTypes.IMPORT_DECL, getContext());
            newEl = newEl.getFirstChild(); // The first child of the dummy holder is the element we need.
            PsiElement newImportEl = this.getParent().replace(newEl);
            PsiElement newImportRefEl = newImportEl.getFirstChild();
            return newImportRefEl;
        }
View Full Code Here

    model.commit();
  }

  public static void checkFileStructure(PsiFile file) throws IncorrectOperationException {
    String originalTree = DebugUtil.psiTreeToString(file, false);
    PsiElementFactory factory = file.getManager().getElementFactory();
    PsiFile dummyFile = factory.createFileFromText(file.getName(), file.getText());
    String reparsedTree = DebugUtil.psiTreeToString(dummyFile, false);
    Assert.assertEquals(reparsedTree, originalTree);
  }
View Full Code Here

TOP

Related Classes of com.intellij.psi.PsiElementFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.