Skip to content

Commit a59c6e6

Browse files
committed
[DEX] Drop redundant classes ExtraLine & Label
1 parent b34f2e3 commit a59c6e6

41 files changed

Lines changed: 685 additions & 702 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/com/reandroid/dex/data/CodeItem.java

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@
2727
import com.reandroid.dex.common.SectionItem;
2828
import com.reandroid.dex.debug.DebugElementBlock;
2929
import com.reandroid.dex.id.IdItem;
30-
import com.reandroid.dex.ins.ExtraLine;
31-
import com.reandroid.dex.ins.Label;
3230
import com.reandroid.dex.key.DataKey;
3331
import com.reandroid.dex.key.Key;
3432
import com.reandroid.dex.key.KeyReference;
33+
import com.reandroid.dex.program.InstructionLabel;
3534
import com.reandroid.dex.reference.DataItemIndirectReference;
3635
import com.reandroid.dex.common.RegistersTable;
3736
import com.reandroid.dex.ins.TryBlock;
@@ -76,7 +75,7 @@ public DataKey<CodeItem> getKey() {
7675
}
7776
@SuppressWarnings("unchecked")
7877
@Override
79-
public void setKey(Key key){
78+
public void setKey(Key key) {
8079
DataKey<CodeItem> codeItemKey = (DataKey<CodeItem>) key;
8180
merge(codeItemKey.getItem());
8281
}
@@ -86,37 +85,37 @@ public SectionType<CodeItem> getSectionType() {
8685
}
8786

8887
@Override
89-
public int getRegistersCount(){
88+
public int getRegistersCount() {
9089
return header.registersCount.get();
9190
}
9291
@Override
93-
public void setRegistersCount(int count){
92+
public void setRegistersCount(int count) {
9493
header.registersCount.set(count);
9594
}
9695
@Override
97-
public int getParameterRegistersCount(){
96+
public int getParameterRegistersCount() {
9897
return header.parameterRegisters.get();
9998
}
10099
@Override
101-
public void setParameterRegistersCount(int count){
100+
public void setParameterRegistersCount(int count) {
102101
header.parameterRegisters.set(count);
103102
}
104103
@Override
105-
public boolean ensureLocalRegistersCount(int locals){
106-
if(locals == 0){
104+
public boolean ensureLocalRegistersCount(int locals) {
105+
if (locals == 0) {
107106
return true;
108107
}
109-
if(locals <= getLocalRegistersCount()){
108+
if (locals <= getLocalRegistersCount()) {
110109
return true;
111110
}
112111
int params = getParameterRegistersCount();
113112
int current = getLocalRegistersCount();
114113
int diff = locals - current;
115114
InstructionList instructionList = getInstructionList();
116-
if(!instructionList.canAddLocalRegisters(diff)) {
115+
if (!instructionList.canAddLocalRegisters(diff)) {
117116
return false;
118117
}
119-
if(diff > 0) {
118+
if (diff > 0) {
120119
instructionList.addLocalRegisters(diff);
121120
}
122121
setRegistersCount(locals + params);
@@ -126,55 +125,55 @@ public boolean ensureLocalRegistersCount(int locals){
126125

127126
public Iterator<DebugElementBlock> getDebugLabels() {
128127
DebugInfo debugInfo = getDebugInfo();
129-
if(debugInfo != null) {
128+
if (debugInfo != null) {
130129
return debugInfo.getExtraLines();
131130
}
132131
return EmptyIterator.of();
133132
}
134-
public DebugInfo getDebugInfo(){
133+
public DebugInfo getDebugInfo() {
135134
return header.debugInfoOffset.getItem();
136135
}
137-
public DebugInfo getOrCreateDebugInfo(){
136+
public DebugInfo getOrCreateDebugInfo() {
138137
return header.debugInfoOffset.getOrCreateUniqueItem(this);
139138
}
140-
public void removeDebugInfo(){
141-
if(getDebugInfo() == null){
139+
public void removeDebugInfo() {
140+
if (getDebugInfo() == null) {
142141
return;
143142
}
144143
setDebugInfo(null);
145144
}
146-
public void setDebugInfo(DebugInfo debugInfo){
145+
public void setDebugInfo(DebugInfo debugInfo) {
147146
header.debugInfoOffset.setItem(debugInfo);
148147
}
149148
public InstructionList getInstructionList() {
150149
return instructionList;
151150
}
152-
public IntegerReference getTryCountReference(){
151+
public IntegerReference getTryCountReference() {
153152
return header.tryBlockCount;
154153
}
155154

156-
public Iterable<ExtraLine> getExtraLines() {
155+
public Iterable<InstructionLabel> getExternalLabels() {
157156
return () -> CombiningIterator.two(
158157
CodeItem.this.getTryBlockLabels(),
159158
CodeItem.this.getDebugLabels());
160159
}
161-
public Iterator<Label> getTryBlockLabels(){
160+
public Iterator<InstructionLabel> getTryBlockLabels() {
162161
TryBlock tryBlock = this.getTryBlock();
163-
if(tryBlock == null || tryBlock.isNull()){
162+
if (tryBlock == null || tryBlock.isNull()) {
164163
return EmptyIterator.of();
165164
}
166165
return tryBlock.getLabels();
167166
}
168-
public TryBlock getTryBlock(){
167+
public TryBlock getTryBlock() {
169168
return tryBlock;
170169
}
171-
public TryBlock getOrCreateTryBlock(){
170+
public TryBlock getOrCreateTryBlock() {
172171
initTryBlock();
173172
return tryBlock;
174173
}
175-
public void removeTryBlock(){
174+
public void removeTryBlock() {
176175
TryBlock tryBlock = this.tryBlock;
177-
if(tryBlock == null){
176+
if (tryBlock == null) {
178177
return;
179178
}
180179
this.tryBlock = null;
@@ -216,37 +215,37 @@ public void setMethodDef(MethodDef methodDef) {
216215
this.methodDef = methodDef;
217216
}
218217

219-
IntegerReference getInstructionCodeUnitsReference(){
218+
IntegerReference getInstructionCodeUnitsReference() {
220219
return header.instructionCodeUnits;
221220
}
222-
IntegerReference getInstructionOutsReference(){
221+
IntegerReference getInstructionOutsReference() {
223222
return header.outs;
224223
}
225-
void initTryBlock(){
226-
if(this.tryBlock == null){
224+
void initTryBlock() {
225+
if (this.tryBlock == null) {
227226
this.tryBlock = new TryBlock(this);
228227
addChildBlock(2, this.tryBlock);
229228
}
230229
}
231230
@Override
232-
public DexPositionAlign getPositionAlign(){
233-
if(this.tryBlock != null){
231+
public DexPositionAlign getPositionAlign() {
232+
if (this.tryBlock != null) {
234233
return this.tryBlock.getPositionAlign();
235-
}else if(this.instructionList != null){
234+
} else if (this.instructionList != null) {
236235
return this.instructionList.getBlockAlign();
237236
}
238237
return new DexPositionAlign();
239238
}
240239
@Override
241-
public void removeLastAlign(){
242-
if(this.tryBlock != null){
240+
public void removeLastAlign() {
241+
if (this.tryBlock != null) {
243242
this.tryBlock.getPositionAlign().setSize(0);
244-
}else if(this.instructionList != null){
243+
} else if (this.instructionList != null) {
245244
this.instructionList.getBlockAlign().setSize(0);
246245
}
247246
}
248247

249-
public void replaceKeys(Key search, Key replace){
248+
public void replaceKeys(Key search, Key replace) {
250249
getInstructionList().replaceKeys(search, replace);
251250
}
252251

@@ -279,32 +278,32 @@ public boolean uses(Key key) {
279278
}
280279

281280
@Override
282-
public Iterator<IdItem> usedIds(){
281+
public Iterator<IdItem> usedIds() {
283282
DebugInfo debugInfo = getDebugInfo();
284283
Iterator<IdItem> iterator1;
285-
if(debugInfo == null){
284+
if (debugInfo == null) {
286285
iterator1 = EmptyIterator.of();
287-
}else {
286+
} else {
288287
iterator1 = debugInfo.usedIds();
289288
}
290289
Iterator<IdItem> iterator2;
291290
TryBlock tryBlock = getTryBlock();
292-
if(tryBlock == null) {
291+
if (tryBlock == null) {
293292
iterator2 = EmptyIterator.of();
294-
}else {
293+
} else {
295294
iterator2 = tryBlock.usedIds();
296295
}
297296
return CombiningIterator.three(getInstructionList().usedIds(), iterator1, iterator2);
298297
}
299298

300-
public void merge(CodeItem codeItem){
301-
if(codeItem == this){
299+
public void merge(CodeItem codeItem) {
300+
if (codeItem == this) {
302301
return;
303302
}
304303
this.header.merge(codeItem.header);
305304
getInstructionList().merge(codeItem.getInstructionList());
306305
TryBlock comingTry = codeItem.getTryBlock();
307-
if(comingTry != null){
306+
if (comingTry != null) {
308307
TryBlock tryBlock = getOrCreateTryBlock();
309308
tryBlock.merge(comingTry);
310309
}
@@ -315,13 +314,13 @@ public void fromSmali(SmaliMethod smaliMethod) {
315314
getInstructionList().fromSmali(smaliMethod.getCodeSet());
316315
Iterator<SmaliCodeTryItem> iterator = smaliMethod.getTryItems();
317316
TryBlock tryBlock = null;
318-
if(iterator.hasNext()){
317+
if (iterator.hasNext()) {
319318
tryBlock = getOrCreateTryBlock();
320319
}
321-
while (iterator.hasNext()){
320+
while (iterator.hasNext()) {
322321
tryBlock.fromSmali(iterator.next());
323322
}
324-
if(smaliMethod.hasDebugElements()){
323+
if (smaliMethod.hasDebugElements()) {
325324
DebugInfo debugInfo = getOrCreateDebugInfo();
326325
debugInfo.getDebugSequence().fromSmali(smaliMethod.getCodeSet());
327326
}
@@ -370,15 +369,15 @@ public int hashCode() {
370369
hash = hash * 31 + instructionList.hashCode();
371370
hash = hash * 31;
372371
TryBlock tryBlock = this.tryBlock;
373-
if(tryBlock != null){
372+
if (tryBlock != null) {
374373
hash = hash + tryBlock.hashCode();
375374
}
376375
return hash;
377376
}
378377

379378
@Override
380379
public String toString() {
381-
if(isNull()){
380+
if (isNull()) {
382381
return "NULL";
383382
}
384383
return header.toString()
@@ -425,12 +424,12 @@ public void onReadBytes(BlockReader reader) throws IOException {
425424
super.onReadBytes(reader);
426425
this.debugInfoOffset.pullItem();
427426
this.debugInfoOffset.addUniqueUser(this.codeItem);
428-
if(this.tryBlockCount.get() != 0){
427+
if (this.tryBlockCount.get() != 0) {
429428
this.codeItem.initTryBlock();
430429
}
431430
}
432431

433-
public void onRemove(){
432+
public void onRemove() {
434433
debugInfoOffset.setItem(null);
435434
}
436435

@@ -439,13 +438,13 @@ public void editInternal(Block user) {
439438
debugInfoOffset.editInternal(user);
440439
}
441440

442-
public void merge(Header header){
441+
public void merge(Header header) {
443442
registersCount.set(header.registersCount.get());
444443
parameterRegisters.set(header.parameterRegisters.get());
445444
outs.set(header.outs.get());
446445
tryBlockCount.set(header.tryBlockCount.get());
447446
DebugInfo comingDebug = header.debugInfoOffset.getItem();
448-
if(comingDebug != null){
447+
if (comingDebug != null) {
449448
debugInfoOffset.setKey(comingDebug.getKey());
450449
debugInfoOffset.addUniqueUser(codeItem);
451450
}
@@ -479,7 +478,7 @@ public int hashCode() {
479478
hash = hash * 31 + instructionCodeUnits.get();
480479
hash = hash * 31;
481480
DebugInfo info = debugInfoOffset.getItem();
482-
if(info != null){
481+
if (info != null) {
483482
hash = hash + info.hashCode();
484483
}
485484
return hash;

0 commit comments

Comments
 (0)