diff options
author | Markus Schorn | 2012-05-04 09:14:06 +0000 |
---|---|---|
committer | Markus Schorn | 2012-05-04 09:14:06 +0000 |
commit | fefa6b2c297752503991dec6dd779c7be6e8ce56 (patch) | |
tree | 6ba2911faa62b39a08ace5b24545d54693ae8d25 /core/org.eclipse.cdt.core | |
parent | b562fc5469193079a98eb002580d428a5c1a3d26 (diff) | |
download | org.eclipse.cdt-fefa6b2c297752503991dec6dd779c7be6e8ce56.tar.gz org.eclipse.cdt-fefa6b2c297752503991dec6dd779c7be6e8ce56.tar.xz org.eclipse.cdt-fefa6b2c297752503991dec6dd779c7be6e8ce56.zip |
Fix some compiler warnings, remove unused code.
Diffstat (limited to 'core/org.eclipse.cdt.core')
12 files changed, 75 insertions, 332 deletions
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/PathEntryContainerChanged.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/PathEntryContainerChanged.java index 7d20c2f4728..75448250778 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/PathEntryContainerChanged.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/PathEntryContainerChanged.java @@ -39,11 +39,6 @@ public class PathEntryContainerChanged { */ IPath fPath; - /** - * Comment for <code>serialVersionUID</code> - */ - private static final long serialVersionUID = 3257565105200705590L; - /** * diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java index 8016d285b12..930ac7c345b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java @@ -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]); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java index 655a190324c..dac4ec123c8 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java @@ -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; } /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java index 16362419e82..87cb8fd2d3e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java @@ -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; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java index d05977e2226..169c315b3f7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java @@ -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; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java index 101e4926023..c13981823cc 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunctionTemplate.java @@ -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; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java index 61c61b34c29..072c70f2344 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java @@ -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) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpander.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpander.java index 9667a1ea3cc..a6f1b990b95 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpander.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroExpander.java @@ -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; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenList.java index d53fc622b6a..e47c293f34b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenList.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/TokenList.java @@ -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; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/IndexerInputAdapter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/IndexerInputAdapter.java index 69349d5fac2..fdcc094188a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/IndexerInputAdapter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/IndexerInputAdapter.java @@ -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); diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java index 0a0e0e3d19f..8e994ecad9e 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java @@ -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() { diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/Util.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/Util.java index 6445ba72cb6..36088f2d2a5 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/Util.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/Util.java @@ -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. |