p5-java-parse / lib / Java / Parser.pm

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
use 5.010;
use utf8;

use Java::Tokeniser;
use MooseX::Declare;
use Moose::Util::TypeConstraints;
use TryCatch;

subtype 'TokeStream',
	as 'Java::Tokeniser';

coerce 'TokeStream',
	from 'Str',
	via { Java::Tokeniser->new(stream => $_)->tokenise };

class Java::Parser
	with Java::Parse::Role::TokenQueue
{
	has tokens => (
		is       => 'ro',
		isa      => 'TokeStream',
		coerce   => 1,
		required => 1,
		handles  => [qw/shift_token push_token count_tokens
			peek_token peek_token_type next_token_matches eat_token
			java_builtin_types java_builtin_modifiers/],
		);
	
	method eat_ws
	{
		$self->eat_token('.Whitespace');
		$self->eat_cruft;
	}

	method eat_cruft
	{
		return unless $self->count_tokens;
		
		while ($self->peek_token->isa('.Whitespace')
		or     $self->peek_token->isa('.Comment'))
		{
			$self->eat_token;
			last unless $self->count_tokens;
		}
	}

	method parse
	{
		my $doc = Java::Ast::Document->new;
		
		#use Data::Printer;
		#p($self->tokens);
		
		$self->eat_cruft;
		while ($self->count_tokens)
		{
			$doc->push_declaration(
				$self->parse_interface_or_class_declaration
				);
			$self->eat_cruft;
		}
		
		$doc;
	}
	
	method parse_modifiers
	{
		my @modifiers;
		
		$self->eat_cruft;
		while ($self->next_token_matches('.Keyword', $self->java_builtin_modifiers))
		{
			push @modifiers, $self->eat_token('.Keyword');
			$self->eat_ws;
			$self->eat_cruft;
		}
		
		map { $_->spelling } @modifiers;
	}
	
	method parse_identifier
	{
		$self->eat_cruft;
		my $id = $self->eat_token('.Identifier');
		
		if (wantarray)
		{
			return ($id->spelling, $id);
		}
		
		return $id->spelling;
	}
	
	method parse_identifier_list
	{
		$self->eat_cruft;
		
		my @ids;
		my $continue = 1;
		while ($continue)
		{
			push @ids, $self->eat_token('.Identifier');
			$self->eat_cruft;
			$continue = 0;
			
			if ($self->next_token_matches('.Comma'))
			{
				$self->eat_token;
				$self->eat_cruft;
				$continue = 1;
			}
		}

		map { $_->spelling } @ids;
	}
	
	method parse_thing_inside_class
	{
		return if $self->next_token_matches('.RightCurly');
		
		my @modifiers = $self->parse_modifiers;
		
		if ($self->next_token_matches('.Keyword', [qw/class interface/]))
		{
			return $self->parse_interface_or_class_declaration(\@modifiers);
		}

		my $type;
		$self->eat_cruft;
		if ($self->next_token_matches('.Identifier'))
		{
			$type = $self->parse_identifier;
		}
		else
		{
			$type = $self->eat_token('.Keyword', $self->java_builtin_types)->spelling;
		}
		$self->eat_cruft;
		
		my ($name, $id) = $self->parse_identifier;
		$self->eat_cruft;
		my $rv;
		
		if ($self->next_token_matches('.LeftRounded'))
		{
			$rv = Java::Ast::MethodDeclaration->new(
				modifiers => \@modifiers,
				name      => $name,
				token     => $id,
				type      => $type,
				);
			$self->eat_token('.LeftRounded');
			$self->eat_cruft;
			# TODO: parameters
			$self->eat_cruft;
			$self->eat_token('.RightRounded');
			$self->eat_cruft;
			
			if ($self->next_token_matches('.Semicolon'))
			{
				$self->eat_token('.Semicolon');
				$self->eat_cruft;
			}
			else
			{
				$rv->body($self->parse_method_body);
			}
		}
		else
		{
			$rv = Java::Ast::MemberDeclaration->new(
				modifiers => \@modifiers,
				name      => $name,
				token     => $id,
				type      => $type,
				);
			
			if ($self->next_token_matches('.Semicolon'))
			{
				$self->eat_token('.Semicolon');
			}
			elsif ($self->next_token_matches('.Op.Assign'))
			{
				$self->eat_token('.Op.Assign');
				$self->eat_cruft;
				$rv->value( $self->parse_expression );
				$self->eat_cruft;				
				$self->eat_token('.Semicolon');
			}
		}
		
		$self->eat_cruft;
		return $rv;
	}
	
	method parse_interface_or_class_declaration ($modifiers?, $declaration_type?)
	{
		my @modifiers = defined $modifiers 
			? @$modifiers
			: $self->parse_modifiers;

		$declaration_type //=
			$self->eat_token('.Keyword', [qw/class interface/])->spelling;
		my $declaration_class = {
			class     => 'Java::Ast::ClassDeclaration',
			interface => 'Java::Ast::InterfaceDeclaration',
			}->{ $declaration_type };
		
		my ($name, $id) = $self->parse_identifier;
		my $declaration = $declaration_class->new(
			name      => $name,
			modifiers => \@modifiers,
			token     => $id,
			);
		
		$self->eat_cruft;
		if ($self->next_token_matches('.Keyword', 'extends'))
		{
			$self->eat_token;
			my @id_list = $self->parse_identifier_list;
			if (@id_list > 1 and $declaration_type eq 'class')
			{
				$declaration->push_warning('Multiple inheritance');
			}
			$declaration->base(\@id_list);
		}
		
		$self->eat_cruft;
		if ($self->next_token_matches('.Keyword', 'implements'))
		{
			$self->eat_token;
			my @id_list = $self->parse_identifier_list;
			$declaration->implements(\@id_list);
		}
		
		$self->eat_cruft;
		$self->eat_token('.LeftCurly');
		
		while (my $member = $self->parse_thing_inside_class)
		{
			if ($member->isa('Java::Ast::TypeDeclaration'))
			{
				$declaration->push_declaration($member);
			}
			elsif ($member->isa('Java::Ast::MethodDeclaration'))
			{
				$declaration->push_method($member);
			}
			else
			{
				$declaration->push_member($member);
			}
		}
		
		$self->eat_cruft;
		$self->eat_token('.RightCurly');
		
		return $declaration;
	}
	
	method parse_block
	{
		$self->eat_cruft;
		my $start = $self->eat_token('.LeftCurly');
		my @statements;
		
		ST: while ('arse')
		{
			$self->eat_cruft;
			
			if ($self->next_token_matches('.Semicolon'))
			{
				$self->eat_token('.Semicolon');
				$self->eat_cruft;
			}
			
			if ($self->next_token_matches('.RightCurly'))
			{
				$self->eat_token('.RightCurly');
				$self->eat_cruft;
				last ST;
			}
			
			push @statements, $self->parse_statement;
		}
		
		return Java::Ast::Block->new(
			token      => $start,
			statements => \@statements,
			);
	}
	
	method parse_statement
	{
		$self->eat_cruft;
		
		if ($self->next_token_matches('.Keyword', 'assert'))
			{ return $self->parse_assert_statement }
		
		if ($self->next_token_matches('.Keyword', 'break'))
			{ return $self->parse_break_statement }
		
		if ($self->next_token_matches('.Keyword', 'case'))
			{ return $self->parse_case_statement }
		
		if ($self->next_token_matches('.Keyword', 'catch'))
			{ return $self->parse_catch_statement }

		if ($self->next_token_matches('.Keyword', 'continue'))
			{ return $self->parse_continue_statement }

		if ($self->next_token_matches('.Keyword', 'do'))
			{ return $self->parse_do_statement }
		
		if ($self->next_token_matches('.Keyword', 'finally'))
			{ return $self->parse_finally_statement }
		
		if ($self->next_token_matches('.Keyword', 'for'))
			{ return $self->parse_for_statement }

		if ($self->next_token_matches('.Keyword', 'if'))
			{ return $self->parse_if_statement }

		if ($self->next_token_matches('.Keyword', 'import'))
			{ return $self->parse_import_statement }

		if ($self->next_token_matches('.Keyword', 'package'))
			{ return $self->parse_package_statement }

		if ($self->next_token_matches('.Keyword', 'return'))
			{ return $self->parse_return_statement }

		if ($self->next_token_matches('.Keyword', 'super'))
			{ return $self->parse_super_statement }

		if ($self->next_token_matches('.Keyword', 'switch'))
			{ return $self->parse_switch_statement }

		if ($self->next_token_matches('.Keyword', 'throw'))
			{ return $self->parse_throw_statement }

		if ($self->next_token_matches('.Keyword', 'try'))
			{ return $self->parse_try_statement }

		if ($self->next_token_matches('.Keyword', 'while'))
			{ return $self->parse_while_statement }

		try {
			$self->eat_cruft;
			my $expr = $self->parse_expression;
			$self->eat_cruft;
			$self->eat_token('.Semicolon');
			$self->eat_cruft;
			return Java::Ast::Statement::Expression->new(
				token      => $expr->token,
				expression => $expr,
				);
		}
		catch {
			confess "that I need to spend some more time on error messages";
		}
	}
	
	method parse_return_statement
	{
		$self->eat_cruft;
		my $tok  = $self->eat_token('.Keyword', 'return');
		$self->eat_cruft;
		my $expr = $self->parse_expression;
		$self->eat_cruft;
		$self->eat_token('.Semicolon');
		$self->eat_cruft;
		return Java::Ast::Statement::Return->new(
			token      => $tok,
			expression => $expr,
			);
	}
	
	# Much props to http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm
	method parse_expression
	{
		return $self->_pe_Exp(0);
	}
	
	method _pe_mkleaf ($token)
	{
		if ($token->isa('.Identifier'))
			{ return Java::Ast::Identifier->new(token => $token) }
		elsif ($token->isa('.Literal'))
			{ return Java::Ast::Constant->new(token => $token) }
		elsif ($token->isa('.Keyword') and $token->spelling ~~ $self->java_builtin_types)
			{ return Java::Ast::Identifier->new(token => $token) }
		else
			{ confess "that I haven't written a good error message yet."; }
	}
	
	method _pe_arglist
	{
		$self->eat_cruft;		
		my @arglist;
		
		ARG: while (1)
		{
			last ARG if $self->next_token_matches('.RightRounded');
			push @arglist, $self->_pe_Exp(0);
			
			$self->eat_cruft;
			if ($self->next_token_matches('.Comma'))
			{
				$self->eat_token('.Comma');
				$self->eat_cruft;
			}
			else
			{
				$self->eat_cruft;
				last ARG;
			}
		}
		
		return @arglist;
	}
	
	method _pe_Exp ($p)
	{
		my $t = $self->_pe_P;
		$self->eat_cruft;
		
		while ($self->count_tokens
			and (
				($self->peek_token->does('Java::Token::Op::Binary')
				 and $self->peek_token->prec_binary >= $p)
				or
				($self->peek_token->does('Java::Token::Op::Ternary')
				 and $self->peek_token->prec_ternary >= $p
				 and defined $self->peek_token->partner)
				or # method invocation
				($self->next_token_matches('.LeftRounded')
				 and $p < 15)
				or # array access
				($self->next_token_matches('.LeftSquare')
				 and $p < 15)
			)
		)
		{
			my $tok = $self->eat_token;
			$self->eat_cruft;
			
			my $op;
			if ($tok->isa('.LeftRounded'))
			{
				$op = Java::Ast::MethodInvocationOperation->new(
					operator   => $tok->spelling,
					token      => $tok,
					left       => $t,
					arguments  => [ $self->_pe_arglist ],
					);
				$self->eat_cruft;
				$self->eat_token('.RightRounded');
				$self->eat_cruft;
			}
			elsif ($tok->isa('.LeftSquare'))
			{
				$op = Java::Ast::ArrayIndexingOperation->new(
					operator   => $tok->spelling,
					token      => $tok,
					left       => $t,
					right      => $self->_pe_Exp(0),
					);
				$self->eat_cruft;
				$self->eat_token('.RightSquare');
				$self->eat_cruft;
			}
			elsif ($tok->does('Java::Token::Op::Ternary'))
			{
				$op = Java::Ast::TernaryOperation->new(
					operator   => $tok->spelling,
					token      => $tok,
					left       => $t,
					);
				my $q  = $op->token->assoc_ternary eq 'right'
					? $tok->prec_ternary
					: (1 + $tok->prec_ternary);
				$op->middle($self->_pe_Exp($q));
				$self->eat_cruft;
				$self->eat_token(undef, $tok->partner);
				$self->eat_cruft;
				$op->right($self->_pe_Exp($q));
			}
			else
			{
				$op = Java::Ast::BinaryOperation->new(
					operator   => $tok->spelling,
					token      => $tok,
					left       => $t,
					);
				my $q  = $op->token->assoc_binary eq 'right'
					? $tok->prec_binary
					: (1 + $tok->prec_binary);
				$op->right($self->_pe_Exp($q));
			}
			
			$t = $op;
		}
		
		return $t;
	}
	
	method _pe_P
	{
		$self->eat_cruft;
		my $t;
		
		if ($self->peek_token->does('Java::Token::Op::Unary'))
		{
			my $tok = $self->eat_token;
			$self->eat_cruft;
			
			$t = Java::Ast::UnaryOperation->new(
				operator   => $tok->spelling,
				token      => $tok,
				right      => $self->_pe_Exp($tok->prec_unary),
				);
		}
		elsif ($self->next_token_matches('.LeftRounded'))
		{
			$self->eat_token('.LeftRounded');
			$self->eat_cruft;
			$t = $self->_pe_Exp(0);
			$self->eat_cruft;
			$self->eat_token('.RightRounded');
			$self->eat_cruft;
			
			if ($t->isa('Java::Ast::Identifier'))
			{
				$t = Java::Ast::TypeCastOperation->new(
					token      => $t->token,
					type       => $t->token->spelling,
					right      => $self->_pe_Exp(12),
					);
			}
		}
		elsif ($self->next_token_matches('.Identifier')
		or     $self->next_token_matches('.Literal')
		or     $self->next_token_matches('.Keyword', $self->java_builtin_types))
		{
			$t = $self->_pe_mkleaf($self->eat_token);
			$self->eat_cruft;			
		}
		else
		{
			confess "that this isn't really a very good error message either.";
		}

		if ($self->next_token_matches('.Op')
		and $self->peek_token->can('assoc_unary')
		and $self->peek_token->assoc_unary eq 'left')
		{
			my $tok = $self->eat_token;
			$self->eat_cruft;
			
			my $tpp = Java::Ast::UnaryOperationPostfix->new(
				operator   => $tok->spelling,
				token      => $tok,
				left       => $t,
				);
			
			return $tpp;
		}
		
		return $t;
	}
}

