Java generator fix for simple types.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7601 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
inoussa
2020-08-13 16:58:05 +00:00
parent d7364ed9f8
commit 8dd89d1af9
2 changed files with 25 additions and 11 deletions

View File

@ -23,6 +23,9 @@ uses
type type
{$SCOPEDENUMS ON}
TSimpleTypeItem = (Simple, Extendable);
{ TInftGenerator } { TInftGenerator }
TInftGenerator = class(TBaseGenerator) TInftGenerator = class(TBaseGenerator)
@ -30,7 +33,7 @@ type
FStream : ISourceStream; FStream : ISourceStream;
private private
function GenerateIntfName(AIntf : TPasElement):string; function GenerateIntfName(AIntf : TPasElement):string;
function GenerateTypeText(AType : TPasType) : string; function GenerateTypeText(AType : TPasType; const AItem : TSimpleTypeItem = TSimpleTypeItem.Simple) : string;
procedure GenerateIntfProcParamsTypes(AProc : TPasProcedure); procedure GenerateIntfProcParamsTypes(AProc : TPasProcedure);
procedure GenerateIntf(AIntf : TPasClassType); procedure GenerateIntf(AIntf : TPasClassType);
@ -58,15 +61,26 @@ begin
Result := AIntf.Name; Result := AIntf.Name;
end; end;
function TInftGenerator.GenerateTypeText(AType : TPasType) : string; function TInftGenerator.GenerateTypeText(AType : TPasType; const AItem : TSimpleTypeItem) : string;
var var
t : TPasType; t : TPasType;
begin begin
t := GetUltimeType(AType); t := GetUltimeType(AType);
if not t.InheritsFrom(TPasArrayType) then begin if not t.InheritsFrom(TPasArrayType) then begin
if (AItem = TSimpleTypeItem.Extendable) and
t.InheritsFrom(TPasNativeSimpleType) and
(TPasNativeSimpleType(t).ExtendableType <> nil)
then begin
t := TPasNativeSimpleType(t).ExtendableType;
end;
Result := t.Name; Result := t.Name;
end else begin end else begin
t := GetUltimeType(TPasArrayType(t).ElType); t := GetUltimeType(TPasArrayType(t).ElType);
if t.InheritsFrom(TPasNativeSimpleType) and
Assigned(TPasNativeSimpleType(t).ExtendableType)
then begin
t := TPasNativeSimpleType(t).ExtendableType;
end;
Result := Format('java.util.List<%s>',[t.Name]); Result := Format('java.util.List<%s>',[t.Name]);
end; end;
end; end;
@ -423,7 +437,7 @@ procedure TInftGenerator.GenerateClass(ASymbol : TPasClassType);
locLine := locLine+';'; locLine := locLine+';';
end else begin end else begin
locType := GetUltimeType(TPasArrayType(locType).ElType); locType := GetUltimeType(TPasArrayType(locType).ElType);
locLine := Format('public java.util.List<%s> %s = new java.util.ArrayList<>();',[GenerateTypeText(locType),SymbolTable.GetExternalName(AProp)]); locLine := Format('public java.util.List<%s> %s = new java.util.ArrayList<>();',[GenerateTypeText(locType,TSimpleTypeItem.Extendable),SymbolTable.GetExternalName(AProp)]);
end; end;
Indent(); WriteLn(locLine); Indent(); WriteLn(locLine);
end; end;

View File

@ -306,14 +306,14 @@ const
// JAVA // JAVA
JAVA_SIMPLE_TYPES_COUNT = 11; JAVA_SIMPLE_TYPES_COUNT = 11;
JAVA_SIMPLE_TYPES : Array[0..Pred(JAVA_SIMPLE_TYPES_COUNT)] Of array[0..2] of string = ( JAVA_SIMPLE_TYPES : Array[0..Pred(JAVA_SIMPLE_TYPES_COUNT)] Of array[0..2] of string = (
('char', '', ''), ('char', 'Character', ''),
('byte', '', ''), ('byte', 'Byte', ''),
('short', '', ''), ('short', 'Short', ''),
('int', '', ''), ('int', 'Integer', ''),
('long', '', ''), ('long', 'Long', ''),
('float', '', ''), ('float', 'Float', ''),
('double', '', ''), ('double', 'Double', ''),
('boolean', '', ''), ('boolean', 'Boolean', ''),
('String', '', 'string'), ('String', '', 'string'),
('String', '', 'dateTime') , //('java.util.OffsetDateTime', '', 'dateTime') , ('String', '', 'dateTime') , //('java.util.OffsetDateTime', '', 'dateTime') ,
//('java.time.OffsetTime', '', 'time') , //('java.time.OffsetTime', '', 'time') ,