<s> package org . eclipse . jdt . core ; import org . eclipse . jdt . core . compiler . CharOperation ; import org . eclipse . jdt . internal . compiler . parser . ScannerHelper ; import org . eclipse . jdt . internal . core . INamingRequestor ; import org . eclipse . jdt . internal . core . InternalNamingConventions ; public final class NamingConventions { static class NamingRequestor implements INamingRequestor { private final static int SIZE = 10 ; private char [ ] [ ] firstPrefixAndFirstSuffixResults = new char [ SIZE ] [ ] ; private int firstPrefixAndFirstSuffixResultsCount = 0 ; private char [ ] [ ] firstPrefixAndSuffixResults = new char [ SIZE ] [ ] ; private int firstPrefixAndSuffixResultsCount = 0 ; private char [ ] [ ] prefixAndFirstSuffixResults = new char [ SIZE ] [ ] ; private int prefixAndFirstSuffixResultsCount = 0 ; private char [ ] [ ] prefixAndSuffixResults = new char [ SIZE ] [ ] ; private int prefixAndSuffixResultsCount = 0 ; private char [ ] [ ] firstPrefixResults = new char [ SIZE ] [ ] ; private int firstPrefixResultsCount = 0 ; private char [ ] [ ] prefixResults = new char [ SIZE ] [ ] ; private int prefixResultsCount = 0 ; private char [ ] [ ] firstSuffixResults = new char [ SIZE ] [ ] ; private int firstSuffixResultsCount = 0 ; private char [ ] [ ] suffixResults = new char [ SIZE ] [ ] ; private int suffixResultsCount = 0 ; private char [ ] [ ] otherResults = new char [ SIZE ] [ ] ; private int otherResultsCount = 0 ; public void acceptNameWithoutPrefixAndSuffix ( char [ ] name , int reusedCharacters ) { int length = this . otherResults . length ; if ( length == this . otherResultsCount ) { System . arraycopy ( this . otherResults , 0 , this . otherResults = new char [ length * 2 ] [ ] , 0 , length ) ; } this . otherResults [ this . otherResultsCount ++ ] = name ; } public void acceptNameWithPrefix ( char [ ] name , boolean isFirstPrefix , int reusedCharacters ) { if ( isFirstPrefix ) { int length = this . firstPrefixResults . length ; if ( length == this . firstPrefixResultsCount ) { System . arraycopy ( this . firstPrefixResults , 0 , this . firstPrefixResults = new char [ length * 2 ] [ ] , 0 , length ) ; } this . firstPrefixResults [ this . firstPrefixResultsCount ++ ] = name ; } else { int length = this . prefixResults . length ; if ( length == this . prefixResultsCount ) { System . arraycopy ( this . prefixResults , 0 , this . prefixResults = new char [ length * 2 ] [ ] , 0 , length ) ; } this . prefixResults [ this . prefixResultsCount ++ ] = name ; } } public void acceptNameWithPrefixAndSuffix ( char [ ] name , boolean isFirstPrefix , boolean isFirstSuffix , int reusedCharacters ) { if ( isFirstPrefix && isFirstSuffix ) { int length = this . firstPrefixAndFirstSuffixResults . length ; if ( length == this . firstPrefixAndFirstSuffixResultsCount ) { System . arraycopy ( this . firstPrefixAndFirstSuffixResults , 0 , this . firstPrefixAndFirstSuffixResults = new char [ length * 2 ] [ ] , 0 , length ) ; } this . firstPrefixAndFirstSuffixResults [ this . firstPrefixAndFirstSuffixResultsCount ++ ] = name ; } else if ( isFirstPrefix ) { int length = this . firstPrefixAndSuffixResults . length ; if ( length == this . firstPrefixAndSuffixResultsCount ) { System . arraycopy ( this . firstPrefixAndSuffixResults , 0 , this . firstPrefixAndSuffixResults = new char [ length * 2 ] [ ] , 0 , length ) ; } this . firstPrefixAndSuffixResults [ this . firstPrefixAndSuffixResultsCount ++ ] = name ; } else if ( isFirstSuffix ) { int length = this . prefixAndFirstSuffixResults . length ; if ( length == this . prefixAndFirstSuffixResultsCount ) { System . arraycopy ( this . prefixAndFirstSuffixResults , 0 , this . prefixAndFirstSuffixResults = new char [ length * 2 ] [ ] , 0 , length ) ; } this . prefixAndFirstSuffixResults [ this . prefixAndFirstSuffixResultsCount ++ ] = name ; } else { int length = this . prefixAndSuffixResults . length ; if ( length == this . prefixAndSuffixResultsCount ) { System . arraycopy ( this . prefixAndSuffixResults , 0 , this . prefixAndSuffixResults = new char [ length * 2 ] [ ] , 0 , length ) ; } this . prefixAndSuffixResults [ this . prefixAndSuffixResultsCount ++ ] = name ; } } public void acceptNameWithSuffix ( char [ ] name , boolean isFirstSuffix , int reusedCharacters ) { if ( isFirstSuffix ) { int length = this . firstSuffixResults . length ; if ( length == this . firstSuffixResultsCount ) { System . arraycopy ( this . firstSuffixResults , 0 , this . firstSuffixResults = new char [ length * 2 ] [ ] , 0 , length ) ; } this . firstSuffixResults [ this . firstSuffixResultsCount ++ ] = name ; } else { int length = this . suffixResults . length ; if ( length == this . suffixResultsCount ) { System . arraycopy ( this . suffixResults , 0 , this . suffixResults = new char [ length * 2 ] [ ] , 0 , length ) ; } this . suffixResults [ this . suffixResultsCount ++ ] = name ; } } public char [ ] [ ] getResults ( ) { int count = this . firstPrefixAndFirstSuffixResultsCount + this . firstPrefixAndSuffixResultsCount + this . prefixAndFirstSuffixResultsCount + this . prefixAndSuffixResultsCount + this . firstPrefixResultsCount + this . prefixResultsCount + this . firstSuffixResultsCount + this . suffixResultsCount + this . otherResultsCount ; char [ ] [ ] results = new char [ count ] [ ] ; int index = 0 ; System . arraycopy ( this . firstPrefixAndFirstSuffixResults , 0 , results , index , this . firstPrefixAndFirstSuffixResultsCount ) ; index += this . firstPrefixAndFirstSuffixResultsCount ; System . arraycopy ( this . firstPrefixAndSuffixResults , 0 , results , index , this . firstPrefixAndSuffixResultsCount ) ; index += this . firstPrefixAndSuffixResultsCount ; System . arraycopy ( this . prefixAndFirstSuffixResults , 0 , results , index , this . prefixAndFirstSuffixResultsCount ) ; index += this . prefixAndFirstSuffixResultsCount ; System . arraycopy ( this . prefixAndSuffixResults , 0 , results , index , this . prefixAndSuffixResultsCount ) ; index += this . prefixAndSuffixResultsCount ; System . arraycopy ( this . firstPrefixResults , 0 , results , index , this . firstPrefixResultsCount ) ; index += this . firstPrefixResultsCount ; System . arraycopy ( this . prefixResults , 0 , results , index , this . prefixResultsCount ) ; index += this . prefixResultsCount ; System . arraycopy ( this . firstSuffixResults , 0 , results , index , this . firstSuffixResultsCount ) ; index += this . firstSuffixResultsCount ; System . arraycopy ( this . suffixResults , 0 , results , index , this . suffixResultsCount ) ; index += this . suffixResultsCount ; System . arraycopy ( this . otherResults , 0 , results , index , this . otherResultsCount ) ; return results ; } } private static final char [ ] GETTER_BOOL_NAME = "is" . toCharArray ( ) ; private static final char [ ] GETTER_NAME = "get" . toCharArray ( ) ; private static final char [ ] SETTER_NAME = "set" . toCharArray ( ) ; public static final int VK_STATIC_FIELD = InternalNamingConventions . VK_STATIC_FIELD ; public static final int VK_INSTANCE_FIELD = InternalNamingConventions . VK_INSTANCE_FIELD ; public static final int VK_STATIC_FINAL_FIELD = InternalNamingConventions . VK_STATIC_FINAL_FIELD ; public static final int VK_PARAMETER = InternalNamingConventions . VK_PARAMETER ; public static final int VK_LOCAL = InternalNamingConventions . VK_LOCAL ; public static final int BK_NAME = InternalNamingConventions . BK_SIMPLE_NAME ; public static final int BK_TYPE_NAME = InternalNamingConventions . BK_SIMPLE_TYPE_NAME ; private static String [ ] convertCharsToString ( char [ ] [ ] c ) { int length = c == null ? 0 : c . length ; String [ ] s = new String [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { s [ i ] = String . valueOf ( c [ i ] ) ; } return s ; } private static char [ ] [ ] convertStringToChars ( String [ ] s ) { int length = s == null ? 0 : s . length ; char [ ] [ ] c = new char [ length ] [ ] ; for ( int i = 0 ; i < length ; i ++ ) { if ( s [ i ] == null ) { c [ i ] = CharOperation . NO_CHAR ; } else { c [ i ] = s [ i ] . toCharArray ( ) ; } } return c ; } public static char [ ] removePrefixAndSuffixForArgumentName ( IJavaProject javaProject , char [ ] argumentName ) { return InternalNamingConventions . removeVariablePrefixAndSuffix ( VK_PARAMETER , javaProject , argumentName ) ; } public static String removePrefixAndSuffixForArgumentName ( IJavaProject javaProject , String argumentName ) { return String . valueOf ( removePrefixAndSuffixForArgumentName ( javaProject , argumentName . toCharArray ( ) ) ) ; } public static char [ ] removePrefixAndSuffixForFieldName ( IJavaProject javaProject , char [ ] fieldName , int modifiers ) { return InternalNamingConventions . removeVariablePrefixAndSuffix ( Flags . isStatic ( modifiers ) ? VK_STATIC_FIELD : VK_INSTANCE_FIELD , javaProject , fieldName ) ; } public static String removePrefixAndSuffixForFieldName ( IJavaProject javaProject , String fieldName , int modifiers ) { return String . valueOf ( removePrefixAndSuffixForFieldName ( javaProject , fieldName . toCharArray ( ) , modifiers ) ) ; } public static char [ ] removePrefixAndSuffixForLocalVariableName ( IJavaProject javaProject , char [ ] localName ) { return InternalNamingConventions . removeVariablePrefixAndSuffix ( VK_LOCAL , javaProject , localName ) ; } public static String removePrefixAndSuffixForLocalVariableName ( IJavaProject javaProject , String localName ) { return String . valueOf ( removePrefixAndSuffixForLocalVariableName ( javaProject , localName . toCharArray ( ) ) ) ; } public static String getBaseName ( int variableKind , String variableName , IJavaProject javaProject ) { return String . valueOf ( InternalNamingConventions . getBaseName ( variableKind , javaProject , variableName . toCharArray ( ) , true ) ) ; } private static int getFieldVariableKind ( int modifiers ) { if ( Flags . isStatic ( modifiers ) ) { if ( Flags . isFinal ( modifiers ) ) { return VK_STATIC_FINAL_FIELD ; } return VK_STATIC_FIELD ; } return VK_INSTANCE_FIELD ; } private static char [ ] suggestAccessorName ( IJavaProject project , char [ ] fieldName , int modifiers ) { char [ ] name = InternalNamingConventions . getBaseName ( getFieldVariableKind ( modifiers ) , project , fieldName , false ) ; if ( name . length > 0 && ScannerHelper . isLowerCase ( name [ 0 ] ) ) { if ( name . length == 1 || ! ScannerHelper . isUpperCase ( name [ 1 ] ) ) { name [ 0 ] = ScannerHelper . toUpperCase ( name [ 0 ] ) ; } } return name ; } public static char [ ] [ ] suggestArgumentNames ( IJavaProject javaProject , char [ ] packageName , char [ ] qualifiedTypeName , int dim , char [ ] [ ] excludedNames ) { if ( qualifiedTypeName == null || qualifiedTypeName . length == 0 ) return CharOperation . NO_CHAR_CHAR ; char [ ] typeName = CharOperation . lastSegment ( qualifiedTypeName , '.' ) ; NamingRequestor requestor = new NamingRequestor ( ) ; InternalNamingConventions . suggestVariableNames ( VK_PARAMETER , BK_TYPE_NAME , typeName , javaProject , dim , null , excludedNames , true , requestor ) ; return requestor . getResults ( ) ; } public static String [ ] suggestArgumentNames ( IJavaProject javaProject , String packageName , String qualifiedTypeName , int dim , String [ ] excludedNames ) { return convertCharsToString ( suggestArgumentNames ( javaProject , packageName . toCharArray ( ) , qualifiedTypeName . toCharArray ( ) , dim , convertStringToChars ( excludedNames ) ) ) ; } public static char [ ] [ ] suggestFieldNames ( IJavaProject javaProject , char [ ] packageName , char [ ] qualifiedTypeName , int dim , int modifiers , char [ ] [ ] excludedNames ) { if ( qualifiedTypeName == null || qualifiedTypeName . length == 0 ) return CharOperation . NO_CHAR_CHAR ; char [ ] typeName = CharOperation . lastSegment ( qualifiedTypeName , '.' ) ; NamingRequestor requestor = new NamingRequestor ( ) ; InternalNamingConventions . suggestVariableNames ( Flags . isStatic ( modifiers ) ? VK_STATIC_FIELD : VK_INSTANCE_FIELD , BK_TYPE_NAME , typeName , javaProject , dim , null , excludedNames , true , requestor ) ; return requestor . getResults ( ) ; } public static String [ ] suggestFieldNames ( IJavaProject javaProject , String packageName , String qualifiedTypeName , int dim , int modifiers , String [ ] excludedNames ) { return convertCharsToString ( suggestFieldNames ( javaProject , packageName . toCharArray ( ) , qualifiedTypeName . toCharArray ( ) , dim , modifiers , convertStringToChars ( excludedNames ) ) ) ; } public static char [ ] suggestGetterName ( IJavaProject project , char [ ] fieldName , int modifiers , boolean isBoolean , char [ ] [ ] excludedNames ) { if ( isBoolean ) { char [ ] name = InternalNamingConventions . getBaseName ( getFieldVariableKind ( modifiers ) , project , fieldName , false ) ; int prefixLen = GETTER_BOOL_NAME . length ; if ( CharOperation . prefixEquals ( GETTER_BOOL_NAME , name ) && name . length > prefixLen && ScannerHelper . isUpperCase ( name [ prefixLen ] ) ) { return suggestNewName ( name , excludedNames ) ; } else { return suggestNewName ( CharOperation . concat ( GETTER_BOOL_NAME , suggestAccessorName ( project , fieldName , modifiers ) ) , excludedNames ) ; } } else { return suggestNewName ( CharOperation . concat ( GETTER_NAME , suggestAccessorName ( project , fieldName , modifiers ) ) , excludedNames ) ; } } public static String suggestGetterName ( IJavaProject project , String fieldName , int modifiers , boolean isBoolean , String [ ] excludedNames ) { return String . valueOf ( suggestGetterName ( project , fieldName . toCharArray ( ) , modifiers , isBoolean , convertStringToChars ( excludedNames ) ) ) ; } public static char [ ] [ ] suggestLocalVariableNames ( IJavaProject javaProject , char [ ] packageName , char [ ] qualifiedTypeName , int dim , char [ ] [ ] excludedNames ) { if ( qualifiedTypeName == null || qualifiedTypeName . length == 0 ) return CharOperation . NO_CHAR_CHAR ; char [ ] typeName = CharOperation . lastSegment ( qualifiedTypeName , '.' ) ; NamingRequestor requestor = new NamingRequestor ( ) ; InternalNamingConventions . suggestVariableNames ( VK_LOCAL , BK_TYPE_NAME , typeName , javaProject , dim , null , excludedNames , true , requestor ) ; return requestor . getResults ( ) ; } public static String [ ] suggestLocalVariableNames ( IJavaProject javaProject , String packageName , String qualifiedTypeName , int dim , String [ ] excludedNames ) { return convertCharsToString ( suggestLocalVariableNames ( javaProject , packageName . toCharArray ( ) , qualifiedTypeName . toCharArray ( ) , dim , convertStringToChars ( excludedNames ) ) ) ; } private static char [ ] suggestNewName ( char [ ] name , char [ ] [ ] excludedNames ) { if ( excludedNames == null ) { return name ; } char [ ] newName = name ; int count = 2 ; int i = 0 ; while ( i < excludedNames . length ) { if ( CharOperation . equals ( newName , excludedNames [ i ] , false ) ) { newName = CharOperation . concat ( name , String . valueOf ( count ++ ) . toCharArray ( ) ) ; i = 0 ; } else { i ++ ; } } return newName ; } public static char [ ] suggestSetterName ( IJavaProject project , char [ ] fieldName , int modifiers , boolean isBoolean , char [ ] [ ] excludedNames ) { if ( isBoolean ) { char [ ] name = InternalNamingConventions . getBaseName ( getFieldVariableKind ( modifiers ) , project , fieldName , false ) ; int prefixLen = GETTER_BOOL_NAME . length ; if ( CharOperation . prefixEquals ( GETTER_BOOL_NAME , name ) && name . length > prefixLen && ScannerHelper . isUpperCase ( name [ prefixLen ] ) ) { name = CharOperation . subarray ( name , prefixLen , name . length ) ; return suggestNewName ( CharOperation . concat ( SETTER_NAME , suggestAccessorName ( project , name , modifiers ) ) , excludedNames ) ; } else { return suggestNewName ( CharOperation . concat ( SETTER_NAME , suggestAccessorName ( project , fieldName , modifiers ) ) , excludedNames ) ; } } else { return suggestNewName ( CharOperation . concat ( SETTER_NAME , suggestAccessorName ( project , fieldName , modifiers ) ) , excludedNames ) ; } } public static String suggestSetterName ( IJavaProject project , String fieldName , int modifiers , boolean isBoolean , String [ ] excludedNames ) { return String . valueOf ( suggestSetterName ( project , fieldName . toCharArray ( ) , modifiers , isBoolean , convertStringToChars ( excludedNames ) ) ) ; } public static String [ ] suggestVariableNames ( int variableKind , int baseNameKind , String baseName , IJavaProject javaProject , int dim , String [ ] excluded , boolean evaluateDefault ) { NamingRequestor requestor = new NamingRequestor ( ) ; InternalNamingConventions . suggestVariableNames ( variableKind , baseNameKind , baseName . toCharArray ( ) , javaProject , dim , null , convertStringToChars ( excluded ) , evaluateDefault , requestor ) ; return convertCharsToString ( requestor . getResults ( ) ) ; } private NamingConventions ( ) { } } </s>