diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ObjectSet.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ObjectSet.java index 5e04eeb4c6b..bcdd92cb9b4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ObjectSet.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ObjectSet.java @@ -33,8 +33,9 @@ public class ObjectSet extends ObjectTable { public static ObjectSet emptySet() { return EMPTY_SET; } + /** - * Construct an empty ObjectSet, allocating an initial storage for the specified + * Constructs an empty ObjectSet, allocating an initial storage for the specified * number of elements * @param initialSize */ @@ -43,7 +44,7 @@ public class ObjectSet extends ObjectTable { } /** - * Construct an ObjectSet populated with the specified items, or an empty ObjectSet + * Constructs an ObjectSet populated with the specified items, or an empty ObjectSet * if the parameter is null * @param items */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index 1c3bf1b8a2a..507fc570139 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -592,7 +592,7 @@ public class CPPSemantics { // don't ascend into enclosing scopes. boolean originalQualified = data.qualified; data.qualified = true; - Set friendFns = new HashSet(2); + Set friendFns = new HashSet<>(2); Set associated = getAssociatedScopes(data, friendFns); for (ICPPNamespaceScope scope : associated) { if (!data.visited.containsKey(scope)) { @@ -717,8 +717,8 @@ public class CPPSemantics { return Collections.emptySet(); IType[] ps = data.getFunctionArgumentTypes(); - Set namespaces = new HashSet(2); - ObjectSet handled = new ObjectSet(2); + Set namespaces = new HashSet<>(2); + ObjectSet handled = new ObjectSet<>(2); for (IType p : ps) { try { getAssociatedScopes(p, namespaces, friendFns, handled, data.getTranslationUnit()); @@ -882,7 +882,7 @@ public class CPPSemantics { */ static CharArrayObjectMap mergePrefixResults(CharArrayObjectMap dest, Object source, boolean scoped) { if (source == null) return dest; - CharArrayObjectMap resultMap = (dest != null) ? dest : new CharArrayObjectMap(2); + CharArrayObjectMap resultMap = (dest != null) ? dest : new CharArrayObjectMap<>(2); CharArrayObjectMap map = null; Object[] objs = null; @@ -1101,7 +1101,7 @@ public class CPPSemantics { } ICPPUsingDirective[] uds= blockScope.getUsingDirectives(); if (uds != null && uds.length > 0) { - HashSet handled= new HashSet(); + HashSet handled= new HashSet<>(); for (final ICPPUsingDirective ud : uds) { if (data.isIgnorePointOfDeclaration() || declaredBefore(ud, data.getLookupPoint(), false)) { storeUsingDirective(data, blockScope, ud, handled); @@ -1127,7 +1127,7 @@ public class CPPSemantics { if (dqname.getLastName() != typeDtorName) return false; } - char[] tchars= new char[typeDtorChars.length-1]; + char[] tchars= new char[typeDtorChars.length - 1]; System.arraycopy(typeDtorChars, 1, tchars, 0, tchars.length); LookupData ld2= new LookupData(tchars, data.fTemplateArguments, data.getLookupPoint()); @@ -1154,7 +1154,7 @@ public class CPPSemantics { } char[] classChars= classType.getNameCharArray(); - char[] classDtorChars= new char[classChars.length+1]; + char[] classDtorChars= new char[classChars.length + 1]; classDtorChars[0]= '~'; System.arraycopy(classChars, 0, classDtorChars, 1, classChars.length); data.setLookupKey(classDtorChars); @@ -1303,7 +1303,7 @@ public class CPPSemantics { break; if (b instanceof ICPPUsingDeclaration || (data.typesOnly && isObject(b))) { - List result= new ArrayList(bindings.length); + List result= new ArrayList<>(bindings.length); expandUsingDeclarations(bindings, data, result); return result.toArray(new IBinding[result.size()]); } @@ -1393,7 +1393,7 @@ public class CPPSemantics { // store the directive with the scope where it has to be considered List listOfNominated= data.usingDirectives.get(appearsIn); if (listOfNominated == null) { - listOfNominated= new ArrayList(1); + listOfNominated= new ArrayList<>(1); if (data.usingDirectives.isEmpty()) { data.usingDirectives= new HashMap>(); } @@ -1421,7 +1421,7 @@ public class CPPSemantics { */ private static ICPPScope getCommonEnclosingScope(IScope s1, IScope s2, ICPPASTTranslationUnit tu) throws DOMException { - ObjectSet set = new ObjectSet(2); + ObjectSet set = new ObjectSet<>(2); IScope parent= s1; while (parent != null) { set.put(parent); @@ -1969,10 +1969,9 @@ public class CPPSemantics { IASTNode lookupPoint = data.getLookupPoint(); final boolean indexBased= data.getIndex() != null; final boolean checkWholeClass= lookupName == null || LookupData.checkWholeClassScope(lookupName); - @SuppressWarnings("unchecked") - ObjectSet fns= ObjectSet.EMPTY_SET; + ObjectSet fns= ObjectSet.emptySet(); IBinding type = null; - IBinding obj = null; + IBinding obj = null; IBinding temp = null; final CPPASTTranslationUnit tu = data.getTranslationUnit(); @@ -2029,7 +2028,7 @@ public class CPPSemantics { continue; } if (fns == ObjectSet.EMPTY_SET) - fns = new ObjectSet(2); + fns = new ObjectSet<>(2); fns.put((ICPPFunction) temp); } else if (temp instanceof IType) { // Specializations are selected during instantiation @@ -2433,13 +2432,14 @@ public class CPPSemantics { // Reduce our set of candidate functions to only those who have the right number of parameters final IType[] argTypes = data.getFunctionArgumentTypes(); ICPPFunction[] tmp= selectByArgumentCount(data, fns); + if (tmp.length == 0 || tmp[0] == null) + return new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns); tmp= CPPTemplates.instantiateForFunctionCall(tmp, data.fTemplateArguments, Arrays.asList(argTypes), Arrays.asList(data.getFunctionArgumentValueCategories()), data.argsContainImpliedObject, lookupPoint); - if (tmp.length == 0 || tmp[0] == null) { + if (tmp.length == 0 || tmp[0] == null) return new ProblemBinding(lookupName, lookupPoint, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, fns); - } int viableCount= 0; for (IFunction f : tmp) { @@ -2487,7 +2487,7 @@ public class CPPSemantics { if (fnCost.hasDeferredUDC()) { if (potentialCosts == null) { - potentialCosts= new ArrayList(); + potentialCosts= new ArrayList<>(); } potentialCosts.add(fnCost); continue; @@ -3592,10 +3592,10 @@ public class CPPSemantics { LookupData data = createLookupData(name); data.contentAssist = true; data.setPrefixLookup(prefixLookup); - data.foundItems = new CharArrayObjectMap(2); + data.foundItems = new CharArrayObjectMap<>(2); // Convert namespaces to scopes. - List nsScopes= new ArrayList(); + List nsScopes= new ArrayList<>(); IASTTranslationUnit tu = name.getTranslationUnit(); if (additionalNamespaces != null && tu instanceof CPPASTTranslationUnit) { for (String nsName : additionalNamespaces) { @@ -3678,7 +3678,7 @@ public class CPPSemantics { scope = global; } - Set bindings = new HashSet(); + Set bindings = new HashSet<>(); // Look for the name in the given scope. findBindingsForQualifiedName(scope, qualifiedName, bindings); @@ -3814,9 +3814,9 @@ public class CPPSemantics { Object[] items = (Object[]) data.foundItems; if (items == null) - return new IBinding[0]; + return IBinding.EMPTY_BINDING_ARRAY; - ObjectSet set = new ObjectSet(items.length); + ObjectSet set = new ObjectSet<>(items.length); IBinding binding = null; for (Object item : items) { if (item instanceof IASTName) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java index bf972718ef0..84e1188fcfb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java @@ -167,7 +167,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.Context; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.UDCMode; - /** * Collection of static methods to perform template instantiation, member specialization and * type instantiation. @@ -780,7 +779,9 @@ public class CPPTemplates { IType instantiatedType = instantiateType(aliasedType, parameterMap, -1, within, id); StringBuilder buf= new StringBuilder(); buf.append(id.getSimpleID()).append(ASTTypeUtil.getArgumentListString(args, false)); - return new CPPAliasTemplateInstance(buf.toString().toCharArray(), aliasTemplate, instantiatedType); + char[] name = new char[buf.length()]; + buf.getChars(0, buf.length(), name, 0); + return new CPPAliasTemplateInstance(name, aliasTemplate, instantiatedType); } static boolean isClassTemplate(ICPPASTTemplateId id) { @@ -1963,12 +1964,13 @@ public class CPPTemplates { if (!haveTemplate && !requireTemplate) return fns; - final List result= new ArrayList(fns.length); + final List result= new ArrayList<>(fns.length); for (ICPPFunction fn : fns) { if (fn != null) { if (fn instanceof ICPPFunctionTemplate) { ICPPFunctionTemplate fnTmpl= (ICPPFunctionTemplate) fn; - ICPPFunction inst = instantiateForFunctionCall(fnTmpl, tmplArgs, fnArgs, argCats, withImpliedObjectArg, point); + ICPPFunction inst = instantiateForFunctionCall(fnTmpl, tmplArgs, fnArgs, argCats, + withImpliedObjectArg, point); if (inst != null) result.add(inst); } else if (!requireTemplate || fn instanceof ICPPUnknownBinding) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionInstance.java index 358d6ccfaf1..19c4c744912 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionInstance.java @@ -6,9 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Bryan Wilkinson (QNX) - Initial API and implementation - * Andrew Ferguson (Symbian) - * Markus Schorn (Wind River Systems) + * Bryan Wilkinson (QNX) - Initial API and implementation + * Andrew Ferguson (Symbian) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom.cpp; @@ -45,10 +45,10 @@ class PDOMCPPFunctionInstance extends PDOMCPPFunctionSpecialization implements I final ICPPTemplateInstance asInstance= (ICPPTemplateInstance) function; final long argListRec= PDOMCPPArgumentList.putArguments(this, asInstance.getTemplateArguments()); final Database db = getDB(); - db.putRecPtr(record+ARGUMENTS, argListRec); + db.putRecPtr(record + ARGUMENTS, argListRec); long exceptSpecRec = PDOMCPPTypeList.putTypes(this, function.getExceptionSpecification()); - db.putRecPtr(record+EXCEPTION_SPEC, exceptSpecRec); + db.putRecPtr(record + EXCEPTION_SPEC, exceptSpecRec); } public PDOMCPPFunctionInstance(PDOMLinkage linkage, long bindingRecord) { @@ -82,7 +82,7 @@ class PDOMCPPFunctionInstance extends PDOMCPPFunctionSpecialization implements I @Override public ICPPTemplateArgument[] getTemplateArguments() { try { - final long rec= getPDOM().getDB().getRecPtr(record+ARGUMENTS); + final long rec= getPDOM().getDB().getRecPtr(record + ARGUMENTS); return PDOMCPPArgumentList.getArguments(this, rec); } catch (CoreException e) { CCorePlugin.log(e); @@ -93,7 +93,7 @@ class PDOMCPPFunctionInstance extends PDOMCPPFunctionSpecialization implements I @Override public IType[] getExceptionSpecification() { try { - final long rec = getPDOM().getDB().getRecPtr(record+EXCEPTION_SPEC); + final long rec = getPDOM().getDB().getRecPtr(record + EXCEPTION_SPEC); return PDOMCPPTypeList.getTypes(this, rec); } catch (CoreException e) { CCorePlugin.log(e); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMInstanceCache.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMInstanceCache.java index 4dea9385eb0..f14d613e5db 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMInstanceCache.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMInstanceCache.java @@ -51,7 +51,7 @@ public class PDOMInstanceCache { private ICPPDeferredClassInstance fDeferredInstance; public PDOMInstanceCache() { - fMap= new HashMap(); + fMap= new HashMap<>(); } synchronized public final void addInstance(ICPPTemplateArgument[] arguments, ICPPTemplateInstance instance) { @@ -102,7 +102,7 @@ public class PDOMInstanceCache { return fDeferredInstance; } - public void putDeferredInstance(ICPPDeferredClassInstance dci) { - fDeferredInstance= dci; + public void putDeferredInstance(ICPPDeferredClassInstance deferredInstance) { + fDeferredInstance= deferredInstance; } }