Package org.eclipse.jdt.core.dom

Examples of org.eclipse.jdt.core.dom.PackageDeclaration


    * Package modifiers
    */
   @Override
   public String getPackage()
   {
      PackageDeclaration pkg = unit.getPackage();
      if (pkg != null)
      {
         return pkg.getName().getFullyQualifiedName();
      }
      else
      {
         return null;
      }
View Full Code Here


  @SuppressWarnings("unchecked")
  public void stackoverflow_answer() {
    AST ast = AST.newAST(AST.JLS8);
    CompilationUnit cu = ast.newCompilationUnit();

    PackageDeclaration p1 = ast.newPackageDeclaration();
    p1.setName(ast.newSimpleName("foo"));
    cu.setPackage(p1);

    ImportDeclaration id = ast.newImportDeclaration();
    id.setName(ast.newName(new String[] {
        "java", "util", "Set" }));
View Full Code Here

     * @return the package {@link Node node} or the passed in <code>outputNode</code> if a package is not found
     * @throws Exception if there is a problem
     */
    protected Node recordPackage( final CompilationUnit compilationUnit,
                                  final Node outputNode ) throws Exception {
        final PackageDeclaration pkg = compilationUnit.getPackage();

        if (pkg == null) {
            return outputNode;
        }

        Node pkgNode = outputNode;

        { // create node for each segment of the package name
            final String pkgName = pkg.getName().getFullyQualifiedName();
            final String[] packagePath = pkgName.split("\\.");

            if (pkgName.length() > 0) {
                for (final String segment : packagePath) {
                    pkgNode = pkgNode.addNode(segment);
                    pkgNode.addMixin(ClassFileSequencerLexicon.PACKAGE);
                }
            }
        }

        { // Javadocs
            final Javadoc javadoc = pkg.getJavadoc();

            if (javadoc != null) {
                record(javadoc, pkgNode);
            }
        }

        { // annotations
            @SuppressWarnings( "unchecked" )
            final List<Annotation> annotations = pkg.annotations();

            if ((annotations != null) && !annotations.isEmpty()) {
                for (final Annotation annotation : annotations) {
                    record(annotation, pkgNode);
                }
View Full Code Here

     */
    @SuppressWarnings( "unchecked" )
    protected PackageMetadata createPackageMetadata( CompilationUnit unit ) {
        PackageMetadata packageMetadata = null;
        List<Annotation> annotations = null;
        PackageDeclaration packageDeclaration = unit.getPackage();
        if (packageDeclaration != null) {
            annotations = packageDeclaration.annotations();
            packageMetadata = new PackageMetadata(JavaMetadataUtil.getName(unit.getPackage().getName()));
            if (!annotations.isEmpty()) {
                for (Object object : annotations) {
                    packageMetadata.getAnnotations().add(createAnnotationMetadataFor((Annotation)object));
                }
View Full Code Here

    * Package modifiers
    */
   @Override
   public String getPackage()
   {
      PackageDeclaration pkg = unit.getPackage();
      if (pkg != null)
      {
         return pkg.getName().getFullyQualifiedName();
      }
      else
      {
         return null;
      }
View Full Code Here

  private void updatePackageStatement(CompilationUnit astCU, String[] pkgName, ASTRewrite rewriter, ICompilationUnit cu) throws JavaModelException {
    boolean defaultPackage = pkgName.length == 0;
    AST ast = astCU.getAST();
    if (defaultPackage) {
      // remove existing package statement
      PackageDeclaration pkg = astCU.getPackage();
      if (pkg != null) {
        int pkgStart;
        Javadoc javadoc = pkg.getJavadoc();
        if (javadoc != null) {
          pkgStart = javadoc.getStartPosition() + javadoc.getLength() + 1;
        } else {
          pkgStart = pkg.getStartPosition();
        }
        int extendedStart = astCU.getExtendedStartPosition(pkg);
        if (pkgStart != extendedStart) {
          // keep the comments associated with package declaration
          // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=247757
          String commentSource = cu.getSource().substring(extendedStart, pkgStart);
          ASTNode comment = rewriter.createStringPlaceholder(commentSource, ASTNode.PACKAGE_DECLARATION);
          rewriter.set(astCU, CompilationUnit.PACKAGE_PROPERTY, comment, null);
        } else {
          rewriter.set(astCU, CompilationUnit.PACKAGE_PROPERTY, null, null);
        }
      }
    } else {
      org.eclipse.jdt.core.dom.PackageDeclaration pkg = astCU.getPackage();
      if (pkg != null) {
        // rename package statement
        Name name = ast.newName(pkgName);
        rewriter.set(pkg, PackageDeclaration.NAME_PROPERTY, name, null);
      } else {
        // create new package statement
        pkg = ast.newPackageDeclaration();
        pkg.setName(ast.newName(pkgName));
        rewriter.set(astCU, CompilationUnit.PACKAGE_PROPERTY, pkg, null);
      }
    }
  }
View Full Code Here

         AnnotationTypeDeclaration annotationTypeDeclaration = (AnnotationTypeDeclaration) declaration;
         return new JavaAnnotationImpl(enclosingType, document, unit, annotationTypeDeclaration);
      }
      else if (declaration instanceof PackageDeclaration)
      {
         PackageDeclaration packageDeclaration = (PackageDeclaration) declaration;
         return new JavaPackageInfoImpl(enclosingType, document, unit, packageDeclaration);
      }
      else
      {
         throw new ParserException("Unknown Java source type [" + declaration + "]");
View Full Code Here

    * Package modifiers
    */
   @Override
   public String getPackage()
   {
      PackageDeclaration pkg = unit.getPackage();
      if (pkg != null)
      {
         return pkg.getName().getFullyQualifiedName();
      }
      else
      {
         return null;
      }
View Full Code Here

    * Package modifiers
    */
   @Override
   public String getPackage()
   {
      PackageDeclaration pkg = unit.getPackage();
      if (pkg != null)
      {
         return pkg.getName().getFullyQualifiedName();
      }
      else
      {
         return null;
      }
View Full Code Here

    * Package modifiers
    */
   @Override
   public String getPackage()
   {
      PackageDeclaration pkg = unit.getPackage();
      if (pkg != null)
      {
         return pkg.getName().getFullyQualifiedName();
      }
      else
      {
         return null;
      }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.PackageDeclaration

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.