de.uni_paderborn.tools.util
Class MethodDeclaration

java.lang.Object
  extended byde.uni_paderborn.tools.util.MethodDeclaration

public class MethodDeclaration
extends java.lang.Object

The class MethodDeclaration provides information about a String that declares a method. It tries to parse the provided parameter, that can be a UML-like or a Java-like declarationn (or both). This declaration is not quite the style for instance demanded by the Java Language Specification. But it should help to interpret the user's input as its best.

Version:
$Revision: 1.16 $
Author:
$Author: fklar $

Field Summary
static java.lang.String EMPTY_DECLARATION
          No comment provided by developer, please add a comment to improve documentation.
static java.lang.String ILLEGAL_PARAMETER_AND_RETURN_TYPE_DECLARATION
          No comment provided by developer, please add a comment to improve documentation.
static java.lang.String ILLEGAL_PARAMETER_DECLARATION
          No comment provided by developer, please add a comment to improve documentation.
static java.lang.String ILLEGAL_RETURN_TYPE_DECLARATION
          No comment provided by developer, please add a comment to improve documentation.
static java.lang.String INVALID_METHOD_DECLARATION
          No comment provided by developer, please add a comment to improve documentation.
private  boolean isAbstract
          No comment provided by developer, please add a comment to improve documentation.
private  boolean isFinal
          No comment provided by developer, please add a comment to improve documentation.
private  boolean isNative
          No comment provided by developer, please add a comment to improve documentation.
private  boolean isPackage
          No comment provided by developer, please add a comment to improve documentation.
private  boolean isParsed
          No comment provided by developer, please add a comment to improve documentation.
private  boolean isPrivate
          No comment provided by developer, please add a comment to improve documentation.
private  boolean isProtected
          No comment provided by developer, please add a comment to improve documentation.
private  boolean isPublic
          No comment provided by developer, please add a comment to improve documentation.
private  boolean isStatic
          No comment provided by developer, please add a comment to improve documentation.
private  boolean isSynchronized
          No comment provided by developer, please add a comment to improve documentation.
private  boolean isTransient
          No comment provided by developer, please add a comment to improve documentation.
private  boolean isVolatile
          No comment provided by developer, please add a comment to improve documentation.
static java.lang.String METHOD_IS_KEYWORD
          No comment provided by developer, please add a comment to improve documentation.
private  java.lang.String methodError
          No comment provided by developer, please add a comment to improve documentation.
private  java.lang.String name
          No comment provided by developer, please add a comment to improve documentation.
static java.lang.String NO_METHOD_NAME_DECLARED
          No comment provided by developer, please add a comment to improve documentation.
private  java.lang.String original
          The originally provided String.
private  java.lang.String[] param
          No comment provided by developer, please add a comment to improve documentation.
private  java.lang.String rType
          No comment provided by developer, please add a comment to improve documentation.
static java.lang.String VALID_DECLARATION
          No comment provided by developer, please add a comment to improve documentation.
private  java.lang.String[] var
          No comment provided by developer, please add a comment to improve documentation.
 
Constructor Summary
MethodDeclaration(java.lang.String declaration)
          Creates a new object fo MethodDeclaration and parses the provided String.
 
Method Summary
 java.lang.String getFullName()
          Constructs the full method-name in fujaba-style, so it can be used for a call to UMLMethod#getFromMethods(String); The resulting string looks like: name(type1,type2,type3,...)
 java.lang.String getMethodError()
          Returns the method error, that is an error occured while parsing.
 java.lang.String getName()
          Returns the name of this Declaration.
 java.lang.String[] getParameters()
          Returns the parameters of this Declaration as an array.
 java.lang.String[] getParameterVariables()
          Returns the variable names of the parameters, in the same order as the parameters.
 java.lang.String getReturnType()
          Returns the return type of this Declaration.
 java.lang.String getStatus()
          Returns information about this declaration.
 int getVisibility()
          Get the visibility attribute of the MethodDeclaration object
 boolean isAbstract()
          Returns true if this Declaration is abstract, false otherwise.
 boolean isEmpty()
          Returns true if this MethodDeclaration is empty.
 boolean isFinal()
          Returns true if this Declaration is final, false otherwise.
 boolean isNative()
          Returns true if this Declaration is native, false otherwise.
 boolean isPackage()
          Returns true if this Declaration's visibility is package-wide, false otherwise.
 boolean isPrivate()
          Returns true if this Declaration's visibility is private, false otherwise.
 boolean isProtected()
          Returns true if this Declaration's visibility is protected, false otherwise.
 boolean isPublic()
          Returns true if this Declaration's visibility is public, false otherwise.
 boolean isStatic()
          Returns true if this Declaration is static, false otherwise.
 boolean isSynchronized()
          Returns true if this Declaration is synchronized, false otherwise.
 boolean isTransient()
          Returns true if this Declaration is transient, false otherwise.
 boolean isValid()
          Returns true, if this declaration is valid, NOT considerung parameters or return type.
 boolean isVolatile()
          Returns true if this Declaration is volatile, false otherwise.
