mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-10 09:45:39 +02:00
Fix some compiler warnings, remove unused code.
This commit is contained in:
parent
b562fc5469
commit
fefa6b2c29
14 changed files with 79 additions and 336 deletions
|
@ -39,11 +39,6 @@ public class PathEntryContainerChanged {
|
||||||
*/
|
*/
|
||||||
IPath fPath;
|
IPath fPath;
|
||||||
|
|
||||||
/**
|
|
||||||
* Comment for <code>serialVersionUID</code>
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 3257565105200705590L;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -188,14 +188,14 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ICElement getElement(String name) {
|
public ICElement getElement(String qname) {
|
||||||
if (name == null || name.length() == 0) {
|
if (qname == null || qname.length() == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
ICElement[] celements = getChildren();
|
ICElement[] celements = getChildren();
|
||||||
for (ICElement celement : celements) {
|
for (ICElement celement : celements) {
|
||||||
if (name.equals(celement.getElementName())) {
|
if (qname.equals(celement.getElementName())) {
|
||||||
return celement;
|
return celement;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,15 +203,15 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] names = name.split("::"); //$NON-NLS-1$
|
String[] names = qname.split("::"); //$NON-NLS-1$
|
||||||
ICElement current = this;
|
ICElement current = this;
|
||||||
for (int j = 0; j < names.length; ++j) {
|
for (String name : names) {
|
||||||
if (current instanceof IParent) {
|
if (current instanceof IParent) {
|
||||||
try {
|
try {
|
||||||
ICElement[] celements = ((IParent) current).getChildren();
|
ICElement[] celements = ((IParent) current).getChildren();
|
||||||
current = null;
|
current = null;
|
||||||
for (ICElement celement : celements) {
|
for (ICElement celement : celements) {
|
||||||
if (names[j].equals(celement.getElementName())) {
|
if (name.equals(celement.getElementName())) {
|
||||||
current = celement;
|
current = celement;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -608,11 +608,19 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
IPath path = this.getLocation();
|
IPath path = this.getLocation();
|
||||||
java.io.File file = path.toFile();
|
java.io.File file = path.toFile();
|
||||||
if (file != null && file.isFile()) {
|
if (file != null && file.isFile()) {
|
||||||
|
InputStream stream= null;
|
||||||
try {
|
try {
|
||||||
InputStream stream = new FileInputStream(file);
|
stream = new FileInputStream(file);
|
||||||
buffer.setContents(Util.getInputStreamAsCharArray(stream, (int)file.length(), null));
|
buffer.setContents(Util.getInputStreamAsCharArray(stream, (int)file.length(), null));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
buffer.setContents(new char[0]);
|
buffer.setContents(new char[0]);
|
||||||
|
} finally {
|
||||||
|
if (stream != null) {
|
||||||
|
try {
|
||||||
|
stream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
buffer.setContents(new char[0]);
|
buffer.setContents(new char[0]);
|
||||||
|
|
|
@ -20,8 +20,6 @@ import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import com.ibm.icu.text.MessageFormat;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.ICLogConstants;
|
import org.eclipse.cdt.core.ICLogConstants;
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
|
@ -36,6 +34,8 @@ import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
|
||||||
|
import com.ibm.icu.text.MessageFormat;
|
||||||
|
|
||||||
public class Util implements ICLogConstants {
|
public class Util implements ICLogConstants {
|
||||||
public static boolean VERBOSE_PARSER = false;
|
public static boolean VERBOSE_PARSER = false;
|
||||||
public static boolean VERBOSE_SCANNER = false;
|
public static boolean VERBOSE_SCANNER = false;
|
||||||
|
@ -69,63 +69,65 @@ public class Util implements ICLogConstants {
|
||||||
/**
|
/**
|
||||||
* Returns the given input stream's contents as a character array. If a
|
* Returns the given input stream's contents as a character array. If a
|
||||||
* length is specified (ie. if length != -1), only length chars are
|
* length is specified (ie. if length != -1), only length chars are
|
||||||
* returned. Otherwise all chars in the stream are returned. Note this
|
* returned. Otherwise all chars in the stream are returned. Closes the stream.
|
||||||
* doesn't close the stream.
|
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* if a problem occured reading the stream.
|
* if a problem occured reading the stream.
|
||||||
*/
|
*/
|
||||||
public static char[] getInputStreamAsCharArray(InputStream stream,
|
public static char[] getInputStreamAsCharArray(InputStream stream,
|
||||||
int length, String encoding) throws IOException {
|
int length, String encoding) throws IOException {
|
||||||
InputStreamReader reader = null;
|
final InputStreamReader reader = encoding == null
|
||||||
reader = encoding == null
|
|
||||||
? new InputStreamReader(stream)
|
? new InputStreamReader(stream)
|
||||||
: new InputStreamReader(stream, encoding);
|
: new InputStreamReader(stream, encoding);
|
||||||
char[] contents;
|
try {
|
||||||
if (length == -1) {
|
char[] contents;
|
||||||
contents = new char[0];
|
if (length == -1) {
|
||||||
int contentsLength = 0;
|
contents = new char[0];
|
||||||
int charsRead = -1;
|
int contentsLength = 0;
|
||||||
do {
|
int charsRead = -1;
|
||||||
int available = stream.available();
|
do {
|
||||||
// resize contents if needed
|
int available = stream.available();
|
||||||
if (contentsLength + available > contents.length) {
|
// resize contents if needed
|
||||||
|
if (contentsLength + available > contents.length) {
|
||||||
|
System.arraycopy(contents, 0,
|
||||||
|
contents = new char[contentsLength + available], 0,
|
||||||
|
contentsLength);
|
||||||
|
}
|
||||||
|
// read as many chars as possible
|
||||||
|
charsRead = reader.read(contents, contentsLength, available);
|
||||||
|
if (charsRead > 0) {
|
||||||
|
// remember length of contents
|
||||||
|
contentsLength += charsRead;
|
||||||
|
}
|
||||||
|
} while (charsRead > 0);
|
||||||
|
// resize contents if necessary
|
||||||
|
if (contentsLength < contents.length) {
|
||||||
System.arraycopy(contents, 0,
|
System.arraycopy(contents, 0,
|
||||||
contents = new char[contentsLength + available], 0,
|
contents = new char[contentsLength], 0, contentsLength);
|
||||||
contentsLength);
|
|
||||||
}
|
}
|
||||||
// read as many chars as possible
|
} else {
|
||||||
charsRead = reader.read(contents, contentsLength, available);
|
contents = new char[length];
|
||||||
if (charsRead > 0) {
|
int len = 0;
|
||||||
// remember length of contents
|
int readSize = 0;
|
||||||
contentsLength += charsRead;
|
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);
|
||||||
}
|
}
|
||||||
} while (charsRead > 0);
|
|
||||||
// resize contents if necessary
|
|
||||||
if (contentsLength < contents.length) {
|
|
||||||
System.arraycopy(contents, 0,
|
|
||||||
contents = new char[contentsLength], 0, contentsLength);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
contents = new char[length];
|
|
||||||
int len = 0;
|
|
||||||
int readSize = 0;
|
|
||||||
while ((readSize != -1) && (len != length)) {
|
|
||||||
// See PR 1FMS89U
|
// See PR 1FMS89U
|
||||||
// We record first the read size. In this case len is the
|
// Now we need to resize in case the default encoding used more
|
||||||
// actual read size.
|
// than one byte for each
|
||||||
len += readSize;
|
// character
|
||||||
readSize = reader.read(contents, len, length - len);
|
if (len != length)
|
||||||
|
System.arraycopy(contents, 0, (contents = new char[len]), 0,
|
||||||
|
len);
|
||||||
}
|
}
|
||||||
// See PR 1FMS89U
|
return contents;
|
||||||
// Now we need to resize in case the default encoding used more
|
} finally {
|
||||||
// than one byte for each
|
reader.close();
|
||||||
// character
|
|
||||||
if (len != length)
|
|
||||||
System.arraycopy(contents, 0, (contents = new char[len]), 0,
|
|
||||||
len);
|
|
||||||
}
|
}
|
||||||
return contents;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -36,7 +36,6 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.core.parser.util.AttributeUtil;
|
import org.eclipse.cdt.core.parser.util.AttributeUtil;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTAttribute;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
|
||||||
import org.eclipse.core.runtime.PlatformObject;
|
import org.eclipse.core.runtime.PlatformObject;
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.core.parser.util.AttributeUtil;
|
import org.eclipse.cdt.core.parser.util.AttributeUtil;
|
||||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTAttribute;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
|
||||||
|
|
|
@ -37,7 +37,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
|
||||||
import org.eclipse.cdt.core.parser.util.AttributeUtil;
|
import org.eclipse.cdt.core.parser.util.AttributeUtil;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTAttribute;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemFunctionType;
|
import org.eclipse.cdt.internal.core.dom.parser.ProblemFunctionType;
|
||||||
|
|
|
@ -447,8 +447,11 @@ public class ChangeGenerator extends ASTVisitor {
|
||||||
while ((piece = clippedEdit(edit2, region)) != null) {
|
while ((piece = clippedEdit(edit2, region)) != null) {
|
||||||
format.addChild(piece);
|
format.addChild(piece);
|
||||||
// The warning "The variable edit2 may be null at this location" is bogus.
|
// The warning "The variable edit2 may be null at this location" is bogus.
|
||||||
if (edit2.getExclusiveEnd() >= end || j >= formatEdits.length) {
|
// Make the compiler happy:
|
||||||
break;
|
if (edit2 != null) {
|
||||||
|
if (edit2.getExclusiveEnd() >= end || j >= formatEdits.length) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
edit2 = formatEdits[j++];
|
edit2 = formatEdits[j++];
|
||||||
}
|
}
|
||||||
|
@ -817,8 +820,7 @@ public class ChangeGenerator extends ASTVisitor {
|
||||||
siblings = parent.getChildren();
|
siblings = parent.getChildren();
|
||||||
}
|
}
|
||||||
boolean beforeNode = false;
|
boolean beforeNode = false;
|
||||||
for (int i = 0; i < siblings.length; i++) {
|
for (IASTNode sibling : siblings) {
|
||||||
IASTNode sibling = siblings[i];
|
|
||||||
if (sibling == node) {
|
if (sibling == node) {
|
||||||
beforeNode = true;
|
beforeNode = true;
|
||||||
} else if (beforeNode) {
|
} else if (beforeNode) {
|
||||||
|
|
|
@ -263,7 +263,7 @@ public class MacroExpander {
|
||||||
final TokenSource[] argInputs= new TokenSource[paramCount];
|
final TokenSource[] argInputs= new TokenSource[paramCount];
|
||||||
final BitSet paramUsage= getParamUsage(macro);
|
final BitSet paramUsage= getParamUsage(macro);
|
||||||
if (tracker != null) {
|
if (tracker != null) {
|
||||||
tracker.startFunctionStyleMacro((Token) lastConsumed.clone());
|
tracker.startFunctionStyleMacro(lastConsumed.clone());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
lastConsumed= parseArguments(input, (FunctionStyleMacro) macro, forbidden, argInputs, tracker);
|
lastConsumed= parseArguments(input, (FunctionStyleMacro) macro, forbidden, argInputs, tracker);
|
||||||
|
@ -482,7 +482,7 @@ public class MacroExpander {
|
||||||
case Lexer.tNEWLINE:
|
case Lexer.tNEWLINE:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
tracker.addFunctionStyleMacroExpansionToken((Token) t.clone());
|
tracker.addFunctionStyleMacroExpansionToken(t.clone());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -841,7 +841,7 @@ public class MacroExpander {
|
||||||
private TokenList clone(TokenList tl) {
|
private TokenList clone(TokenList tl) {
|
||||||
TokenList result= new TokenList();
|
TokenList result= new TokenList();
|
||||||
for (Token t= tl.first(); t != null; t= (Token) t.getNext()) {
|
for (Token t= tl.first(); t != null; t= (Token) t.getNext()) {
|
||||||
result.append((Token) t.clone());
|
result.append(t.clone());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ class TokenList {
|
||||||
TokenList result= new TokenList();
|
TokenList result= new TokenList();
|
||||||
for (Token t= fFirst; t != null; t= (Token) t.getNext()) {
|
for (Token t= fFirst; t != null; t= (Token) t.getNext()) {
|
||||||
if (t.getType() != CPreprocessor.tSCOPE_MARKER) {
|
if (t.getType() != CPreprocessor.tSCOPE_MARKER) {
|
||||||
result.append((Token) t.clone());
|
result.append(t.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -67,7 +67,7 @@ public abstract class IndexerInputAdapter extends ASTFilePathResolver {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the given file should be indexed unconditionally.
|
* Checks whether the given file should be indexed unconditionally.
|
||||||
* @param ifl The Location of the file.
|
* @param location The Location of the file.
|
||||||
* @return {@code true} if the file should be indexed unconditionally.
|
* @return {@code true} if the file should be indexed unconditionally.
|
||||||
*/
|
*/
|
||||||
public abstract boolean isIndexedUnconditionally(IIndexFileLocation location);
|
public abstract boolean isIndexedUnconditionally(IIndexFileLocation location);
|
||||||
|
|
|
@ -282,9 +282,9 @@ public class CCorePlugin extends Plugin {
|
||||||
return MessageFormat.format(getResourceString(key), new Object[] { arg });
|
return MessageFormat.format(getResourceString(key), new Object[] { arg });
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("cast") // java.text.MessageFormat would require the cast
|
|
||||||
public static String getFormattedString(String key, String[] args) {
|
public static String getFormattedString(String key, String[] args) {
|
||||||
return MessageFormat.format(getResourceString(key), (Object[])args);
|
final Object[] objArgs = args;
|
||||||
|
return MessageFormat.format(getResourceString(key), objArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResourceBundle getResourceBundle() {
|
public static ResourceBundle getResourceBundle() {
|
||||||
|
|
|
@ -10,274 +10,13 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core;
|
package org.eclipse.cdt.internal.core;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.core.resources.IContainer;
|
|
||||||
import org.eclipse.core.resources.IResource;
|
|
||||||
import org.eclipse.core.runtime.IPath;
|
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
|
||||||
public class Util {
|
public class Util {
|
||||||
|
|
||||||
private static final int DEFAULT_READING_SIZE = 8192;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the contents of the given file as a byte array.
|
|
||||||
* @throws IOException if a problem occured reading the file.
|
|
||||||
*/
|
|
||||||
public static byte[] getFileByteContent(File file) throws IOException {
|
|
||||||
InputStream stream = null;
|
|
||||||
try {
|
|
||||||
stream = new BufferedInputStream(new FileInputStream(file));
|
|
||||||
return getInputStreamAsByteArray(stream, (int) file.length());
|
|
||||||
} finally {
|
|
||||||
if (stream != null) {
|
|
||||||
try {
|
|
||||||
stream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Returns the contents of the given file as a char array.
|
|
||||||
* When encoding is null, then the platform default one is used
|
|
||||||
* @throws IOException if a problem occured reading the file.
|
|
||||||
*/
|
|
||||||
public static char[] getFileCharContent(File file, String encoding) throws IOException {
|
|
||||||
InputStream stream = null;
|
|
||||||
try {
|
|
||||||
stream = new BufferedInputStream(new FileInputStream(file));
|
|
||||||
return Util.getInputStreamAsCharArray(stream, (int) file.length(), encoding);
|
|
||||||
}
|
|
||||||
catch (OutOfMemoryError er){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
if (stream != null) {
|
|
||||||
try {
|
|
||||||
stream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the given input stream's contents as a byte array.
|
|
||||||
* If a length is specified (ie. if length != -1), only length bytes
|
|
||||||
* are returned. Otherwise all bytes in the stream are returned.
|
|
||||||
* Note this doesn't close the stream.
|
|
||||||
* @throws IOException if a problem occured reading the stream.
|
|
||||||
*/
|
|
||||||
public static byte[] getInputStreamAsByteArray(InputStream stream, int length)
|
|
||||||
throws IOException {
|
|
||||||
byte[] contents;
|
|
||||||
if (length == -1) {
|
|
||||||
contents = new byte[0];
|
|
||||||
int contentsLength = 0;
|
|
||||||
int amountRead = -1;
|
|
||||||
do {
|
|
||||||
int amountRequested = Math.max(stream.available(), DEFAULT_READING_SIZE); // read at least 8K
|
|
||||||
|
|
||||||
// resize contents if needed
|
|
||||||
if (contentsLength + amountRequested > contents.length) {
|
|
||||||
System.arraycopy(
|
|
||||||
contents,
|
|
||||||
0,
|
|
||||||
contents = new byte[contentsLength + amountRequested],
|
|
||||||
0,
|
|
||||||
contentsLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
// read as many bytes as possible
|
|
||||||
amountRead = stream.read(contents, contentsLength, amountRequested);
|
|
||||||
|
|
||||||
if (amountRead > 0) {
|
|
||||||
// remember length of contents
|
|
||||||
contentsLength += amountRead;
|
|
||||||
}
|
|
||||||
} while (amountRead != -1);
|
|
||||||
|
|
||||||
// resize contents if necessary
|
|
||||||
if (contentsLength < contents.length) {
|
|
||||||
System.arraycopy(
|
|
||||||
contents,
|
|
||||||
0,
|
|
||||||
contents = new byte[contentsLength],
|
|
||||||
0,
|
|
||||||
contentsLength);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
contents = new byte[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 = stream.read(contents, len, length - len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return contents;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the given input stream's contents as a character array.
|
|
||||||
* If a length is specified (ie. if length != -1), only length chars
|
|
||||||
* are returned. Otherwise all chars in the stream are returned.
|
|
||||||
* Note this doesn't close the stream.
|
|
||||||
* @throws IOException if a problem occured reading the stream.
|
|
||||||
*/
|
|
||||||
public static char[] getInputStreamAsCharArray(InputStream stream, int length, String encoding)
|
|
||||||
throws IOException {
|
|
||||||
InputStreamReader reader = null;
|
|
||||||
reader = encoding == null
|
|
||||||
? new InputStreamReader(stream)
|
|
||||||
: new InputStreamReader(stream, encoding);
|
|
||||||
char[] contents;
|
|
||||||
if (length == -1) {
|
|
||||||
contents = CharOperation.NO_CHAR;
|
|
||||||
int contentsLength = 0;
|
|
||||||
int amountRead = -1;
|
|
||||||
do {
|
|
||||||
int amountRequested = Math.max(stream.available(), DEFAULT_READING_SIZE); // read at least 8K
|
|
||||||
|
|
||||||
// resize contents if needed
|
|
||||||
if (contentsLength + amountRequested > contents.length) {
|
|
||||||
System.arraycopy(
|
|
||||||
contents,
|
|
||||||
0,
|
|
||||||
contents = new char[contentsLength + amountRequested],
|
|
||||||
0,
|
|
||||||
contentsLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
// read as many chars as possible
|
|
||||||
amountRead = reader.read(contents, contentsLength, amountRequested);
|
|
||||||
|
|
||||||
if (amountRead > 0) {
|
|
||||||
// remember length of contents
|
|
||||||
contentsLength += amountRead;
|
|
||||||
}
|
|
||||||
} while (amountRead != -1);
|
|
||||||
|
|
||||||
// resize contents if necessary
|
|
||||||
if (contentsLength < contents.length) {
|
|
||||||
System.arraycopy(
|
|
||||||
contents,
|
|
||||||
0,
|
|
||||||
contents = new char[contentsLength],
|
|
||||||
0,
|
|
||||||
contentsLength);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method - returns the targeted item (IResource if internal or java.io.File if external),
|
|
||||||
* or null if unbound
|
|
||||||
* Internal items must be referred to using container relative paths.
|
|
||||||
*/
|
|
||||||
public static Object getTarget(IContainer container, IPath path, boolean checkResourceExistence) {
|
|
||||||
|
|
||||||
if (path == null) return null;
|
|
||||||
|
|
||||||
// lookup - inside the container
|
|
||||||
if (path.getDevice() == null) { // container relative paths should not contain a device
|
|
||||||
// (see http://dev.eclipse.org/bugs/show_bug.cgi?id=18684)
|
|
||||||
// (case of a workspace rooted at d:\ )
|
|
||||||
IResource resource = container.findMember(path);
|
|
||||||
if (resource != null){
|
|
||||||
if (!checkResourceExistence ||resource.exists()) return resource;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if path is relative, it cannot be an external path
|
|
||||||
// (see http://dev.eclipse.org/bugs/show_bug.cgi?id=22517)
|
|
||||||
if (!path.isAbsolute()) return null;
|
|
||||||
|
|
||||||
// lookup - outside the container
|
|
||||||
File externalFile = new File(path.toOSString());
|
|
||||||
if (!checkResourceExistence) {
|
|
||||||
return externalFile;
|
|
||||||
} else if (existingExternalFiles.contains(externalFile)) {
|
|
||||||
return externalFile;
|
|
||||||
} else {
|
|
||||||
if (externalFile.exists()) {
|
|
||||||
// cache external file
|
|
||||||
existingExternalFiles.add(externalFile);
|
|
||||||
return externalFile;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* A set of java.io.Files used as a cache of external jars that
|
|
||||||
* are known to be existing.
|
|
||||||
* Note this cache is kept for the whole session.
|
|
||||||
*/
|
|
||||||
public static HashSet<File> existingExternalFiles = new HashSet<File>();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns whether the given resource matches one of the exclusion patterns.
|
|
||||||
*
|
|
||||||
* @see IClasspathEntry#getExclusionPatterns
|
|
||||||
*/
|
|
||||||
public final static boolean isExcluded(IResource resource, char[][] exclusionPatterns) {
|
|
||||||
IPath path = resource.getFullPath();
|
|
||||||
// ensure that folders are only excluded if all of their children are excluded
|
|
||||||
if (resource.getType() == IResource.FOLDER)
|
|
||||||
path = path.append("*"); //$NON-NLS-1$
|
|
||||||
return isExcluded(path, exclusionPatterns);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns whether the given resource path matches one of the exclusion
|
|
||||||
* patterns.
|
|
||||||
*
|
|
||||||
* @see IClasspathEntry#getExclusionPatterns
|
|
||||||
*/
|
|
||||||
public final static boolean isExcluded(IPath resourcePath, char[][] exclusionPatterns) {
|
|
||||||
if (exclusionPatterns == null) return false;
|
|
||||||
char[] path = resourcePath.toString().toCharArray();
|
|
||||||
for (char[] exclusionPattern : exclusionPatterns)
|
|
||||||
if (CharOperation.pathMatch(exclusionPattern, path, true, '/'))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an IStatus object with severity IStatus.ERROR based on the
|
* Returns an IStatus object with severity IStatus.ERROR based on the
|
||||||
* given Throwable.
|
* given Throwable.
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.eclipse.swt.graphics.RGB;
|
||||||
import org.eclipse.cdt.ui.text.CSourceViewerConfiguration;
|
import org.eclipse.cdt.ui.text.CSourceViewerConfiguration;
|
||||||
import org.eclipse.cdt.ui.text.ICPartitions;
|
import org.eclipse.cdt.ui.text.ICPartitions;
|
||||||
import org.eclipse.cdt.ui.text.IColorManager;
|
import org.eclipse.cdt.ui.text.IColorManager;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.text.CPresentationReconciler;
|
import org.eclipse.cdt.internal.ui.text.CPresentationReconciler;
|
||||||
import org.eclipse.cdt.internal.ui.text.CSourceViewerScalableConfiguration;
|
import org.eclipse.cdt.internal.ui.text.CSourceViewerScalableConfiguration;
|
||||||
|
|
||||||
|
@ -481,7 +482,7 @@ public class SemanticHighlightingManager implements IPropertyChangeListener {
|
||||||
* Handle the given property change event
|
* Handle the given property change event
|
||||||
*
|
*
|
||||||
* @param event The event
|
* @param event The event
|
||||||
* @return
|
* @return whether a refresh is needed
|
||||||
*/
|
*/
|
||||||
protected boolean handlePropertyChangeEvent(PropertyChangeEvent event) {
|
protected boolean handlePropertyChangeEvent(PropertyChangeEvent event) {
|
||||||
if (fPreferenceStore == null)
|
if (fPreferenceStore == null)
|
||||||
|
|
|
@ -200,8 +200,8 @@ public class SourceViewerInformationControl implements IInformationControl, IInf
|
||||||
fStatusField.setText(statusFieldText);
|
fStatusField.setText(statusFieldText);
|
||||||
Font font= fStatusField.getFont();
|
Font font= fStatusField.getFont();
|
||||||
FontData[] fontDatas= font.getFontData();
|
FontData[] fontDatas= font.getFontData();
|
||||||
for (int i= 0; i < fontDatas.length; i++)
|
for (FontData fontData : fontDatas)
|
||||||
fontDatas[i].setHeight(fontDatas[i].getHeight() * 9 / 10);
|
fontData.setHeight(fontData.getHeight() * 9 / 10);
|
||||||
fStatusTextFont= new Font(fStatusField.getDisplay(), fontDatas);
|
fStatusTextFont= new Font(fStatusField.getDisplay(), fontDatas);
|
||||||
fStatusField.setFont(fStatusTextFont);
|
fStatusField.setFont(fStatusTextFont);
|
||||||
GridData gd2= new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
|
GridData gd2= new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
|
||||||
|
@ -227,7 +227,6 @@ public class SourceViewerInformationControl implements IInformationControl, IInf
|
||||||
*
|
*
|
||||||
* @return the interpolated color
|
* @return the interpolated color
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("null")
|
|
||||||
private static RGB blend(RGB bg, RGB fg, float factor) {
|
private static RGB blend(RGB bg, RGB fg, float factor) {
|
||||||
// copy of org.eclipse.jface.internal.text.revisions.Colors#blend(..)
|
// copy of org.eclipse.jface.internal.text.revisions.Colors#blend(..)
|
||||||
Assert.isLegal(bg != null);
|
Assert.isLegal(bg != null);
|
||||||
|
|
Loading…
Add table
Reference in a new issue