class Java::Ast
{
	has token => (
		is       => 'ro',
		isa      => 'Java::Token',
		);
	has warnings => (
		is       => 'rw',
		isa      => 'ArrayRef[Str]',
		traits   => [qw/Array/],
		default  => sub { [] },
		handles  => { push_warning => 'push' },
		);
}

role Java::Ast::WithModifiers
{
	has modifiers => (
		is       => 'rw',
		isa      => 'ArrayRef',
		);
}

role Java::Ast::WithDeclarations
{
	has declarations => (
		is       => 'rw',
		isa      => 'ArrayRef[Java::Ast::TypeDeclaration]',
		traits   => [qw/Array/],
		default  => sub { [] },
		handles  => { push_declaration => 'push' },
		);
}

class Java::Ast::Document
	extends Java::Ast
	with Java::Ast::WithDeclarations;

class Java::Ast::TypeDeclaration
	extends Java::Ast
	with Java::Ast::WithDeclarations
	with Java::Ast::WithModifiers
{
	has name => (
		is       => 'rw',
		isa      => 'Str',
		);
	
	has members => (
		is       => 'rw',
		isa      => 'ArrayRef',
		traits   => [qw/Array/],
		default  => sub { [] },
		handles  => { push_member => 'push' },
		);

	has methods => (
		is       => 'rw',
		isa      => 'ArrayRef',		
		traits   => [qw/Array/],
		default  => sub { [] },
		handles  => { push_method => 'push' },
		);
}

