1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2016-01-08 10:19:19 -08:00
parent ea73b8149c
commit 1d75c92c77

View file

@ -7,7 +7,7 @@
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser; package org.eclipse.cdt.internal.core.dom.parser;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
@ -70,23 +70,23 @@ public class ASTQueries {
} }
} }
private static NameSearch NAME_SEARCH= new NameSearch(); private static NameSearch NAME_SEARCH= new NameSearch();
/** /**
* Tests whether the given node can contain ast-names, suitable to be used before ambiguity * Tests whether the given node can contain ast-names, suitable to be used before ambiguity
* resolution. * resolution.
*/ */
public static boolean canContainName(IASTNode node) { public static boolean canContainName(IASTNode node) {
if (node == null) if (node == null)
return false; return false;
NAME_SEARCH.reset(); NAME_SEARCH.reset();
node.accept(NAME_SEARCH); node.accept(NAME_SEARCH);
return NAME_SEARCH.foundName(); return NAME_SEARCH.foundName();
} }
/** /**
* Returns the outermost declarator the given <code>declarator</code> nests within, or * Returns the outermost declarator the given {@code declarator} nests within, or
* <code>declarator</code> itself. * the given {@code declarator} itself.
*/ */
public static IASTDeclarator findOutermostDeclarator(IASTDeclarator declarator) { public static IASTDeclarator findOutermostDeclarator(IASTDeclarator declarator) {
IASTDeclarator outermost= null; IASTDeclarator outermost= null;
@ -98,9 +98,9 @@ public class ASTQueries {
return outermost; return outermost;
} }
/** /**
* Returns the innermost declarator nested within the given <code>declarator</code>, or * Returns the innermost declarator nested within the given {@code declarator}, or
* <code>declarator</code> itself. * the given {@code declarator} itself.
*/ */
public static IASTDeclarator findInnermostDeclarator(IASTDeclarator declarator) { public static IASTDeclarator findInnermostDeclarator(IASTDeclarator declarator) {
IASTDeclarator innermost= null; IASTDeclarator innermost= null;
@ -117,9 +117,9 @@ public class ASTQueries {
public static IASTDeclarator findTypeRelevantDeclarator(IASTDeclarator declarator) { public static IASTDeclarator findTypeRelevantDeclarator(IASTDeclarator declarator) {
if (declarator == null) if (declarator == null)
return null; return null;
IASTDeclarator result= findInnermostDeclarator(declarator); IASTDeclarator result= findInnermostDeclarator(declarator);
while (result.getPointerOperators().length == 0 while (result.getPointerOperators().length == 0
&& !(result instanceof IASTFieldDeclarator) && !(result instanceof IASTFieldDeclarator)
&& !(result instanceof IASTFunctionDeclarator) && !(result instanceof IASTFunctionDeclarator)
&& !(result instanceof IASTArrayDeclarator)) { && !(result instanceof IASTArrayDeclarator)) {
@ -147,9 +147,9 @@ public class ASTQueries {
} }
return (T) node; return (T) node;
} }
/** /**
* Searches for the function enclosing the given node. May return <code>null</code>. * Searches for the function enclosing the given node. May return {@code null}.
*/ */
public static IBinding findEnclosingFunction(IASTNode node) { public static IBinding findEnclosingFunction(IASTNode node) {
IASTFunctionDefinition functionDefinition = findAncestorWithType(node, IASTFunctionDefinition.class); IASTFunctionDefinition functionDefinition = findAncestorWithType(node, IASTFunctionDefinition.class);
@ -169,7 +169,7 @@ public class ASTQueries {
/** /**
* Extracts the active declarations from an array of declarations. * Extracts the active declarations from an array of declarations.
*/ */
public static IASTDeclaration[] extractActiveDeclarations(final IASTDeclaration[] allDeclarations, final int size) { public static IASTDeclaration[] extractActiveDeclarations(IASTDeclaration[] allDeclarations, int size) {
IASTDeclaration[] active; IASTDeclaration[] active;
if (size == 0) { if (size == 0) {
active= IASTDeclaration.EMPTY_DECLARATION_ARRAY; active= IASTDeclaration.EMPTY_DECLARATION_ARRAY;
@ -182,7 +182,7 @@ public class ASTQueries {
active[j++]= d; active[j++]= d;
} }
} }
active= ArrayUtil.trimAt(IASTDeclaration.class, active, j-1); active= ArrayUtil.trim(active, j);
} }
return active; return active;
} }
@ -194,7 +194,7 @@ public class ASTQueries {
return false; return false;
return type1.isSameType(type2); return type1.isSameType(type2);
} }
protected static boolean areArraysOfTheSameElementType(IType t1, IType t2) { protected static boolean areArraysOfTheSameElementType(IType t1, IType t2) {
if (t1 instanceof IArrayType && t2 instanceof IArrayType) { if (t1 instanceof IArrayType && t2 instanceof IArrayType) {
IArrayType a1 = (IArrayType) t1; IArrayType a1 = (IArrayType) t1;
@ -203,9 +203,9 @@ public class ASTQueries {
} }
return false; return false;
} }
/** /**
* Check whether 'ancestor' is an ancestor of 'descendant' in the AST. * Check whether 'ancestor' is an ancestor of 'descendant' in the AST.
*/ */
public static boolean isAncestorOf(IASTNode ancestor, IASTNode descendant) { public static boolean isAncestorOf(IASTNode ancestor, IASTNode descendant) {
do { do {
@ -222,19 +222,19 @@ public class ASTQueries {
if (parent instanceof IASTUnaryExpression) { if (parent instanceof IASTUnaryExpression) {
int operator = ((IASTUnaryExpression) parent).getOperator(); int operator = ((IASTUnaryExpression) parent).getOperator();
labelReference = operator == IASTUnaryExpression.op_labelReference; labelReference = operator == IASTUnaryExpression.op_labelReference;
} }
return labelReference; return labelReference;
} }
private static class FindLabelsAction extends ASTVisitor { private static class FindLabelsAction extends ASTVisitor {
public IASTLabelStatement[] labels = IASTLabelStatement.EMPTY_ARRAY; public IASTLabelStatement[] labels = IASTLabelStatement.EMPTY_ARRAY;
public FindLabelsAction() { public FindLabelsAction() {
shouldVisitStatements = true; shouldVisitStatements = true;
} }
@Override @Override
public int visit(IASTStatement statement) { public int visit(IASTStatement statement) {
if (statement instanceof IASTLabelStatement) { if (statement instanceof IASTLabelStatement) {
@ -243,12 +243,12 @@ public class ASTQueries {
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }
} }
protected static ILabel[] getLabels(IASTFunctionDefinition functionDefinition) { protected static ILabel[] getLabels(IASTFunctionDefinition functionDefinition) {
FindLabelsAction action = new FindLabelsAction(); FindLabelsAction action = new FindLabelsAction();
functionDefinition.accept(action); functionDefinition.accept(action);
ILabel[] result = ILabel.EMPTY_ARRAY; ILabel[] result = ILabel.EMPTY_ARRAY;
if (action.labels != null) { if (action.labels != null) {
for (int i = 0; i < action.labels.length && action.labels[i] != null; i++) { for (int i = 0; i < action.labels.length && action.labels[i] != null; i++) {
@ -260,11 +260,11 @@ public class ASTQueries {
} }
return ArrayUtil.trim(result); return ArrayUtil.trim(result);
} }
protected static IBinding resolveLabel(IASTName labelReference) { protected static IBinding resolveLabel(IASTName labelReference) {
char[] labelName = labelReference.toCharArray(); char[] labelName = labelReference.toCharArray();
IASTFunctionDefinition functionDefinition = findAncestorWithType(labelReference, IASTFunctionDefinition functionDefinition =
IASTFunctionDefinition.class); findAncestorWithType(labelReference, IASTFunctionDefinition.class);
if (functionDefinition != null) { if (functionDefinition != null) {
for (ILabel label : getLabels(functionDefinition)) { for (ILabel label : getLabels(functionDefinition)) {
if (CharArrayUtils.equals(label.getNameCharArray(), labelName)) { if (CharArrayUtils.equals(label.getNameCharArray(), labelName)) {
@ -272,8 +272,8 @@ public class ASTQueries {
} }
} }
} }
// label not found // Label not found.
return new ProblemBinding(labelReference, IProblemBinding.SEMANTIC_LABEL_STATEMENT_NOT_FOUND, return new ProblemBinding(labelReference, IProblemBinding.SEMANTIC_LABEL_STATEMENT_NOT_FOUND,
labelName); labelName);
} }
} }