2022-03-07 09:34:54 +00:00
package lombok.core.configuration ;
import java.io.IOException ;
import java.util.Map ;
import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
2022-03-30 18:14:40 +00:00
/* loaded from: com.discord-121110.apk:lombok/core/configuration/ConfigurationParser.SCL.lombok */
2022-03-07 09:34:54 +00:00
public class ConfigurationParser {
private static final Pattern LINE = Pattern . compile ( " (?:clear \\ s+([^=]+))|(?:( \\ S*?) \\ s*([-+]?=) \\ s*(.*?)) " ) ;
private static final Pattern NEWLINE_FINDER = Pattern . compile ( " ^[ \ t ]*(.*?)[ \ t \ r ]*$ " , 8 ) ;
private static final Pattern IMPORT = Pattern . compile ( " import \\ s+(.+?) " ) ;
private ConfigurationProblemReporter reporter ;
2022-03-30 18:14:40 +00:00
/* loaded from: com.discord-121110.apk:lombok/core/configuration/ConfigurationParser$Collector.SCL.lombok */
2022-03-07 09:34:54 +00:00
public interface Collector {
void addImport ( ConfigurationFile configurationFile , ConfigurationFile configurationFile2 , int i ) ;
void clear ( ConfigurationKey < ? > configurationKey , ConfigurationFile configurationFile , int i ) ;
void set ( ConfigurationKey < ? > configurationKey , Object obj , ConfigurationFile configurationFile , int i ) ;
void add ( ConfigurationKey < ? > configurationKey , Object obj , ConfigurationFile configurationFile , int i ) ;
void remove ( ConfigurationKey < ? > configurationKey , Object obj , ConfigurationFile configurationFile , int i ) ;
}
public ConfigurationParser ( ConfigurationProblemReporter configurationProblemReporter ) {
if ( configurationProblemReporter = = null ) {
throw new NullPointerException ( " reporter " ) ;
}
this . reporter = configurationProblemReporter ;
}
public void parse ( ConfigurationFile configurationFile , Collector collector ) {
String str ;
String str2 ;
String str3 ;
CharSequence contents = contents ( configurationFile ) ;
if ( contents ! = null ) {
Map < String , ConfigurationKey < ? > > registeredKeys = ConfigurationKey . registeredKeys ( ) ;
int i = 0 ;
Matcher matcher = NEWLINE_FINDER . matcher ( contents ) ;
boolean z2 = true ;
while ( matcher . find ( ) ) {
CharSequence subSequence = contents . subSequence ( matcher . start ( 1 ) , matcher . end ( 1 ) ) ;
i + + ;
if ( ! ( subSequence . length ( ) = = 0 | | subSequence . charAt ( 0 ) = = '#' ) ) {
Matcher matcher2 = IMPORT . matcher ( subSequence ) ;
if ( ! matcher2 . matches ( ) ) {
Matcher matcher3 = LINE . matcher ( subSequence ) ;
if ( ! matcher3 . matches ( ) ) {
this . reporter . report ( configurationFile . description ( ) , " Invalid line " , i , subSequence ) ;
} else {
z2 = false ;
if ( matcher3 . group ( 1 ) = = null ) {
str2 = matcher3 . group ( 2 ) ;
str3 = matcher3 . group ( 3 ) ;
str = matcher3 . group ( 4 ) ;
} else {
str2 = matcher3 . group ( 1 ) ;
str3 = " clear " ;
str = null ;
}
ConfigurationKey < ? > configurationKey = registeredKeys . get ( str2 ) ;
if ( configurationKey = = null ) {
this . reporter . report ( configurationFile . description ( ) , " Unknown key ' " + str2 + " ' " , i , subSequence ) ;
} else {
ConfigurationDataType type = configurationKey . getType ( ) ;
if ( ( str3 . equals ( " += " ) | | str3 . equals ( " -= " ) ) & & ! type . isList ( ) ) {
this . reporter . report ( configurationFile . description ( ) , " ' " + str2 + " ' is not a list and doesn't support " + str3 + " (only = and clear) " , i , subSequence ) ;
} else if ( ! str3 . equals ( " = " ) | | ! type . isList ( ) ) {
Object obj = null ;
if ( str ! = null ) {
try {
obj = type . getParser ( ) . parse ( str ) ;
} catch ( Exception unused ) {
this . reporter . report ( configurationFile . description ( ) , " Error while parsing the value for ' " + str2 + " ' value ' " + str + " ' (should be " + type . getParser ( ) . exampleValue ( ) + " ) " , i , subSequence ) ;
}
}
if ( str3 . equals ( " clear " ) ) {
collector . clear ( configurationKey , configurationFile , i ) ;
} else if ( str3 . equals ( " = " ) ) {
collector . set ( configurationKey , obj , configurationFile , i ) ;
} else if ( str3 . equals ( " += " ) ) {
collector . add ( configurationKey , obj , configurationFile , i ) ;
} else {
collector . remove ( configurationKey , obj , configurationFile , i ) ;
}
} else {
this . reporter . report ( configurationFile . description ( ) , " ' " + str2 + " ' is a list and cannot be assigned to (use +=, -= and clear instead) " , i , subSequence ) ;
}
}
}
} else if ( ! z2 ) {
this . reporter . report ( configurationFile . description ( ) , " Imports are only allowed in the top of the file " , i , subSequence ) ;
} else {
ConfigurationFile resolve = configurationFile . resolve ( matcher2 . group ( 1 ) ) ;
if ( resolve = = null ) {
this . reporter . report ( configurationFile . description ( ) , " Import is not valid " , i , subSequence ) ;
} else if ( ! resolve . exists ( ) ) {
this . reporter . report ( configurationFile . description ( ) , " Imported file does not exist " , i , subSequence ) ;
} else {
collector . addImport ( resolve , configurationFile , i ) ;
}
}
}
}
}
}
private CharSequence contents ( ConfigurationFile configurationFile ) {
try {
return configurationFile . contents ( ) ;
} catch ( IOException e ) {
this . reporter . report ( configurationFile . description ( ) , " Exception while reading file: " + e . getMessage ( ) , 0 , null ) ;
return null ;
}
}
}