Search in sources :

Example 1 with FileLocation

use of com.buschmais.jqassistant.core.report.api.model.source.FileLocation in project jqa-java-plugin by buschmais.

the class TypeSourceHelper method getSourceLocation.

static Optional<FileLocation> getSourceLocation(TypeDescriptor typeDescriptor, Optional<Integer> startLine, Optional<Integer> endLine) {
    if (typeDescriptor instanceof ClassFileDescriptor) {
        ClassFileDescriptor classFileDescriptor = (ClassFileDescriptor) typeDescriptor;
        for (FileDescriptor parent : classFileDescriptor.getParents()) {
            if (parent instanceof PackageDescriptor) {
                // File location can only safely built if a parent package exists.
                PackageDescriptor packageDescriptor = (PackageDescriptor) parent;
                FileLocation.FileLocationBuilder fileLocationBuilder = FileLocation.builder();
                fileLocationBuilder.parent(FileSourceHelper.getParentLocation(classFileDescriptor));
                fileLocationBuilder.fileName(packageDescriptor.getFileName() + "/" + classFileDescriptor.getSourceFileName());
                fileLocationBuilder.startLine(startLine);
                fileLocationBuilder.endLine(endLine);
                return of(fileLocationBuilder.build());
            }
        }
    }
    return empty();
}
Also used : FileLocation(com.buschmais.jqassistant.core.report.api.model.source.FileLocation) PackageDescriptor(com.buschmais.jqassistant.plugin.java.api.model.PackageDescriptor) ClassFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.ClassFileDescriptor) ClassFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.ClassFileDescriptor) FileDescriptor(com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor)

Example 2 with FileLocation

use of com.buschmais.jqassistant.core.report.api.model.source.FileLocation in project jqa-core-framework by buschmais.

the class XmlReportPlugin method writeColumn.

/**
 * Determines the language and language element of a descriptor from a result
 * column.
 *
 * @param columnName
 *            The name of the column.
 * @param value
 *            The value.
 * @throws XMLStreamException
 *             If a problem occurs.
 */
private void writeColumn(String columnName, Object value) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("column");
    xmlStreamWriter.writeAttribute("name", columnName);
    String label = null;
    if (value instanceof CompositeObject) {
        CompositeObject descriptor = (CompositeObject) value;
        LanguageElement elementValue = LanguageHelper.getLanguageElement(descriptor);
        if (elementValue != null) {
            xmlStreamWriter.writeStartElement("element");
            xmlStreamWriter.writeAttribute("language", elementValue.getLanguage());
            xmlStreamWriter.writeCharacters(elementValue.name());
            // element
            xmlStreamWriter.writeEndElement();
            SourceProvider sourceProvider = elementValue.getSourceProvider();
            label = sourceProvider.getName(descriptor);
            Optional<FileLocation> sourceLocation = sourceProvider.getSourceLocation(descriptor);
            if (sourceLocation.isPresent()) {
                xmlStreamWriter.writeStartElement("source");
                writeSourceLocation(sourceLocation.get());
                // sourceFile
                xmlStreamWriter.writeEndElement();
            }
        }
    } else if (value != null) {
        label = ReportHelper.getLabel(value);
    }
    writeElementWithCharacters("value", label);
    // column
    xmlStreamWriter.writeEndElement();
}
Also used : CompositeObject(com.buschmais.xo.api.CompositeObject) LanguageElement(com.buschmais.jqassistant.core.report.api.model.LanguageElement) FileLocation(com.buschmais.jqassistant.core.report.api.model.source.FileLocation)

Aggregations

FileLocation (com.buschmais.jqassistant.core.report.api.model.source.FileLocation)2 LanguageElement (com.buschmais.jqassistant.core.report.api.model.LanguageElement)1 FileDescriptor (com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor)1 ClassFileDescriptor (com.buschmais.jqassistant.plugin.java.api.model.ClassFileDescriptor)1 PackageDescriptor (com.buschmais.jqassistant.plugin.java.api.model.PackageDescriptor)1 CompositeObject (com.buschmais.xo.api.CompositeObject)1