diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java index d99156cece2..bb3c28109da 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java @@ -495,8 +495,8 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { @Override public void setUp() throws Exception { cproject = cpp ? - CProjectHelper.createCCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) : - CProjectHelper.createCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); + CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER) : + CProjectHelper.createCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); Bundle b = CTestPlugin.getDefault().getBundle(); testData = TestSourceReader.getContentsForTest(b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 2); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTLambdaExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTLambdaExpression.java index bf04d08f418..9c54f21d77c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTLambdaExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTLambdaExpression.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; @@ -16,7 +16,7 @@ import org.eclipse.cdt.core.dom.ast.IASTImplicitName; import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner; /** - * Lambda expression, introduced in C++0x. + * Lambda expression, introduced in C++11. * * @since 5.3 * @noextend This interface is not intended to be extended by clients. @@ -64,8 +64,7 @@ public interface ICPPASTLambdaExpression extends ICPPASTExpression, IASTImplicit * when creating AST for content assist. */ IASTCompoundStatement getBody(); - - + /** * Not allowed on frozen AST. * @see #getCaptureDefault() diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPParserExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPParserExtensionConfiguration.java index 8f7fe9ce6f8..36cef5e89bd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPParserExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPParserExtensionConfiguration.java @@ -12,121 +12,79 @@ package org.eclipse.cdt.core.dom.parser.cpp; import java.util.Collections; -import java.util.HashMap; import java.util.Map; import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider; -import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.IToken.ContextSensitiveTokenType; +import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider; - /** * Abstract C++ parser extension configuration to help model C++ dialects. * * @since 4.0 */ public abstract class AbstractCPPParserExtensionConfiguration implements ICPPParserExtensionConfiguration { - - /* - * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#allowRestrictPointerOperators() - */ @Override public boolean allowRestrictPointerOperators() { return false; } - /* - * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportAlignOfUnaryExpression() - */ @Override public boolean supportAlignOfUnaryExpression() { return false; } - /* - * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportAttributeSpecifiers() - */ @Override public boolean supportAttributeSpecifiers() { return false; } - /* - * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportComplexNumbers() - */ @Override public boolean supportComplexNumbers() { return false; } - /* - * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportDeclspecSpecifiers() - */ @Override public boolean supportDeclspecSpecifiers() { return false; } - /* - * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportExtendedTemplateSyntax() - */ @Override public boolean supportExtendedTemplateSyntax() { return false; } - /* - * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportGCCOtherBuiltinSymbols() - */ @Override public boolean supportGCCOtherBuiltinSymbols() { return false; } - /* - * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportKnRC() - */ @Override public boolean supportKnRC() { return false; } - /* - * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportLongLongs() - */ @Override public boolean supportLongLongs() { return false; } - /* - * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportMinAndMaxOperators() - */ @Override public boolean supportMinAndMaxOperators() { return false; } - /* - * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportRestrictKeyword() - */ @Override public boolean supportRestrictKeyword() { return false; } - /* - * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportStatementsInExpressions() - */ @Override public boolean supportStatementsInExpressions() { return false; } - /* - * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#supportTypeofUnaryExpressions() - */ @Override public boolean supportTypeofUnaryExpressions() { return false; @@ -159,9 +117,6 @@ public abstract class AbstractCPPParserExtensionConfiguration implements ICPPPar return false; } - /* - * @see org.eclipse.cdt.core.dom.parser.cpp.ICPPParserExtensionConfiguration#getBuiltinBindingsProvider() - */ @Override public IBuiltinBindingsProvider getBuiltinBindingsProvider() { return new GCCBuiltinSymbolProvider(ParserLanguage.CPP, supportGCCOtherBuiltinSymbols()); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousSimpleDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousSimpleDeclaration.java index a896e7f1379..647af5e7717 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousSimpleDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousSimpleDeclaration.java @@ -30,8 +30,9 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTInternalScope; /** * Handles ambiguities for parameter declarations. - *
+ *
  * void function(const D*); // is D a type?
+ * 
* @since 5.0.1 */ public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements IASTAmbiguousSimpleDeclaration { @@ -47,7 +48,7 @@ public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements @Override protected void beforeResolution() { - // populate containing scope, so that it will not be affected by the alternative branches. + // Populate containing scope, so that it will not be affected by the alternative branches. IScope scope= CVisitor.getContainingScope(this); if (scope instanceof IASTInternalScope) { ((IASTInternalScope) scope).populateCache(); @@ -94,6 +95,7 @@ public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements return fSimpleDecl.getAttributes(); } + @Deprecated @Override public void addAttribute(IASTAttribute attribute) { fSimpleDecl.addAttribute(attribute); @@ -114,18 +116,18 @@ public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements final IASTAmbiguityParent owner= (IASTAmbiguityParent) getParent(); IASTNode nodeToReplace= this; - // handle nested ambiguities first + // Handle nested ambiguities first. owner.replace(nodeToReplace, fSimpleDecl); IASTDeclSpecifier declSpec= fSimpleDecl.getDeclSpecifier(); declSpec.accept(resolver); - // find nested names + // Find nested names. final NameCollector nameCollector= new NameCollector(); declSpec.accept(nameCollector); final IASTName[] names= nameCollector.getNames(); - // resolve names + // Resolve names. boolean hasIssue= false; for (IASTName name : names) { try { @@ -140,13 +142,13 @@ public class CASTAmbiguousSimpleDeclaration extends ASTAmbiguousNode implements } } if (hasIssue) { - // use the alternate version + // Use the alternate version. final IASTAmbiguityParent parent = (IASTAmbiguityParent) fSimpleDecl; parent.replace(declSpec, fAltDeclSpec); parent.replace(fSimpleDecl.getDeclarators()[0], fAltDtor); } - // resolve further nested ambiguities + // Resolve further nested ambiguities. fSimpleDecl.accept(resolver); return fSimpleDecl; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java index 18160fab4d6..c8404e94ba4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java @@ -15,11 +15,13 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import java.util.ArrayDeque; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; +import java.util.Deque; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -95,7 +97,7 @@ public class ClassTypeHelper { return new IBinding[] { new ProblemBinding(node, IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, host.getNameCharArray()) }; } } - ObjectSet resultSet = new ObjectSet(2); + ObjectSet resultSet = new ObjectSet<>(2); IASTDeclaration[] members = host.getCompositeTypeSpecifier().getMembers(); for (IASTDeclaration decl : members) { while (decl instanceof ICPPASTTemplateDeclaration) { @@ -134,7 +136,7 @@ public class ClassTypeHelper { * A class is considered a friend of itself. * @param binding a binding. * @param classType a class. - * @return true if binding is a friend of classType. + * @return {@code true} if {@code binding} is a friend of {@code classType}. */ public static boolean isFriend(IBinding binding, ICPPClassType classType) { IType type; @@ -282,7 +284,7 @@ public class ClassTypeHelper { * @return An array of base classes in arbitrary order. */ public static ICPPClassType[] getAllBases(ICPPClassType classType, IASTNode point) { - HashSet result= new HashSet(); + HashSet result= new HashSet<>(); result.add(classType); getAllBases(classType, result, point); result.remove(classType); @@ -304,7 +306,7 @@ public class ClassTypeHelper { /** * Checks inheritance relationship between two classes. - * @return true if {@code subclass} is a subclass of {@code superclass}. + * @return {@code true} if {@code subclass} is a subclass of {@code superclass}. */ public static boolean isSubclass(ICPPClassType subclass, ICPPClassType superclass, IASTNode point) { ICPPBase[] bases= getBases(subclass, point); @@ -348,7 +350,7 @@ public class ClassTypeHelper { * include methods declared in base classes. */ public static ObjectSet getOwnMethods(ICPPClassType classType, IASTNode point) { - ObjectSet set= new ObjectSet(4); + ObjectSet set= new ObjectSet<>(4); set.addAll(ClassTypeHelper.getDeclaredMethods(classType, point)); set.addAll(getImplicitMethods(classType, point)); return set; @@ -585,8 +587,8 @@ public class ClassTypeHelper { if (mcl == null) return ICPPMethod.EMPTY_CPPMETHOD_ARRAY; - final ArrayList result= new ArrayList(); - final HashMap virtualInClass= new HashMap(); + final ArrayList result= new ArrayList<>(); + final HashMap virtualInClass= new HashMap<>(); final ICPPFunctionType methodType= method.getType(); virtualInClass.put(mcl, method.isVirtual()); @@ -679,7 +681,7 @@ public class ClassTypeHelper { public static ICPPMethod[] findOverriders(ICPPClassType[] subclasses, ICPPMethod method) { final char[] mname= method.getNameCharArray(); final ICPPFunctionType mft= method.getType(); - final ArrayList result= new ArrayList(); + final ArrayList result= new ArrayList<>(); for (ICPPClassType subClass : subclasses) { ICPPMethod[] methods= subClass.getDeclaredMethods(); for (ICPPMethod candidate : methods) { @@ -693,14 +695,15 @@ public class ClassTypeHelper { } private static ICPPClassType[] getSubClasses(IIndex index, ICPPClassType mcl) throws CoreException { - List result= new LinkedList(); - HashSet handled= new HashSet(); + Deque result= new ArrayDeque<>(); + HashSet handled= new HashSet<>(); getSubClasses(index, mcl, result, handled); result.remove(0); return result.toArray(new ICPPClassType[result.size()]); } - private static void getSubClasses(IIndex index, ICPPBinding classOrTypedef, List result, HashSet handled) throws CoreException { + private static void getSubClasses(IIndex index, ICPPBinding classOrTypedef, + Collection result, HashSet handled) throws CoreException { if (!(classOrTypedef instanceof IType)) return; @@ -778,7 +781,7 @@ public class ClassTypeHelper { ICPPParameter[] parameters = method.getParameters(); if (parameters.length == 0) return Collections.emptyList(); - List types = new ArrayList(parameters.length); + List types = new ArrayList<>(parameters.length); for (ICPPParameter parameter : parameters) { if (!parameter.hasDefaultValue() && !parameter.isParameterPack()) types.add(parameter.getType()); @@ -800,7 +803,7 @@ public class ClassTypeHelper { if (kind == MethodKind.OTHER) return null; - List inheritedTypeids = new ArrayList(); + List inheritedTypeids = new ArrayList<>(); ICPPClassType[] bases= getAllBases(owner, point); for (ICPPClassType base : bases) { if (!(base instanceof ICPPDeferredClassInstance)) { @@ -874,11 +877,11 @@ public class ClassTypeHelper { } /** - * Returns the visibility for a given member in the host. - * Throws an IllegalArgumentException if member is not a member of host + * Returns the visibility for a given {@code member} in the {@code host}. + * Throws an IllegalArgumentException if {@code member} is not a member of {@code host} * * @param classType The class to get the member's visibility specifier of. - * @return the visibility of the member. + * @return the visibility of the {@code member}. */ public static int getVisibility(ICPPInternalClassTypeMixinHost classType, IBinding member) { if (classType.getDefinition() == null) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/DeclarationGeneratorImpl.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/DeclarationGeneratorImpl.java index 654a08ab043..584f60451b7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/DeclarationGeneratorImpl.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/DeclarationGeneratorImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Tomasz Wesolowski + * Copyright (c) 2010, 2014 Tomasz Wesolowski * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -39,6 +39,7 @@ import org.eclipse.cdt.core.dom.ast.INodeFactory; import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IQualifierType; import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNameSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; @@ -128,18 +129,19 @@ public class DeclarationGeneratorImpl extends DeclarationGenerator { IASTDeclarator returnedDeclarator = null; try { - // Addition of pointer operators has to be in reverse order, so it's deferred until the end + // Addition of pointer operators has to be in reverse order, so it's deferred until + // the end. Map> pointerOperatorMap = new HashMap>(); IASTName newName = name != null ? factory.newName(name) : factory.newName(); - // If the type is an array of something, create a declaration of a pointer to something instead - // (to allow assignment, etc) + // If the type is an array of something, create a declaration of a pointer to something + // instead (to allow assignment, etc). boolean replaceInitialArrayWithPointer = true; // If the type is a function, create a declaration of a pointer to this function - // (shorthand notation for function address) + // (shorthand notation for function address). boolean changeInitialFunctionToFuncPtr = true; @@ -151,7 +153,7 @@ public class DeclarationGeneratorImpl extends DeclarationGenerator { } else if (changeInitialFunctionToFuncPtr && type instanceof IFunctionType) { returnedDeclarator = factory.newDeclarator(newName); returnedDeclarator.addPointerOperator(factory.newPointer()); - // leave type as it is, next iteration will handle the function + // Leave type as it is, next iteration will handle the function. } else if (type instanceof IArrayType) { IArrayType arrayType = (IArrayType) type; IASTArrayDeclarator arrayDeclarator = factory.newArrayDeclarator(null); @@ -161,7 +163,7 @@ public class DeclarationGeneratorImpl extends DeclarationGenerator { arrayDeclarator.setNestedDeclarator(returnedDeclarator); arrayDeclarator.setName(factory.newName()); } - // consume all immediately following array expressions + // Consume all immediately following array expressions. while (type instanceof IArrayType) { arrayType = (IArrayType) type; IASTExpression arraySizeExpression = arrayType.getArraySizeExpression(); @@ -233,7 +235,7 @@ public class DeclarationGeneratorImpl extends DeclarationGenerator { IASTDeclarator returnedDeclarator, IASTPointerOperator ptrOp) { LinkedList list; if (!pointerOperatorMap.containsKey(returnedDeclarator)) { - list = new LinkedList(); + list = new LinkedList<>(); pointerOperatorMap.put(returnedDeclarator, list); } else { list = pointerOperatorMap.get(returnedDeclarator); @@ -289,13 +291,12 @@ public class DeclarationGeneratorImpl extends DeclarationGenerator { ICPPASTTemplateId tempId = getTemplateId(type, templateName); ICPPASTQualifiedName newQualifiedName = - ((ICPPNodeFactory) factory).newQualifiedName(); + ((ICPPNodeFactory) factory).newQualifiedName(tempId); ICPPASTNameSpecifier[] qualifier = fullQualifiedName.getQualifier(); int nbQualifiedNames = qualifier.length; for (int i = 0; i < nbQualifiedNames; i++) { newQualifiedName.addNameSpecifier(qualifier[i].copy(CopyStyle.withLocations)); } - newQualifiedName.setLastName(tempId); return factory.newTypedefNameSpecifier(newQualifiedName); } else { @@ -329,9 +330,12 @@ public class DeclarationGeneratorImpl extends DeclarationGenerator { char[][] qualifiedNameCharArray = CPPVisitor.getQualifiedNameCharArray(binding); IASTName name; if (qualifiedNameCharArray.length > 1) { - name = ((ICPPNodeFactory) factory).newQualifiedName(); - for (char[] cs : qualifiedNameCharArray) { - ((ICPPASTQualifiedName) name).addName(factory.newName(cs)); + char[] cs = qualifiedNameCharArray[qualifiedNameCharArray.length - 1]; + IASTName segment = factory.newName(cs); + name = ((ICPPNodeFactory) factory).newQualifiedName((ICPPASTName) segment); + for (int i = 0; i < qualifiedNameCharArray.length - 1; i++) { + segment = factory.newName(cs); + ((ICPPASTQualifiedName) name).addName(factory.newName(qualifiedNameCharArray[i])); } } else if (qualifiedNameCharArray.length == 1) { name = factory.newName(qualifiedNameCharArray[0]); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java index 029d0dc4bca..d9acfc6a976 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java @@ -234,12 +234,12 @@ public class MacroDefinitionParser { default: throw new InvalidMacroDefinitionException(name.getCharImage(), name.getOffset(), param.getEndOffset()); } - } - while (fHasVarArgs==0 && next.getType() == IToken.tCOMMA); + } while (fHasVarArgs == 0 && next.getType() == IToken.tCOMMA); + if (next.getType() != IToken.tRPAREN) { throw new InvalidMacroDefinitionException(name.getCharImage(), name.getOffset(), next.getEndOffset()); } - next= lex.nextToken(); // consume the closing parenthesis + next= lex.nextToken(); // Consume the closing parenthesis. return paramList.toArray(new char[paramList.size()][]); }