Class ExploreClass

From Ssdlpedia

Jump to: navigation, search

Contents

[edit] Synopsis of Class ExploreClass

public class ExploreClass { 
    /*
     * Forge (1)
     */
        ExploreClass(); 
    /*
     * Utilities (1)
     */
        static void main(String[] args) throws ClassNotFoundException; 
} 


Exception types: ClassNotFoundException.

[edit] Code

// SSDLPedia
package il.ac.technion.cs.cs236700.classfile;

import il.ac.technion.cs.ssdl.files.CLASSFILES;
import il.ac.technion.cs.ssdl.stereotypes.Application;

import java.io.IOException;
import java.io.InputStream;

/**
 * A small application demonstrating the constants' pool can be printed.
 * 
 * Author: Yossi Gil, the Technion.
 * 
 * See:  06/08/2008
 */
@Application public class ExploreClass {
    /**
     * Search for classes in the usual Java search path (JRE, Java extensions,
     * and then the classpath), and prints the constant pool onto
     * System.out.
     * 
     * args full names of Java classes to print
     * ClassNotFoundException in case the corresponding Class
     *             object could not be found
     */
    public static void main(final String[] args) throws ClassNotFoundException {
        if (args.length == 0)
            System.out.println("Usage: java ExploreClass className(s)");
        for (int i = 0; i < args.length; i++)
            explore(args[i]);
    }
    
    /**
     * Print out information
     * 
     * className full name of a class to explore
     * ClassNotFoundException in case the corresponding Class
     *             object could not be found
     */
    private static void explore(final String className) throws ClassNotFoundException {
        InputStream is = null;
        try {
            is = CLASSFILES.find(className);
            if (is == null)
                throw new ClassNotFoundException(className);
            printConstantPool(new Pool(is));
        } catch (final IOException e) {
            System.out.println(e);
        } finally {
            try {
                if (is != null)
                    is.close();
            } catch (final IOException _) {
                // so, close failed, so what?
            }
        }
    }
    
    /**
     * Print a constants pool
     * 
     * p a constant pool to print
     */
    private static void printConstantPool(final Pool p) {
        for (int i = 1; i < p.pool.length; i++)
            System.out.println(i + "/" + (p.pool.length - 1) + ": " + p.pool[i].typeName() + ": " + p.pool[i]);
    }
}

[edit] Metrics

MetricValueAcronymExplanation
LOC70Lines Of CodeTotal number of lines in the code
SCC18SemiColons CountTotal number of semicolon tokens found in the code.
NOT286Number Of TokensComments, whitespace and text which cannot be made into a token not included.
VCC1592Visible Characters CountThe total number of non-white (i.e., not space, tab, newline, carriage return, form feed) characters.
CCC910Code Characters CountTotal number of non-white characters in tokens. White space characters in string and character literals are not counted.
UIC37Unique Identifiers CountThe number of different identifiers found in the code
WHC4Weighted Horizontal ComplexityA heuritistic on horizontal complexity

[edit] Statistics

StatiticValue
Average token length 3.2
Tokens/line 4.1
Visible characters/line 23
Code characters/line 13
Semicolons/tokens6%
Comment text percentage42%

[edit] Tokens by Kind

Token KindOccurrences
KEYWORD41
OPERATOR18
LITERAL8
ID95
PUNCTUATION124
COMMENT6
OTHER131
Personal tools