summaryrefslogtreecommitdiffstats
path: root/src/proguard/classfile/editor/AttributesEditor.java
diff options
context:
space:
mode:
authorBrian Carlstrom <bdc@google.com>2015-01-08 08:24:06 -0800
committerBrian Carlstrom <bdc@google.com>2015-01-08 09:27:15 -0800
commit2270795fbe0b277bfd49f40950ecaa78583175cc (patch)
tree9ac962825d41c4fb8ad1ec0fc2e8b441b42d3869 /src/proguard/classfile/editor/AttributesEditor.java
parent9961286c06c25cd03464d3e2b00bd9b9dedf96ba (diff)
downloadexternal_proguard-2270795fbe0b277bfd49f40950ecaa78583175cc.tar.gz
external_proguard-2270795fbe0b277bfd49f40950ecaa78583175cc.tar.bz2
external_proguard-2270795fbe0b277bfd49f40950ecaa78583175cc.zip
Upgrade Proguard to 5.1.
Downloaded from: http://sourceforge.net/projects/proguard/files/proguard/5.1/ Bug: 17550647 Change-Id: I2b4eab16eb7821fc232b294ab7f433aae08f71e1
Diffstat (limited to 'src/proguard/classfile/editor/AttributesEditor.java')
-rw-r--r--src/proguard/classfile/editor/AttributesEditor.java71
1 files changed, 58 insertions, 13 deletions
diff --git a/src/proguard/classfile/editor/AttributesEditor.java b/src/proguard/classfile/editor/AttributesEditor.java
index f50b8f1..ce38a6b 100644
--- a/src/proguard/classfile/editor/AttributesEditor.java
+++ b/src/proguard/classfile/editor/AttributesEditor.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
+ * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
@@ -79,6 +79,27 @@ public class AttributesEditor
/**
+ * Finds the specified attribute in the target.
+ */
+ public Attribute findAttribute(String attributeName)
+ {
+ // What's the target?
+ return
+ targetAttribute != null ?
+ findAttribute(targetAttribute.u2attributesCount,
+ targetAttribute.attributes,
+ attributeName) :
+ targetMember != null ?
+ findAttribute(targetMember.u2attributesCount,
+ targetMember.attributes,
+ attributeName) :
+ findAttribute(targetClass.u2attributesCount,
+ targetClass.attributes,
+ attributeName);
+ }
+
+
+ /**
* Adds the given attribute to the target.
*/
public void addAttribute(Attribute attribute)
@@ -171,17 +192,17 @@ public class AttributesEditor
// Small utility methods.
/**
- * Tries put the given attribute in place of an existing attribute of the
- * same name, returning whether it was present.
+ * Tries to put the given attribute in place of an existing attribute of
+ * the same name, returning whether it was present.
*/
private boolean replaceAttribute(int attributesCount,
Attribute[] attributes,
Attribute attribute)
{
// Find the attribute with the same name.
- int index = findAttribute(attributesCount,
- attributes,
- attribute.getAttributeName(targetClass));
+ int index = findAttributeIndex(attributesCount,
+ attributes,
+ attribute.getAttributeName(targetClass));
if (index < 0)
{
return false;
@@ -228,9 +249,9 @@ public class AttributesEditor
String attributeName)
{
// Find the attribute.
- int index = findAttribute(attributesCount,
- attributes,
- attributeName);
+ int index = findAttributeIndex(attributesCount,
+ attributes,
+ attributeName);
if (index < 0)
{
return attributesCount;
@@ -252,13 +273,15 @@ public class AttributesEditor
* Finds the index of the attribute with the given name in the given
* array of attributes.
*/
- private int findAttribute(int attributesCount,
- Attribute[] attributes,
- String attributeName)
+ private int findAttributeIndex(int attributesCount,
+ Attribute[] attributes,
+ String attributeName)
{
for (int index = 0; index < attributesCount; index++)
{
- if (attributes[index].getAttributeName(targetClass).equals(attributeName))
+ Attribute attribute = attributes[index];
+
+ if (attribute.getAttributeName(targetClass).equals(attributeName))
{
return index;
}
@@ -266,4 +289,26 @@ public class AttributesEditor
return -1;
}
+
+
+ /**
+ * Finds the attribute with the given name in the given
+ * array of attributes.
+ */
+ private Attribute findAttribute(int attributesCount,
+ Attribute[] attributes,
+ String attributeName)
+ {
+ for (int index = 0; index < attributesCount; index++)
+ {
+ Attribute attribute = attributes[index];
+
+ if (attribute.getAttributeName(targetClass).equals(attributeName))
+ {
+ return attribute;
+ }
+ }
+
+ return null;
+ }
}