role Java::Ast::WithNameAndType
{
	has name => (
		is       => 'rw',
		isa      => 'Str',
		);
	
	has type => (
		is       => 'rw',
		isa      => 'Str',
		);
}

class Java::Ast::MethodDeclaration
	extends Java::Ast
	with Java::Ast::WithNameAndType
	with Java::Ast::WithModifiers
{
	has body => (
		is       => 'rw',
		);
	
	has parameters => (
		is       => 'rw',
		isa      => 'ArrayRef',
		handles  => { push_parameters => 'push' },
		);
}

class Java::Ast::MemberDeclaration
	extends Java::Ast
	with Java::Ast::WithNameAndType
	with Java::Ast::WithModifiers
{
	has value => (
		is       => 'rw',
		isa      => 'Java::Ast::Expression',
		);
}

class Java::Ast::Block
	extends Java::Ast
{
	has statements => (
		is       => 'rw',
		isa      => 'ArrayRef',
		);
}

class Java::Ast::Statement
	extends Java::Ast;

class Java::Ast::Statement::Expression
	extends Java::Ast
{
	has expression => (
		is       => 'rw',
		isa      => 'Java::Ast::Expression',
		);
}

class Java::Ast::Statement::Return
	extends Java::Ast
{
	has expression => (
		is       => 'rw',
		isa      => 'Java::Ast::Expression',
		);
}

