Tangible Software Solutions
VB to Java Converter Help
Contents
- Project & Folder Conversion
- File & Snippet Conversion
- Code Formatting Options
- Type & Member Replacements
- Conversion Message Options
- Custom String Replacements
- Diagnostic Options
- File Encoding Options
- Project Conversion Groups
- Default Shared Assemblies for Conversions
- Assumed Imported Namespaces for Snippet Conversions
- Package & File Options
- Property Conversion Options
- Additions & Omissions
- .NET to Java Class Library Options
- Omit Types from Conversion
- Miscellaneous Options
- Assembly Resolution
- Conversion of 'ByRef' Parameters
- Conversion of Lambdas and Delegates
Project & Folder Conversion
The Project & Folder Converter tab allows you to convert
all VB code within a project or folder. Once the conversion is finished, you can then
view VB to Java Converter comments, compare converted code files
to original code files, and view the converted code folder.
The Conversion History listview displays previously converted sources and allows you
to view remaining VB to Java Converter comments and view the converted code folder.
Note that due to the lack of similarity between VB and Java project types and
project files, VB to Java Converter does not generate Java project files. You need
to assemble the resulting .java files generated by VB to Java Converter into a new
Java project.
File & Snippet Conversion
The File & Snippet Converter tab allows you to convert
VB code snippets or files. From the left side textbox, you can type or paste code
snippets, insert files, or view VB to Java Converter sample snippets. Once a file or
snippet is converted, you can select and copy the results, save the results to a file,
or search the results.
- Braces: You can choose whether to place opening
braces on the next line after the construct header (default) or at the end of the same line.
You can choose whether to have braces vertically aligned with the construct (default) or
indented. Loops and if or else blocks with a single statement are converted by default
with enclosing braces. If you prefer to exclude braces for these cases then check
the preference to remove braces for single statement loops and if/else blocks.
- Indentation: You can choose whether the converted code uses
tabs or spaces for the leading white space. If you choose tabs for leading white space, then
leading spaces in the original code of the length that you specify are replaced by tabs. If you
choose spaces for leading white space, then tabs in the original code are replaced by spaces
of the length that you specify.
- Spacing: You can choose the degree to which
VB to Java Converter inserts spaces in the converted code. By default, binary operators
are padded with spaces and control structures have a space inserted after the keyword,
but you can switch off this behavior or insert spaces in other situations.
- Line Endings: By default, the converter separates
lines of code in the output by the Windows line ending \r\n. If you want the
non-Windows line ending \n, then you can choose this option.
- Control Statements: If you
select this option, the converter will break apart control structure statements
(if and while statements) by the main conditions. See the output in the
textbox to see the effect of this option.
- Method Declarations: If you select this
option, the converter will break apart method declarations by the method parameters. See the
output in the textbox to see the effect of this option.
- Method Calls: If you select this
option, the converter will break apart method calls by the method call arguments. See the
output in the textbox to see the effect of this option.
- String Literal Concatenation: If you select this
option, the converter will break apart multiple string literal concatenations to separate
lines. See the output in the textbox to see the effect of this option.
Type & Member Replacements
VB to Java Converter allows you to specify your own custom type and
member replacements in the converted code. This can be useful for cases where you wish
to specify replacements for .NET library member calls of a specific type that are not
handled by VB to Java Converter.
For each external type, you can specify an optional type replacement and multiple member
replacements. For types, you can specify generic types, which may include '?' as
a wildcard type. A wildcard in the replacement type must have a matching wildcard in the
same position in the original type.
e.g., the following will replace all references to type 'Foo' having one 'int' type parameter
with 'Bar', having no type parameters:
original type: Foo(Of Integer)
replacement type: Bar
e.g., the following will replace all references to type 'Foo' having one type parameter of any
type with 'Bar', having the same type parameter:
original type: Foo(Of ?)
replacement type: Bar<?>
For each member replacement, you specify the original member name, whether the member
is static or not, and whether the member is a method or a field/property. You also
specify the number of arguments you expect.
For the replacement member, you specify whether the replacement is static or not, and
whether the replacement is a method or a field/property. You also specify the new list
of arguments and can add literal arguments. For replacement of static methods with
instance members, you also specify the argument position which corresponds to the object
instance for the new instance member. For replacement of instance members with static
members, you specify the new class name used to call the static member (for static methods,
you also specify the position in the argument list to insert the previous instance
qualifier, using the string "instance" (quotes not included) at the appropriate position
in the "new argument list" field). For example, if you want to replace all instance
calls to the 'Foo' type method 'Bar' where you want the instance qualifier to be the
new first argument, you would specify "instance, a1" (quotes not included) for the
"new argument list" field, assuming that there was one argument in the original
method calls.
Conversion Message Options
On this options dialog, you can customize the comment prefixes
that the converter uses for messages and also toggle the messages that VB to Java Converter
displays on or off.
You can easily set all or none to display via the 'Select All' and 'Select None' buttons.
Custom String Replacements
VB to Java Converter allows you to specify your own
custom replacements in the converted Java code. This can be useful for customizing
code according to style preferences that may be different in Java than in VB. It's
also useful for cases where a .NET method without a Java equivalent will be replaced
by your own custom method to be called from the converted code.
For each replacement string you can specify the regex option, when to perform the replacement
(pre or post conversion), whether or not to match case, whether to match whole words only,
and whether comments or string literals should be modified. The whole words and string literals
options do not apply if the regex option is selected.
To span mulitple lines, either paste directly into the 'Find' and 'Replacement'
textboxes, or use the escaped characters: \r\n\t.
The "Active" checkbox can be unchecked if you wish to temporarily bypass the replacement.
Replacements are made in the order that they appear on the options dialog. For example,
the second replacement is made to each line of code after the first replacement has already
been made. To change the order of replacements, use the 'Up' and 'Down' buttons.
For an example of the regex option, you could do a custom replacement of "Foo(x)" with "Bar(x)",
where "x" is any argument, by specifying the "Find" field as "Foo(([\sa-zA-Z_$]*))" and the
"Replace" field as "Bar$1". Note that there are differences in various regex engines - the
regex engine used by the converter is .NET System.Text.RegularExpressions.Regex.
Diagnostic Options
These options are intended to provide information to
Tangible Software Solutions if a conversion is taking longer than expected.
'Record processing by file' instructs the converter to make a record of the files
processed and the time taken for each process. 'Record the last 100 lines of code
parsed before cancelling conversion' instructs the converter to make a record of the
most recent lines parsed before you cancelled the conversion.
File Encoding Options
The converter detects input file encoding from the byte order
mark (BOM), but if the BOM is missing the converter assumes by default that the file encoding
is UTF-8. You can use this option to specify a different default encoding to use in the absence
of a BOM. Output is written in the same encoding as the encoding detected for the original file,
or your default encoding option if the original coding was not detected via the BOM.
For UTF-8, you can choose whether or not to include the BOM for the output - this is normally
used in Windows environments.
Project Conversion Groups
If you need to regularly convert many projects at the same time,
use the Conversion Groups feature. This is most commonly used to convert sets of sample
projects to Java.
To configure Conversion Groups, go to Options->Project Conversion Groups on the main menu
or toolbar.
If you enter a folder for "common folder for added helper classes", the converter will
write all helper class files to this location. If nothing is entered here,
the helper class files will be written for each project in the group separately.
To convert a Conversion Group, go to Convert->Convert Group on the main menu.
Default Shared Assemblies for Conversions
For snippet and folder conversions, you can specify the
assemblies that the converter should resolve when interpreting the original code.
For .NET Core SDK projects, the project file contains no information about the shared
assemblies used by the project. The converter will not automatically attempt to resolve
every assembly in the .NET Core shared assembly location since it takes time to resolve the type
information in each assembly. Instead, we resolve only the shared assembly defining the core types
(System.Private.CoreLib) and allow you to select other assemblies for each project SDK that
you typically use.
For .NET Framework SDK projects, the project file contains no information about the GAC
assemblies used by the project. The converter will not automatically attempt to resolve
every assembly in the .NET Framework GAC assembly location since it takes time to resolve the type
information in each assembly. Instead, we resolve only the GAC assemblies 'mscorlib' and
'System' and allow you to select other assemblies for each project SDK that
you typically use.
Assumed Imported Namespaces for Snippet Conversions
You can specify namespaces that you would like the snippet converter
to assume are available when interpreting the original code. The snippet converter will then
convert as if the snippet contained the corresponding 'Imports' directives.
Package & File Options
- Package name if namespace is absent: If types in the
original code are not within a namespace, then the converter will use the package name
that you specify here.
- Place types in separate files named after the type: Standard
Java practice is to dedicate a file to a single type (class, interface, or enum).
VB to Java Converter does this by default, but you can also choose to keep the converted
code in a file structure corresponding to the original file structure.
- Base output folder structure on package structure:
Standard Java practice is to have the source code folder structure mimic the package structure.
VB to Java Converter does this by default, but you can also choose to keep the converted code
in a folder structure corresponding to the original folder structure.
- Convert to lowercase package names:
Standard Java practice is to use lowercase package names. VB to Java Converter does this
by default, but you can also choose to leave the original namespace names unchanged.
Property Conversion Options
- Convert automatic properties to fields: Automatic
properties are converted by default to get/set methods, but you can choose
to have these converted simply to fields.
- Adjust syntax of assembly property calls to get/set naming: Calls
to properties in referenced assemblies are not adjusted by default, but you can choose to have
these adjusted to get/set naming if you select this option.
- Naming convention of the final accessor and mutator methods: VB
properties convert to Java accessor and mutator methods (get/set methods). You have the
option of using different naming conventions for these methods.
Additions & Omissions
- Add to the top of all converted files: If you add text
for this option, that text will be added to the top of every converted file. This option
does not apply to code snippet conversions.
- Omit code regions for these preprocessor tokens:
VB to Java Converter will remove regions of code from the conversion output which are in
preprocessor blocks positively conditional on any of these tokens (e.g., #If OMIT Then).
- Copy code unconverted for these preprocessor tokens:
VB to Java Converter will leave regions of code unconverted which are in preprocessor blocks
positively conditional on any of these tokens (e.g., #If COPY Then).
Any #ElseIf or #Else blocks following the #If section are removed from the conversion
output.
.NET to Java Class Library Options
- System.DateTime: By default,
we convert System.DateTime to the Java 8 java.time.LocalDateTime, but you can
choose to convert to java.util.Date or to leave DateTime references unchanged.
- Unsigned types:
By default, VB to Java Converter only provides a warning for unsigned integer types (which
are not available in Java). You can instead choose one of the other two options:
1. use bitmasks to reproduce the unsigned integer behavior or 2. promote to the next
larger integer type. These last two options do not apply to 'ULong'.
- Nullable types: By default,
VB to Java Converter only converts System.Nullable when the type argument
is a primitive type and converts these cases to the Java wrapper types
(e.g., Integer) and converts other cases to the simple type argument (since
non-primitive Structure types convert to regular class types in Java).
- Bypass conversion of .NET attributes: Check this
preference if you would prefer to not have VB to Java Converter attempt to
convert the .NET attributes that have Java 1.5 annotation equivalents.
- Convert generic List methods which have System.Predicate parameters:
By default, the converter uses a helper class to convert many generic List methods
which have a System.Predicate parameter to Java using the Java 8
java.util.function.Predicate type.
- Convert System.String Trim methods to Java 11 strip,
stripLeading, & stripTrailing methods:
If this option is selected, the zero-argument string Trim, TrimStart, & TrimEnd
methods convert to the Java 11 strip, stripLeading, & stripTrailing methods.
Otherwise, 'Trim' converts to Java 'trim' and 'TrimStart' and 'TrimEnd'
are converted using helper methods.
- Use Java 9 java.util.Map.ofEntries for Dictionary initializer conversions:
By default,the converter uses Java 9 Map.ofEntries to convert VB Dictionary initializers, but you
can choose to convert to the Java 8 equivalent where the initializer is extracted to a separate statement.
Omit Types from Conversion
Any type entered here will be omitted from most
conversion logic. You would normally enter library type names here to prevent the
default conversion of objects of those types.
Miscellaneous Options
- Handling of preprocessor '#Region': The default behavior
of the converter is to comment out #Region preprocessor directives,
and their associated #End Region directives. You can also choose to
remove them completely.
- Renaming tag for Java keyword conflicts: VB to Java Converter
must occasionally rename identifiers that are keywords in Java. You can choose your own
renaming tag and whether to place it at the beginning or end of the original name when
this is necessary.
- Allow switch on strings: In Java, the switch
statement can operate on strings since Java 7, so by default we convert VB
Select Case statements operating on strings to Java switch statements.
- Use generic type inference (diamond syntax):
Select this option to convert VB generic variable initializations to the streamlined
'diamond syntax' available since Java 7
(e.g., Foo<Integer> instance = new Foo<>();.
- Convert 'Using' blocks to automatic resource mgt.:
Select this option to convert VB Using blocks to the Java 7 try block
with automatic resource management.
- Add @FunctionalInterface annotation to interfaces created from delegates:
Select this option to add this annotation to interfaces which the converter created
from VB delegates.
- Bypass assembly resolution dialogs: By default,
VB to Java Converter prompts you for the location of assembly dll's that it cannot
find - this aids in identifying the best conversion for some references to these
assemblies. Also, VB to Java Converter will display message boxes if it cannot
resolve the types or members within an assembly. Select this option if you do
not want to see these dialogs.
- Use helper 'stringsEqual' method to handle null strings:
Check this preference if you would prefer to have VB to Java Converter use a helper
method for string equality instead of Java's String equals method. The helper
method checks that the instance variable is not null.
- Generate method overloads for optional parameters:
By default, VB to Java Converter generates method overloads for methods with optional
parameters. If you turn off this option, then no method overloads will be generated and
any missing optional arguments will be added to the method calls.
- Insert temporary variables for 'For' loop ending conditions that are not constant:
VB evaluates the ending condition of For loops exactly once, while Java evaluates
it on every iteration. If VB to Java Converter determines that it is possible that the
ending condition may change, then it inserts a temporary variable set to the original
ending condition and uses that temporary variable in the Java for loop.
- Use postfix operator where possible:
You have the option of converting unitary increment/decrement statements such
as i = i + 1 or i += 1 to the very concise Java postfix form i++.
- Convert inferred typing to Java 10 inferred typing: Java 10
allows inferred typing for local variables via the 'var' keyword. Check this option if you
want the converter to convert VB inferred typing to Java 'var'.
- Assume 'Option Strict On' for snippets if no 'Option Strict' statement found:
By default, the converter assumes 'Option Strict Off' for snippet conversions if no
'Option Strict' statement is found.
- Assume 'Option Infer On' for snippets if no 'Option Infer' statement found:
By default, the converter assumes 'Option Infer On' for snippet conversions if no
'Option Infer' statement is found.
- Copy non-code files in project or folder conversions: By default,
the converter does not copy non-code files in project or folder conversions. If you select this
option, all non-code files are copied to the target folder.
- Convert AssemblyInfo attributes to fields: Checking
this option causes the converter to create a class called AssemblyInfo to contain fields
corresponding to the assembly attributes contained in the AssemblyInfo file.
- Convert multiline string literals to Java 15 text blocks: Java 15
text blocks are used for conversion of VB multiline string literals if you select this option.
Conversion of 'ByRef' Parameters
Java has no equivalent to VB's ByRef parameters, but
VB to Java Converter uses the helper class RefObject to provide a conversion which
reproduces the same behavior.
e.g., the following VB method:
Public Sub Test(ByRef i As Integer)
is converted to:
public void Test(tangible.RefObject<Integer> i)
and a call to this method is converted to:
tangible.RefObject<Integer> tempRef_i = new tangible.RefObject<Integer>(i);
Test(tempRef_i);
i = tempRef_i.argValue;
The definition of RefObject is inserted into the converted code. RefObject is defined
as follows:
public final class RefObject<T>
{
public T argValue;
public RefObject(T refArg)
{
argValue = refArg;
}
}
Conversion of Lambdas and Delegates
Most VB delegates are converted to interfaces and VB
lambdas are converted to Java 8 lambdas.
For example, the following VB code:
Public Delegate Sub myVoidDelegate(ByVal i As Integer)
Public voidDelegateVar As myVoidDelegate
Private Sub Test()
voidDelegateVar = New myVoidDelegate(AddressOf instanceMethod)
voidDelegateVar = Sub(i) instanceMethod(i)
End Sub
is converted to the following Java code:
@FunctionalInterface
public interface myVoidDelegate
{
void invoke(int i);
}
public myVoidDelegate voidDelegateVar;
private void Test()
{
voidDelegateVar = (int i) -> instanceMethod(i);
voidDelegateVar = (i) -> instanceMethod(i);
}
Assembly Resolution
Assemblies referenced by projects are examined to
determine the nature of the types and members within the assembly to improve the conversion
quality.
During the project conversion process you may be prompted
by the converter to find specific assemblies referenced by your project if they
cannot otherwise be found by the converter.
If the converter does not resolve all assemblies, you can still
continue the project conversion, but the conversion may not be optimal for code which
references the unresolved assemblies. This just means that a few more manual adjustments
may be required.
If the assembly does not require an install, you can forward it
to us in a zip file to determine why it is not resolving.
Copyright © Tangible Software Solutions, Inc.