Cleanup (minor optimization)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +21,8 @@ import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class BytecodeMappingTracer {
|
||||
public static final BytecodeMappingTracer DUMMY = new BytecodeMappingTracer();
|
||||
|
||||
private int currentSourceLine;
|
||||
private StructLineNumberTableAttribute lineNumberTable = null;
|
||||
private final Map<Integer, Integer> mapping = new HashMap<Integer, Integer>(); // bytecode offset, source line
|
||||
|
||||
@@ -15,13 +15,6 @@
|
||||
*/
|
||||
package org.jetbrains.java.decompiler.modules.decompiler.exps;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jetbrains.java.decompiler.main.DecompilerContext;
|
||||
import org.jetbrains.java.decompiler.main.TextBuffer;
|
||||
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer;
|
||||
@@ -34,8 +27,10 @@ import org.jetbrains.java.decompiler.struct.match.MatchEngine;
|
||||
import org.jetbrains.java.decompiler.struct.match.MatchNode;
|
||||
import org.jetbrains.java.decompiler.struct.match.MatchNode.RuleValue;
|
||||
|
||||
public class Exprent implements IMatchable {
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class Exprent implements IMatchable {
|
||||
public static final int MULTIPLE_USES = 1;
|
||||
public static final int SIDE_EFFECTS_FREE = 2;
|
||||
public static final int BOTH_FLAGS = 3;
|
||||
@@ -145,14 +140,13 @@ public class Exprent implements IMatchable {
|
||||
// IMatchable implementation
|
||||
// *****************************************************************************
|
||||
|
||||
@Override
|
||||
public IMatchable findObject(MatchNode matchNode, int index) {
|
||||
|
||||
if (matchNode.getType() != MatchNode.MATCHNODE_EXPRENT) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Exprent> lstAllExprents = getAllExprents();
|
||||
|
||||
if (lstAllExprents == null || lstAllExprents.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
@@ -160,35 +154,31 @@ public class Exprent implements IMatchable {
|
||||
String position = (String)matchNode.getRuleValue(MatchProperties.EXPRENT_POSITION);
|
||||
if (position != null) {
|
||||
if (position.matches("-?\\d+")) {
|
||||
return lstAllExprents.get((lstAllExprents.size() + Integer.parseInt(position)) % lstAllExprents.size()); // care for negative positions
|
||||
return lstAllExprents
|
||||
.get((lstAllExprents.size() + Integer.parseInt(position)) % lstAllExprents.size()); // care for negative positions
|
||||
}
|
||||
} else if(index < lstAllExprents.size()) { // use 'index' parameter
|
||||
}
|
||||
else if (index < lstAllExprents.size()) { // use 'index' parameter
|
||||
return lstAllExprents.get(index);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(MatchNode matchNode, MatchEngine engine) {
|
||||
|
||||
if (matchNode.getType() != MatchNode.MATCHNODE_EXPRENT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Entry<MatchProperties, RuleValue> rule : matchNode.getRules().entrySet()) {
|
||||
switch(rule.getKey()) {
|
||||
case EXPRENT_TYPE:
|
||||
if(this.type != ((Integer)rule.getValue().value).intValue()) {
|
||||
MatchProperties key = rule.getKey();
|
||||
if (key == MatchProperties.EXPRENT_TYPE && this.type != ((Integer)rule.getValue().value).intValue()) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case EXPRENT_RET:
|
||||
if(!engine.checkAndSetVariableValue((String)rule.getValue().value, this)) {
|
||||
if (key == MatchProperties.EXPRENT_RET && !engine.checkAndSetVariableValue((String)rule.getValue().value, this)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -196,6 +186,6 @@ public class Exprent implements IMatchable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toJava(0, new BytecodeMappingTracer()).toString();
|
||||
return toJava(0, BytecodeMappingTracer.DUMMY).toString();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -494,11 +494,6 @@ public class Statement implements IMatchable {
|
||||
return false;
|
||||
}
|
||||
|
||||
// to be overwritten
|
||||
public TextBuffer toJava() {
|
||||
return toJava(0, new BytecodeMappingTracer());
|
||||
}
|
||||
|
||||
public TextBuffer toJava(int indent, BytecodeMappingTracer tracer) {
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user