private  void parse()
          Calls parseJavaMethod() and parseUMLMethod() in this order.
private  void parseJavaMethod()
          Tries to parse the declaration as a Java-like expression.
private  void parseJavaParam(java.lang.String str)
          Parses the parameters of a java-like-declaration
private  void parseUMLMethod()
          Tries to parse the declaration as an UML-like expression.
private  void parseUMLParam(java.lang.String str)
          Parses the parameters of a UML-like-declaration.
private  boolean setSignifierMethod(java.lang.String str, boolean adjustType)
          Sets all the signifiers by examining the String str.
 void showStatus()
          Shows the status provided by getStatus() in a JOptionPane.
static java.lang.String userReadableSignature(UMLMethod method)
          No comment provided by developer, please add a comment to improve documentation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALID_DECLARATION

public static final java.lang.String VALID_DECLARATION
No comment provided by developer, please add a comment to improve documentation.

See Also:
Constant Field Values

EMPTY_DECLARATION

public static final java.lang.String EMPTY_DECLARATION
No comment provided by developer, please add a comment to improve documentation.

See Also:
Constant Field Values

INVALID_METHOD_DECLARATION

public static final java.lang.String INVALID_METHOD_DECLARATION
No comment provided by developer, please add a comment to improve documentation.

See Also:
Constant Field Values

NO_METHOD_NAME_DECLARED

public static final java.lang.String NO_METHOD_NAME_DECLARED
No comment provided by developer, please add a comment to improve documentation.

See Also:
Constant Field Values

METHOD_IS_KEYWORD

public static final java.lang.String METHOD_IS_KEYWORD
No comment provided by developer, please add a comment to improve documentation.

See Also:
Constant Field Values

ILLEGAL_RETURN_TYPE_DECLARATION

public static final java.lang.String ILLEGAL_RETURN_TYPE_DECLARATION
No comment provided by developer, please add a comment to improve documentation.

See Also:
Constant Field Values

ILLEGAL_PARAMETER_DECLARATION

public static final java.lang.String ILLEGAL_PARAMETER_DECLARATION
No comment provided by developer, please add a comment to improve documentation.

See Also:
Constant Field Values

ILLEGAL_PARAMETER_AND_RETURN_TYPE_DECLARATION

public static final java.lang.String ILLEGAL_PARAMETER_AND_RETURN_TYPE_DECLARATION
No comment provided by developer, please add a comment to improve documentation.

See Also:
Constant Field Values

original

private java.lang.String original
The originally provided String.


methodError

private java.lang.String methodError
No comment provided by developer, please add a comment to improve documentation.


isParsed

private boolean isParsed
No comment provided by developer, please add a comment to improve documentation.


isPublic

private boolean isPublic
No comment provided by developer, please add a comment to improve documentation.


isPackage

private boolean isPackage
No comment provided by developer, please add a comment to improve documentation.


isProtected

private boolean isProtected
No comment provided by developer, please add a comment to improve documentation.


isPrivate

private boolean isPrivate
No comment provided by developer, please add a comment to improve documentation.


isFinal

private boolean isFinal
No comment provided by developer, please add a comment to improve documentation.


isAbstract

private boolean isAbstract
No comment provided by developer, please add a comment to improve documentation.


isStatic

private boolean isStatic
No comment provided by developer, please add a comment to improve documentation.


isSynchronized

private boolean isSynchronized
No comment provided by developer, please add a comment to improve documentation.


isTransient

private boolean isTransient
No comment provided by developer, please add a comment to improve documentation.


isVolatile

