1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2011-01-07 04:38:39 +00:00
parent b2d8caa6b0
commit b0e167dd8e

View file

@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.utils; package org.eclipse.cdt.internal.ui.refactoring.utils;
@ -42,7 +42,6 @@ import org.eclipse.cdt.internal.ui.refactoring.MethodContext;
* General class for common Node operations. * General class for common Node operations.
* *
* @author Lukas Felber & Guido Zgraggen * @author Lukas Felber & Guido Zgraggen
*
*/ */
public class NodeHelper { public class NodeHelper {
@ -56,18 +55,17 @@ public class NodeHelper {
} }
return new IASTDeclaration[0]; return new IASTDeclaration[0];
} }
public static IASTNode findFollowingNode(IASTNode currentNode) { public static IASTNode findFollowingNode(IASTNode currentNode) {
if(currentNode == null || currentNode.getParent() == null) { if (currentNode == null || currentNode.getParent() == null) {
return null; return null;
} }
boolean match = false; boolean match = false;
for(IASTNode actNode : getDeclarations(currentNode.getParent())) { for (IASTNode actNode : getDeclarations(currentNode.getParent())) {
if(match) { if (match) {
return actNode; return actNode;
} }
if(actNode.equals(currentNode)) { if (actNode.equals(currentNode)) {
match = true; match = true;
} }
} }
@ -75,14 +73,14 @@ public class NodeHelper {
} }
public static IASTNode findTopLevelParent(IASTNode currentNode) { public static IASTNode findTopLevelParent(IASTNode currentNode) {
while(currentNode != null && currentNode.getParent() != null && currentNode.getParent().getParent() != null) { while (currentNode != null && currentNode.getParent() != null && currentNode.getParent().getParent() != null) {
return findTopLevelParent(currentNode.getParent()); return findTopLevelParent(currentNode.getParent());
} }
return currentNode; return currentNode;
} }
public static boolean isSameNode(IASTNode node1, IASTNode node2) { public static boolean isSameNode(IASTNode node1, IASTNode node2) {
if(node1 == null || node2 == null) { if (node1 == null || node2 == null) {
return false; return false;
} }
return node1.getNodeLocations()[0].getNodeOffset() == node2.getNodeLocations()[0].getNodeOffset() return node1.getNodeLocations()[0].getNodeOffset() == node2.getNodeLocations()[0].getNodeOffset()
@ -91,7 +89,7 @@ public class NodeHelper {
} }
public static IASTSimpleDeclaration findSimpleDeclarationInParents(IASTNode node) { public static IASTSimpleDeclaration findSimpleDeclarationInParents(IASTNode node) {
while(node != null){ while (node != null){
if (node instanceof IASTSimpleDeclaration) { if (node instanceof IASTSimpleDeclaration) {
return (IASTSimpleDeclaration) node; return (IASTSimpleDeclaration) node;
} }
@ -106,9 +104,9 @@ public class NodeHelper {
MethodContext context = new MethodContext(); MethodContext context = new MethodContext();
context.setType(MethodContext.ContextType.NONE); context.setType(MethodContext.ContextType.NONE);
IASTName name = null; IASTName name = null;
while(node != null && !found){ while (node != null && !found){
node = node.getParent(); node = node.getParent();
if(node instanceof IASTFunctionDeclarator){ if (node instanceof IASTFunctionDeclarator){
name=((IASTFunctionDeclarator)node).getName(); name=((IASTFunctionDeclarator)node).getName();
found = true; found = true;
context.setType(MethodContext.ContextType.FUNCTION); context.setType(MethodContext.ContextType.FUNCTION);
@ -118,18 +116,17 @@ public class NodeHelper {
context.setType(MethodContext.ContextType.FUNCTION); context.setType(MethodContext.ContextType.FUNCTION);
} }
} }
if(index != null) { if (index != null) {
getMethodContexWithIndex(index, translationUnit, context, name); getMethodContexWithIndex(index, translationUnit, context, name);
}else { } else {
getMethodContex(translationUnit, context, name); getMethodContex(translationUnit, context, name);
} }
return context; return context;
} }
private static void getMethodContex(IASTTranslationUnit translationUnit, MethodContext context,
private static void getMethodContex(IASTTranslationUnit translationUnit, IASTName name) {
MethodContext context, IASTName name) { if (name instanceof ICPPASTQualifiedName){
if(name instanceof ICPPASTQualifiedName){
ICPPASTQualifiedName qname =( ICPPASTQualifiedName )name; ICPPASTQualifiedName qname =( ICPPASTQualifiedName )name;
context.setMethodQName(qname); context.setMethodQName(qname);
IBinding bind = qname.resolveBinding(); IBinding bind = qname.resolveBinding();
@ -141,30 +138,27 @@ public class NodeHelper {
context.setType(MethodContext.ContextType.METHOD); context.setType(MethodContext.ContextType.METHOD);
} }
} }
} }
} }
private static void getMethodContexWithIndex(IIndex index, IASTTranslationUnit translationUnit,
private static void getMethodContexWithIndex(IIndex index, MethodContext context, IASTName name) throws CoreException {
IASTTranslationUnit translationUnit, MethodContext context,
IASTName name) throws CoreException {
IBinding bind = name.resolveBinding(); IBinding bind = name.resolveBinding();
if (bind instanceof ICPPMethod) { if (bind instanceof ICPPMethod) {
context.setType(MethodContext.ContextType.METHOD); context.setType(MethodContext.ContextType.METHOD);
IIndexName[] decl; IIndexName[] decl;
decl = index.findDeclarations(bind); decl = index.findDeclarations(bind);
String tuFileLoc = translationUnit.getFileLocation().getFileName(); String tuFileLoc = translationUnit.getFileLocation().getFileName();
if(decl.length == 0) { if (decl.length == 0) {
context.setMethodDeclarationName(name); context.setMethodDeclarationName(name);
} }
for (IIndexName tmpname : decl) { for (IIndexName tmpname : decl) {
IASTTranslationUnit locTu = translationUnit; IASTTranslationUnit locTu = translationUnit;
if(!tuFileLoc.equals(tmpname.getFileLocation().getFileName())) { if (!tuFileLoc.equals(tmpname.getFileLocation().getFileName())) {
locTu = TranslationUnitHelper.loadTranslationUnit(tmpname.getFileLocation().getFileName(), false); locTu = TranslationUnitHelper.loadTranslationUnit(tmpname.getFileLocation().getFileName(), false);
} }
IASTName declName = DeclarationFinder.findDeclarationInTranslationUnit(locTu, tmpname); IASTName declName = DeclarationFinder.findDeclarationInTranslationUnit(locTu, tmpname);
if(declName != null) { if (declName != null) {
IASTNode methoddefinition = declName.getParent().getParent(); IASTNode methoddefinition = declName.getParent().getParent();
if (methoddefinition instanceof IASTSimpleDeclaration || methoddefinition instanceof IASTFunctionDefinition) { if (methoddefinition instanceof IASTSimpleDeclaration || methoddefinition instanceof IASTFunctionDefinition) {
context.setMethodDeclarationName(declName); context.setMethodDeclarationName(declName);
@ -172,14 +166,14 @@ public class NodeHelper {
} }
} }
} }
if(name instanceof ICPPASTQualifiedName){ if (name instanceof ICPPASTQualifiedName){
ICPPASTQualifiedName qname =( ICPPASTQualifiedName )name; ICPPASTQualifiedName qname =( ICPPASTQualifiedName )name;
context.setMethodQName(qname); context.setMethodQName(qname);
} }
} }
public static IASTCompoundStatement findCompoundStatementInAncestors(IASTNode node) { public static IASTCompoundStatement findCompoundStatementInAncestors(IASTNode node) {
while(node != null){ while (node != null){
if (node instanceof IASTCompoundStatement) { if (node instanceof IASTCompoundStatement) {
return (IASTCompoundStatement) node; return (IASTCompoundStatement) node;
} }
@ -189,8 +183,8 @@ public class NodeHelper {
} }
public static IASTCompositeTypeSpecifier findClassInAncestors(IASTNode node) { public static IASTCompositeTypeSpecifier findClassInAncestors(IASTNode node) {
while(!(node instanceof IASTCompositeTypeSpecifier)){ while (!(node instanceof IASTCompositeTypeSpecifier)){
if(node instanceof IASTTranslationUnit) { if (node instanceof IASTTranslationUnit) {
return null; return null;
} }
node = node.getParent(); node = node.getParent();
@ -199,7 +193,7 @@ public class NodeHelper {
} }
public static IASTFunctionDefinition findFunctionDefinitionInAncestors(IASTNode node) { public static IASTFunctionDefinition findFunctionDefinitionInAncestors(IASTNode node) {
while(node != null){ while (node != null){
if (node instanceof IASTFunctionDefinition) { if (node instanceof IASTFunctionDefinition) {
return (IASTFunctionDefinition) node; return (IASTFunctionDefinition) node;
} }
@ -209,14 +203,14 @@ public class NodeHelper {
} }
public static boolean isMethodDeclaration(IASTSimpleDeclaration simpleDeclaration) { public static boolean isMethodDeclaration(IASTSimpleDeclaration simpleDeclaration) {
if(simpleDeclaration == null) { if (simpleDeclaration == null) {
return false; return false;
} }
return simpleDeclaration.getDeclarators().length == 1 && simpleDeclaration.getDeclarators()[0] instanceof ICPPASTFunctionDeclarator; return simpleDeclaration.getDeclarators().length == 1 && simpleDeclaration.getDeclarators()[0] instanceof ICPPASTFunctionDeclarator;
} }
public static boolean isContainedInTemplateDeclaration(IASTNode node) { public static boolean isContainedInTemplateDeclaration(IASTNode node) {
if(node == null) { if (node == null) {
return false; return false;
} else if (node instanceof ICPPASTTemplateDeclaration) { } else if (node instanceof ICPPASTTemplateDeclaration) {
return true; return true;