Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Clinit.java51
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java413
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/impl/JavaDevelopmentContextImpl.java13
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/impl/StateImpl.java45
4 files changed, 307 insertions, 215 deletions
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Clinit.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Clinit.java
index b0771d8e74..53753f40cf 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Clinit.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Clinit.java
@@ -82,6 +82,45 @@ public class Clinit extends AbstractMethodDeclaration {
}
try {
clinitOffset = classFile.contentsOffset;
+ this.generateCode(classScope, classFile, clinitOffset);
+ } catch (AbortMethod e) {
+ // should never occur
+ // the clinit referenceContext is the type declaration
+ // All clinit problems will be reported against the type: AbortType instead of AbortMethod
+ // reset the contentsOffset to the value before generating the clinit code
+ // decrement the number of method info as well.
+ // This is done in the addProblemMethod and addProblemConstructor for other
+ // cases.
+ if (e.compilationResult == CodeStream.RESTART_IN_WIDE_MODE) {
+ // a branch target required a goto_w, restart code gen in wide mode.
+ try {
+ if (statements != null) {
+ for (int i = 0, max = statements.length; i < max; i++)
+ statements[i].resetStateForCodeGeneration();
+ }
+ classFile.contentsOffset = clinitOffset;
+ classFile.methodCount--;
+ classFile.codeStream.wideMode = true; // request wide mode
+ this.generateCode(classScope, classFile, clinitOffset); // restart method generation
+ } catch(AbortMethod e2) {
+ classFile.contentsOffset = clinitOffset;
+ classFile.methodCount--;
+ }
+ } else {
+ // produce a problem method accounting for this fatal error
+ classFile.contentsOffset = clinitOffset;
+ classFile.methodCount--;
+ }
+ }
+ }
+
+ /**
+ * Bytecode generation for a <clinit> method
+ *
+ * @param classScope org.eclipse.jdt.internal.compiler.lookup.ClassScope
+ * @param classFile org.eclipse.jdt.internal.compiler.codegen.ClassFile
+ */
+ private void generateCode(ClassScope classScope, ClassFile classFile, int clinitOffset) {
ConstantPool constantPool = classFile.constantPool;
int constantPoolOffset = constantPool.currentOffset;
int constantPoolIndex = constantPool.currentIndex;
@@ -145,19 +184,9 @@ public class Clinit extends AbstractMethodDeclaration {
codeStream.recordPositionsFrom(0, declaringType);
classFile.completeCodeAttributeForClinit(codeAttributeOffset);
}
- } catch (AbortMethod e) {
- // should never occur
- // the clinit referenceContext is the type declaration
- // All clinit problems will be reported against the type: AbortType instead of AbortMethod
- // reset the contentsOffset to the value before generating the clinit code
- // decrement the number of method info as well.
- // This is done in the addProblemMethod and addProblemConstructor for other
- // cases.
- classFile.contentsOffset = clinitOffset;
- classFile.methodCount--;
- }
}
+
public boolean isClinit() {
return true;
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java
index d381484182..2d16d8e31a 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java
@@ -60,6 +60,11 @@ public class CodeStream implements OperatorIds, ClassFileConstants, Opcodes, Bas
public int countLabels;
public int allLocalsCounter;
public int maxFieldCount;
+
+ // to handle goto_w
+ public boolean wideMode = false;
+ public static final CompilationResult RESTART_IN_WIDE_MODE = new CompilationResult((char[])null, 0, 0);
+
public CodeStream(ClassFile classFile) {
generateLineNumberAttributes = (classFile.produceDebugAttributes & CompilerOptions.Lines) != 0;
generateLocalVariableTableAttributes = (classFile.produceDebugAttributes & CompilerOptions.Vars) != 0;
@@ -1765,51 +1770,6 @@ public void generateInlinedValue(boolean inlinedValue) {
else
this.iconst_0();
}
-public void generateObjectWrapperForType(TypeBinding valueType) {
-
- /* The top of stack must be encapsulated inside
- * a wrapper object if it corresponds to a base type
- */
- char[][] wrapperTypeCompoundName = null;
- switch (valueType.id) {
- case T_int : // new: java.lang.Integer
- wrapperTypeCompoundName = new char[][] {"java".toCharArray(), "lang".toCharArray(), "Integer".toCharArray()}; //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-3$
- break;
- case T_boolean : // new: java.lang.Boolean
- wrapperTypeCompoundName = new char[][] {"java".toCharArray(), "lang".toCharArray(), "Boolean".toCharArray()}; //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-3$
- break;
- case T_byte : // new: java.lang.Byte
- wrapperTypeCompoundName = new char[][] {"java".toCharArray(), "lang".toCharArray(), "Byte".toCharArray()}; //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-3$
- break;
- case T_char : // new: java.lang.Character
- wrapperTypeCompoundName = new char[][] {"java".toCharArray(), "lang".toCharArray(), "Character".toCharArray()}; //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-3$
- break;
- case T_float : // new: java.lang.Float
- wrapperTypeCompoundName = new char[][] {"java".toCharArray(), "lang".toCharArray(), "Float".toCharArray()}; //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-3$
- break;
- case T_double : // new: java.lang.Double
- wrapperTypeCompoundName = new char[][] {"java".toCharArray(), "lang".toCharArray(), "Double".toCharArray()}; //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-3$
- break;
- case T_short : // new: java.lang.Short
- wrapperTypeCompoundName = new char[][] {"java".toCharArray(), "lang".toCharArray(), "Short".toCharArray()}; //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-3$
- break;
- case T_long : // new: java.lang.Long
- wrapperTypeCompoundName = new char[][] {"java".toCharArray(), "lang".toCharArray(), "Long".toCharArray()}; //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-3$
- break;
- }
- TypeBinding wrapperType = methodDeclaration.scope.getType(wrapperTypeCompoundName);
- new_(wrapperType);
- if (valueType.id == T_long || valueType.id == T_double) {
- dup_x2();
- dup_x2();
- pop();
- } else {
- dup_x1();
- swap();
- }
- MethodBinding methodBinding = methodDeclaration.scope.getMethod(wrapperType, QualifiedNamesConstants.Init, new TypeBinding[] {valueType}, null);
- invokespecial(methodBinding);
-}
public void generateOuterAccess(Object[] mappingSequence, AstNode invocationSite, Scope scope) {
if (mappingSequence == null)
return;
@@ -2165,6 +2125,51 @@ public void getTYPE(int baseTypeID) {
* We didn't call it goto, because there is a conflit with the goto keyword
*/
final public void goto_(Label lbl) {
+ if (this.wideMode) {
+ this.goto_w(lbl);
+ return;
+ }
+ try {
+ lbl.inlineForwardReferencesFromLabelsTargeting(position);
+ /*
+ Possible optimization for code such as:
+ public Object foo() {
+ boolean b = true;
+ if (b) {
+ if (b)
+ return null;
+ } else {
+ if (b) {
+ return null;
+ }
+ }
+ return null;
+ }
+ The goto around the else block for the first if will
+ be unreachable, because the thenClause of the second if
+ returns.
+ See inlineForwardReferencesFromLabelsTargeting defined
+ on the Label class for the remaining part of this
+ optimization.
+ if (!lbl.isBranchTarget(position)) {
+ switch(bCodeStream[classFileOffset-1]) {
+ case OPC_return :
+ case OPC_areturn:
+ return;
+ }
+ }*/
+ position++;
+ bCodeStream[classFileOffset++] = OPC_goto;
+ } catch (IndexOutOfBoundsException e) {
+ resizeByteArray(OPC_goto);
+ }
+ lbl.branch();
+}
+
+/**
+ * We didn't call it goto, because there is a conflit with the goto keyword
+ */
+final public void internal_goto_(Label lbl) {
try {
lbl.inlineForwardReferencesFromLabelsTargeting(position);
/*
@@ -2406,179 +2411,243 @@ final public void idiv() {
}
final public void if_acmpeq(Label lbl) {
countLabels = 0;
- stackDepth -= 2;
- try {
- position++;
- bCodeStream[classFileOffset++] = OPC_if_acmpeq;
- } catch (IndexOutOfBoundsException e) {
- resizeByteArray(OPC_if_acmpeq);
+ stackDepth-=2;
+ if (this.wideMode) {
+ generateWideConditionalBranch(OPC_if_acmpeq, lbl);
+ } else {
+ try {
+ position++;
+ bCodeStream[classFileOffset++] = OPC_if_acmpeq;
+ } catch (IndexOutOfBoundsException e) {
+ resizeByteArray(OPC_if_acmpeq);
+ }
+ lbl.branch();
}
- lbl.branch();
}
final public void if_acmpne(Label lbl) {
countLabels = 0;
- stackDepth -= 2;
- try {
- position++;
- bCodeStream[classFileOffset++] = OPC_if_acmpne;
- } catch (IndexOutOfBoundsException e) {
- resizeByteArray(OPC_if_acmpne);
+ stackDepth-=2;
+ if (this.wideMode) {
+ generateWideConditionalBranch(OPC_if_acmpne, lbl);
+ } else {
+ try {
+ position++;
+ bCodeStream[classFileOffset++] = OPC_if_acmpne;
+ } catch (IndexOutOfBoundsException e) {
+ resizeByteArray(OPC_if_acmpne);
+ }
+ lbl.branch();
}
- lbl.branch();
}
final public void if_icmpeq(Label lbl) {
countLabels = 0;
stackDepth -= 2;
- try {
- position++;
- bCodeStream[classFileOffset++] = OPC_if_icmpeq;
- } catch (IndexOutOfBoundsException e) {
- resizeByteArray(OPC_if_icmpeq);
+ if (this.wideMode) {
+ generateWideConditionalBranch(OPC_if_icmpeq, lbl);
+ } else {
+ try {
+ position++;
+ bCodeStream[classFileOffset++] = OPC_if_icmpeq;
+ } catch (IndexOutOfBoundsException e) {
+ resizeByteArray(OPC_if_icmpeq);
+ }
+ lbl.branch();
}
- lbl.branch();
}
final public void if_icmpge(Label lbl) {
countLabels = 0;
stackDepth -= 2;
- try {
- position++;
- bCodeStream[classFileOffset++] = OPC_if_icmpge;
- } catch (IndexOutOfBoundsException e) {
- resizeByteArray(OPC_if_icmpge);
+ if (this.wideMode) {
+ generateWideConditionalBranch(OPC_if_icmpge, lbl);
+ } else {
+ try {
+ position++;
+ bCodeStream[classFileOffset++] = OPC_if_icmpge;
+ } catch (IndexOutOfBoundsException e) {
+ resizeByteArray(OPC_if_icmpge);
+ }
+ lbl.branch();
}
- lbl.branch();
}
final public void if_icmpgt(Label lbl) {
countLabels = 0;
stackDepth -= 2;
- try {
- position++;
- bCodeStream[classFileOffset++] = OPC_if_icmpgt;
- } catch (IndexOutOfBoundsException e) {
- resizeByteArray(OPC_if_icmpgt);
+ if (this.wideMode) {
+ generateWideConditionalBranch(OPC_if_icmpgt, lbl);
+ } else {
+ try {
+ position++;
+ bCodeStream[classFileOffset++] = OPC_if_icmpgt;
+ } catch (IndexOutOfBoundsException e) {
+ resizeByteArray(OPC_if_icmpgt);
+ }
+ lbl.branch();
}
- lbl.branch();
}
final public void if_icmple(Label lbl) {
countLabels = 0;
stackDepth -= 2;
- try {
- position++;
- bCodeStream[classFileOffset++] = OPC_if_icmple;
- } catch (IndexOutOfBoundsException e) {
- resizeByteArray(OPC_if_icmple);
+ if (this.wideMode) {
+ generateWideConditionalBranch(OPC_if_icmple, lbl);
+ } else {
+ try {
+ position++;
+ bCodeStream[classFileOffset++] = OPC_if_icmple;
+ } catch (IndexOutOfBoundsException e) {
+ resizeByteArray(OPC_if_icmple);
+ }
+ lbl.branch();
}
- lbl.branch();
}
final public void if_icmplt(Label lbl) {
countLabels = 0;
stackDepth -= 2;
- try {
- position++;
- bCodeStream[classFileOffset++] = OPC_if_icmplt;
- } catch (IndexOutOfBoundsException e) {
- resizeByteArray(OPC_if_icmplt);
+ if (this.wideMode) {
+ generateWideConditionalBranch(OPC_if_icmplt, lbl);
+ } else {
+ try {
+ position++;
+ bCodeStream[classFileOffset++] = OPC_if_icmplt;
+ } catch (IndexOutOfBoundsException e) {
+ resizeByteArray(OPC_if_icmplt);
+ }
+ lbl.branch();
}
- lbl.branch();
}
final public void if_icmpne(Label lbl) {
countLabels = 0;
stackDepth -= 2;
- try {
- position++;
- bCodeStream[classFileOffset++] = OPC_if_icmpne;
- } catch (IndexOutOfBoundsException e) {
- resizeByteArray(OPC_if_icmpne);
+ if (this.wideMode) {
+ generateWideConditionalBranch(OPC_if_icmpne, lbl);
+ } else {
+ try {
+ position++;
+ bCodeStream[classFileOffset++] = OPC_if_icmpne;
+ } catch (IndexOutOfBoundsException e) {
+ resizeByteArray(OPC_if_icmpne);
+ }
+ lbl.branch();
}
- lbl.branch();
}
final public void ifeq(Label lbl) {
countLabels = 0;
stackDepth--;
- try {
- position++;
- bCodeStream[classFileOffset++] = OPC_ifeq;
- } catch (IndexOutOfBoundsException e) {
- resizeByteArray(OPC_ifeq);
+ if (this.wideMode) {
+ generateWideConditionalBranch(OPC_ifeq, lbl);
+ } else {
+ try {
+ position++;
+ bCodeStream[classFileOffset++] = OPC_ifeq;
+ } catch (IndexOutOfBoundsException e) {
+ resizeByteArray(OPC_ifeq);
+ }
+ lbl.branch();
}
- lbl.branch();
}
final public void ifge(Label lbl) {
countLabels = 0;
stackDepth--;
- try {
- position++;
- bCodeStream[classFileOffset++] = OPC_ifge;
- } catch (IndexOutOfBoundsException e) {
- resizeByteArray(OPC_ifge);
+ if (this.wideMode) {
+ generateWideConditionalBranch(OPC_ifge, lbl);
+ } else {
+ try {
+ position++;
+ bCodeStream[classFileOffset++] = OPC_ifge;
+ } catch (IndexOutOfBoundsException e) {
+ resizeByteArray(OPC_ifge);
+ }
+ lbl.branch();
}
- lbl.branch();
}
final public void ifgt(Label lbl) {
countLabels = 0;
stackDepth--;
- try {
- position++;
- bCodeStream[classFileOffset++] = OPC_ifgt;
- } catch (IndexOutOfBoundsException e) {
- resizeByteArray(OPC_ifgt);
+ if (this.wideMode) {
+ generateWideConditionalBranch(OPC_ifgt, lbl);
+ } else {
+ try {
+ position++;
+ bCodeStream[classFileOffset++] = OPC_ifgt;
+ } catch (IndexOutOfBoundsException e) {
+ resizeByteArray(OPC_ifgt);
+ }
+ lbl.branch();
}
- lbl.branch();
}
final public void ifle(Label lbl) {
countLabels = 0;
stackDepth--;
- try {
- position++;
- bCodeStream[classFileOffset++] = OPC_ifle;
- } catch (IndexOutOfBoundsException e) {
- resizeByteArray(OPC_ifle);
+ if (this.wideMode) {
+ generateWideConditionalBranch(OPC_ifle, lbl);
+ } else {
+ try {
+ position++;
+ bCodeStream[classFileOffset++] = OPC_ifle;
+ } catch (IndexOutOfBoundsException e) {
+ resizeByteArray(OPC_ifle);
+ }
+ lbl.branch();
}
- lbl.branch();
}
final public void iflt(Label lbl) {
countLabels = 0;
stackDepth--;
- try {
- position++;
- bCodeStream[classFileOffset++] = OPC_iflt;
- } catch (IndexOutOfBoundsException e) {
- resizeByteArray(OPC_iflt);
+ if (this.wideMode) {
+ generateWideConditionalBranch(OPC_iflt, lbl);
+ } else {
+ try {
+ position++;
+ bCodeStream[classFileOffset++] = OPC_iflt;
+ } catch (IndexOutOfBoundsException e) {
+ resizeByteArray(OPC_iflt);
+ }
+ lbl.branch();
}
- lbl.branch();
}
final public void ifne(Label lbl) {
countLabels = 0;
stackDepth--;
- try {
- position++;
- bCodeStream[classFileOffset++] = OPC_ifne;
- } catch (IndexOutOfBoundsException e) {
- resizeByteArray(OPC_ifne);
+ if (this.wideMode) {
+ generateWideConditionalBranch(OPC_ifne, lbl);
+ } else {
+ try {
+ position++;
+ bCodeStream[classFileOffset++] = OPC_ifne;
+ } catch (IndexOutOfBoundsException e) {
+ resizeByteArray(OPC_ifne);
+ }
+ lbl.branch();
}
- lbl.branch();
}
final public void ifnonnull(Label lbl) {
countLabels = 0;
stackDepth--;
- try {
- position++;
- bCodeStream[classFileOffset++] = OPC_ifnonnull;
- } catch (IndexOutOfBoundsException e) {
- resizeByteArray(OPC_ifnonnull);
+ if (this.wideMode) {
+ generateWideConditionalBranch(OPC_ifnonnull, lbl);
+ } else {
+ try {
+ position++;
+ bCodeStream[classFileOffset++] = OPC_ifnonnull;
+ } catch (IndexOutOfBoundsException e) {
+ resizeByteArray(OPC_ifnonnull);
+ }
+ lbl.branch();
}
- lbl.branch();
}
final public void ifnull(Label lbl) {
countLabels = 0;
stackDepth--;
- try {
- position++;
- bCodeStream[classFileOffset++] = OPC_ifnull;
- } catch (IndexOutOfBoundsException e) {
- resizeByteArray(OPC_ifnull);
+ if (this.wideMode) {
+ generateWideConditionalBranch(OPC_ifnull, lbl);
+ } else {
+ try {
+ position++;
+ bCodeStream[classFileOffset++] = OPC_ifnull;
+ } catch (IndexOutOfBoundsException e) {
+ resizeByteArray(OPC_ifnull);
+ }
+ lbl.branch();
}
- lbl.branch();
}
final public void iinc(int index, int value) {
countLabels = 0;
@@ -5477,54 +5546,54 @@ public final void writeSignedShort(int pos, int b) {
public final void writeSignedWord(int value) {
try {
position++;
- bCodeStream[classFileOffset++] = (byte) (value >> 24);
+ bCodeStream[classFileOffset++] = (byte) ((value & 0xFF000000) >> 24);
} catch (IndexOutOfBoundsException e) {
- resizeByteArray((byte) (value >> 24));
+ resizeByteArray((byte) ((value & 0xFF000000) >> 24));
}
try {
position++;
- bCodeStream[classFileOffset++] = (byte) (value >> 16);
+ bCodeStream[classFileOffset++] = (byte) ((value & 0xFF0000) >> 16);
} catch (IndexOutOfBoundsException e) {
- resizeByteArray((byte) (value >> 16));
+ resizeByteArray((byte) ((value & 0xFF0000) >> 16));
}
try {
position++;
- bCodeStream[classFileOffset++] = (byte) (value >> 8);
+ bCodeStream[classFileOffset++] = (byte) ((value & 0xFF00) >> 8);
} catch (IndexOutOfBoundsException e) {
- resizeByteArray((byte) (value >> 8));
+ resizeByteArray((byte) ((value & 0xFF00) >> 8));
}
try {
position++;
- bCodeStream[classFileOffset++] = (byte) value;
+ bCodeStream[classFileOffset++] = (byte) (value & 0xFF);
} catch (IndexOutOfBoundsException e) {
- resizeByteArray((byte) value);
+ resizeByteArray((byte) (value & 0xFF));
}
}
public final void writeSignedWord(int pos, int value) {
int currentOffset = startingClassFileOffset + pos;
try {
- bCodeStream[currentOffset] = (byte) (value >> 24);
+ bCodeStream[currentOffset++] = (byte) ((value & 0xFF000000) >> 24);
} catch (IndexOutOfBoundsException e) {
resizeByteArray();
- bCodeStream[currentOffset] = (byte) (value >> 24);
+ bCodeStream[currentOffset] = (byte) ((value & 0xFF000000) >> 24);
}
try {
- bCodeStream[currentOffset + 1] = (byte) (value >> 16);
+ bCodeStream[currentOffset++] = (byte) ((value & 0xFF0000) >> 16);
} catch (IndexOutOfBoundsException e) {
resizeByteArray();
- bCodeStream[currentOffset + 1] = (byte) (value >> 16);
+ bCodeStream[currentOffset] = (byte) ((value & 0xFF0000) >> 16);
}
try {
- bCodeStream[currentOffset + 2] = (byte) (value >> 8);
+ bCodeStream[currentOffset++] = (byte) ((value & 0xFF00) >> 8);
} catch (IndexOutOfBoundsException e) {
resizeByteArray();
- bCodeStream[currentOffset + 2] = (byte) (value >> 8);
+ bCodeStream[currentOffset] = (byte) ((value & 0xFF00) >> 8);
}
try {
- bCodeStream[currentOffset + 3] = (byte) value;
+ bCodeStream[currentOffset++] = (byte) (value & 0xFF);
} catch (IndexOutOfBoundsException e) {
resizeByteArray();
- bCodeStream[currentOffset + 3] = (byte) value;
+ bCodeStream[currentOffset] = (byte) (value & 0xFF);
}
}
/**
@@ -5587,4 +5656,30 @@ public final void writeUnsignedWord(int value) {
resizeByteArray((byte) value);
}
}
+
+public void generateWideConditionalBranch(byte opcode, Label lbl) {
+ /* we handle the goto_w problem inside an if.... with some macro expansion
+ * at the bytecode level
+ * instead of:
+ * if_...... lbl
+ * we have:
+ * ifne <l1>
+ * goto <l2>
+ * l1 gotow <l3> // l3 is a wide target
+ * l2 ....
+ */
+ Label l1 = new Label(this);
+ try {
+ position++;
+ bCodeStream[classFileOffset++] = opcode;
+ } catch (IndexOutOfBoundsException e) {
+ resizeByteArray(opcode);
+ }
+ l1.branch();
+ Label l2 = new Label(this);
+ this.internal_goto_(l2);
+ l1.place();
+ this.goto_w(lbl);
+ l2.place();
+}
}
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/impl/JavaDevelopmentContextImpl.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/impl/JavaDevelopmentContextImpl.java
index 67fb6b46c8..58fd5affa9 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/impl/JavaDevelopmentContextImpl.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/impl/JavaDevelopmentContextImpl.java
@@ -4,10 +4,7 @@ package org.eclipse.jdt.internal.core.builder.impl;
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
import java.util.Locale;
import java.util.Map;
import java.util.Vector;
@@ -18,6 +15,7 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.compiler.Compiler;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
@@ -170,11 +168,8 @@ public IBinaryBroker getBinaryBroker() {
*/
byte[] getBinaryFromFileSystem(org.eclipse.core.resources.IFile file) {
try {
- IPath location = file.getLocation();
- if (location == null) return new byte[0];
- InputStream input = new java.io.FileInputStream(location.toOSString());
- return org.eclipse.jdt.internal.core.Util.readContentsAsBytes(input);
- } catch (IOException e) {
+ return Util.getResourceContentsAsByteArray(file);
+ } catch (JavaModelException e) {
return new byte[0];
}
}
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/impl/StateImpl.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/impl/StateImpl.java
index 24d7dc99d3..66804f639d 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/impl/StateImpl.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/impl/StateImpl.java
@@ -770,15 +770,7 @@ public class StateImpl implements IState {
if (zipEntry == null) {
return new byte[0];
}
- InputStream input= zipFile.getInputStream(zipEntry);
- if (input == null){
- return new byte[0];
- }
- byte[] contents= Util.readContentsAsBytes(input);
- if (contents == null) {
- return new byte[0];
- }
- return contents;
+ return org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(zipEntry, zipFile);
} catch (CoreException e) {
return new byte[0];
} catch (IOException e) {
@@ -797,13 +789,9 @@ public class StateImpl implements IState {
try {
// Fix for 1FVTLHB: ITPCORE:WINNT - Importing a project does not import class files
JavaModelManager.getJavaModelManager().ensureLocal(file);
- return Util.readContentsAsBytes(file.getContents(true));
+ return Util.getResourceContentsAsByteArray(file);
} catch (CoreException e) {
return fDevelopmentContext.getBinaryFromFileSystem(file);
- } catch (IOException e) {
- String message= e.getMessage();
- message= (message == null ? "." : " due to " + message + "."); //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-1$
- return new byte[0];
}
}
}
@@ -813,34 +801,19 @@ public class StateImpl implements IState {
protected char[] getElementContentCharArray(SourceEntry entry) {
// TBD: need proper byte->char conversion
byte[] bytes= getElementContentBytes(entry);
- BufferedReader reader = null;
+ InputStream stream = null;
try {
- reader= new BufferedReader(new InputStreamReader(new ByteArrayInputStream(bytes)));
- int length= bytes.length;
- char[] contents= new char[length];
- int len= 0;
- int readSize= 0;
- while ((readSize != -1) && (len != length)) {
- // See PR 1FMS89U
- // We record first the read size. In this case len is the actual read size.
- len += readSize;
- readSize= reader.read(contents, len, length - len);
- }
- reader.close();
- // See PR 1FMS89U
- // Now we need to resize in case the default encoding used more than one byte for each
- // character
- if (len != length)
- System.arraycopy(contents, 0, (contents= new char[len]), 0, len);
- return contents;
+ stream = new ByteArrayInputStream(bytes);
+ return org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsCharArray(stream, bytes.length);
} catch (IOException e) {
- if (reader != null) {
+ return new char[0];
+ } finally {
+ if (stream != null) {
try {
- reader.close();
+ stream.close();
} catch(IOException ioe) {
}
}
- return new char[0];
}
}
/**

Back to the top