Skip to content

Commit db61c7b

Browse files
committed
API Doc
1 parent 5eec65b commit db61c7b

File tree

2 files changed

+106
-12
lines changed

2 files changed

+106
-12
lines changed

src/com/inet/lib/less/Operation.java

Lines changed: 86 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Operation extends Expression {
4242

4343
private int type;
4444

45-
private static final HashMap<String, HashMap<String, Double>> unitConversions = new HashMap<>();
45+
private static final HashMap<String, HashMap<String, Double>> UNIT_CONVERSIONS = new HashMap<>();
4646
static {
4747
HashMap<String, Double> length = new HashMap<>();
4848
putConvertion( length, "m", 1 );
@@ -64,31 +64,50 @@ class Operation extends Expression {
6464
putConvertion( angle, "turn", 1 );
6565
}
6666

67+
/**
68+
* Helper for creating static unit conversions.
69+
*
70+
* @param group the unit group like length, duration or angles. Units of one group can convert in another.
71+
* @param unit the unit name
72+
* @param factor the convert factor
73+
*/
6774
private static void putConvertion( HashMap<String, Double> group, String unit, double factor ) {
68-
unitConversions.put(unit, group );
75+
UNIT_CONVERSIONS.put(unit, group );
6976
group.put( unit, factor );
7077
}
7178

72-
Operation( LessObject reader, Expression left, char operator ) {
73-
this( reader, operator );
79+
/**
80+
* Create a new instance.
81+
*
82+
* @param obj another LessObject with parse position.
83+
* @param left left operand
84+
* @param operator the operator like +, -, *, etc.
85+
*/
86+
Operation( LessObject obj, Expression left, char operator ) {
87+
this( obj, operator );
7488
if( left != null ) {
7589
this.operands.add( left );
7690
}
7791
}
7892

7993
/**
80-
* Empty parameter list
94+
* Create a new instance with an empty parameter list.
95+
*
96+
* @param obj another LessObject with parse position.
97+
* @param operator the operator like +, -, *, etc.
8198
*/
82-
Operation( LessObject reader, char operator ) {
83-
super( reader, String.valueOf( operator ) );
99+
Operation( LessObject obj, char operator ) {
100+
super( obj, String.valueOf( operator ) );
84101
this.operator = operator;
85102
}
86103

87104
/**
88-
* Empty parameter list
105+
* Create a new instance with an empty parameter list and a comma as operation.
106+
*
107+
* @param obj another LessObject with parse position.
89108
*/
90-
Operation( LessObject reader ) {
91-
super( reader, "," );
109+
Operation( LessObject obj ) {
110+
super( obj, "," );
92111
this.operator = ',';
93112
}
94113

@@ -112,12 +131,18 @@ ArrayList<Expression> getOperands() {
112131

113132
/**
114133
* Add the next operand. It must use the same operator like this operation.
134+
*
115135
* @param right the next operand
116136
*/
117137
void addOperand( Expression right ) {
118138
this.operands.add( right );
119139
}
120140

141+
/**
142+
* Add an operand on the top position to the operand list.
143+
*
144+
* @param left operand the new operand
145+
*/
121146
void addLeftOperand( Expression left ) {
122147
this.operands.add( 0, left );
123148
}
@@ -149,6 +174,11 @@ public int getDataType( CssFormatter formatter ) {
149174
return type;
150175
}
151176

177+
/**
178+
* Get the highest data type of different operands
179+
* @param formatter current formatter
180+
* @return the data type
181+
*/
152182
private int maxOperadType( CssFormatter formatter ) {
153183
int dataType = operands.get( 0 ).getDataType( formatter );
154184
for( int i = 1; i < operands.size(); i++ ) {
@@ -251,18 +281,20 @@ public void appendTo( CssFormatter formatter ) {
251281

252282
/**
253283
* Calculate the factor between 2 units.
284+
*
254285
* @param leftUnit left unit
255286
* @param rightUnit right unit
256287
* @param fail true, should be fail if units incompatible; false, return 1 is incompatible
257288
* @return the factor between the 2 units.
289+
* @throws LessException if unit are incompatible and fail is true
258290
*/
259291
static double unitFactor( String leftUnit, String rightUnit, boolean fail ) {
260292
if( leftUnit.length() == 0 || rightUnit.length() == 0 || leftUnit.equals( rightUnit ) ) {
261293
return 1;
262294
}
263-
HashMap<String, Double> leftGroup = unitConversions.get( leftUnit );
295+
HashMap<String, Double> leftGroup = UNIT_CONVERSIONS.get( leftUnit );
264296
if( leftGroup != null ) {
265-
HashMap<String, Double> rightGroup = unitConversions.get( rightUnit );
297+
HashMap<String, Double> rightGroup = UNIT_CONVERSIONS.get( rightUnit );
266298
if( leftGroup == rightGroup ) {
267299
return leftGroup.get( leftUnit ) / leftGroup.get( rightUnit );
268300
}
@@ -305,6 +337,13 @@ public double doubleValue( CssFormatter formatter ) {
305337
return value;
306338
}
307339

340+
/**
341+
* Calculate the number value of two operands if possible.
342+
*
343+
* @param left the left
344+
* @param right the right
345+
* @return the result.
346+
*/
308347
private double doubleValue( double left, double right ) {
309348
switch( operator ) {
310349
case '+':
@@ -320,24 +359,48 @@ private double doubleValue( double left, double right ) {
320359
}
321360
}
322361

362+
/**
363+
* Calculate a color on left with a number on the right side. The calculation occur for every color channel.
364+
*
365+
* @param color the color
366+
* @param right the right
367+
* @return color value as long
368+
*/
323369
private double doubleValueLeftColor( double color, double right ) {
324370
return rgba( doubleValue( red( color ), right ), //
325371
doubleValue( green( color ), right ), //
326372
doubleValue( blue( color ), right ), 1 );
327373
}
328374

375+
/**
376+
* Calculate a number on left with a color on the right side. The calculation occur for every color channel.
377+
*
378+
* @param left the left
379+
* @param color the color
380+
* @return color value as long
381+
*/
329382
private double doubleValueRightColor( double left, double color ) {
330383
return rgba( doubleValue( left, red( color ) ), //
331384
doubleValue( left, green( color ) ), //
332385
doubleValue( left, blue( color ) ), 1 );
333386
}
334387

388+
/**
389+
* Calculate two colors. The calculation occur for every color channel.
390+
*
391+
* @param left the left color
392+
* @param right the right color
393+
* @return color value as long
394+
*/
335395
private double doubleValue2Colors( double left, double right ) {
336396
return rgba( doubleValue( red( left ), red( right ) ), //
337397
doubleValue( green( left ), green( right ) ), //
338398
doubleValue( blue( left ), blue( right ) ), 1 );
339399
}
340400

401+
/**
402+
* {@inheritDoc}
403+
*/
341404
@Override
342405
public boolean booleanValue(CssFormatter formatter) {
343406
Expression leftOp = operands.get( 0 );
@@ -572,17 +635,28 @@ static int level( char operator ) {
572635
return 0;
573636
}
574637

638+
/**
639+
* Helper class to count the resulting unit of an operation with different units
640+
*/
575641
private static class Unit {
576642
private int numerator;
577643

578644
private int denominator;
579645

580646
private final String unit;
581647

648+
/**
649+
* Create a new instance.
650+
* @param unit the unit to count.
651+
*/
582652
Unit( String unit ) {
583653
this.unit = unit;
584654
}
585655

656+
/**
657+
* The resulting usage count of the unit.
658+
* @return the count
659+
*/
586660
int useCount() {
587661
return numerator - denominator;
588662
}

src/com/inet/lib/less/Rule.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,12 @@ private void ruleset( String[] sel, CssFormatter formatter ) {
279279
formatter.endBlock();
280280
}
281281

282+
/**
283+
* Append the mixins of this rule to current output.
284+
*
285+
* @param parentSelector the resulting parent selector
286+
* @param formatter current formatter
287+
*/
282288
void appendMixinsTo( String[] parentSelector, CssFormatter formatter ) {
283289
for( Formattable prop : properties ) {
284290
switch( prop.getType()) {
@@ -293,6 +299,11 @@ void appendMixinsTo( String[] parentSelector, CssFormatter formatter ) {
293299
}
294300
}
295301

302+
/**
303+
* Append the properties of the rule.
304+
*
305+
* @param formatter current formatter
306+
*/
296307
void appendPropertiesTo( CssFormatter formatter ) {
297308
for( Formattable prop : properties ) {
298309
switch( prop.getType() ) {
@@ -397,6 +408,11 @@ private Map<String, Expression> getMixinParams( CssFormatter formatter, List<Exp
397408
}
398409
}
399410

411+
/**
412+
* The selectors of the rule.
413+
*
414+
* @return the selectors
415+
*/
400416
String[] getSelectors() {
401417
return selectors;
402418
}
@@ -409,6 +425,10 @@ public HashMap<String, Expression> getVariables() {
409425
return variables;
410426
}
411427

428+
/**
429+
* get the subrules if there any.
430+
* @return the rules or an empty list.
431+
*/
412432
List<Rule> getSubrules() {
413433
return subrules;
414434
}

0 commit comments

Comments
 (0)