Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipe Mulet2001-08-21 21:06:32 +0000
committerPhilipe Mulet2001-08-21 21:06:32 +0000
commit4087231d30a4b358686cbbdca168b3172502840a (patch)
tree3e3225bdc6433d5f4f3115abac17a603f3e66191
parente8bfbe29d1a41c17d354a1ace5cc2f80708a3b5f (diff)
downloadeclipse.jdt.core-4087231d30a4b358686cbbdca168b3172502840a.tar.gz
eclipse.jdt.core-4087231d30a4b358686cbbdca168b3172502840a.tar.xz
eclipse.jdt.core-4087231d30a4b358686cbbdca168b3172502840a.zip
Class file comparator changes
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java202
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/FieldInfo.java13
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfo.java13
3 files changed, 222 insertions, 6 deletions
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java
index cbdfa91584..0f9d6aa8ad 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java
@@ -4,12 +4,15 @@ package org.eclipse.jdt.internal.compiler.classfmt;
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
+import org.eclipse.jdt.internal.compiler.codegen.*;
import org.eclipse.jdt.internal.compiler.env.*;
-
+import org.eclipse.jdt.internal.compiler.impl.Constant;
+import org.eclipse.jdt.internal.compiler.impl.NullConstant;
+import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
import org.eclipse.jdt.internal.compiler.util.*;
-import org.eclipse.jdt.internal.compiler.codegen.*;
import java.io.*;
+import java.util.Arrays;
public class ClassFileReader extends ClassFileStruct implements AttributeNamesConstants, IBinaryType {
private int constantPoolCount;
@@ -516,4 +519,199 @@ public String toString() {
print.flush();
return out.toString();
}
+/**
+ * Check if the receiver has structural changes compare to the byte array in argument.
+ * Structural changes are:
+ * - modifiers changes for the class, the fields or the methods
+ * - signature changes for fields or methods.
+ * - changes in the number of fields or methods
+ * - changes for field constants
+ * - changes for thrown exceptions
+ * - change for the super class or any super interfaces.
+ * If any of these changes occurs, the method returns true. false otherwise.
+ */
+public boolean hasStructuralChanges(byte[] newBytes) {
+ try {
+ ClassFileReader newClassFile =
+ new ClassFileReader(newBytes, this.classFileName);
+ // type level comparison
+ // modifiers
+ if (this.getModifiers() != newClassFile.getModifiers()) {
+ return true;
+ }
+ // superclass
+ if (!CharOperation.equals(this.getSuperclassName(), newClassFile.getSuperclassName())) {
+ return true;
+ }
+ // interfaces
+ char[][] newInterfacesNames = newClassFile.getInterfaceNames();
+ int newInterfacesLength = newInterfacesNames == null ? 0 : newInterfacesNames.length;
+ if (newInterfacesLength != this.interfacesCount) {
+ return true;
+ }
+ if (this.interfacesCount != 0) {
+ int matchCounter = 0;
+ for (int i = 0, max = this.interfacesCount; i < max; i++) {
+ for (int j = 0; j < newInterfacesLength; j++) {
+ if (CharOperation.equals(this.interfaceNames[i], newInterfacesNames[j])) {
+ matchCounter++;
+ break;
+ }
+ }
+ }
+ if (matchCounter != this.interfacesCount) {
+ return true;
+ }
+ }
+ // fields
+ FieldInfo[] otherFieldInfos = (FieldInfo[]) newClassFile.getFields();
+ int otherFieldInfosLength = otherFieldInfos == null ? 0 : otherFieldInfos.length;
+ if (this.fieldsCount != otherFieldInfosLength) {
+ return true;
+ }
+ if (otherFieldInfos != null) {
+ Arrays.sort(this.fields);
+ Arrays.sort(otherFieldInfos);
+ for (int i = 0; i < otherFieldInfosLength; i++) {
+ FieldInfo currentFieldInfo = this.fields[i];
+ FieldInfo otherFieldInfo = otherFieldInfos[i];
+ if (currentFieldInfo.getModifiers() != otherFieldInfo.getModifiers()) {
+ return true;
+ }
+ if (!CharOperation.equals(currentFieldInfo.getName(), otherFieldInfo.getName())) {
+ return true;
+ }
+ if (currentFieldInfo.hasConstant()) {
+ Constant currentConstant = currentFieldInfo.getConstant();
+ Constant otherConstant = otherFieldInfo.getConstant();
+ if (!currentConstant.getClass().equals(otherConstant.getClass())) {
+ return true;
+ }
+ switch (currentConstant.typeID()) {
+ case TypeIds.T_int :
+ if (otherConstant.typeID() != TypeIds.T_int) {
+ return true;
+ }
+ if (otherConstant.intValue() != currentConstant.intValue()) {
+ return true;
+ }
+ break;
+ case TypeIds.T_byte :
+ if (otherConstant.typeID() != TypeIds.T_byte) {
+ return true;
+ }
+ if (otherConstant.byteValue() != currentConstant.byteValue()) {
+ return true;
+ }
+ break;
+ case TypeIds.T_short :
+ if (otherConstant.typeID() != TypeIds.T_short) {
+ return true;
+ }
+ if (otherConstant.shortValue() != currentConstant.shortValue()) {
+ return true;
+ }
+ break;
+ case TypeIds.T_char :
+ if (otherConstant.typeID() != TypeIds.T_char) {
+ return true;
+ }
+ if (otherConstant.charValue() != currentConstant.charValue()) {
+ return true;
+ }
+ break;
+ case TypeIds.T_float :
+ if (otherConstant.typeID() != TypeIds.T_float) {
+ return true;
+ }
+ if (otherConstant.floatValue() != currentConstant.floatValue()) {
+ return true;
+ }
+ break;
+ case TypeIds.T_double :
+ if (otherConstant.typeID() != TypeIds.T_double) {
+ return true;
+ }
+ if (otherConstant.doubleValue() != currentConstant.doubleValue()) {
+ return true;
+ }
+ break;
+ case TypeIds.T_boolean :
+ if (otherConstant.typeID() != TypeIds.T_boolean) {
+ return true;
+ }
+ if (otherConstant.booleanValue() != currentConstant.booleanValue()) {
+ return true;
+ }
+ break;
+ case TypeIds.T_String :
+ if (otherConstant.typeID() != TypeIds.T_String) {
+ return true;
+ }
+ if (otherConstant.stringValue() != currentConstant.stringValue()) {
+ return true;
+ }
+ break;
+ case TypeIds.T_null :
+ if (otherConstant.typeID() != TypeIds.T_null) {
+ return true;
+ }
+ if (otherConstant != NullConstant.Default) {
+ return true;
+ }
+ }
+ } else if (otherFieldInfo.hasConstant()) {
+ return true;
+ }
+ }
+ }
+ // methods
+ MethodInfo[] otherMethodInfos = (MethodInfo[]) newClassFile.getMethods();
+ int otherMethodInfosLength = otherMethodInfos == null ? 0 : otherMethodInfos.length;
+ if (this.methodsCount != otherMethodInfosLength) {
+ return true;
+ }
+ if (otherMethodInfos != null) {
+ Arrays.sort(this.methods);
+ Arrays.sort(otherMethodInfos);
+ for (int i = 0; i < otherMethodInfosLength; i++) {
+ MethodInfo otherMethodInfo = otherMethodInfos[i];
+ MethodInfo currentMethodInfo = this.methods[i];
+ if (otherMethodInfo.getModifiers() != currentMethodInfo.getModifiers()) {
+ return true;
+ }
+ if (!CharOperation.equals(otherMethodInfo.getSelector(), currentMethodInfo.getSelector())) {
+ return true;
+ }
+ if (!CharOperation.equals(otherMethodInfo.getMethodDescriptor(), currentMethodInfo.getMethodDescriptor())) {
+ return true;
+ }
+ char[][] otherThrownExceptions = otherMethodInfo.getExceptionTypeNames();
+ int otherThrownExceptionsLength = otherThrownExceptions == null ? 0 : otherThrownExceptions.length;
+ char[][] currentThrownExceptions = currentMethodInfo.getExceptionTypeNames();
+ int currentThrownExceptionsLength = currentThrownExceptions == null ? 0 : currentThrownExceptions.length;
+ if (currentThrownExceptionsLength != otherThrownExceptionsLength) {
+ return true;
+ }
+ if (currentThrownExceptionsLength != 0) {
+ int matchCounter = 0;
+ for (int k = 0; k < currentThrownExceptionsLength; k++) {
+ for (int j = 0; j < otherThrownExceptionsLength; j++) {
+ if (CharOperation.equals(currentThrownExceptions[k], otherThrownExceptions[j])) {
+ matchCounter++;
+ break;
+ }
+ }
+ }
+ if (matchCounter != currentThrownExceptionsLength) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ } catch (ClassFormatException e) {
+ return true;
+ }
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/FieldInfo.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/FieldInfo.java
index 193ab19deb..5f4676f148 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/FieldInfo.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/FieldInfo.java
@@ -11,7 +11,7 @@ import org.eclipse.jdt.internal.compiler.ast.*;
import org.eclipse.jdt.internal.compiler.codegen.*;
import org.eclipse.jdt.internal.compiler.util.*;
-public class FieldInfo extends ClassFileStruct implements AttributeNamesConstants, IBinaryField {
+public class FieldInfo extends ClassFileStruct implements AttributeNamesConstants, IBinaryField, Comparable {
private Constant constant;
private boolean isDeprecated;
private int[] constantPoolOffsets;
@@ -38,8 +38,8 @@ public FieldInfo (byte classFileBytes[], int offsets[], int offset) throws Class
}
/**
* Return the constant of the field.
- * Return org.eclipse.jdt.internal.compiler.Constant.NotAConstant if there is none.
- * @return org.eclipse.jdt.internal.compiler.Constant
+ * Return org.eclipse.jdt.internal.compiler.impl.Constant.NotAConstant if there is none.
+ * @return org.eclipse.jdt.internal.compiler.impl.Constant
*/
public Constant getConstant() {
if (constant == null) {
@@ -279,4 +279,11 @@ public String toString() {
.append("}") //$NON-NLS-1$
.toString();
}
+
+public int compareTo(Object o) {
+ if (!(o instanceof FieldInfo)) {
+ throw new ClassCastException();
+ }
+ return new String(this.getName()).compareTo(new String(((FieldInfo) o).getName()));
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfo.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfo.java
index 6521526d20..9e806b029e 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfo.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfo.java
@@ -10,7 +10,7 @@ import org.eclipse.jdt.internal.compiler.ast.*;
import org.eclipse.jdt.internal.compiler.codegen.*;
import org.eclipse.jdt.internal.compiler.util.*;
-public class MethodInfo extends ClassFileStruct implements IBinaryMethod, AttributeNamesConstants {
+public class MethodInfo extends ClassFileStruct implements IBinaryMethod, AttributeNamesConstants, Comparable {
private char[][] exceptionNames;
private int[] constantPoolOffsets;
private boolean isDeprecated;
@@ -207,4 +207,15 @@ public String toString() {
.append("}") //$NON-NLS-1$
.toString();
}
+public int compareTo(Object o) {
+ if (!(o instanceof MethodInfo)) {
+ throw new ClassCastException();
+ }
+ StringBuffer currentComparisonKey = new StringBuffer();
+ currentComparisonKey.append(this.getSelector()).append(this.getMethodDescriptor());
+ StringBuffer otherComparisonKey = new StringBuffer();
+ MethodInfo otherMethodInfo = (MethodInfo) o;
+ otherComparisonKey.append(otherMethodInfo.getSelector()).append(otherMethodInfo.getMethodDescriptor());
+ return currentComparisonKey.toString().compareTo(otherComparisonKey.toString());
+}
}

Back to the top