Example usage for org.eclipse.jdt.core.dom Comment toString

List of usage examples for org.eclipse.jdt.core.dom Comment toString

Introduction

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

Prototype

@Override
public final String toString() 

Source Link

Document

Returns a string representation of this node suitable for debugging purposes only.

Usage

From source file:org.eclipse.modisco.java.discoverer.internal.io.java.JDTVisitor.java

License:Open Source License

@Override
public void endVisit(final org.eclipse.jdt.core.dom.CompilationUnit node) {
    CompilationUnit element = (CompilationUnit) this.binding.get(node);

    // if any type of this cu already exists in the model, we don't
    // visit this cu
    if (this.isAlreadyVisited) {
        return;/*from w w w. j a  va 2 s. c  o  m*/
    }

    this.jdtModel.getCompilationUnits().add(element);
    ITypeRoot rootType = node.getTypeRoot();

    if (rootType != null) {
        if (rootType instanceof IClassFile) {
            // type comes from a .class file
            ClassFile classFile = this.factory.createClassFile();
            classFile.setName(rootType.getElementName());
            classFile.setAttachedSource(element);
            classFile.setOriginalFilePath(this.currentFilePath);

            Archive ar = LibraryReader.getArchive((IClassFile) rootType, this.factory, this.jdtModel);
            if (ar == null) {
                this.jdtModel.getClassFiles().add(classFile);
            } else {
                ar.getClassFiles().add(classFile);
            }
        } else if (rootType instanceof ICompilationUnit) {
            // type comes a .java file
            IPath absolutePath = null;
            try {
                absolutePath = rootType.getCorrespondingResource().getLocation();
            } catch (JavaModelException e) {
                absolutePath = ResourcesPlugin.getWorkspace().getRoot().getRawLocation()
                        .append(rootType.getPath());
            }
            element.setOriginalFilePath(absolutePath.toOSString());
        } else {
            element.setOriginalFilePath(""); //$NON-NLS-1$
        }
        element.setName(rootType.getElementName());
    } else {
        element.setProxy(true);
    }

    Package packageDeclaration = (Package) this.binding.get(node.getPackage());
    element.setPackage(packageDeclaration);

    for (Object importNode : node.imports()) {
        ImportDeclaration importDeclaration = (ImportDeclaration) this.binding.get(importNode);
        element.getImports().add(importDeclaration);
    }

    for (Object typeNode : node.types()) {
        AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) this.binding.get(typeNode);
        element.getTypes().add(typeDeclaration);
    }

    try {
        // accessing BlockComment and LineComment
        // (https://bugs.eclipse.org/bugs/show_bug.cgi?format=multiple&id=84528)
        List<?> comments = node.getCommentList();
        for (Object name : comments) {
            org.eclipse.jdt.core.dom.Comment aComment = (org.eclipse.jdt.core.dom.Comment) name;

            Comment commentElement = null;
            if (aComment.isLineComment()) {
                commentElement = this.factory.createLineComment();
                initializeNode(commentElement, aComment);
                String content = CommentsManager.extractCommentContent(aComment, this.javaContent);
                commentElement.setContent(content);
                this.binding.put(aComment, commentElement);
            } else if (aComment.isBlockComment()) {
                commentElement = this.factory.createBlockComment();
                initializeNode(commentElement, aComment);
                String content = CommentsManager.extractCommentContent(aComment, this.javaContent);
                commentElement.setContent(content);
                this.binding.put(aComment, commentElement);
            } else if (aComment.isDocComment()) {
                // one javadoc node (and its tag elements) should have been
                // already visited

                commentElement = (Javadoc) this.binding.get(aComment);
                if (commentElement == null) { // happen if more than one javadoc
                    // for a node
                    commentElement = this.factory.createJavadoc();
                    initializeNode(commentElement, aComment);
                }
                commentElement.setContent(aComment.toString());
            }

            getCommentsBinding().put(aComment, commentElement);
            // initialisation of element CompilationUnit
            element.getCommentList().add(commentElement);
        }

        CommentsManager.resolveCommentPositions(this);
    } catch (StringIndexOutOfBoundsException e) {
        // IGNORE hub, sam, markus
    }
}