GenerateJavaInterfaces.cpp revision 230bd8589bba39933ac5ec21482d6186d675e604
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Java XPCOM Bindings.
*
* The Initial Developer of the Original Code is
* IBM Corporation.
* Portions created by the Initial Developer are Copyright (C) 2005
* IBM Corporation. All Rights Reserved.
*
* Contributor(s):
* Javier Pedemonte (jhpedemonte@gmail.com)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsXPCOM.h"
#include "nsString.h"
#include "nsILocalFile.h"
#include "nsIInterfaceInfoManager.h"
#include "xptinfo.h"
#include "nsCOMPtr.h"
#include "prmem.h"
#include "xptcall.h"
#ifdef VBOX
#include "nsFileStreams.h"
static nsresult
PRInt32 aBehaviorFlags = 0)
{
if (NS_SUCCEEDED(rv))
return rv;
}
inline nsresult
PRInt32 aBehaviorFlags = 0)
{
if (NS_SUCCEEDED(rv))
return rv;
}
#else
#include "nsNetUtil.h"
#endif
#include "nsHashSets.h"
#include "nsIWeakReference.h"
#include <stdio.h>
#ifdef WIN32
#endif
#define WRITE_NOSCRIPT_METHODS
class TypeInfo
{
public:
{
if (!parent) {
*aParentInfo = nsnull;
*aParentMethodCount = 0;
return NS_OK;
}
*aParentInfo = parent;
return rv;
}
const nsXPTParamInfo* aParamInfo,
char** aResult)
{
static const char isupp_str[] = "nsISupports";
// GetIIDForParam will sometimes fail to find an interface, particularly
// if that interface is not defined in an IDL file. In those cases, just
// return |nsISupports|.
//
// For example, the |onStreamComplete| method for the interface
// |nsIUnicharStreamLoaderObserver| takes a param of
// |nsIUnicharInputStream|, which is defined in a simple header file, not
// an IDL file.
} else {
// In Javaconnect, we handle weak references internally; no need for the
// |nsIWeakReference| interface. So just return |nsISupports|.
} else {
// Some methods take parameters of non-scriptable interfaces. But we
// only output scriptable interfaces. So if one of the param types is
// a non-scriptable interface, output |nsISupports| instead of the
// interface name.
if (NS_SUCCEEDED(rv)) {
}
} else {
// If is scriptable, get name for given IID
}
}
}
return rv;
}
};
static const char* kJavaKeywords[] = {
"abstract", "default", "if" , "private" , "this" ,
"boolean" , "do" , "implements", "protected" , "throw" ,
"break" , "double" , "import", "public" , "throws" ,
"byte" , "else" , "instanceof", "return" , "transient",
"case" , "extends", "int" , "short" , "try" ,
"catch" , "final" , "interface" , "static" , "void" ,
"char" , "finally", "long" , "strictfp" , "volatile" ,
"class" , "float" , "native" , "super" , "while" ,
"const" , "for" , "new" , "switch" ,
"continue", "goto" , "package" , "synchronized",
"assert" , /* added in Java 1.4 */
"enum" , /* added in Java 5.0 */
"clone" , /* clone is a member function of java.lang.Object */
"finalize" /* finalize is a member function of java.lang.Object */
};
#ifdef WRITE_NOSCRIPT_METHODS
// SWT uses [noscript] methods of the following interfaces, so we need to
// output the [noscript] methods for these interfaces.
static const char* kNoscriptMethodIfaces[] = {
"nsIBaseWindow", "nsIEmbeddingSiteWindow"
};
#endif
class Generate
{
#ifdef WRITE_NOSCRIPT_METHODS
#endif
public:
{
}
#ifdef WRITE_NOSCRIPT_METHODS
}
#endif
}
~Generate()
{
}
{
// loop over interfaces
do {
// get current interface
if (!iface)
break;
// we only care about scriptable interfaces, so skip over those
// that aren't
if (!scriptable) {
// XXX SWT uses non-scriptable interface 'nsIAppShell' (bug 270892), so
// include that one.
const char* iface_name;
continue;
}
return NS_OK;
}
{
// write each interface only once
const char* iface_name;
return NS_OK;
// write any parent interface
if (parentInfo)
// create file for interface
// write contents to file
return rv;
}
{
// create interface file in output dir
// create interface file
if (exists)
// create output stream for writing to file
return NS_OK;
}
{
}
{
static const char kHeader1[] =
"/**\n"
" * NOTE: THIS IS A GENERATED FILE. PLEASE CONSULT THE ORIGINAL IDL FILE\n"
" * FOR THE FULL DOCUMENTION AND LICENSE.\n"
" *\n"
" * @see <a href=\"http://lxr.mozilla.org/mozilla/search?string=";
static const char kHeader2[]= "\">\n **/\n\n";
static const char kPackage[] = "package org.mozilla.interfaces;\n\n";
// LXR limits to 29 chars
return rv;
}
{
static const char kIfaceDecl1[] = "public interface ";
static const char kParentDecl[] = " extends ";
static const char kIfaceDecl2[] = "\n{\n";
const char* iface_name;
if (aParentInfo) {
const char* parent_name;
}
return rv;
}
{
}
{
static const char kIIDDecl1[] = " public static final String ";
static const char kIIDDecl2[] = " =\n \"";
static const char kIIDDecl3[] = "\";\n\n";
if (!iid)
return NS_ERROR_OUT_OF_MEMORY;
// create iid field name
const char* iface_name;
} else {
}
// get iid string
if (!iid_str)
return NS_ERROR_OUT_OF_MEMORY;
// cleanup
return NS_OK;
}
{
static const char kConstDecl1[] = " public static final ";
static const char kConstDecl2[] = " = ";
static const char kConstDecl3[] = ";\n\n";
const nsXPTConstant* constInfo;
}
return NS_OK;
}
const nsXPTCMiniVariant* aValue)
{
char buf[32];
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
else
break;
break;
break;
default:
NS_WARNING("unexpected constant type");
return NS_ERROR_UNEXPECTED;
}
}
{
#ifdef DEBUG_bird /* attributes first, then method. For making diffing easier. */
#endif
const nsXPTMethodInfo* methodInfo;
#ifdef WRITE_NOSCRIPT_METHODS
// XXX
// SWT makes use of [noscript] methods in some classes, so output them
// for those classes.
// skip [notxpcom] methods
if (methodInfo->IsNotXPCOM())
continue;
// skip most hidden ([noscript]) methods
if (methodInfo->IsHidden()) {
const char* iface_name;
continue;
}
#else
// skip hidden ([noscript]) or [notxpcom] methods
continue;
#endif
#ifdef DEBUG_bird /* attributes first, then method. For making diffing easier. */
continue;
#endif
}
return NS_OK;
}
const nsXPTMethodInfo* aMethodInfo,
{
static const char kMethodDecl1[] = " public ";
static const char kVoidReturn[] = "void";
static const char kParamSeparator[] = ", ";
static const char kMethodDecl2[] = ");\n\n";
// write return type
for (PRUint8 i = 0; i < paramCount; i++) {
resultInfo = ¶mInfo;
break;
}
}
if (resultInfo) {
} else {
}
// write method name string
if (aMethodInfo->IsGetter())
else
} else {
// don't use Java keywords as method names
}
// write parameters
for (PRUint8 j = 0; j < paramCount; j++) {
continue;
if (j != 0) {
}
}
return rv;
}
{
// if parameter is 'out' or 'inout', make it a Java array
}
// write name for parameter (but not for 'retval' param)
if (aIndex) {
char buf[10];
}
return NS_OK;
}
/**
* Write out the Java type for the given XPIDL type.
*
* NOTE: Java doesn't support unsigned types. So for any unsigned XPIDL type,
* we move up to the next largest Java type. This way we ensure that we don't
* lose any info.
*/
const nsXPTParamInfo* aParamInfo)
{
break;
break;
break;
break;
break;
// XXX how should we handle 64-bit values?
break;
break;
break;
case nsXPTType::T_CHAR_STR:
case nsXPTType::T_WCHAR_STR:
case nsXPTType::T_DOMSTRING:
case nsXPTType::T_UTF8STRING:
case nsXPTType::T_PSTRING_SIZE_IS:
case nsXPTType::T_PWSTRING_SIZE_IS:
break;
case nsXPTType::T_INTERFACE:
{
char* iface_name = nsnull;
&iface_name);
break;
}
break;
}
case nsXPTType::T_INTERFACE_IS:
break;
break;
{
// get array type
break;
break;
break;
}
default:
return NS_ERROR_UNEXPECTED;
}
return rv;
}
};
void PrintUsage(char** argv)
{
static const char usage_str[] =
"Usage: %s -d path\n"
" -d output directory for Java interface files\n";
}
#ifdef VBOX
using namespace com;
#include <iprt/initterm.h>
#endif
{
#ifdef VBOX
#if defined(VBOX_PATH_APP_PRIVATE_ARCH) && defined(VBOX_PATH_SHARED_LIBS)
#else
if (pszHome) {
} else {
}
#endif
#endif
// handle command line arguments
for (int i = 1; i < argc; i++) {
if (argv[i][0] != '-') {
break;
}
switch (argv[i][1]) {
case 'd': {
if (i + 1 == argc) {
break;
}
// see if given path exists
{
"ERROR: output directory doesn't exist / isn't a directory\n");
break;
}
break;
}
default: {
break;
}
}
}
return 1;
}
#ifdef VBOX
#else
#endif
#ifdef VBOX
// very short-living XPCOM processes trigger problem on shutdown - ignoring it not a big deal anyway
//com::Shutdown();
#else
#endif
return rv;
}