1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-09 09:15:38 +02:00

Fix some compiler warnings, remove unused code.

This commit is contained in:
Markus Schorn 2012-05-04 11:14:06 +02:00
parent b562fc5469
commit fefa6b2c29
14 changed files with 79 additions and 336 deletions

View file

@ -39,11 +39,6 @@ public class PathEntryContainerChanged {
*/
IPath fPath;
/**
* Comment for <code>serialVersionUID</code>
*/
private static final long serialVersionUID = 3257565105200705590L;
/**
*

View file

@ -188,14 +188,14 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
}
@Override
public ICElement getElement(String name) {
if (name == null || name.length() == 0) {
public ICElement getElement(String qname) {
if (qname == null || qname.length() == 0) {
return null;
}
try {
ICElement[] celements = getChildren();
for (ICElement celement : celements) {
if (name.equals(celement.getElementName())) {
if (qname.equals(celement.getElementName())) {
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;
for (int j = 0; j < names.length; ++j) {
for (String name : names) {
if (current instanceof IParent) {
try {
ICElement[] celements = ((IParent) current).getChildren();
current = null;
for (ICElement celement : celements) {
if (names[j].equals(celement.getElementName())) {
if (name.equals(celement.getElementName())) {
current = celement;
break;
}
@ -608,11 +608,19 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
IPath path = this.getLocation();
java.io.File file = path.toFile();
if (file != null && file.isFile()) {
InputStream stream= null;
try {
InputStream stream = new FileInputStream(file);
stream = new FileInputStream(file);
buffer.setContents(Util.getInputStreamAsCharArray(stream, (int)file.length(), null));
} catch (IOException e) {
buffer.setContents(new char[0]);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
}
}
}
} else {
buffer.setContents(new char[0]);

View file

@ -20,8 +20,6 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import com.ibm.icu.text.MessageFormat;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICLogConstants;
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.Status;
import com.ibm.icu.text.MessageFormat;
public class Util implements ICLogConstants {
public static boolean VERBOSE_PARSER = 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
* 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.
* returned. Otherwise all chars in the stream are returned. Closes 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
final InputStreamReader reader = encoding == null
? new InputStreamReader(stream)
: new InputStreamReader(stream, encoding);
char[] contents;
if (length == -1) {
contents = new char[0];
int contentsLength = 0;
int charsRead = -1;
do {
int available = stream.available();
// resize contents if needed
if (contentsLength + available > contents.length) {
try {
char[] contents;
if (length == -1) {
contents = new char[0];
int contentsLength = 0;
int charsRead = -1;
do {
int available = stream.available();
// 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,
contents = new char[contentsLength + available], 0,
contentsLength);
contents = new char[contentsLength], 0, contentsLength);
}
// read as many chars as possible
charsRead = reader.read(contents, contentsLength, available);
if (charsRead > 0) {
// remember length of contents
contentsLength += charsRead;
} 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);
}
} 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
// We record first the read size. In this case len is the
// actual read size.
len += readSize;
readSize = reader.read(contents, len, length - len);
// 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);
}
// 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;
} finally {
reader.close();
}
return contents;
}
/**

View file

@ -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.CharArrayUtils;
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.core.runtime.PlatformObject;

View file

@ -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.AttributeUtil;
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.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;

View file

@ -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.ICPPParameter;
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.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.ProblemFunctionType;

View file

@ -447,8 +447,11 @@ public class ChangeGenerator extends ASTVisitor {
while ((piece = clippedEdit(edit2, region)) != null) {
format.addChild(piece);
// The warning "The variable edit2 may be null at this location" is bogus.
if (edit2.getExclusiveEnd() >= end || j >= formatEdits.length) {
break;
// Make the compiler happy:
if (edit2 != null) {
if (edit2.getExclusiveEnd() >= end || j >= formatEdits.length) {
break;
}
}
edit2 = formatEdits[j++];
}
@ -817,8 +820,7 @@ public class ChangeGenerator extends ASTVisitor {
siblings = parent.getChildren();
}
boolean beforeNode = false;
for (int i = 0; i < siblings.length; i++) {
IASTNode sibling = siblings[i];
for (IASTNode sibling : siblings) {
if (sibling == node) {
beforeNode = true;
} else if (beforeNode) {

View file

@ -263,7 +263,7 @@ public class MacroExpander {
final TokenSource[] argInputs= new TokenSource[paramCount];
final BitSet paramUsage= getParamUsage(macro);
if (tracker != null) {
tracker.startFunctionStyleMacro((Token) lastConsumed.clone());
tracker.startFunctionStyleMacro(lastConsumed.clone());
}
try {
lastConsumed= parseArguments(input, (FunctionStyleMacro) macro, forbidden, argInputs, tracker);
@ -482,7 +482,7 @@ public class MacroExpander {
case Lexer.tNEWLINE:
break;
default:
tracker.addFunctionStyleMacroExpansionToken((Token) t.clone());
tracker.addFunctionStyleMacroExpansionToken(t.clone());
break;
}
}
@ -841,7 +841,7 @@ public class MacroExpander {
private TokenList clone(TokenList tl) {
TokenList result= new TokenList();
for (Token t= tl.first(); t != null; t= (Token) t.getNext()) {
result.append((Token) t.clone());
result.append(t.clone());
}
return result;
}

View file

@ -86,7 +86,7 @@ class TokenList {
TokenList result= new TokenList();
for (Token t= fFirst; t != null; t= (Token) t.getNext()) {
if (t.getType() != CPreprocessor.tSCOPE_MARKER) {
result.append((Token) t.clone());
result.append(t.clone());
}
}
return result;

View file

@ -67,7 +67,7 @@ public abstract class IndexerInputAdapter extends ASTFilePathResolver {
/**
* 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.
*/
public abstract boolean isIndexedUnconditionally(IIndexFileLocation location);

View file

@ -282,9 +282,9 @@ public class CCorePlugin extends Plugin {
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) {
return MessageFormat.format(getResourceString(key), (Object[])args);
final Object[] objArgs = args;
return MessageFormat.format(getResourceString(key), objArgs);
}
public static ResourceBundle getResourceBundle() {

View file

@ -10,274 +10,13 @@
*******************************************************************************/
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.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.Platform;
import org.eclipse.core.runtime.Status;
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
* given Throwable.

View file

@ -31,6 +31,7 @@ import org.eclipse.swt.graphics.RGB;
import org.eclipse.cdt.ui.text.CSourceViewerConfiguration;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.ui.text.IColorManager;
import org.eclipse.cdt.internal.ui.text.CPresentationReconciler;
import org.eclipse.cdt.internal.ui.text.CSourceViewerScalableConfiguration;
@ -481,7 +482,7 @@ public class SemanticHighlightingManager implements IPropertyChangeListener {
* Handle the given property change event
*
* @param event The event
* @return
* @return whether a refresh is needed
*/
protected boolean handlePropertyChangeEvent(PropertyChangeEvent event) {
if (fPreferenceStore == null)

View file

@ -200,8 +200,8 @@ public class SourceViewerInformationControl implements IInformationControl, IInf
fStatusField.setText(statusFieldText);
Font font= fStatusField.getFont();
FontData[] fontDatas= font.getFontData();
for (int i= 0; i < fontDatas.length; i++)
fontDatas[i].setHeight(fontDatas[i].getHeight() * 9 / 10);
for (FontData fontData : fontDatas)
fontData.setHeight(fontData.getHeight() * 9 / 10);
fStatusTextFont= new Font(fStatusField.getDisplay(), fontDatas);
fStatusField.setFont(fStatusTextFont);
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
*/
@SuppressWarnings("null")
private static RGB blend(RGB bg, RGB fg, float factor) {
// copy of org.eclipse.jface.internal.text.revisions.Colors#blend(..)
Assert.isLegal(bg != null);