class Java::Ast::ClassDeclaration
	extends Java::Ast::TypeDeclaration
{
	has base => (
		is       => 'rw',
		isa      => 'ArrayRef[Str]', # Java allows maximum of one base class here
		);

	has implements => (
		is       => 'rw',
		isa      => 'ArrayRef[Str]',
		);
}

class Java::Ast::InterfaceDeclaration
	extends Java::Ast::TypeDeclaration
{
	has base => (
		is       => 'rw',
		isa      => 'ArrayRef[Str]',
		);
}

class Java::Ast::Expression
	extends Java::Ast;

class Java::Ast::Operation
	extends Java::Ast::Expression
{
	has operator => (
		is       => 'rw',
		isa      => 'Str',
		);
}

role Java::Ast::WithRightOperand
{
	has right => (
		is       => 'rw',
		isa      => 'Java::Ast::Expression',
		);
}

role Java::Ast::WithLeftOperand
{
	has left => (
		is       => 'rw',
		isa      => 'Java::Ast::Expression',
		);
}

role Java::Ast::WithMiddleOperand
{
	has middle => (
		is       => 'rw',
		isa      => 'Java::Ast::Expression',
		);
}

class Java::Ast::UnaryOperation
	extends Java::Ast::Operation
	with Java::Ast::WithRightOperand
{
	method debug_string
	{
		return sprintf(
			'(%s%s)',
			$self->operator,
			$self->right->debug_string,
			);
	}
}

