Search in sources :

Example 1 with SourcePosition

use of com.webcohesion.enunciate.javac.decorations.SourcePosition in project enunciate by stoicflame.

the class JavaJSONClientModule method copyServerSideType.

protected void copyServerSideType(File sourceDir, TypeElement type) throws IOException {
    SourcePosition source = this.context.getProcessingEnvironment().findSourcePosition(type);
    JavaFileObject sourceFile = source.getSourceFile();
    File destFile = getServerSideDestFile(sourceDir, sourceFile, type);
    FileWriter writer = new FileWriter(destFile);
    debug("Writing server-side java type to %s.", destFile);
    writer.write(sourceFile.getCharContent(false).toString());
    writer.flush();
    writer.close();
}
Also used : JavaFileObject(javax.tools.JavaFileObject) SourcePosition(com.webcohesion.enunciate.javac.decorations.SourcePosition)

Example 2 with SourcePosition

use of com.webcohesion.enunciate.javac.decorations.SourcePosition in project enunciate by stoicflame.

the class JavaXMLClientModule method copyServerSideType.

protected void copyServerSideType(File sourceDir, TypeElement type) throws IOException {
    SourcePosition source = this.context.getProcessingEnvironment().findSourcePosition(type);
    JavaFileObject sourceFile = source.getSourceFile();
    File destFile = getServerSideDestFile(sourceDir, sourceFile, type);
    FileWriter writer = new FileWriter(destFile);
    debug("Writing server-side java type to %s.", destFile);
    writer.write(sourceFile.getCharContent(false).toString());
    writer.flush();
    writer.close();
}
Also used : JavaFileObject(javax.tools.JavaFileObject) SourcePosition(com.webcohesion.enunciate.javac.decorations.SourcePosition)

Example 3 with SourcePosition

use of com.webcohesion.enunciate.javac.decorations.SourcePosition in project enunciate by stoicflame.

the class MemberComparator method compare.

// Inherited.
public int compare(Member accessor1, Member accessor2) {
    if (isSameId(accessor1, accessor2)) {
        // if the elements have the same identifier.
        return 0;
    }
    // they're not the same, so now determine relative order:
    String propertyName1 = accessor1.getSimpleName().toString();
    String propertyName2 = accessor2.getSimpleName().toString();
    if (this.propOrder != null && this.propOrder.length > 0) {
        // apply the specified property order
        int propertyIndex1 = find(this.propOrder, propertyName1);
        int propertyIndex2 = find(this.propOrder, propertyName2);
        if (propertyIndex1 < 0) {
            // not in the property list; just use the hash.
            propertyIndex1 = Math.abs(propertyName1.hashCode());
        }
        if (propertyIndex2 < 0) {
            // not in the property list; just use the hash.
            propertyIndex2 = Math.abs(propertyName2.hashCode());
        }
        return propertyIndex1 - propertyIndex2;
    } else if (this.alphabetical) {
        return propertyName1.compareTo(propertyName2);
    }
    // If no order is specified, it's undefined. We'll put it in source order.
    SourcePosition position1 = this.env.findSourcePosition(accessor1);
    SourcePosition position2 = this.env.findSourcePosition(accessor2);
    if (position1 != null && position2 != null) {
        return position1.compareTo(position2);
    } else {
        // don't have source positions... just provide a random sort order.
        return accessor1.hashCode() - accessor2.hashCode();
    }
}
Also used : SourcePosition(com.webcohesion.enunciate.javac.decorations.SourcePosition)

Example 4 with SourcePosition

use of com.webcohesion.enunciate.javac.decorations.SourcePosition in project enunciate by stoicflame.

the class BasicGeneratingModule method findSourceTimestamp.

public long findSourceTimestamp(DecoratedProcessingEnvironment env, Element apiElement) {
    SourcePosition sp = env.findSourcePosition(apiElement);
    URI uri = sp == null ? null : sp.getPath() == null ? null : sp.getPath().getCompilationUnit() == null ? null : sp.getPath().getCompilationUnit().getSourceFile() == null ? null : sp.getPath().getCompilationUnit().getSourceFile().toUri();
    if (uri != null && "file".equalsIgnoreCase(uri.getScheme())) {
        // it's a file uri.
        return new File(uri.getPath()).lastModified();
    }
    return 0;
}
Also used : SourcePosition(com.webcohesion.enunciate.javac.decorations.SourcePosition) URI(java.net.URI) File(java.io.File)

Example 5 with SourcePosition

use of com.webcohesion.enunciate.javac.decorations.SourcePosition in project enunciate by stoicflame.

the class ElementComparator method compare.

// Inherited.
public int compare(Element accessor1, Element accessor2) {
    if (isSameId(accessor1, accessor2)) {
        // if the elements have the same identifier.
        return 0;
    }
    // they're not the same, so now determine relative order:
    String propertyName1 = accessor1.getSimpleName().toString();
    String propertyName2 = accessor2.getSimpleName().toString();
    if (this.propOrder != null) {
        // apply the specified property order
        int propertyIndex1 = find(this.propOrder, propertyName1);
        int propertyIndex2 = find(this.propOrder, propertyName2);
        if (propertyIndex1 < 0) {
            throw new EnunciateException("Property '" + propertyName1 + "' isn't included in the specified property order.");
        }
        if (propertyIndex2 < 0) {
            throw new EnunciateException("Property '" + propertyName2 + "' isn't included in the specified property order.");
        }
        return propertyIndex1 - propertyIndex2;
    } else if (accessOrder == XmlAccessOrder.ALPHABETICAL) {
        return propertyName1.compareTo(propertyName2);
    }
    // If no order is specified, it's undefined. We'll put it in source order.
    SourcePosition position1 = this.env.findSourcePosition(accessor1);
    SourcePosition position2 = this.env.findSourcePosition(accessor2);
    if (position1 != null && position2 != null) {
        return position1.compareTo(position2);
    } else {
        // don't have source positions... just provide a random sort order.
        return accessor1.hashCode() - accessor2.hashCode();
    }
}
Also used : EnunciateException(com.webcohesion.enunciate.EnunciateException) SourcePosition(com.webcohesion.enunciate.javac.decorations.SourcePosition)

Aggregations

SourcePosition (com.webcohesion.enunciate.javac.decorations.SourcePosition)6 JavaFileObject (javax.tools.JavaFileObject)2 EnunciateException (com.webcohesion.enunciate.EnunciateException)1 File (java.io.File)1 URI (java.net.URI)1