private boolean isVolatile
No comment provided by developer, please add a comment to improve documentation.


isNative

private boolean isNative
No comment provided by developer, please add a comment to improve documentation.


name

private java.lang.String name
No comment provided by developer, please add a comment to improve documentation.


rType

private java.lang.String rType
No comment provided by developer, please add a comment to improve documentation.


param

private java.lang.String[] param
No comment provided by developer, please add a comment to improve documentation.


var

private java.lang.String[] var
No comment provided by developer, please add a comment to improve documentation.

Constructor Detail

MethodDeclaration

public MethodDeclaration(java.lang.String declaration)
Creates a new object fo MethodDeclaration and parses the provided String.

Parameters:
declaration - The String to be a method declaration.
Throws:
NullPointerException, - if declaration is null.
Method Detail

parse

private void parse()
Calls parseJavaMethod() and parseUMLMethod() in this order.


parseJavaMethod

private void parseJavaMethod()
Tries to parse the declaration as a Java-like expression. A Java-like expression consists NOT of a grammatical correct expression as defined in the Java Specification Language. The following expressions are to be considered as Java-like-correct (spaces between parenthesis and other expressions are meaningless except square brackets indicating an array, which have to follow right after the type with no spaces between):

DECLARATION LITERAL EXAMPLE method_name_only doSomething method_name parenthesis doSomething () method_name parenthesis_with_parameter(s) doSomething (int, String) method_name parenthesis semicolon doSomething (); method_name parenthesis_with_parameter(s) semicolon doSomething (int, String); signifier(s) method_name public (static ...) doSomething method_name parenthesis semicolon doSomething (); method_name parenthesis_with_parameter(s) semicolon doSomething (int, String); signifier(s) method_name parenthesis semicolon public (static ...) doSomething (); signifier(s) method_name parenthesis_with_parameter(s) semicolon public (static ...) doSomething (int, String); return_type method_name void doSomething return_type method_name parenthesis void doSomething () return_type method_name parenthesis_with_parameter(s) void doSomething (int, String) return_type method_name parenthesis semicolon void doSomething (); return_type method_name parenthesis_with_parameter(s) semicolon void doSomething (int, String); signifier(s) return_type method_name public (static ...) void doSomething signifier(s) return_type method_name parenthesis public (static ...) void doSomething () signifier(s) return_type method_name parenthesis_with_parameter(s) public (static ...) void doSomething (int, String) signifier(s) return_type method_name parenthesis semicolon public (static ...) void doSomething (); signifier(s) return_type method_name parenthesis_with_parameter(s) semicolon public (static ...) void doSomething (int, String);

Parameters have to be divided by komma, otherwise they won't be recognized. You can provide different types only, or even a type with a variable.
When the method name is a Java keyword this declaration is invalid. Note:
Since you cannot define a package visible method explicitly (when making no specifications like in Java itself, the visibility will be ignored here), here it is allowed to write the keyword 'package' as visibility type.


parseUMLMethod

private void parseUMLMethod()
Tries to parse the declaration as an UML-like expression. Since UML is graphically oriented, this UML-like declaration referres to the text-presentation of methods. The following expressions are to be considered as UML-like-correct (spaces between parenthesis and other expressions, between visibility and method name or between colon and other expressions are meaningless, except square brackets indicating an array, which have to follow right after the type with no spaces between):

DECLARATION LITERAL EXAMPLE method_name_only doSomething method_name return_type doSomething : int visibility method_name + doSomething visibility method_name return_type + doSomething : int method_name parenthesis doSomething () method_name parenthesis return_type doSomething () : int method_name parenthesis parameter(s) doSomething (int, String) method_name parenthesis parameter(s) return_type doSomething (int, String):int visibility method_name parenthesis + doSomething () visibility method_name parenthesisb return_type + doSomething ():int visibility method_name parenthesis parameter(s) + doSomething (int, String) visibility method_name parenthesis parameter(s) return_type + doSomething (int, String):int Parameters have to be divided by komma or semicolon, otherwise they won't be recognized. You can provide different types only, or even a type with a variable.
When the method name is a Java keyword this declaration is invalid.


parseUMLParam

private void parseUMLParam(java.lang.String str)
Parses the parameters of a UML-like-declaration.

Parameters:
str - No description provided

parseJavaParam

private void parseJavaParam(java.lang.String str)
Parses the parameters of a java-like-declaration