class Java::Ast::TypeCastOperation
	extends Java::Ast::Operation
	with Java::Ast::WithRightOperand
{
	has type => (
		is       => 'rw',
		isa      => 'Str',
		);
	
	has '+operator' => (
		default  => 'CAST',
		);
	
	method debug_string
	{
		return sprintf(
			'%s(%s as %s)',
			$self->operator,
			$self->right->debug_string,
			$self->type,
			);
	}
}

class Java::Ast::UnaryOperationPostfix
	extends Java::Ast::Operation
	with Java::Ast::WithLeftOperand
{
	method debug_string
	{
		return sprintf(
			'(%s%s)',
			$self->left->debug_string,
			$self->operator,
			);
	}
}

class Java::Ast::BinaryOperation
	extends Java::Ast::Operation
	with Java::Ast::WithLeftOperand
	with Java::Ast::WithRightOperand
{
	method debug_string
	{
		return sprintf(
			'(%s %s %s)',
			$self->left->debug_string,
			$self->operator,
			$self->right->debug_string,
			);
	}
}

class Java::Ast::MethodInvocationOperation
	extends Java::Ast::Operation
	with Java::Ast::WithLeftOperand
{
	has arguments => (
		is       => 'rw',
		isa      => 'ArrayRef[Java::Ast::Expression]',
		);	
	
	method debug_string
	{
		return sprintf(
			'%s(%s)',
			$self->left->debug_string,
			join q{, }, (map {$_->debug_string} @{$self->arguments}),
			);
	}
}

class Java::Ast::ArrayIndexingOperation
	extends Java::Ast::Operation
	with Java::Ast::WithLeftOperand
	with Java::Ast::WithRightOperand
{
	method debug_string
	{
		return sprintf(
			'%s[%s]',
			$self->left->debug_string,
			$self->right->debug_string,
			);
	}
}

class Java::Ast::TernaryOperation
	extends Java::Ast::Operation
	with Java::Ast::WithLeftOperand
	with Java::Ast::WithMiddleOperand
	with Java::Ast::WithRightOperand
{
	method debug_string
	{
		return sprintf(
			'(%s %s %s %s %s)',
			$self->left->debug_string,
			$self->operator,
			$self->middle->debug_string,
			$self->token->partner,
			$self->right->debug_string,
			);
	}
}

class Java::Ast::Identifier
	extends Java::Ast::Expression
{
	method debug_string
	{
		$self->token->spelling;
	}
}

class Java::Ast::Constant
	extends Java::Ast::Expression
{
	method debug_string
	{
		$self->token->spelling;
	}
}

1;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.