Source file src/cmd/fix/jnitype.go

     1  // Copyright 2017 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"go/ast"
     9  )
    10  
    11  func init() {
    12  	register(jniFix)
    13  }
    14  
    15  var jniFix = fix{
    16  	name:     "jni",
    17  	date:     "2017-12-04",
    18  	f:        jnifix,
    19  	desc:     `Fixes initializers of JNI's jobject and subtypes`,
    20  	disabled: false,
    21  }
    22  
    23  // Old state:
    24  //
    25  //	type jobject *_jobject
    26  //
    27  // New state:
    28  //
    29  //	type jobject uintptr
    30  //
    31  // and similar for subtypes of jobject.
    32  // This fix finds nils initializing these types and replaces the nils with 0s.
    33  func jnifix(f *ast.File) bool {
    34  	return typefix(f, func(s string) bool {
    35  		switch s {
    36  		case "C.jobject":
    37  			return true
    38  		case "C.jclass":
    39  			return true
    40  		case "C.jthrowable":
    41  			return true
    42  		case "C.jstring":
    43  			return true
    44  		case "C.jarray":
    45  			return true
    46  		case "C.jbooleanArray":
    47  			return true
    48  		case "C.jbyteArray":
    49  			return true
    50  		case "C.jcharArray":
    51  			return true
    52  		case "C.jshortArray":
    53  			return true
    54  		case "C.jintArray":
    55  			return true
    56  		case "C.jlongArray":
    57  			return true
    58  		case "C.jfloatArray":
    59  			return true
    60  		case "C.jdoubleArray":
    61  			return true
    62  		case "C.jobjectArray":
    63  			return true
    64  		case "C.jweak":
    65  			return true
    66  		}
    67  		return false
    68  	})
    69  }
    70  

View as plain text