Parameters:
str - No description provided

getName

public java.lang.String getName()
Returns the name of this Declaration.

Returns:
The name value

getFullName

public java.lang.String getFullName()
Constructs the full method-name in fujaba-style, so it can be used for a call to UMLMethod#getFromMethods(String);
 The resulting string looks like:
   name(type1,type2,type3,...)
 where type is a name without preceeding packagename
 e.g.
   parseJavaParam(String)
 

Returns:
The full method-name.

getReturnType

public java.lang.String getReturnType()
Returns the return type of this Declaration. If no return type is defined, an empty String will be returned.

Returns:
The returnType value

getParameters

public java.lang.String[] getParameters()
Returns the parameters of this Declaration as an array. If there are no parameters, an array with length 0 will be returned.

Returns:
The parameters value

getParameterVariables

public java.lang.String[] getParameterVariables()
Returns the variable names of the parameters, in the same order as the parameters. If a parameter has no variable, an empty String is provided in this case. The returned array is exact as long as the array containing the parameters.

Returns:
The parameterVariables value

getStatus

public java.lang.String getStatus()
Returns information about this declaration. These information contain:
  • the name of the Declaration
  • the type of the Declaration
  • the visibility of this Declaration (if defined)
  • the return type (if defined)
  • the parameters and their variables (if defined)
The String is formatted to be shown best with a JOptionPane. Use showStatus() to do this.

Returns:
The status value

showStatus

public void showStatus()
Shows the status provided by getStatus() in a JOptionPane.


getMethodError

public java.lang.String getMethodError()
Returns the method error, that is an error occured while parsing. If no error occured an appropriate message is returned.

Returns:
The methodError value

getVisibility

public int getVisibility()
Get the visibility attribute of the MethodDeclaration object

Returns:
The visibility value

isPublic

public boolean isPublic()
Returns true if this Declaration's visibility is public, false otherwise.

Returns:
The public value

isPackage

public boolean isPackage()
Returns true if this Declaration's visibility is package-wide, false otherwise.

Returns:
The package value

isProtected

public boolean isProtected()
Returns true if this Declaration's visibility is protected, false otherwise.

Returns:
The protected value

isPrivate

public boolean isPrivate()
Returns true if this Declaration's visibility is private, false otherwise.

Returns:
The private value

isFinal

public boolean isFinal()
Returns true if this Declaration is final, false otherwise.

Returns:
The final value

isAbstract

public boolean isAbstract()
Returns true if this Declaration is abstract, false otherwise.

Returns:
The abstract value

isStatic

public boolean isStatic()
Returns true if this Declaration is static, false otherwise.

Returns:
The static value

isSynchronized

public boolean isSynchronized()
Returns true if this Declaration is synchronized, false otherwise.

Returns:
The synchronized value

isTransient

public boolean isTransient()
Returns true if this Declaration is transient, false otherwise.

Returns:
The transient value

isVolatile

public boolean isVolatile()
Returns true if this Declaration is volatile, false otherwise.

Returns:
The volatile value

isNative

public boolean isNative()
Returns true if this Declaration is native, false otherwise.

Returns:
The native value

isEmpty

public boolean isEmpty()
Returns true if this MethodDeclaration is empty.

Returns:
The empty value

setSignifierMethod

private boolean setSignifierMethod(java.lang.String str,
                                   boolean adjustType)
Sets all the signifiers by examining the String str. For instance, if str is "public" the variable isPublic will be set to true, but only if e. g. isPrivate is NOT set to true. If a conflict occurs in that way, the boolean variable "adjustType" decides, if the variable type will be set to type &= ~METHOD. Thus, if adjustType is true, the type will be adjusted, otherwise no type changes will be done. Returns true if, and only if one of the signifiers could be set without any ambiguity or error. It returns false if an error has occured or nothing could be changed because the given String was not a signifier.

Parameters:
str - The new signifierMethod value
adjustType - The new signifierMethod value
Returns:
No description provided

isValid

public boolean isValid()
Returns true, if this declaration is valid, NOT considerung parameters or return type. An empty declaration is not valid.

Returns:
The valid value

userReadableSignature

public static java.lang.String userReadableSignature(UMLMethod method)
No comment provided by developer, please add a comment to improve documentation.

Parameters:
method - No description provided
Returns:
No description provided