Dali Provisional API
Release 3.2

org.eclipse.jpt.common.core.utility
Class BodySourceWriter

java.lang.Object
  extended by java.io.Writer
      extended by java.io.PrintWriter
          extended by org.eclipse.jpt.common.utility.io.IndentingPrintWriter
              extended by org.eclipse.jpt.common.core.utility.BodySourceWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable

public class BodySourceWriter
extends org.eclipse.jpt.common.utility.io.IndentingPrintWriter

Extend IndentingPrintWriter with some methods that facilitate building class source code.


Nested Class Summary
protected static class BodySourceWriter.ImportEntriesComparator
           
protected static class BodySourceWriter.ImportEntriesTransformer
           
protected  class BodySourceWriter.ImportEntryIsRequired
           
protected static class BodySourceWriter.ImportPackage
          We need a 'collision' flag for when we encounter a class from 'java.lang' followed by a class from the current compilation unit's package.
 
Field Summary
protected  String className
           
protected static Comparator<Map.Entry<String,BodySourceWriter.ImportPackage>> IMPORT_ENTRIES_COMPARATOR
           
protected static org.eclipse.jpt.common.utility.transformer.Transformer<Map.Entry<String,BodySourceWriter.ImportPackage>,String> IMPORT_ENTRIES_TRANSFORMER
           
protected  HashMap<String,BodySourceWriter.ImportPackage> imports
           
protected  String packageName
           
 
Fields inherited from class org.eclipse.jpt.common.utility.io.IndentingPrintWriter
DEFAULT_INDENT
 
Fields inherited from class java.io.PrintWriter
out
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
BodySourceWriter(String packageName, String className, String lineSeparator)
           
 
Method Summary
protected  String buildImportedTypeDeclaration(String typeDeclaration)
          Return the specified class's "imported" name.
protected  Comparator<Map.Entry<String,BodySourceWriter.ImportPackage>> buildImportEntriesComparator()
           
protected  org.eclipse.jpt.common.utility.transformer.Transformer<Map.Entry<String,BodySourceWriter.ImportPackage>,String> buildImportEntriesTransformer()
           
protected  org.eclipse.jpt.common.utility.predicate.Predicate<Map.Entry<String,BodySourceWriter.ImportPackage>> buildImportEntryIsRequired()
           
protected  String buildMemberClassTypeDeclaration(String typeDeclaration)
          e.g.
 Iterable<String> getImports()
           
 int getLength()
           
protected  Iterable<Map.Entry<String,BodySourceWriter.ImportPackage>> getRequiredImportEntries()
          strip off any non-required imports (e.g.
protected  Iterable<Map.Entry<String,BodySourceWriter.ImportPackage>> getSortedRequiredImportEntries()
          sort by package first, then class (*not* by fully-qualified class name)
protected  Iterable<String> getSortedRequiredImports()
          transform our map entries to class names
 String getSource()
           
 void printAnnotation(String annotationName)
           
protected  void printField(String fieldName, String typeDeclaration, String visibility)
           
protected  void printParameterizedField(String fieldName, String typeDeclaration, String parameterTypeDeclaration, String visibility)
           
 void printStringLiteral(String string)
          Convert the specified string to a String Literal and print it, adding the surrounding double-quotes and escaping characters as necessary.
 void printTypeDeclaration(String typeDeclaration)
           
protected  void printVisibility(String visibilityModifier)
           
protected  boolean typeDeclarationIsMemberClass(String typeDeclaration)
          e.g.
 
Methods inherited from class org.eclipse.jpt.common.utility.io.IndentingPrintWriter
decrementIndentLevel, getIndentLevel, incrementIndentLevel, indent, println, setIndentLevel, undent, write, write, write
 
Methods inherited from class java.io.PrintWriter
append, append, append, checkError, clearError, close, flush, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, setError, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

packageName

protected final String packageName

className

protected final String className

imports

protected final HashMap<String,BodySourceWriter.ImportPackage> imports

IMPORT_ENTRIES_TRANSFORMER

protected static final org.eclipse.jpt.common.utility.transformer.Transformer<Map.Entry<String,BodySourceWriter.ImportPackage>,String> IMPORT_ENTRIES_TRANSFORMER

IMPORT_ENTRIES_COMPARATOR

protected static final Comparator<Map.Entry<String,BodySourceWriter.ImportPackage>> IMPORT_ENTRIES_COMPARATOR
Constructor Detail

BodySourceWriter

public BodySourceWriter(String packageName,
                        String className,
                        String lineSeparator)
Method Detail

getSource

public String getSource()

getLength

public int getLength()

printVisibility

protected void printVisibility(String visibilityModifier)

printAnnotation

public void printAnnotation(String annotationName)

printTypeDeclaration

public void printTypeDeclaration(String typeDeclaration)

printField

protected void printField(String fieldName,
                          String typeDeclaration,
                          String visibility)

printParameterizedField

protected void printParameterizedField(String fieldName,
                                       String typeDeclaration,
                                       String parameterTypeDeclaration,
                                       String visibility)

printStringLiteral

public void printStringLiteral(String string)
Convert the specified string to a String Literal and print it, adding the surrounding double-quotes and escaping characters as necessary.


buildImportedTypeDeclaration

protected String buildImportedTypeDeclaration(String typeDeclaration)
Return the specified class's "imported" name. The class declaration must be of the form: "int" "int[]" (not "[I") "java.lang.Object" "java.lang.Object[]" (not "[Ljava.lang.Object;") "java.util.Map.Entry" (not "java.util.Map$Entry") "java.util.Map.Entry[][]" (not "[[Ljava.util.Map$Entry;") To really do this right, we would need to gather all the types from the "unamed" (default) package that were referenced in the compilation unit beforehand. *Any* collisions with one of these types would have to be fully qualified (whether it was from 'java.lang' or the same package as the current compilation unit). In other words, if we have any types from the "unnamed" package, results are unpredictable....


typeDeclarationIsMemberClass

protected boolean typeDeclarationIsMemberClass(String typeDeclaration)
e.g. "foo.bar.Employee.PK" will return true


buildMemberClassTypeDeclaration

protected String buildMemberClassTypeDeclaration(String typeDeclaration)
e.g. "foo.bar.Employee.PK" will return "Employee.PK" this prevents collisions with other imported classes (e.g. "joo.jar.PK")


getImports

public Iterable<String> getImports()

getSortedRequiredImports

protected Iterable<String> getSortedRequiredImports()
transform our map entries to class names


buildImportEntriesTransformer

protected org.eclipse.jpt.common.utility.transformer.Transformer<Map.Entry<String,BodySourceWriter.ImportPackage>,String> buildImportEntriesTransformer()

getSortedRequiredImportEntries

protected Iterable<Map.Entry<String,BodySourceWriter.ImportPackage>> getSortedRequiredImportEntries()
sort by package first, then class (*not* by fully-qualified class name)


buildImportEntriesComparator

protected Comparator<Map.Entry<String,BodySourceWriter.ImportPackage>> buildImportEntriesComparator()

getRequiredImportEntries

protected Iterable<Map.Entry<String,BodySourceWriter.ImportPackage>> getRequiredImportEntries()
strip off any non-required imports (e.g. "java.lang.Object')


buildImportEntryIsRequired

protected org.eclipse.jpt.common.utility.predicate.Predicate<Map.Entry<String,BodySourceWriter.ImportPackage>> buildImportEntryIsRequired()

Dali Provisional API
Release 3.2

Copyright (c) 2012 Oracle. All rights reserved.