private static Bindings getBindings( Object value ) { if( value instanceof Pair ) { value = ((Pair)value).getSecond(); } return value instanceof Bindings ? (Bindings)value : null; }
private static List getList( Object value ) { if( value instanceof Pair ) { value = ((Pair)value).getSecond(); } return value instanceof List ? (List)value : null; }
private static String getJSchema_Name( Bindings docObj ) { Object value = docObj.get( JSCH_NAME ); String name; if( value instanceof Pair ) { name = (String)((Pair)value).getSecond(); } else { name = (String)value; } return name; }
Boolean isNullable( List list ) { for( Object elem: list ) { if( elem instanceof Pair ) { elem = ((Pair)elem).getSecond(); } if( "null".equals( ((Bindings)elem).get( JSCH_TYPE ) ) ) { return true; } } return null; }
private void assignAttribute( Bindings jsonObj, String attr ) { boolean hasAttr = jsonObj.containsKey( attr ); if( hasAttr ) { Object attrValue = jsonObj.get( attr ); if( attrValue instanceof Pair ) { attrValue = ((Pair)attrValue).getSecond(); } _attributes.put( attr, attrValue ); } }
private IJsonType findFragmentType( Token token, URI uri, Pair<IJsonType, JsonSchemaTransformer> pair ) { String fragment = uri.getFragment(); IJsonType baseType = pair.getFirst(); if( fragment == null || fragment.isEmpty() ) { return baseType; } return pair.getSecond().findFragmentRef( (JsonSchemaType)baseType, ((JsonSchemaType)baseType).getFile(), token, uri ); }
public void enterElement( XMLParser.ElementContext ctx ) { XmlElement parent = _elements.isEmpty() ? null : _elements.peek().getSecond(); XmlElement xmlElement = new XmlElement( ctx, parent ); if( parent != null ) { parent.addChild( xmlElement ); } _elements.push( new Pair<>( ctx, xmlElement ) ); if( _root == null ) { _root = xmlElement; } }
private static boolean typeMatches( Bindings bindings, Type testType ) { Object type = bindings.get( JsonSchemaTransformer.JSCH_TYPE ); if( type == null ) { return false; } String typeName; if( type instanceof Pair ) { typeName = (String)((Pair)type).getSecond(); } else { typeName = (String)type; } return typeName != null && typeName.equals( testType.getName() ); }
/** * Add resource paths more precisely via our JPS plugin in IntelliJ */ private void deriveResourcePath( Set<Pair<String, JavaFileObject>> inputFiles, Set<String> resourcePath ) { for( Pair<String, JavaFileObject> inputFile : inputFiles ) { JavaFileObject fo = inputFile.getSecond(); if( !isPhysicalFile( fo ) ) { continue; } String filename = fo.getName(); if( filename.contains( "_Manifold_Temp_Main_" ) ) { File file = new File( filename ); if( file.isFile() ) { addResourcePaths( file, resourcePath ); } } } }
private JsonFormatType resolveFormatType( Bindings jsonObj ) { JsonFormatType resolvedType = null; for( IJsonFormatTypeResolver resolver: Objects.requireNonNull( FormatTypeResolvers.get() ) ) { Object format = jsonObj.get( JSCH_FORMAT ); format = format instanceof Pair ? ((Pair)format).getSecond() : format; resolvedType = resolver.resolveType( (String)format ); if( resolvedType != null ) { break; } } return resolvedType; }
private boolean isPropertiesDefined( Bindings jsonObj ) { return (jsonObj.get( JSCH_PROPERTIES ) instanceof Bindings) || jsonObj.get( JSCH_PROPERTIES ) instanceof Pair && ((Pair)jsonObj.get( JSCH_PROPERTIES )).getSecond() instanceof Bindings; }
private SrcClass makeSrcClassStubFromProducedClass( String fqn, JavaFileManager.Location location ) { BasicJavacTask[] task = new BasicJavacTask[1]; Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> pair = getClassSymbolForProducedClass( fqn, task ); if( pair == null ) { throw new NullPointerException( "Could not find ClassSymbol for: " + fqn ); } Symbol.ClassSymbol classSymbol = pair.getFirst(); return SrcClassUtil.instance().makeStub( _module, fqn, classSymbol, pair.getSecond(), task[0] ); }
@Override public Bindings parseJson( String jsonText, boolean withBigNumbers, boolean withTokens ) throws ScriptException { SimpleParserImpl parser = new SimpleParserImpl( new Tokenizer( new StringReader( jsonText ) ), withBigNumbers ); Object result = parser.parse( withTokens ); List<String> errors = parser.getErrors(); if( errors.size() != 0 ) { StringBuilder sb = new StringBuilder( "Found errors:\n" ); for( String err : errors ) { sb.append( err ).append( "\n" ); } throw new ScriptException( sb.toString() ); } if( result instanceof Pair ) { result = ((Pair)result).getSecond(); } if( result instanceof Bindings ) { return (Bindings)result; } return wrapValueInBindings( result ); }
@Override public void enterAttribute( XMLParser.AttributeContext ctx ) { if( _attribute != null ) { throw new IllegalStateException( "Error processing attribute '" + ctx.Name().getText() + "'," + " there is already an attribute processing: '" + _attribute.getName().getRawText() ); } XmlElement parent = _elements.peek().getSecond(); _attribute = new XmlAttribute( ctx, parent ); parent.addAttribute( _attribute ); }
public static void toJson( StringBuilder target, int indent, Object value ) { if( value instanceof Pair ) { value = ((Pair)value).getSecond(); } if( value instanceof Bindings ) { toJson( ((Bindings)value), target, indent + 2 ); } else if( value instanceof List ) { listToJson( target, indent, (List)value ); } else { appendValue( target, value ); } }
private void checkExtensionClassError( JCTree.JCClassDecl typeDecl ) { JavacPlugin javacPlugin = JavacPlugin.instance(); if( javacPlugin == null ) { return; } if( !isExtensionClass( typeDecl ) ) { return; } String extendedFqn = getExtendedClassName(); if( javacPlugin.getJavaInputFiles().stream().anyMatch( pair -> !(pair.getSecond() instanceof GeneratedJavaStubFileObject) && pair.getFirst().equals( extendedFqn ) ) ) { _tp.report( typeDecl, Diagnostic.Kind.WARNING, ExtIssueMsg.MSG_CANNOT_EXTEND_SOURCE_FILE.get( extendedFqn ) ); } }
private void checkExtensionClassError( JCTree.JCClassDecl typeDecl ) { JavacPlugin javacPlugin = JavacPlugin.instance(); if( javacPlugin == null ) { return; } if( !isExtensionClass( typeDecl ) ) { return; } String extendedFqn = getExtendedClassName(); if( javacPlugin.getJavaInputFiles().stream().anyMatch( pair -> !(pair.getSecond() instanceof GeneratedJavaStubFileObject) && pair.getFirst().equals( extendedFqn ) ) ) { _tp.report( typeDecl, Diagnostic.Kind.WARNING, ExtIssueMsg.MSG_CANNOT_EXTEND_SOURCE_FILE.get( extendedFqn ) ); } }
@Override public void visitTerminal( TerminalNode node ) { Token symbol = node.getSymbol(); if( _attribute != null ) { if( symbol.getType() == XMLLexer.STRING ) { _attribute.setRawValue( new XmlTerminal( symbol, _attribute ) ); } } else if( !_elements.isEmpty() ) { if( symbol.getType() == XMLLexer.TEXT || symbol.getType() == XMLLexer.STRING || symbol.getType() == XMLLexer.CDATA ) { XmlElement second = _elements.peek().getSecond(); second.setRawContent( new XmlTerminal( symbol, second ) ); } } } }
public SrcClass makeSrcClassStub( String fqn, JavaFileManager.Location location ) { BasicJavacTask javacTask = location != null && JavacPlugin.instance() != null ? JavacPlugin.instance().getJavacTask() : getJavacTask_PlainFileMgr(); Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> pair = getClassSymbol( javacTask, location, fqn ); if( pair == null ) { throw new IllegalStateException( "Failed to find class, '" + fqn + "'" ); } Symbol.ClassSymbol classSymbol = pair.getFirst(); if( classSymbol == null ) { // For the case where the class is generated from a type manifold esp. from a IExtensionClassProducer return makeSrcClassStubFromProducedClass( fqn, location ); } return SrcClassUtil.instance().makeStub( _module, fqn, classSymbol, pair.getSecond(), getJavacTask_PlainFileMgr() ); }
private static Bindings parseYaml( String yaml, boolean withBigNumbers, boolean withTokens ) throws ScriptException { LoadSettings loadSettings = new LoadSettingsBuilder() .setUseMarks( true ) .setDefaultMap( DataBindings::new ) .build(); Load load = new Load( loadSettings, new MyConstructor( loadSettings, withTokens ) ); Object result = load.loadFromString( yaml ); if( result instanceof Pair ) { result = ((Pair)result).getSecond(); } if( result instanceof Bindings ) { return (Bindings)result; } return wrapValueInBindings( result ); }