Example usage for org.eclipse.jdt.core.dom TypeDeclaration JAVADOC_PROPERTY

List of usage examples for org.eclipse.jdt.core.dom TypeDeclaration JAVADOC_PROPERTY

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom TypeDeclaration JAVADOC_PROPERTY.

Prototype

ChildPropertyDescriptor JAVADOC_PROPERTY

To view the source code for org.eclipse.jdt.core.dom TypeDeclaration JAVADOC_PROPERTY.

Click Source Link

Document

The "javadoc" structural property of this node type (child type: Javadoc ).

Usage

From source file:de.akra.idocit.java.services.JavadocGeneratorTest.java

License:Apache License

/**
 * This is not a real unit test. It is a trial to use the ITextFileBufferManager to
 * save the changes in a CompilationUnit.<br />
 * Test for/* w w  w.j  a va 2 s.c  om*/
 * {@link JavaInterfaceGenerator#updateJavadocInAST(de.akra.idocit.java.structure.JavaInterfaceArtifact)}
 * .
 * 
 * @throws FileNotFoundException
 * @throws IOException
 * @throws BadLocationException
 * @throws MalformedTreeException
 * @throws CoreException
 * @throws ParsingException
 */
@Ignore
public void testJavaInterfaceGenerator2() throws FileNotFoundException, IOException, MalformedTreeException,
        BadLocationException, CoreException, ParsingException {

    ParserOutput output = JavaTestUtils
            .createCompilationUnit(AllIDocItJavaTests.SOURCE_DIR + "ParsingService2.java");
    CompilationUnit unit = output.getCompilationUnit();
    String originalCU = unit.toString();

    TypeDeclaration typeDecl = (TypeDeclaration) unit.types().get(0);
    AST ast = typeDecl.getAST();
    ASTRewrite rewriter = ASTRewrite.create(ast);

    List<JavadocTagElement> jDocTags = new ArrayList<JavadocTagElement>();
    JavadocTagElement tagElem = new JavadocTagElement(TagElement.TAG_PARAM, "paramName",
            createParamDocumentations(), SignatureElement.EMPTY_SIGNATURE_ELEMENT);
    jDocTags.add(tagElem);

    List<TagElement> additionalTags = Collections.emptyList();
    Javadoc javadoc = JavaInterfaceGenerator.createOrUpdateJavadoc(jDocTags, additionalTags, ast.newJavadoc(),
            ast, null, JavadocGenerator.INSTANCE, null);

    rewriter.set(typeDecl, TypeDeclaration.JAVADOC_PROPERTY, javadoc, null);

    // get the buffer manager
    ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
    IPath path = unit.getJavaElement().getPath();

    try {
        bufferManager.connect(path, LocationKind.IFILE, null);
        // retrieve the buffer
        ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(path, LocationKind.IFILE);

        if (textFileBuffer != null) {
            logger.log(Level.INFO, "isSynchronized=" + textFileBuffer.isSynchronized());

            IDocument document = textFileBuffer.getDocument();

            logger.log(Level.INFO, document.toString());

            // ... edit the document ...
            TextEdit edit = rewriter.rewriteAST(document, null);
            edit.apply(document);

            // commit changes to underlying file
            textFileBuffer.commit(null /* ProgressMonitor */, false /* Overwrite */);
        } else {
            logger.log(Level.SEVERE, "textFileBuffer == null");
        }
    } finally {
        bufferManager.disconnect(path, LocationKind.IFILE, null);
    }

    String changedCU = unit.toString();

    logger.log(Level.INFO, originalCU);
    logger.log(Level.INFO, changedCU);
}

From source file:de.ovgu.cide.language.jdt.SimplePrintVisitor.java

License:Open Source License

public boolean visit(IASTNode node) {
    if (node instanceof ASTStringNode) {
        printToken(((ASTStringNode) node).getValue());
        return false;
    }/*from  w  w  w.ja v a  2  s . com*/
    if (node instanceof ASTTextNode) {
        printToken(((ASTTextNode) node).getValue());
        return false;
    }
    if (node instanceof UnifiedASTNode) {
        UnifiedASTNode unode = (UnifiedASTNode) node;

        if (unode.getEclipseASTNodeClass().equals("AnnotationTypeDeclaration")) {

            accept(node, AnnotationTypeDeclaration.JAVADOC_PROPERTY.getId());

        }

        if (unode.getEclipseASTNodeClass().equals(CompilationUnit.class.getSimpleName())) {
            accept(unode, CompilationUnit.PACKAGE_PROPERTY.getId());
            accept(unode, CompilationUnit.IMPORTS_PROPERTY.getId());
            accept(unode, CompilationUnit.TYPES_PROPERTY.getId());
        }

        if (unode.getEclipseASTNodeClass().equals(TypeDeclaration.class.getSimpleName())) {

            accept(node, TypeDeclaration.JAVADOC_PROPERTY.getId());
            accept(node, TypeDeclaration.MODIFIERS2_PROPERTY.getId());
            accept(node, TypeDeclaration.INTERFACE_PROPERTY.getId());
            accept(node, TypeDeclaration.NAME_PROPERTY.getId());
            accept(node, TypeDeclaration.TYPE_PARAMETERS_PROPERTY.getId(), "<", ",", ">", true);
            //            this.buffer.append(" ");//$NON-NLS-1$

            accept(node, TypeDeclaration.SUPERCLASS_TYPE_PROPERTY.getId(), "extends", "", "", false);
            accept(node, TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY.getId(), "implements", ",", "", false);
            printToken("{");
            hintNewLine();
            hintIncIndent();

            accept(node, TypeDeclaration.BODY_DECLARATIONS_PROPERTY.getId());

            hintDecIndent();
            printToken("}");
            hintNewLine();
        }

        printToken(unode.getEclipseASTNodeClass());
    }
    return false;
}

From source file:edu.illinois.compositerefactorings.refactorings.NewClassCreator.java

License:Open Source License

public List<ResourceChange> createTopLevelParameterObject() throws CoreException {
    List<ResourceChange> changes = new ArrayList<ResourceChange>();
    ICompilationUnit unit = getPackageFragment()
            .getCompilationUnit(getClassName() + JavaModelUtil.DEFAULT_CU_SUFFIX);
    Assert.isTrue(!unit.exists());//from w  w  w  .j  a v  a 2  s. c  o m
    IJavaProject javaProject = unit.getJavaProject();
    ICompilationUnit workingCopy = unit.getWorkingCopy(null);

    try {
        // create stub with comments and dummy type
        String lineDelimiter = StubUtility.getLineDelimiterUsed(javaProject);
        String fileComment = getFileComment(workingCopy, lineDelimiter);
        String typeComment = getTypeComment(workingCopy, lineDelimiter);
        String content = CodeGeneration.getCompilationUnitContent(workingCopy, fileComment, typeComment,
                "class " + getClassName() + "{}", lineDelimiter); //$NON-NLS-1$ //$NON-NLS-2$
        workingCopy.getBuffer().setContents(content);

        CompilationUnitRewrite cuRewrite = new CompilationUnitRewrite(workingCopy);
        ASTRewrite rewriter = cuRewrite.getASTRewrite();
        CompilationUnit root = cuRewrite.getRoot();
        AST ast = cuRewrite.getAST();
        ImportRewrite importRewrite = cuRewrite.getImportRewrite();

        if (fSuperclassType != null) {
            importRewrite.addImport(fSuperclassType.resolveBinding());
        }

        // retrieve&replace dummy type with real class
        ListRewrite types = rewriter.getListRewrite(root, CompilationUnit.TYPES_PROPERTY);
        ASTNode dummyType = (ASTNode) types.getOriginalList().get(0);
        TypeDeclaration classDeclaration = createClassDeclaration(getClassName(), cuRewrite);
        classDeclaration.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
        Javadoc javadoc = (Javadoc) dummyType.getStructuralProperty(TypeDeclaration.JAVADOC_PROPERTY);
        rewriter.set(classDeclaration, TypeDeclaration.JAVADOC_PROPERTY, javadoc, null);
        types.replace(dummyType, classDeclaration, null);

        // Apply rewrites and discard workingcopy
        // Using CompilationUnitRewrite.createChange() leads to strange
        // results
        String charset = ResourceUtil.getFile(unit).getCharset(false);
        Document document = new Document(content);
        try {
            rewriter.rewriteAST().apply(document);
            TextEdit rewriteImports = importRewrite.rewriteImports(null);
            rewriteImports.apply(document);
        } catch (BadLocationException e) {
            throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(),
                    RefactoringCoreMessages.IntroduceParameterObjectRefactoring_parameter_object_creation_error,
                    e));
        }
        String docContent = document.get();
        CreateCompilationUnitChange compilationUnitChange = new CreateCompilationUnitChange(unit, docContent,
                charset);
        changes.add(compilationUnitChange);
    } finally {
        workingCopy.discardWorkingCopy();
    }
    return changes;
}