From df9ff7f340a5ab4e07efc613f5f264eeae63d4c7 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 3 Jul 2014 16:06:47 +0200 Subject: Code Clean-Up based on our Recommended Settings (jogamp-scripting c47bc86ae2ee268a1f38c5580d11f93d7f8d6e74) Code Clean-Up based on our Recommended Settings (jogamp-scripting c47bc86ae2ee268a1f38c5580d11f93d7f8d6e74) - Change non static accesses to static members using declaring type - Change indirect accesses to static members to direct accesses (accesses through subtypes) - Add final modifier to private fields - Add final modifier to method parameters - Add final modifier to local variables - Remove unnecessary casts - Remove unnecessary '$NON-NLS$' tags - Remove trailing white spaces on all lines --- src/java/jogamp/common/os/elf/Ehdr.java | 36 ++++++++++------------ src/java/jogamp/common/os/elf/ElfHeader.java | 14 ++++----- src/java/jogamp/common/os/elf/IOUtils.java | 14 ++++----- src/java/jogamp/common/os/elf/Section.java | 2 +- .../jogamp/common/os/elf/SectionArmAttributes.java | 24 +++++++-------- src/java/jogamp/common/os/elf/SectionHeader.java | 12 ++++---- src/java/jogamp/common/os/elf/Shdr.java | 28 ++++++++--------- 7 files changed, 61 insertions(+), 69 deletions(-) (limited to 'src/java/jogamp/common/os/elf') diff --git a/src/java/jogamp/common/os/elf/Ehdr.java b/src/java/jogamp/common/os/elf/Ehdr.java index d787f67..e12ef4f 100644 --- a/src/java/jogamp/common/os/elf/Ehdr.java +++ b/src/java/jogamp/common/os/elf/Ehdr.java @@ -3,10 +3,6 @@ package jogamp.common.os.elf; -import java.nio.*; - -import com.jogamp.gluegen.runtime.*; -import com.jogamp.common.os.*; import com.jogamp.common.nio.*; import jogamp.common.os.MachineDescriptionRuntime; @@ -41,11 +37,11 @@ public class Ehdr { return create(Buffers.newDirectByteBuffer(size())); } - public static Ehdr create(java.nio.ByteBuffer buf) { + public static Ehdr create(final java.nio.ByteBuffer buf) { return new Ehdr(buf); } - Ehdr(java.nio.ByteBuffer buf) { + Ehdr(final java.nio.ByteBuffer buf) { accessor = new StructAccessor(buf); } @@ -53,14 +49,14 @@ public class Ehdr { return accessor.getBuffer(); } - public Ehdr setE_ident(byte[] val) { + public Ehdr setE_ident(final byte[] val) { accessor.setBytesAt(e_ident_offset[mdIdx], val); return this; } public byte[] getE_ident() { return accessor.getBytesAt(e_ident_offset[mdIdx], new byte[16]); } - public Ehdr setE_type(short val) { + public Ehdr setE_type(final short val) { accessor.setShortAt(e_type_offset[mdIdx], val); return this; } @@ -69,7 +65,7 @@ public class Ehdr { return accessor.getShortAt(e_type_offset[mdIdx]); } - public Ehdr setE_machine(short val) { + public Ehdr setE_machine(final short val) { accessor.setShortAt(e_machine_offset[mdIdx], val); return this; } @@ -78,7 +74,7 @@ public class Ehdr { return accessor.getShortAt(e_machine_offset[mdIdx]); } - public Ehdr setE_version(int val) { + public Ehdr setE_version(final int val) { accessor.setIntAt(e_version_offset[mdIdx], val); return this; } @@ -87,7 +83,7 @@ public class Ehdr { return accessor.getIntAt(e_version_offset[mdIdx]); } - public Ehdr setE_entry(long val) { + public Ehdr setE_entry(final long val) { accessor.setLongAt(e_entry_offset[mdIdx], val, MachineDescriptionRuntime.getStatic().md.longSizeInBytes()); return this; } @@ -96,7 +92,7 @@ public class Ehdr { return accessor.getLongAt(e_entry_offset[mdIdx], MachineDescriptionRuntime.getStatic().md.longSizeInBytes()); } - public Ehdr setE_phoff(long val) { + public Ehdr setE_phoff(final long val) { accessor.setLongAt(e_phoff_offset[mdIdx], val, MachineDescriptionRuntime.getStatic().md.longSizeInBytes()); return this; } @@ -105,7 +101,7 @@ public class Ehdr { return accessor.getLongAt(e_phoff_offset[mdIdx], MachineDescriptionRuntime.getStatic().md.longSizeInBytes()); } - public Ehdr setE_shoff(long val) { + public Ehdr setE_shoff(final long val) { accessor.setLongAt(e_shoff_offset[mdIdx], val, MachineDescriptionRuntime.getStatic().md.longSizeInBytes()); return this; } @@ -114,7 +110,7 @@ public class Ehdr { return accessor.getLongAt(e_shoff_offset[mdIdx], MachineDescriptionRuntime.getStatic().md.longSizeInBytes()); } - public Ehdr setE_flags(int val) { + public Ehdr setE_flags(final int val) { accessor.setIntAt(e_flags_offset[mdIdx], val); return this; } @@ -123,7 +119,7 @@ public class Ehdr { return accessor.getIntAt(e_flags_offset[mdIdx]); } - public Ehdr setE_ehsize(short val) { + public Ehdr setE_ehsize(final short val) { accessor.setShortAt(e_ehsize_offset[mdIdx], val); return this; } @@ -132,7 +128,7 @@ public class Ehdr { return accessor.getShortAt(e_ehsize_offset[mdIdx]); } - public Ehdr setE_phentsize(short val) { + public Ehdr setE_phentsize(final short val) { accessor.setShortAt(e_phentsize_offset[mdIdx], val); return this; } @@ -141,7 +137,7 @@ public class Ehdr { return accessor.getShortAt(e_phentsize_offset[mdIdx]); } - public Ehdr setE_phnum(short val) { + public Ehdr setE_phnum(final short val) { accessor.setShortAt(e_phnum_offset[mdIdx], val); return this; } @@ -150,7 +146,7 @@ public class Ehdr { return accessor.getShortAt(e_phnum_offset[mdIdx]); } - public Ehdr setE_shentsize(short val) { + public Ehdr setE_shentsize(final short val) { accessor.setShortAt(e_shentsize_offset[mdIdx], val); return this; } @@ -159,7 +155,7 @@ public class Ehdr { return accessor.getShortAt(e_shentsize_offset[mdIdx]); } - public Ehdr setE_shnum(short val) { + public Ehdr setE_shnum(final short val) { accessor.setShortAt(e_shnum_offset[mdIdx], val); return this; } @@ -168,7 +164,7 @@ public class Ehdr { return accessor.getShortAt(e_shnum_offset[mdIdx]); } - public Ehdr setE_shstrndx(short val) { + public Ehdr setE_shstrndx(final short val) { accessor.setShortAt(e_shstrndx_offset[mdIdx], val); return this; } diff --git a/src/java/jogamp/common/os/elf/ElfHeader.java b/src/java/jogamp/common/os/elf/ElfHeader.java index f12ccad..3447107 100644 --- a/src/java/jogamp/common/os/elf/ElfHeader.java +++ b/src/java/jogamp/common/os/elf/ElfHeader.java @@ -358,7 +358,7 @@ public class ElfHeader { public static final short EM_MICROBLAZE = 189; public static final short EM_CUDA = 190; - public static final boolean isIdentityValid(byte[] ident) { + public static final boolean isIdentityValid(final byte[] ident) { return ELFMAG0 == ident[0] && ELFMAG1 == ident[1] && ELFMAG2 == ident[2] && @@ -381,7 +381,7 @@ public class ElfHeader { * @throws IOException if reading from the given input stream fails or less then ELF Header size bytes * @throws IllegalArgumentException if the given input stream does not represent an ELF Header */ - public static ElfHeader read(RandomAccessFile in) throws IOException, IllegalArgumentException { + public static ElfHeader read(final RandomAccessFile in) throws IOException, IllegalArgumentException { final int eh_sz = Ehdr.size(); final byte[] buf = new byte[eh_sz]; readBytes (in, buf, 0, eh_sz); @@ -394,7 +394,7 @@ public class ElfHeader { * @throws IllegalArgumentException if the given buffer does not represent an ELF Header * @throws IOException */ - ElfHeader(java.nio.ByteBuffer buf, RandomAccessFile in) throws IllegalArgumentException, IOException { + ElfHeader(final java.nio.ByteBuffer buf, final RandomAccessFile in) throws IllegalArgumentException, IOException { d = Ehdr.create(buf); if( !isIdentityValid(d.getE_ident()) ) { throw new IllegalArgumentException("Buffer is not an ELF Header"); @@ -530,7 +530,7 @@ public class ElfHeader { } /** Returns the 1st occurence of matching SectionHeader {@link SectionHeader#getType() type}, or null if not exists. */ - public final SectionHeader getSectionHeader(int type) { + public final SectionHeader getSectionHeader(final int type) { for(int i=0; i= num ) { throw new IllegalArgumentException("EHdr sh_num == 0 and 1st SHdr size == 0"); diff --git a/src/java/jogamp/common/os/elf/IOUtils.java b/src/java/jogamp/common/os/elf/IOUtils.java index 57b7a48..62b47db 100644 --- a/src/java/jogamp/common/os/elf/IOUtils.java +++ b/src/java/jogamp/common/os/elf/IOUtils.java @@ -36,11 +36,11 @@ import com.jogamp.common.util.Bitstream; class IOUtils { static final long MAX_INT_VALUE = ( Integer.MAX_VALUE & 0xffffffffL ) ; - static String toHexString(int i) { return "0x"+Integer.toHexString(i); } + static String toHexString(final int i) { return "0x"+Integer.toHexString(i); } - static String toHexString(long i) { return "0x"+Long.toHexString(i); } + static String toHexString(final long i) { return "0x"+Long.toHexString(i); } - static int shortToInt(short s) { + static int shortToInt(final short s) { return s & 0x0000ffff; } @@ -57,7 +57,7 @@ class IOUtils { in.readFully(out, offset, len); } - static void seek(final RandomAccessFile in, long newPos) throws IOException { + static void seek(final RandomAccessFile in, final long newPos) throws IOException { in.seek(newPos); } @@ -83,7 +83,7 @@ class IOUtils { * @return the parsed string * @throws IndexOutOfBoundsException if offset + remaining > sb.length. */ - static String getString(final byte[] sb, final int offset, final int remaining, int[] offset_post) throws IndexOutOfBoundsException { + static String getString(final byte[] sb, final int offset, final int remaining, final int[] offset_post) throws IndexOutOfBoundsException { Bitstream.checkBounds(sb, offset, remaining); int strlen = 0; for(; strlen < remaining && sb[strlen + offset] != 0; strlen++) { } @@ -102,7 +102,7 @@ class IOUtils { * @return the number of parsed strings * @throws IndexOutOfBoundsException if offset + remaining > sb.length. */ - static int getStringCount(final byte[] sb, int offset, final int remaining) throws IndexOutOfBoundsException { + static int getStringCount(final byte[] sb, final int offset, final int remaining) throws IndexOutOfBoundsException { Bitstream.checkBounds(sb, offset, remaining); int strnum=0; for(int i=0; i < remaining; i++) { @@ -120,7 +120,7 @@ class IOUtils { * @return the parsed strings * @throws IndexOutOfBoundsException if offset + remaining > sb.length. */ - public static String[] getStrings(final byte[] sb, int offset, final int remaining) throws IndexOutOfBoundsException { + public static String[] getStrings(final byte[] sb, final int offset, final int remaining) throws IndexOutOfBoundsException { final int strnum = getStringCount(sb, offset, remaining); // System.err.println("XXX: strnum "+strnum+", sb_off "+sb_off+", sb_len "+sb_len); diff --git a/src/java/jogamp/common/os/elf/Section.java b/src/java/jogamp/common/os/elf/Section.java index 01dc62b..29dc209 100644 --- a/src/java/jogamp/common/os/elf/Section.java +++ b/src/java/jogamp/common/os/elf/Section.java @@ -33,7 +33,7 @@ public class Section { public int offset; public int length; - Section(SectionHeader sh, byte[] data, int offset, int length) { + Section(final SectionHeader sh, final byte[] data, final int offset, final int length) { this.sh = sh; this.data = data; this.offset = offset; diff --git a/src/java/jogamp/common/os/elf/SectionArmAttributes.java b/src/java/jogamp/common/os/elf/SectionArmAttributes.java index db6710a..91e8c31 100644 --- a/src/java/jogamp/common/os/elf/SectionArmAttributes.java +++ b/src/java/jogamp/common/os/elf/SectionArmAttributes.java @@ -48,7 +48,7 @@ public class SectionArmAttributes extends Section { * Returns true if value is either {@link #ABI_VFP_ARGS_IS_VFP_VARIANT} or {@link #ABI_VFP_ARGS_IS_BOTH_BASE_AND_VFP_VARIANT} * @param v ULEB128 Value from {@link Tag#ABI_VFP_args} attribute */ - public static final boolean abiVFPArgsAcceptsVFPVariant(byte v) { + public static final boolean abiVFPArgsAcceptsVFPVariant(final byte v) { return ABI_VFP_ARGS_IS_VFP_VARIANT == v || ABI_VFP_ARGS_IS_BOTH_BASE_AND_VFP_VARIANT == v; } @@ -113,7 +113,7 @@ public class SectionArmAttributes extends Section { return null; } - Tag(int id, Type type){ + Tag(final int id, final Type type){ this.id = id; this.type = type; } @@ -123,7 +123,7 @@ public class SectionArmAttributes extends Section { public final Tag tag; private final Object value; - Attribute(Tag tag, Object value) { + Attribute(final Tag tag, final Object value) { this.tag = tag; this.value = value; } @@ -158,7 +158,7 @@ public class SectionArmAttributes extends Section { public final String vendor; public final List attributes; - VendorAttributes(String vendor, List attributes) { + VendorAttributes(final String vendor, final List attributes) { this.vendor = vendor; this.attributes = attributes; } @@ -170,7 +170,7 @@ public class SectionArmAttributes extends Section { } public final List vendorAttributesList; - SectionArmAttributes(SectionHeader sh, byte[] data, int offset, int length) throws IndexOutOfBoundsException, IllegalArgumentException { + SectionArmAttributes(final SectionHeader sh, final byte[] data, final int offset, final int length) throws IndexOutOfBoundsException, IllegalArgumentException { super(sh, data, offset, length); this.vendorAttributesList = parse(data, offset, length); } @@ -180,7 +180,7 @@ public class SectionArmAttributes extends Section { return "SectionArmAttributes["+super.toSubString()+", "+vendorAttributesList.toString()+"]"; } - public final Attribute get(Tag tag) { + public final Attribute get(final Tag tag) { for(int i=0; i attributes = vendorAttributesList.get(i).attributes; for(int j=0; j get(String vendor) { + public final List get(final String vendor) { return get(vendorAttributesList, vendor); } - static final List get(final List vendorAttributesList, String vendor) { + static final List get(final List vendorAttributesList, final String vendor) { for(int i=0; i attributes = new ArrayList(); while(i < secLen) { - int[] i_post = new int[] { 0 }; + final int[] i_post = new int[] { 0 }; parseSub(in, i, secLen - i, i_post, attributes); i = i_post[0]; } @@ -268,7 +268,7 @@ public class SectionArmAttributes extends Section { * @throws IndexOutOfBoundsException if offset + remaining > sb.length. * @throws IllegalArgumentException if section parsing failed, i.e. incompatible version or data. */ - static void parseSub(final byte[] in, final int offset, final int remaining, int[] offset_post, List attributes) throws IndexOutOfBoundsException, IllegalArgumentException { + static void parseSub(final byte[] in, final int offset, final int remaining, final int[] offset_post, final List attributes) throws IndexOutOfBoundsException, IllegalArgumentException { Bitstream.checkBounds(in, offset, remaining); // Starts w/ sub-section Tag @@ -299,7 +299,7 @@ public class SectionArmAttributes extends Section { switch(tag.type) { case NTBS: { - int[] i_post = new int[] { 0 }; + final int[] i_post = new int[] { 0 }; final String value = getString(in, i, subSecLen + offset - i, i_post); attributes.add(new Attribute(tag, value)); i = i_post[0]; diff --git a/src/java/jogamp/common/os/elf/SectionHeader.java b/src/java/jogamp/common/os/elf/SectionHeader.java index 8a83b61..20a40a5 100644 --- a/src/java/jogamp/common/os/elf/SectionHeader.java +++ b/src/java/jogamp/common/os/elf/SectionHeader.java @@ -174,13 +174,13 @@ public class SectionHeader { /** Public access to the raw elf section header */ public final Shdr d; - private int idx; + private final int idx; private String name; - SectionHeader(byte[] buf, int offset, int length, int sectionIdx) { + SectionHeader(final byte[] buf, final int offset, final int length, final int sectionIdx) { this( ByteBuffer.wrap(buf, 0, buf.length), sectionIdx ); } - SectionHeader(java.nio.ByteBuffer buf, int idx) { + SectionHeader(final java.nio.ByteBuffer buf, final int idx) { d = Shdr.create(buf); this.idx = idx; name = null; @@ -231,7 +231,7 @@ public class SectionHeader { * @throws IOException if read error occurs * @throws IllegalArgumentException if section offset or size mismatch including size > {@link Integer#MAX_VALUE} */ - public Section readSection(RandomAccessFile in) throws IOException, IllegalArgumentException { + public Section readSection(final RandomAccessFile in) throws IOException, IllegalArgumentException { final int s_size = long2Int(d.getSh_size()); if( 0 == s_size || 0 > s_size ) { throw new IllegalArgumentException("Shdr["+idx+"] has invalid int size: "+d.getSh_size()+" -> "+s_size); @@ -251,7 +251,7 @@ public class SectionHeader { * @throws IllegalArgumentException if section offset or size mismatch including size > {@link Integer#MAX_VALUE} * @throws IllegalArgumentException if requested read length is > section size */ - public Section readSection(RandomAccessFile in, byte[] b, int b_off, int r_len) throws IOException, IllegalArgumentException { + public Section readSection(final RandomAccessFile in, final byte[] b, final int b_off, final int r_len) throws IOException, IllegalArgumentException { final int s_size = long2Int(d.getSh_size()); if( 0 == s_size || 0 > s_size ) { throw new IllegalArgumentException("Shdr["+idx+"] has invalid int size: "+d.getSh_size()+" -> "+s_size); @@ -262,7 +262,7 @@ public class SectionHeader { return readSectionImpl(in, b, b_off, r_len); } - Section readSectionImpl(RandomAccessFile in, byte[] b, int b_off, int r_len) throws IOException, IllegalArgumentException { + Section readSectionImpl(final RandomAccessFile in, final byte[] b, final int b_off, final int r_len) throws IOException, IllegalArgumentException { final long s_off = d.getSh_offset(); seek(in, s_off); readBytes(in, b, b_off, r_len); diff --git a/src/java/jogamp/common/os/elf/Shdr.java b/src/java/jogamp/common/os/elf/Shdr.java index 5465b3d..d31aec2 100644 --- a/src/java/jogamp/common/os/elf/Shdr.java +++ b/src/java/jogamp/common/os/elf/Shdr.java @@ -3,10 +3,6 @@ package jogamp.common.os.elf; -import java.nio.*; - -import com.jogamp.gluegen.runtime.*; -import com.jogamp.common.os.*; import com.jogamp.common.nio.*; import jogamp.common.os.MachineDescriptionRuntime; @@ -37,11 +33,11 @@ public class Shdr { return create(Buffers.newDirectByteBuffer(size())); } - public static Shdr create(java.nio.ByteBuffer buf) { + public static Shdr create(final java.nio.ByteBuffer buf) { return new Shdr(buf); } - Shdr(java.nio.ByteBuffer buf) { + Shdr(final java.nio.ByteBuffer buf) { accessor = new StructAccessor(buf); } @@ -49,7 +45,7 @@ public class Shdr { return accessor.getBuffer(); } - public Shdr setSh_name(int val) { + public Shdr setSh_name(final int val) { accessor.setIntAt(sh_name_offset[mdIdx], val); return this; } @@ -58,7 +54,7 @@ public class Shdr { return accessor.getIntAt(sh_name_offset[mdIdx]); } - public Shdr setSh_type(int val) { + public Shdr setSh_type(final int val) { accessor.setIntAt(sh_type_offset[mdIdx], val); return this; } @@ -67,7 +63,7 @@ public class Shdr { return accessor.getIntAt(sh_type_offset[mdIdx]); } - public Shdr setSh_flags(long val) { + public Shdr setSh_flags(final long val) { accessor.setLongAt(sh_flags_offset[mdIdx], val, MachineDescriptionRuntime.getStatic().md.longSizeInBytes()); return this; } @@ -76,7 +72,7 @@ public class Shdr { return accessor.getLongAt(sh_flags_offset[mdIdx], MachineDescriptionRuntime.getStatic().md.longSizeInBytes()); } - public Shdr setSh_addr(long val) { + public Shdr setSh_addr(final long val) { accessor.setLongAt(sh_addr_offset[mdIdx], val, MachineDescriptionRuntime.getStatic().md.longSizeInBytes()); return this; } @@ -85,7 +81,7 @@ public class Shdr { return accessor.getLongAt(sh_addr_offset[mdIdx], MachineDescriptionRuntime.getStatic().md.longSizeInBytes()); } - public Shdr setSh_offset(long val) { + public Shdr setSh_offset(final long val) { accessor.setLongAt(sh_offset_offset[mdIdx], val, MachineDescriptionRuntime.getStatic().md.longSizeInBytes()); return this; } @@ -94,7 +90,7 @@ public class Shdr { return accessor.getLongAt(sh_offset_offset[mdIdx], MachineDescriptionRuntime.getStatic().md.longSizeInBytes()); } - public Shdr setSh_size(long val) { + public Shdr setSh_size(final long val) { accessor.setLongAt(sh_size_offset[mdIdx], val, MachineDescriptionRuntime.getStatic().md.longSizeInBytes()); return this; } @@ -103,7 +99,7 @@ public class Shdr { return accessor.getLongAt(sh_size_offset[mdIdx], MachineDescriptionRuntime.getStatic().md.longSizeInBytes()); } - public Shdr setSh_link(int val) { + public Shdr setSh_link(final int val) { accessor.setIntAt(sh_link_offset[mdIdx], val); return this; } @@ -112,7 +108,7 @@ public class Shdr { return accessor.getIntAt(sh_link_offset[mdIdx]); } - public Shdr setSh_info(int val) { + public Shdr setSh_info(final int val) { accessor.setIntAt(sh_info_offset[mdIdx], val); return this; } @@ -121,7 +117,7 @@ public class Shdr { return accessor.getIntAt(sh_info_offset[mdIdx]); } - public Shdr setSh_addralign(long val) { + public Shdr setSh_addralign(final long val) { accessor.setLongAt(sh_addralign_offset[mdIdx], val, MachineDescriptionRuntime.getStatic().md.longSizeInBytes()); return this; } @@ -130,7 +126,7 @@ public class Shdr { return accessor.getLongAt(sh_addralign_offset[mdIdx], MachineDescriptionRuntime.getStatic().md.longSizeInBytes()); } - public Shdr setSh_entsize(long val) { + public Shdr setSh_entsize(final long val) { accessor.setLongAt(sh_entsize_offset[mdIdx], val, MachineDescriptionRuntime.getStatic().md.longSizeInBytes()); return this; } -- cgit v1.2.3