private void parseMemberSpecificationArguments(String externalClassName, ClassSpecification classSpecification) throws ParseException, IOException { // Clear the annotation name. String annotationType = null; // Parse the class member access modifiers, if any. int requiredSetMemberAccessFlags = 0; int requiredUnsetMemberAccessFlags = 0; while (!configurationEnd(true)) { // Parse the annotation type, if any. if (ConfigurationConstants.ANNOTATION_KEYWORD.equals(nextWord)) { annotationType = ListUtil.commaSeparatedString( parseCommaSeparatedList("annotation type", true, false, false, false, true, false, false, true, null), false); continue; } String strippedWord = nextWord.startsWith("!") ? nextWord .substring(1) : nextWord; // Parse the class member access modifiers. int accessFlag = strippedWord .equals(ClassConstants.EXTERNAL_ACC_PUBLIC) ? ClassConstants.INTERNAL_ACC_PUBLIC : strippedWord.equals(ClassConstants.EXTERNAL_ACC_PRIVATE) ? ClassConstants.INTERNAL_ACC_PRIVATE : strippedWord .equals(ClassConstants.EXTERNAL_ACC_PROTECTED) ? ClassConstants.INTERNAL_ACC_PROTECTED : strippedWord .equals(ClassConstants.EXTERNAL_ACC_STATIC) ? ClassConstants.INTERNAL_ACC_STATIC : strippedWord .equals(ClassConstants.EXTERNAL_ACC_FINAL) ? ClassConstants.INTERNAL_ACC_FINAL : strippedWord .equals(ClassConstants.EXTERNAL_ACC_SYNCHRONIZED) ? ClassConstants.INTERNAL_ACC_SYNCHRONIZED : strippedWord .equals(ClassConstants.EXTERNAL_ACC_VOLATILE) ? ClassConstants.INTERNAL_ACC_VOLATILE : strippedWord .equals(ClassConstants.EXTERNAL_ACC_TRANSIENT) ? ClassConstants.INTERNAL_ACC_TRANSIENT : strippedWord .equals(ClassConstants.EXTERNAL_ACC_BRIDGE) ? ClassConstants.INTERNAL_ACC_BRIDGE : strippedWord .equals(ClassConstants.EXTERNAL_ACC_VARARGS) ? ClassConstants.INTERNAL_ACC_VARARGS : strippedWord .equals(ClassConstants.EXTERNAL_ACC_NATIVE) ? ClassConstants.INTERNAL_ACC_NATIVE : strippedWord .equals(ClassConstants.EXTERNAL_ACC_ABSTRACT) ? ClassConstants.INTERNAL_ACC_ABSTRACT : strippedWord .equals(ClassConstants.EXTERNAL_ACC_STRICT) ? ClassConstants.INTERNAL_ACC_STRICT : strippedWord .equals(ClassConstants.EXTERNAL_ACC_SYNTHETIC) ? ClassConstants.INTERNAL_ACC_SYNTHETIC : 0; if (accessFlag == 0) { // Not a class member access modifier. Stop parsing them. break; } if (strippedWord.equals(nextWord)) { requiredSetMemberAccessFlags |= accessFlag; } else { requiredUnsetMemberAccessFlags |= accessFlag; } // Make sure the user doesn't try to set and unset the same // access flags simultaneously. if ((requiredSetMemberAccessFlags & requiredUnsetMemberAccessFlags) != 0) { throw new ParseException( "Conflicting class member access modifiers for " + reader.locationDescription()); } readNextWord("class member description"); } // Parse the class member type and name part. // Did we get a special wildcard? if (ConfigurationConstants.ANY_CLASS_MEMBER_KEYWORD.equals(nextWord) || ConfigurationConstants.ANY_FIELD_KEYWORD.equals(nextWord) || ConfigurationConstants.ANY_METHOD_KEYWORD.equals(nextWord)) { // Act according to the type of wildcard.. if (ConfigurationConstants.ANY_CLASS_MEMBER_KEYWORD .equals(nextWord)) { checkFieldAccessFlags(requiredSetMemberAccessFlags, requiredUnsetMemberAccessFlags); checkMethodAccessFlags(requiredSetMemberAccessFlags, requiredUnsetMemberAccessFlags); classSpecification.addField(new MemberSpecification( requiredSetMemberAccessFlags, requiredUnsetMemberAccessFlags, annotationType, null, null)); classSpecification.addMethod(new MemberSpecification( requiredSetMemberAccessFlags, requiredUnsetMemberAccessFlags, annotationType, null, null)); } else if (ConfigurationConstants.ANY_FIELD_KEYWORD .equals(nextWord)) { checkFieldAccessFlags(requiredSetMemberAccessFlags, requiredUnsetMemberAccessFlags); classSpecification.addField(new MemberSpecification( requiredSetMemberAccessFlags, requiredUnsetMemberAccessFlags, annotationType, null, null)); } else if (ConfigurationConstants.ANY_METHOD_KEYWORD .equals(nextWord)) { checkMethodAccessFlags(requiredSetMemberAccessFlags, requiredUnsetMemberAccessFlags); classSpecification.addMethod(new MemberSpecification( requiredSetMemberAccessFlags, requiredUnsetMemberAccessFlags, annotationType, null, null)); } // We still have to read the closing separator. readNextWord("separator '" + ConfigurationConstants.SEPARATOR_KEYWORD + "'"); if (!ConfigurationConstants.SEPARATOR_KEYWORD.equals(nextWord)) { throw new ParseException("Expecting separator '" + ConfigurationConstants.SEPARATOR_KEYWORD + "' before " + reader.locationDescription()); } } else { // Make sure we have a proper type. checkJavaIdentifier("java type"); String type = nextWord; readNextWord("class member name"); String name = nextWord; // Did we get just one word before the opening parenthesis? if (ConfigurationConstants.OPEN_ARGUMENTS_KEYWORD.equals(name)) { // This must be a constructor then. // Make sure the type is a proper constructor name. if (!(type.equals(ClassConstants.INTERNAL_METHOD_NAME_INIT) || type.equals(externalClassName) || type .equals(ClassUtil .externalShortClassName(externalClassName)))) { throw new ParseException("Expecting type and name " + "instead of just '" + type + "' before " + reader.locationDescription()); } // Assign the fixed constructor type and name. type = ClassConstants.EXTERNAL_TYPE_VOID; name = ClassConstants.INTERNAL_METHOD_NAME_INIT; } else { // It's not a constructor. // Make sure we have a proper name. checkJavaIdentifier("class member name"); // Read the opening parenthesis or the separating // semi-colon. readNextWord("opening '" + ConfigurationConstants.OPEN_ARGUMENTS_KEYWORD + "' or separator '" + ConfigurationConstants.SEPARATOR_KEYWORD + "'"); } // Are we looking at a field, a method, or something else? if (ConfigurationConstants.SEPARATOR_KEYWORD.equals(nextWord)) { // It's a field. checkFieldAccessFlags(requiredSetMemberAccessFlags, requiredUnsetMemberAccessFlags); // We already have a field descriptor. String descriptor = ClassUtil.internalType(type); // Add the field. classSpecification.addField(new MemberSpecification( requiredSetMemberAccessFlags, requiredUnsetMemberAccessFlags, annotationType, name, descriptor)); } else if (ConfigurationConstants.OPEN_ARGUMENTS_KEYWORD .equals(nextWord)) { // It's a method. checkMethodAccessFlags(requiredSetMemberAccessFlags, requiredUnsetMemberAccessFlags); // Parse the method arguments. String descriptor = ClassUtil.internalMethodDescriptor( type, parseCommaSeparatedList("argument", true, true, true, false, true, false, false, false, null)); if (!ConfigurationConstants.CLOSE_ARGUMENTS_KEYWORD .equals(nextWord)) { throw new ParseException("Expecting separating '" + ConfigurationConstants.ARGUMENT_SEPARATOR_KEYWORD + "' or closing '" + ConfigurationConstants.CLOSE_ARGUMENTS_KEYWORD + "' before " + reader.locationDescription()); } // Read the separator after the closing parenthesis. readNextWord("separator '" + ConfigurationConstants.SEPARATOR_KEYWORD + "'"); if (!ConfigurationConstants.SEPARATOR_KEYWORD.equals(nextWord)) { throw new ParseException("Expecting separator '" + ConfigurationConstants.SEPARATOR_KEYWORD + "' before " + reader.locationDescription()); } // Add the method. classSpecification.addMethod(new MemberSpecification( requiredSetMemberAccessFlags, requiredUnsetMemberAccessFlags, annotationType, name, descriptor)); } else { // It doesn't look like a field or a method. throw new ParseException("Expecting opening '" + ConfigurationConstants.OPEN_ARGUMENTS_KEYWORD + "' or separator '" + ConfigurationConstants.SEPARATOR_KEYWORD + "' before " + reader.locationDescription()); } } } |