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 5c398e912c3..437dff982a4 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 @@ -65,6 +65,7 @@ import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfoProvider; import org.eclipse.cdt.core.parser.IncludeFileContentProvider; import org.eclipse.cdt.core.parser.ParserUtil; +import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit; @@ -245,13 +246,13 @@ public class TranslationUnit extends Openable implements ITranslationUnit { @Override public IInclude[] getIncludes() throws CModelException { ICElement[] celements = getChildren(); - ArrayList aList = new ArrayList(); + ArrayList includes = new ArrayList<>(); for (ICElement celement : celements) { if (celement.getElementType() == ICElement.C_INCLUDE) { - aList.add(celement); + includes.add(celement); } } - return aList.toArray(new IInclude[0]); + return includes.toArray(new IInclude[includes.size()]); } @Override @@ -273,13 +274,13 @@ public class TranslationUnit extends Openable implements ITranslationUnit { @Override public IUsing[] getUsings() throws CModelException { ICElement[] celements = getChildren(); - ArrayList aList = new ArrayList(); + ArrayList usings = new ArrayList<>(); for (ICElement celement : celements) { if (celement.getElementType() == ICElement.C_USING) { - aList.add(celement); + usings.add(celement); } } - return aList.toArray(new IUsing[0]); + return usings.toArray(new IUsing[usings.size()]); } @Override @@ -314,13 +315,13 @@ public class TranslationUnit extends Openable implements ITranslationUnit { @Override public INamespace[] getNamespaces() throws CModelException { ICElement[] celements = getChildren(); - ArrayList elementList = new ArrayList(); + ArrayList namespaces = new ArrayList<>(); for (ICElement celement : celements) { if (celement.getElementType() == ICElement.C_NAMESPACE) { - elementList.add(celement); + namespaces.add(celement); } } - return elementList.toArray(new INamespace[0]); + return namespaces.toArray(new INamespace[namespaces.size()]); } protected void setLocationURI(URI loc) { @@ -470,7 +471,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit { IBuffer buffer = this.getBuffer(); return buffer == null ? null : buffer.getCharacters(); } catch (CModelException e) { - return new char[0]; + return CharArrayUtils.EMPTY_CHAR_ARRAY; } } @@ -611,9 +612,9 @@ public class TranslationUnit extends Openable implements ITranslationUnit { InputStream stream= null; try { 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) { - buffer.setContents(new char[0]); + buffer.setContents(CharArrayUtils.EMPTY_CHAR_ARRAY); } finally { if (stream != null) { try { @@ -623,7 +624,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit { } } } else { - buffer.setContents(new char[0]); + buffer.setContents(CharArrayUtils.EMPTY_CHAR_ARRAY); } } } @@ -942,7 +943,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit { } public static IIndexFile getParsedInContext(IIndexFile indexFile) throws CoreException { - HashSet visited= new HashSet(); + HashSet visited= new HashSet<>(); // Bug 199412, may recurse. while (visited.add(indexFile)) { IIndexInclude include= indexFile.getParsedInContext(); @@ -1109,7 +1110,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit { // optional: parameters String[] mementoParams= {}; if (memento.hasMoreTokens()) { - List params= new ArrayList(); + List params= new ArrayList<>(); do { token= memento.nextToken(); if (token.charAt(0) != CEM_PARAMETER) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameProcessor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameProcessor.java index 14891cddede..806ad2145a4 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameProcessor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameProcessor.java @@ -59,7 +59,7 @@ public class CRenameProcessor extends RenameProcessor { private final CRefactory fManager; private final ASTManager fAstManager; private IIndex fIndex; - private int indexLockCount; + private int fIndexLockCount; private RefactoringStatus fInitialConditionsStatus; private Change fChange; @@ -303,7 +303,7 @@ public class CRenameProcessor extends RenameProcessor { } public void lockIndex() throws CoreException, InterruptedException { - if (indexLockCount == 0) { + if (fIndexLockCount == 0) { if (fIndex == null) { ICProject[] projects= CoreModel.getDefault().getCModel().getCProjects(); fIndex = CCorePlugin.getIndexManager().getIndex(projects, @@ -311,11 +311,11 @@ public class CRenameProcessor extends RenameProcessor { } fIndex.acquireReadLock(); } - indexLockCount++; + fIndexLockCount++; } public void unlockIndex() { - if (--indexLockCount <= 0) { + if (--fIndexLockCount <= 0) { if (fAstManager != null) { fAstManager.dispose(); }