]> source.dussan.org Git - poi.git/commitdiff
Fix some compilation warnings
authorDominik Stadler <centic@apache.org>
Fri, 30 Dec 2016 22:11:48 +0000 (22:11 +0000)
committerDominik Stadler <centic@apache.org>
Fri, 30 Dec 2016 22:11:48 +0000 (22:11 +0000)
Update Javadoc
Reformat code somewhat
Supress IntelliJ warnings in findbugs-filters.xml

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1776645 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/FormulaRecord.java
src/java/org/apache/poi/sl/draw/DrawTextParagraph.java
src/ooxml/java/org/apache/poi/util/DocumentHelper.java
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java
src/resources/devtools/findbugs-filters.xml

index 4eae6ce5c2f02c380e11981e16f42b8308bdf1fc..0ef07d470f951c1e243359ab4fd899600478389f 100644 (file)
@@ -21,11 +21,7 @@ import org.apache.poi.ss.formula.Formula;
 import org.apache.poi.ss.formula.eval.ErrorEval;
 import org.apache.poi.ss.formula.ptg.Ptg;
 import org.apache.poi.ss.usermodel.CellType;
-import org.apache.poi.util.BitField;
-import org.apache.poi.util.BitFieldFactory;
-import org.apache.poi.util.HexDump;
-import org.apache.poi.util.LittleEndianInput;
-import org.apache.poi.util.LittleEndianOutput;
+import org.apache.poi.util.*;
 
 /**
  * Formula Record (0x0006).
@@ -65,6 +61,7 @@ public final class FormulaRecord extends CellRecord implements Cloneable {
                private SpecialCachedValue(byte[] data) {
                        _variableData = data;
                }
+
                public int getTypeCode() {
                        return _variableData[0];
                }
@@ -91,42 +88,55 @@ public final class FormulaRecord extends CellRecord implements Cloneable {
                                case EMPTY:
                                        break;
                                default:
-                                       throw new RecordFormatException("Bad special value code (" + result[0] + ")");
+                                       throw new org.apache.poi.util.RecordFormatException("Bad special value code (" + result[0] + ")");
                        }
                        return new SpecialCachedValue(result);
                }
+
                public void serialize(LittleEndianOutput out) {
                        out.write(_variableData);
                        out.writeShort(0xFFFF);
                }
+
                public String formatDebugString() {
                        return formatValue() + ' ' + HexDump.toHex(_variableData);
                }
+
                private String formatValue() {
                        int typeCode = getTypeCode();
                        switch (typeCode) {
-                               case STRING:     return "<string>";
-                               case BOOLEAN:   return getDataValue() == 0 ? "FALSE" : "TRUE";
-                               case ERROR_CODE: return ErrorEval.getText(getDataValue());
-                               case EMPTY:       return "<empty>";
+                               case STRING:
+                                       return "<string>";
+                               case BOOLEAN:
+                                       return getDataValue() == 0 ? "FALSE" : "TRUE";
+                               case ERROR_CODE:
+                                       return ErrorEval.getText(getDataValue());
+                               case EMPTY:
+                                       return "<empty>";
                        }
                        return "#error(type=" + typeCode + ")#";
                }
+
                private int getDataValue() {
                        return _variableData[DATA_INDEX];
                }
+
                public static SpecialCachedValue createCachedEmptyValue() {
                        return create(EMPTY, 0);
                }
+
                public static SpecialCachedValue createForString() {
                        return create(STRING, 0);
                }
+
                public static SpecialCachedValue createCachedBoolean(boolean b) {
                        return create(BOOLEAN, b ? 1 : 0);
                }
+
                public static SpecialCachedValue createCachedErrorCode(int errorCode) {
                        return create(ERROR_CODE, errorCode);
                }
+
                private static SpecialCachedValue create(int code, int data) {
                        byte[] vd = {
                                        (byte) code,
@@ -138,13 +148,12 @@ public final class FormulaRecord extends CellRecord implements Cloneable {
                        };
                        return new SpecialCachedValue(vd);
                }
+
                @Override
         public String toString() {
-                       StringBuffer sb = new StringBuffer(64);
-                       sb.append(getClass().getName());
-                       sb.append('[').append(formatValue()).append(']');
-                       return sb.toString();
+                       return getClass().getName() + '[' + formatValue() + ']';
                }
+
                public int getValueType() {
                        int typeCode = getTypeCode();
                        switch (typeCode) {
@@ -155,12 +164,14 @@ public final class FormulaRecord extends CellRecord implements Cloneable {
                        }
                        throw new IllegalStateException("Unexpected type id (" + typeCode + ")");
                }
+
                public boolean getBooleanValue() {
                        if (getTypeCode() != BOOLEAN) {
                                throw new IllegalStateException("Not a boolean cached value - " + formatValue());
                        }
                        return getDataValue() != 0;
                }
+
                public int getErrorValue() {
                        if (getTypeCode() != ERROR_CODE) {
                                throw new IllegalStateException("Not an error cached value - " + formatValue());
@@ -192,19 +203,18 @@ public final class FormulaRecord extends CellRecord implements Cloneable {
 
        public FormulaRecord(RecordInputStream ris) {
                super(ris);
-               LittleEndianInput in = ris;
-               long valueLongBits  = in.readLong();
-               field_5_options = in.readShort();
+               long valueLongBits  = ris.readLong();
+               field_5_options = ris.readShort();
                specialCachedValue = SpecialCachedValue.create(valueLongBits);
                if (specialCachedValue == null) {
                        field_4_value = Double.longBitsToDouble(valueLongBits);
                }
 
-               field_6_zero = in.readInt();
+               field_6_zero = ris.readInt();
 
-               int field_7_expression_len = in.readShort(); // this length does not include any extra array data
-               int nBytesAvailable = in.available();
-               field_8_parsed_expr = Formula.read(field_7_expression_len, in, nBytesAvailable);
+               int field_7_expression_len = ris.readShort(); // this length does not include any extra array data
+               int nBytesAvailable = ris.available();
+               field_8_parsed_expr = Formula.read(field_7_expression_len, ris, nBytesAvailable);
        }
 
        /**
@@ -235,10 +245,8 @@ public final class FormulaRecord extends CellRecord implements Cloneable {
         *  evaluation.
         */
        public boolean hasCachedResultString() {
-               if (specialCachedValue == null) {
-                       return false;
-               }
-               return specialCachedValue.getTypeCode() == SpecialCachedValue.STRING;
+               return specialCachedValue != null &&
+                               specialCachedValue.getTypeCode() == SpecialCachedValue.STRING;
        }
 
        public int getCachedResultType() {
index 65c22d7817496bfa67024e84c6695359521eda41..b1fbd9b0671316a9ad59ca1af5c22e5664436ac0 100644 (file)
@@ -62,7 +62,7 @@ public class DrawTextParagraph implements Drawable {
     protected List<DrawTextFragment> lines = new ArrayList<DrawTextFragment>();\r
     protected String rawText;\r
     protected DrawTextFragment bullet;\r
-    protected int autoNbrIdx = 0;\r
+    protected int autoNbrIdx;\r
 \r
     /**\r
      * the highest line in this paragraph. Used for line spacing.\r
@@ -226,7 +226,7 @@ public class DrawTextParagraph implements Drawable {
     /**\r
      * break text into lines, each representing a line of text that fits in the wrapping width\r
      *\r
-     * @param graphics\r
+     * @param graphics The drawing context for computing text-lengths.\r
      */\r
     protected void breakText(Graphics2D graphics){\r
         lines.clear();\r
@@ -479,7 +479,7 @@ public class DrawTextParagraph implements Drawable {
      */\r
     @SuppressWarnings("rawtypes")\r
     private PlaceableShape<?,?> getParagraphShape() {\r
-        PlaceableShape<?,?> ps = new PlaceableShape(){\r
+        return new PlaceableShape(){\r
             public ShapeContainer<?,?> getParent() { return null; }\r
             public Rectangle2D getAnchor() { return paragraph.getParentShape().getAnchor(); }\r
             public void setAnchor(Rectangle2D anchor) {}\r
@@ -491,7 +491,6 @@ public class DrawTextParagraph implements Drawable {
             public boolean getFlipVertical() { return false; }\r
             public Sheet<?,?> getSheet() { return paragraph.getParentShape().getSheet(); }\r
         };\r
-        return ps;\r
     }\r
 \r
     protected AttributedString getAttributedString(Graphics2D graphics, StringBuilder text){\r
@@ -633,7 +632,7 @@ public class DrawTextParagraph implements Drawable {
 \r
         return string;\r
     }\r
-    \r
+\r
     protected boolean isHSLF() {\r
         return paragraph.getClass().getName().contains("HSLF");\r
     }\r
index 1ec47953abf73e93d4321a9f543431a1c17746e0..f86e60fd90bf2c6370e8269566ef416204be7445 100644 (file)
@@ -78,6 +78,9 @@ public final class DocumentHelper {
     
     /**
      * Creates a new document builder, with sensible defaults
+     *
+     * @throws IllegalStateException If creating the DocumentBuilder fails, e.g.
+     *  due to {@link ParserConfigurationException}.
      */
     public static synchronized DocumentBuilder newDocumentBuilder() {
         try {
index 5bc1ece94e3c395f8b8033e9c8776fb73773725a..e3f51e774d4475afe8ce47f11feb51659fc8f49f 100644 (file)
@@ -31,21 +31,19 @@ import org.apache.poi.util.IOUtils;
 /**
  * Raw picture data, normally attached to a WordprocessingML Drawing.
  * As a rule, pictures are stored in the /word/media/ part of a WordprocessingML package.
- */
-
-/**
+ *
  * @author Philipp Epp
  */
 public class XWPFPictureData extends POIXMLDocumentPart {
 
     /**
-     * Relationships for each known picture type\r
-     */\r
-    protected static final POIXMLRelation[] RELATIONS;\r
-\r
-    static {\r
-        RELATIONS = new POIXMLRelation[13];\r
-        RELATIONS[Document.PICTURE_TYPE_EMF] = XWPFRelation.IMAGE_EMF;\r
+     * Relationships for each known picture type
+     */
+    protected static final POIXMLRelation[] RELATIONS;
+
+    static {
+        RELATIONS = new POIXMLRelation[13];
+        RELATIONS[Document.PICTURE_TYPE_EMF] = XWPFRelation.IMAGE_EMF;
         RELATIONS[Document.PICTURE_TYPE_WMF] = XWPFRelation.IMAGE_WMF;
         RELATIONS[Document.PICTURE_TYPE_PICT] = XWPFRelation.IMAGE_PICT;
         RELATIONS[Document.PICTURE_TYPE_JPEG] = XWPFRelation.IMAGE_JPEG;
@@ -58,13 +56,13 @@ public class XWPFPictureData extends POIXMLDocumentPart {
         RELATIONS[Document.PICTURE_TYPE_WPG] = XWPFRelation.IMAGE_WPG;
     }
 
-    private Long checksum = null;
-\r
-    /**\r
-     * Create a new XWPFGraphicData node\r
-     */\r
-    protected XWPFPictureData() {\r
-        super();\r
+    private Long checksum;
+
+    /**
+     * Create a new XWPFGraphicData node
+     */
+    protected XWPFPictureData() {
+        super();
     }
 
     /**
@@ -90,13 +88,13 @@ public class XWPFPictureData extends POIXMLDocumentPart {
      * You can grab the picture data directly from the underlying package part as follows:
      * <br/>
      * <code>
-     * InputStream is = getPackagePart().getInputStream();\r
-     * </code>\r
-     * </p>\r
-     *\r
-     * @return the Picture data.\r
-     */\r
-    public byte[] getData() {\r
+     * InputStream is = getPackagePart().getInputStream();
+     * </code>
+     * </p>
+     *
+     * @return the Picture data.
+     */
+    public byte[] getData() {
         try {
             return IOUtils.toByteArray(getPackagePart().getInputStream());
         } catch (IOException e) {
@@ -113,22 +111,22 @@ public class XWPFPictureData extends POIXMLDocumentPart {
         String name = getPackagePart().getPartName().getName();
         return name.substring(name.lastIndexOf('/') + 1);
     }
-\r
-    /**\r
-     * Suggests a file extension for this image.\r
-     *\r
-     * @return the file extension.\r
-     */\r
-    public String suggestFileExtension() {\r
+
+    /**
+     * Suggests a file extension for this image.
+     *
+     * @return the file extension.
+     */
+    public String suggestFileExtension() {
         return getPackagePart().getPartName().getExtension();
     }
-\r
-    /**\r
-     * Return an integer constant that specifies type of this picture\r
-     *\r
-     * @return an integer constant that specifies type of this picture\r
-     * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_EMF\r
-     * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_WMF\r
+
+    /**
+     * Return an integer constant that specifies type of this picture
+     *
+     * @return an integer constant that specifies type of this picture
+     * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_EMF
+     * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_WMF
      * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_PICT
      * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_JPEG
      * @see org.apache.poi.xwpf.usermodel.Document#PICTURE_TYPE_PNG
@@ -171,7 +169,7 @@ public class XWPFPictureData extends POIXMLDocumentPart {
 
     @Override
     public boolean equals(Object obj) {
-        /**
+        /*
          * In case two objects ARE equal, but its not the same instance, this
          * implementation will always run through the whole
          * byte-array-comparison before returning true. If this will turn into a
@@ -216,13 +214,13 @@ public class XWPFPictureData extends POIXMLDocumentPart {
 
                 if (!ownPackage.equals(foreignPackage)) {
                     return false;
-                }\r
-            }\r
-        }\r
-\r
-        Long foreignChecksum = picData.getChecksum();\r
-        Long localChecksum = getChecksum();\r
-\r
+                }
+            }
+        }
+
+        Long foreignChecksum = picData.getChecksum();
+        Long localChecksum = getChecksum();
+
         if (!(localChecksum.equals(foreignChecksum))) {
             return false;
         }
@@ -232,13 +230,13 @@ public class XWPFPictureData extends POIXMLDocumentPart {
     @Override
     public int hashCode() {
         return getChecksum().hashCode();
-    }\r
-\r
-    /**\r
-     * *PictureData objects store the actual content in the part directly without keeping a\r
-     * copy like all others therefore we need to handle them differently.\r
-     */\r
-    @Override\r
+    }
+
+    /**
+     * *PictureData objects store the actual content in the part directly without keeping a
+     * copy like all others therefore we need to handle them differently.
+     */
+    @Override
     protected void prepareForCommit() {
         // do not clear the part here
     }
index 98c2ffb1cdc4fbf7c2dc2737240c07f2bf9e4055..0355a441a150b8e63d9306a91b7fead51bc7caf1 100644 (file)
@@ -17,6 +17,7 @@
    limitations under the License.
    ====================================================================
 -->
+<!--suppress DeprecatedClassUsageInspection -->
 <FindBugsFilter>
        <Match>
                <Bug code="EI,EI2" pattern="CN_IMPLEMENTS_CLONE_BUT_NOT_CLONEABLE,MS_PKGPROTECT,MS_MUTABLE_ARRAY"/>