Patch for Devin Steffler.
UI Infrastructure for testing the DOM AST Interfaces.
BIN
core/org.eclipse.cdt.ui.tests/icons/sample.gif
Normal file
After Width: | Height: | Size: 855 B |
BIN
core/org.eclipse.cdt.ui.tests/icons/used/brkpd_obj.gif
Normal file
After Width: | Height: | Size: 136 B |
BIN
core/org.eclipse.cdt.ui.tests/icons/used/cdeclaration_obj.gif
Normal file
After Width: | Height: | Size: 146 B |
BIN
core/org.eclipse.cdt.ui.tests/icons/used/define_obj.gif
Normal file
After Width: | Height: | Size: 109 B |
BIN
core/org.eclipse.cdt.ui.tests/icons/used/disassembly.gif
Normal file
After Width: | Height: | Size: 158 B |
BIN
core/org.eclipse.cdt.ui.tests/icons/used/enumerator_obj.gif
Normal file
After Width: | Height: | Size: 853 B |
BIN
core/org.eclipse.cdt.ui.tests/icons/used/expression_obj.gif
Normal file
After Width: | Height: | Size: 909 B |
BIN
core/org.eclipse.cdt.ui.tests/icons/used/jump_co.gif
Normal file
After Width: | Height: | Size: 92 B |
BIN
core/org.eclipse.cdt.ui.tests/icons/used/method_public_obj.gif
Normal file
After Width: | Height: | Size: 97 B |
BIN
core/org.eclipse.cdt.ui.tests/icons/used/output_obj.gif
Normal file
After Width: | Height: | Size: 161 B |
BIN
core/org.eclipse.cdt.ui.tests/icons/used/showasarray_co.gif
Normal file
After Width: | Height: | Size: 117 B |
After Width: | Height: | Size: 157 B |
BIN
core/org.eclipse.cdt.ui.tests/icons/used/statement_obj.gif
Normal file
After Width: | Height: | Size: 891 B |
BIN
core/org.eclipse.cdt.ui.tests/icons/used/tnames_co.gif
Normal file
After Width: | Height: | Size: 101 B |
BIN
core/org.eclipse.cdt.ui.tests/icons/used/types.gif
Normal file
After Width: | Height: | Size: 364 B |
BIN
core/org.eclipse.cdt.ui.tests/icons/used/var_declaration_obj.gif
Normal file
After Width: | Height: | Size: 895 B |
BIN
core/org.eclipse.cdt.ui.tests/icons/used/var_pointer.gif
Normal file
After Width: | Height: | Size: 130 B |
BIN
core/org.eclipse.cdt.ui.tests/icons/used/var_simple.gif
Normal file
After Width: | Height: | Size: 132 B |
BIN
core/org.eclipse.cdt.ui.tests/icons/used/variable_local_obj.gif
Normal file
After Width: | Height: | Size: 94 B |
BIN
core/org.eclipse.cdt.ui.tests/icons/used/variable_obj.gif
Normal file
After Width: | Height: | Size: 78 B |
BIN
core/org.eclipse.cdt.ui.tests/icons/used/warning_obj.gif
Normal file
After Width: | Height: | Size: 139 B |
BIN
core/org.eclipse.cdt.ui.tests/icons/used/watch_globals.gif
Normal file
After Width: | Height: | Size: 105 B |
|
@ -17,6 +17,9 @@
|
||||||
<import plugin="org.eclipse.cdt.ui"/>
|
<import plugin="org.eclipse.cdt.ui"/>
|
||||||
<import plugin="org.eclipse.swt"/>
|
<import plugin="org.eclipse.swt"/>
|
||||||
<import plugin="org.eclipse.ui"/>
|
<import plugin="org.eclipse.ui"/>
|
||||||
|
<import plugin="org.eclipse.ui.editors"/>
|
||||||
|
<import plugin="org.eclipse.ui.views"/>
|
||||||
|
<import plugin="org.eclipse.ui.workbench.texteditor"/>
|
||||||
<import plugin="org.junit"/>
|
<import plugin="org.junit"/>
|
||||||
<import plugin="org.eclipse.cdt.core"/>
|
<import plugin="org.eclipse.cdt.core"/>
|
||||||
<import plugin="org.eclipse.cdt.core.tests"/>
|
<import plugin="org.eclipse.cdt.core.tests"/>
|
||||||
|
@ -38,5 +41,47 @@
|
||||||
|
|
||||||
</extension>
|
</extension>
|
||||||
|
|
||||||
|
<extension
|
||||||
|
point="org.eclipse.ui.views">
|
||||||
|
<view
|
||||||
|
allowMultiple="false"
|
||||||
|
class="org.eclipse.cdt.ui.tests.DOMAST.DOMAST"
|
||||||
|
icon="icons/sample.gif"
|
||||||
|
category="org.eclipse.cdt.ui.views"
|
||||||
|
name="DOM AST"
|
||||||
|
id="org.eclipse.cdt.ui.tests.DOMAST.DOMAST">
|
||||||
|
</view>
|
||||||
|
</extension>
|
||||||
|
<extension
|
||||||
|
point="org.eclipse.ui.perspectiveExtensions">
|
||||||
|
<perspectiveExtension
|
||||||
|
targetID="org.eclipse.ui.resourcePerspective">
|
||||||
|
<view
|
||||||
|
ratio="0.5"
|
||||||
|
relative="org.eclipse.ui.views.TaskList"
|
||||||
|
relationship="right"
|
||||||
|
id="org.eclipse.cdt.ui.tests.DOMAST.DOMAST">
|
||||||
|
</view>
|
||||||
|
</perspectiveExtension>
|
||||||
|
</extension>
|
||||||
|
<extension
|
||||||
|
point="org.eclipse.ui.popupMenus">
|
||||||
|
<viewerContribution
|
||||||
|
targetID="org.eclipse.cdt.ui.CView"
|
||||||
|
id="org.eclipse.cdt.ui.CView">
|
||||||
|
<action
|
||||||
|
label="Show in DOM AST"
|
||||||
|
class="org.eclipse.cdt.ui.tests.DOMAST.OpenDOMViewAction"
|
||||||
|
menubarPath="additions"
|
||||||
|
id="org.eclipse.cdt.ui.tests.DOMAST.OpenDOMViewAction"/>
|
||||||
|
<visibility>
|
||||||
|
<or>
|
||||||
|
<objectState name="extension" value="cpp"/>
|
||||||
|
<objectState name="extension" value="c"/>
|
||||||
|
</or>
|
||||||
|
</visibility>
|
||||||
|
</viewerContribution>
|
||||||
|
</extension>
|
||||||
|
|
||||||
|
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
|
@ -0,0 +1,165 @@
|
||||||
|
/**********************************************************************
|
||||||
|
* Copyright (c) 2005 IBM Canada and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v0.5
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v05.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Rational Software - Initial API and implementation
|
||||||
|
**********************************************************************/
|
||||||
|
package org.eclipse.cdt.ui.tests.DOMAST;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author dsteffle
|
||||||
|
*/
|
||||||
|
public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IPopulateDOMASTAction {
|
||||||
|
{
|
||||||
|
processNames = true;
|
||||||
|
processDeclarations = true;
|
||||||
|
processInitializers = true;
|
||||||
|
processParameterDeclarations = true;
|
||||||
|
processDeclarators = true;
|
||||||
|
processDeclSpecifiers = true;
|
||||||
|
processExpressions = true;
|
||||||
|
processStatements = true;
|
||||||
|
processTypeIds = true;
|
||||||
|
processEnumerators = true;
|
||||||
|
processBaseSpecifiers = true;
|
||||||
|
processNamespaces = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TreeParent root = null;
|
||||||
|
|
||||||
|
public CPPPopulateASTViewAction(IASTTranslationUnit tu) {
|
||||||
|
root = new TreeParent(tu);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addRoot(IASTNode node) {
|
||||||
|
TreeParent parent = root.findParentOfNode(node);
|
||||||
|
|
||||||
|
if ( parent != null ) {
|
||||||
|
parent.addChild(new TreeParent(node));
|
||||||
|
} else {
|
||||||
|
root.addChild(new TreeParent(node));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
|
||||||
|
*/
|
||||||
|
public int processDeclaration(IASTDeclaration declaration) {
|
||||||
|
addRoot(declaration);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator)
|
||||||
|
*/
|
||||||
|
public int processDeclarator(IASTDeclarator declarator) {
|
||||||
|
addRoot(declarator);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processBaseSpecifier(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier)
|
||||||
|
*/
|
||||||
|
public int processBaseSpecifier(ICPPASTBaseSpecifier specifier) {
|
||||||
|
addRoot(specifier);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier)
|
||||||
|
*/
|
||||||
|
public int processDeclSpecifier(IASTDeclSpecifier declSpec) {
|
||||||
|
addRoot(declSpec);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator)
|
||||||
|
*/
|
||||||
|
public int processEnumerator(IASTEnumerator enumerator) {
|
||||||
|
addRoot(enumerator);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression)
|
||||||
|
*/
|
||||||
|
public int processExpression(IASTExpression expression) {
|
||||||
|
addRoot(expression);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer)
|
||||||
|
*/
|
||||||
|
public int processInitializer(IASTInitializer initializer) {
|
||||||
|
addRoot(initializer);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName)
|
||||||
|
*/
|
||||||
|
public int processName(IASTName name) {
|
||||||
|
addRoot(name);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processNamespace(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition)
|
||||||
|
*/
|
||||||
|
public int processNamespace(ICPPASTNamespaceDefinition namespace) {
|
||||||
|
addRoot(namespace);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration)
|
||||||
|
*/
|
||||||
|
public int processParameterDeclaration(
|
||||||
|
IASTParameterDeclaration parameterDeclaration) {
|
||||||
|
addRoot(parameterDeclaration);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement)
|
||||||
|
*/
|
||||||
|
public int processStatement(IASTStatement statement) {
|
||||||
|
addRoot(statement);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId)
|
||||||
|
*/
|
||||||
|
public int processTypeId(IASTTypeId typeId) {
|
||||||
|
addRoot(typeId);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TreeParent getTree() {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,146 @@
|
||||||
|
/**********************************************************************
|
||||||
|
* Copyright (c) 2005 IBM Canada and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v0.5
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v05.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Rational Software - Initial API and implementation
|
||||||
|
**********************************************************************/
|
||||||
|
package org.eclipse.cdt.ui.tests.DOMAST;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author dsteffle
|
||||||
|
*/
|
||||||
|
public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopulateDOMASTAction {
|
||||||
|
{
|
||||||
|
processNames = true;
|
||||||
|
processDeclarations = true;
|
||||||
|
processInitializers = true;
|
||||||
|
processParameterDeclarations = true;
|
||||||
|
processDeclarators = true;
|
||||||
|
processDeclSpecifiers = true;
|
||||||
|
processExpressions = true;
|
||||||
|
processStatements = true;
|
||||||
|
processTypeIds = true;
|
||||||
|
processEnumerators = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TreeParent root = null; // TODO what about using a hashtable/hashmap for the tree?
|
||||||
|
|
||||||
|
public CPopulateASTViewAction(IASTTranslationUnit tu) {
|
||||||
|
root = new TreeParent(tu);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addRoot(IASTNode node) {
|
||||||
|
TreeParent parent = root.findParentOfNode(node);
|
||||||
|
|
||||||
|
if ( parent != null ) {
|
||||||
|
parent.addChild(new TreeParent(node));
|
||||||
|
} else {
|
||||||
|
root.addChild(new TreeParent(node));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
|
||||||
|
*/
|
||||||
|
public int processDeclaration(IASTDeclaration declaration) {
|
||||||
|
addRoot(declaration);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator)
|
||||||
|
*/
|
||||||
|
public int processDeclarator(IASTDeclarator declarator) {
|
||||||
|
addRoot(declarator);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier)
|
||||||
|
*/
|
||||||
|
public int processDeclSpecifier(IASTDeclSpecifier declSpec) {
|
||||||
|
addRoot(declSpec);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator)
|
||||||
|
*/
|
||||||
|
public int processEnumerator(IASTEnumerator enumerator) {
|
||||||
|
addRoot(enumerator);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression)
|
||||||
|
*/
|
||||||
|
public int processExpression(IASTExpression expression) {
|
||||||
|
addRoot(expression);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer)
|
||||||
|
*/
|
||||||
|
public int processInitializer(IASTInitializer initializer) {
|
||||||
|
addRoot(initializer);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName)
|
||||||
|
*/
|
||||||
|
public int processName(IASTName name) {
|
||||||
|
addRoot(name);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration)
|
||||||
|
*/
|
||||||
|
public int processParameterDeclaration(
|
||||||
|
IASTParameterDeclaration parameterDeclaration) {
|
||||||
|
addRoot(parameterDeclaration);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement)
|
||||||
|
*/
|
||||||
|
public int processStatement(IASTStatement statement) {
|
||||||
|
addRoot(statement);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId)
|
||||||
|
*/
|
||||||
|
public int processTypeId(IASTTypeId typeId) {
|
||||||
|
addRoot(typeId);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TreeParent getTree() {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,535 @@
|
||||||
|
/**********************************************************************
|
||||||
|
* Copyright (c) 2005 IBM Canada and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v0.5
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v05.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Rational Software - Initial API and implementation
|
||||||
|
**********************************************************************/
|
||||||
|
package org.eclipse.cdt.ui.tests.DOMAST;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.ui.tests.DOMAST.DOMASTPluginImages;
|
||||||
|
import org.eclipse.cdt.ui.tests.DOMAST.CPPPopulateASTViewAction;
|
||||||
|
import org.eclipse.cdt.ui.tests.DOMAST.CPopulateASTViewAction;
|
||||||
|
import org.eclipse.cdt.ui.tests.DOMAST.IPopulateDOMASTAction;
|
||||||
|
import org.eclipse.cdt.ui.tests.DOMAST.TreeObject;
|
||||||
|
import org.eclipse.cdt.ui.tests.DOMAST.TreeParent;
|
||||||
|
import org.eclipse.swt.widgets.Composite;
|
||||||
|
import org.eclipse.ui.part.*;
|
||||||
|
import org.eclipse.jface.viewers.*;
|
||||||
|
import org.eclipse.swt.graphics.Image;
|
||||||
|
import org.eclipse.jface.action.*;
|
||||||
|
import org.eclipse.jface.dialogs.MessageDialog;
|
||||||
|
import org.eclipse.ui.*;
|
||||||
|
import org.eclipse.swt.widgets.Menu;
|
||||||
|
import org.eclipse.swt.SWT;
|
||||||
|
import org.eclipse.cdt.core.parser.CodeReader;
|
||||||
|
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||||
|
import org.eclipse.cdt.core.parser.NullLogService;
|
||||||
|
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
||||||
|
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||||
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
|
import org.eclipse.cdt.core.parser.IScanner;
|
||||||
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
|
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||||
|
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.c.GCCParserExtensionConfiguration;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||||
|
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This sample class demonstrates how to plug-in a new
|
||||||
|
* workbench view. The view shows data obtained from the
|
||||||
|
* model. The sample creates a dummy model on the fly,
|
||||||
|
* but a real implementation would connect to the model
|
||||||
|
* available either in this or another plug-in (e.g. the workspace).
|
||||||
|
* The view is connected to the model using a content provider.
|
||||||
|
* <p>
|
||||||
|
* The view uses a label provider to define how model
|
||||||
|
* objects should be presented in the view. Each
|
||||||
|
* view can present the same model objects using
|
||||||
|
* different labels and icons, if needed. Alternatively,
|
||||||
|
* a single label provider can be shared between views
|
||||||
|
* in order to ensure that objects of the same type are
|
||||||
|
* presented in the same way everywhere.
|
||||||
|
* <p>
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class DOMAST extends ViewPart {
|
||||||
|
private static final String VIEW_NAME = "DOM View"; //$NON-NLS-1$
|
||||||
|
private static final String POPUPMENU = "#PopupMenu"; //$NON-NLS-1$
|
||||||
|
private static final String OPEN_DEFINITIONS = "Open Definitions"; //$NON-NLS-1$
|
||||||
|
private static final String OPEN_REFERENCES = "Open References"; //$NON-NLS-1$
|
||||||
|
private TreeViewer viewer;
|
||||||
|
private DrillDownAdapter drillDownAdapter;
|
||||||
|
private Action action1;
|
||||||
|
private Action action2;
|
||||||
|
private Action singleClickAction;
|
||||||
|
private IFile file = null;
|
||||||
|
private IEditorPart part = null;
|
||||||
|
private ParserLanguage lang = null;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The content provider class is responsible for
|
||||||
|
* providing objects to the view. It can wrap
|
||||||
|
* existing objects in adapters or simply return
|
||||||
|
* objects as-is. These objects may be sensitive
|
||||||
|
* to the current input of the view, or ignore
|
||||||
|
* it and always show the same content
|
||||||
|
* (like Task List, for example).
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ViewContentProvider implements IStructuredContentProvider,
|
||||||
|
ITreeContentProvider {
|
||||||
|
private TreeParent invisibleRoot;
|
||||||
|
private IFile aFile = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public ViewContentProvider() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public ViewContentProvider(IFile file) {
|
||||||
|
this.aFile = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void inputChanged(Viewer v, Object oldInput, Object newInput) {
|
||||||
|
}
|
||||||
|
public void dispose() {
|
||||||
|
}
|
||||||
|
public Object[] getElements(Object parent) {
|
||||||
|
if (parent.equals(getViewSite())) {
|
||||||
|
if (invisibleRoot==null) initialize();
|
||||||
|
return getChildren(invisibleRoot);
|
||||||
|
}
|
||||||
|
return getChildren(parent);
|
||||||
|
}
|
||||||
|
public Object getParent(Object child) {
|
||||||
|
if (child instanceof TreeObject) {
|
||||||
|
return ((TreeObject)child).getParent();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public Object [] getChildren(Object parent) {
|
||||||
|
if (parent instanceof TreeParent) {
|
||||||
|
return ((TreeParent)parent).getChildren();
|
||||||
|
}
|
||||||
|
return new Object[0];
|
||||||
|
}
|
||||||
|
public boolean hasChildren(Object parent) {
|
||||||
|
if (parent instanceof TreeParent)
|
||||||
|
return ((TreeParent)parent).hasChildren();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initialize() {
|
||||||
|
if ( aFile == null || lang == null) return;
|
||||||
|
|
||||||
|
IPopulateDOMASTAction action = null;
|
||||||
|
|
||||||
|
// TODO could use something like below to work with working copy... i.e. refresh button
|
||||||
|
// IProject currentProject = aFile.getProject();
|
||||||
|
// IWorkingCopy workingCopy = null;
|
||||||
|
// if( editor.isDirty() ){
|
||||||
|
// IWorkingCopy [] workingCopies = CUIPlugin.getSharedWorkingCopies();
|
||||||
|
// if( workingCopies != null ){
|
||||||
|
// for( int i = 0; i < workingCopies.length; i++ ){
|
||||||
|
// if( workingCopies[i].getUnderlyingResource().equals( file ) ){
|
||||||
|
// workingCopy = workingCopies[i];
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
CodeReader reader = null;
|
||||||
|
try {
|
||||||
|
// if( workingCopy == null )
|
||||||
|
reader = new CodeReader(aFile.getLocation().toOSString(), aFile.getCharset() );
|
||||||
|
// else
|
||||||
|
// reader = new CodeReader(file.getLocation().toOSString(), workingCopy.getContents());
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch ( CoreException e ) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// get IFile
|
||||||
|
// IWorkspace workspace= ResourcesPlugin.getWorkspace();
|
||||||
|
// workspace.setDescription(desc);
|
||||||
|
// getWorkbench().getActiveWorkbenchWindow();
|
||||||
|
|
||||||
|
// parse IFile
|
||||||
|
ParserMode mode = ParserMode.COMPLETE_PARSE;
|
||||||
|
Map definitions = new Hashtable();
|
||||||
|
|
||||||
|
String [] includePaths = new String[0];
|
||||||
|
IScannerInfo scannerInfo = new ScannerInfo( definitions, includePaths );
|
||||||
|
IScanner scanner = ParserFactory.createScanner(
|
||||||
|
reader,
|
||||||
|
scannerInfo,
|
||||||
|
mode,
|
||||||
|
lang,
|
||||||
|
new NullSourceElementRequestor(),
|
||||||
|
null,
|
||||||
|
null );
|
||||||
|
AbstractGNUSourceCodeParser parser = null;
|
||||||
|
if ( lang == ParserLanguage.C ) {
|
||||||
|
parser = new GNUCSourceParser(
|
||||||
|
scanner,
|
||||||
|
mode,
|
||||||
|
new NullLogService(),
|
||||||
|
new GCCParserExtensionConfiguration()
|
||||||
|
);
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parser.parse();
|
||||||
|
|
||||||
|
action = new CPopulateASTViewAction(tu);
|
||||||
|
CVisitor.visitTranslationUnit(tu, (CBaseVisitorAction)action);
|
||||||
|
} else if ( lang == ParserLanguage.CPP ){
|
||||||
|
parser = new GNUCPPSourceParser(
|
||||||
|
scanner,
|
||||||
|
mode,
|
||||||
|
new NullLogService(),
|
||||||
|
new GPPParserExtensionConfiguration()
|
||||||
|
);
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parser.parse();
|
||||||
|
|
||||||
|
action = new CPPPopulateASTViewAction(tu);
|
||||||
|
CPPVisitor.visitTranslationUnit(tu, (CPPBaseVisitorAction)action);
|
||||||
|
}
|
||||||
|
|
||||||
|
// display roots
|
||||||
|
invisibleRoot = new TreeParent(null); //$NON-NLS-1$
|
||||||
|
invisibleRoot.addChild(action.getTree());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ViewLabelProvider extends LabelProvider {
|
||||||
|
|
||||||
|
public String getText(Object obj) {
|
||||||
|
return obj.toString();
|
||||||
|
}
|
||||||
|
public Image getImage(Object obj) {
|
||||||
|
String imageKey = DOMASTPluginImages.IMG_DEFAULT;
|
||||||
|
|
||||||
|
IASTNode node = null;
|
||||||
|
if (obj instanceof TreeObject) {
|
||||||
|
node = ((TreeObject)obj).getNode();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( node instanceof IASTArrayModifier ) {
|
||||||
|
imageKey = DOMASTPluginImages.IMG_IASTArrayModifier;
|
||||||
|
} else if ( node instanceof IASTDeclaration ) {
|
||||||
|
imageKey = DOMASTPluginImages.IMG_IASTDeclaration;
|
||||||
|
} else if ( node instanceof IASTDeclarator ) {
|
||||||
|
imageKey = DOMASTPluginImages.IMG_IASTDeclarator;
|
||||||
|
} else if ( node instanceof IASTDeclSpecifier ) {
|
||||||
|
imageKey = DOMASTPluginImages.IMG_IASTDeclSpecifier;
|
||||||
|
} else if ( node instanceof IASTEnumerator ) {
|
||||||
|
imageKey = DOMASTPluginImages.IMG_IASTEnumerator;
|
||||||
|
} else if ( node instanceof IASTExpression ) {
|
||||||
|
imageKey = DOMASTPluginImages.IMG_IASTExpression;
|
||||||
|
} else if ( node instanceof IASTInitializer ) {
|
||||||
|
imageKey = DOMASTPluginImages.IMG_IASTInitializer;
|
||||||
|
} else if ( node instanceof IASTName ) {
|
||||||
|
imageKey = DOMASTPluginImages.IMG_IASTName;
|
||||||
|
} else if ( node instanceof IASTParameterDeclaration ) {
|
||||||
|
imageKey = DOMASTPluginImages.IMG_IASTParameterDeclaration;
|
||||||
|
} else if ( node instanceof IASTPointerOperator ) {
|
||||||
|
imageKey = DOMASTPluginImages.IMG_IASTPointerOperator;
|
||||||
|
} else if ( node instanceof IASTPreprocessorStatement ) {
|
||||||
|
imageKey = DOMASTPluginImages.IMG_IASTPreprocessorStatement;
|
||||||
|
} else if ( node instanceof IASTProblem ) {
|
||||||
|
imageKey = DOMASTPluginImages.IMG_IASTProblem;
|
||||||
|
} else if ( node instanceof IASTSimpleDeclaration ) {
|
||||||
|
imageKey = DOMASTPluginImages.IMG_IASTSimpleDeclaration;
|
||||||
|
} else if ( node instanceof IASTStatement ) {
|
||||||
|
imageKey = DOMASTPluginImages.IMG_IASTStatement;
|
||||||
|
} else if ( node instanceof IASTTranslationUnit ) {
|
||||||
|
imageKey = DOMASTPluginImages.IMG_IASTTranslationUnit;
|
||||||
|
} else if ( node instanceof IASTTypeId ) {
|
||||||
|
imageKey = DOMASTPluginImages.IMG_IASTTypeId;
|
||||||
|
} else if ( node instanceof ICASTDesignator ) {
|
||||||
|
imageKey = DOMASTPluginImages.IMG_ICASTDesignator;
|
||||||
|
} else if ( node instanceof ICPPASTConstructorChainInitializer ) {
|
||||||
|
imageKey = DOMASTPluginImages.IMG_ICPPASTConstructorChainInitializer;
|
||||||
|
} else if ( node instanceof ICPPASTTemplateParameter ) {
|
||||||
|
imageKey = DOMASTPluginImages.IMG_ICPPASTTemplateParameter;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DOMASTPluginImages.get(imageKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class NameSorter extends ViewerSorter {
|
||||||
|
}
|
||||||
|
|
||||||
|
public DOMAST() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a callback that will allow us
|
||||||
|
* to create the viewer and initialize it.
|
||||||
|
*/
|
||||||
|
public void createPartControl(Composite parent) {
|
||||||
|
|
||||||
|
if (part == null) {
|
||||||
|
IWorkbenchPage[] pages = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPages();
|
||||||
|
|
||||||
|
if (pages.length == 0) {
|
||||||
|
// TODO determine how to hide view if no pages found and part==null
|
||||||
|
}
|
||||||
|
|
||||||
|
outerLoop: for(int i=0; i<pages.length; i++) {
|
||||||
|
IEditorReference[] editorRefs = pages[i].getEditorReferences();
|
||||||
|
for (int j=0; j<editorRefs.length; j++) {
|
||||||
|
part = editorRefs[j].getEditor(false);
|
||||||
|
if (part instanceof CEditor) {
|
||||||
|
// TODO set the language properly if implement the above TODO
|
||||||
|
lang = ParserLanguage.CPP;
|
||||||
|
break outerLoop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null &&
|
||||||
|
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() != null)
|
||||||
|
part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
|
||||||
|
}
|
||||||
|
|
||||||
|
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
|
||||||
|
drillDownAdapter = new DrillDownAdapter(viewer);
|
||||||
|
|
||||||
|
if (part instanceof CEditor)
|
||||||
|
viewer.setContentProvider( new ViewContentProvider(((CEditor)part).getInputFile()) );
|
||||||
|
else
|
||||||
|
viewer.setContentProvider(new ViewContentProvider(file));
|
||||||
|
|
||||||
|
viewer.setLabelProvider(new ViewLabelProvider());
|
||||||
|
viewer.setInput(getViewSite());
|
||||||
|
makeActions();
|
||||||
|
hookContextMenu();
|
||||||
|
hookSingleClickAction();
|
||||||
|
contributeToActionBars();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContentProvider(ViewContentProvider vcp) {
|
||||||
|
viewer.setContentProvider(vcp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void hookContextMenu() {
|
||||||
|
MenuManager menuMgr = new MenuManager(POPUPMENU);
|
||||||
|
menuMgr.setRemoveAllWhenShown(true);
|
||||||
|
menuMgr.addMenuListener(new IMenuListener() {
|
||||||
|
public void menuAboutToShow(IMenuManager manager) {
|
||||||
|
DOMAST.this.fillContextMenu(manager);
|
||||||
|
IContributionItem[] items = manager.getItems();
|
||||||
|
for (int i=0; i<items.length; i++) {
|
||||||
|
// TODO Devin put in the check here if IASTName or not... if it isn't, and item is open declaration (make constant) then hide it
|
||||||
|
if (items[i] instanceof ActionContributionItem &&
|
||||||
|
(((ActionContributionItem)items[i]).getAction().getText().equals(OPEN_REFERENCES) ||
|
||||||
|
((ActionContributionItem)items[i]).getAction().getText().equals(OPEN_DEFINITIONS) )) {
|
||||||
|
if (viewer.getSelection() instanceof StructuredSelection &&
|
||||||
|
((StructuredSelection)viewer.getSelection()).getFirstElement() instanceof TreeObject &&
|
||||||
|
((TreeObject)((StructuredSelection)viewer.getSelection()).getFirstElement()).getNode() instanceof IASTName) {
|
||||||
|
items[i].setVisible(true);
|
||||||
|
} else {
|
||||||
|
items[i].setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Menu menu = menuMgr.createContextMenu(viewer.getControl());
|
||||||
|
viewer.getControl().setMenu(menu);
|
||||||
|
getSite().registerContextMenu(menuMgr, viewer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void contributeToActionBars() {
|
||||||
|
IActionBars bars = getViewSite().getActionBars();
|
||||||
|
fillLocalPullDown(bars.getMenuManager());
|
||||||
|
fillLocalToolBar(bars.getToolBarManager());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillLocalPullDown(IMenuManager manager) {
|
||||||
|
// manager.add(action1); // TODO determine the groups/filters to use
|
||||||
|
// manager.add(new Separator());
|
||||||
|
// manager.add(action2);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillContextMenu(IMenuManager manager) {
|
||||||
|
manager.add(action1);
|
||||||
|
manager.add(action2);
|
||||||
|
manager.add(new Separator());
|
||||||
|
drillDownAdapter.addNavigationActions(manager);
|
||||||
|
// Other plug-ins can contribute there actions here
|
||||||
|
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillLocalToolBar(IToolBarManager manager) {
|
||||||
|
// manager.add(action1); // TODO determine the groups/filters to use
|
||||||
|
// manager.add(action2);
|
||||||
|
// manager.add(new Separator());
|
||||||
|
// drillDownAdapter.addNavigationActions(manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void makeActions() {
|
||||||
|
action1 = new Action() {
|
||||||
|
public void run() {
|
||||||
|
showMessage("Action 1 executed"); // TODO Devin open declarations action ... john probably wants all of them highlighted... wouldn't I have to use annotations then???
|
||||||
|
}
|
||||||
|
};
|
||||||
|
action1.setText(OPEN_REFERENCES);
|
||||||
|
action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
|
||||||
|
getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
|
||||||
|
|
||||||
|
action2 = new Action() {
|
||||||
|
public void run() {
|
||||||
|
showMessage("Action 2 executed"); // TODO Devin open definitions action ... use annotations to highlight definitions?
|
||||||
|
}
|
||||||
|
};
|
||||||
|
action2.setText(OPEN_DEFINITIONS);
|
||||||
|
action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
|
||||||
|
getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
|
||||||
|
|
||||||
|
singleClickAction = new ASTHighlighterAction(part);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ASTHighlighterAction extends Action {
|
||||||
|
IEditorPart aPart = null;
|
||||||
|
|
||||||
|
public ASTHighlighterAction(IEditorPart part) {
|
||||||
|
this.aPart = part;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPart(IEditorPart part) {
|
||||||
|
this.aPart = part;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
ISelection selection = viewer.getSelection();
|
||||||
|
Object obj = ((IStructuredSelection)selection).getFirstElement();
|
||||||
|
if (aPart instanceof CEditor && obj instanceof TreeObject) {
|
||||||
|
((CEditor)aPart).selectAndReveal(((TreeObject)obj).getOffset(), ((TreeObject)obj).getLength());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO need to create a new action with the following for annotations (get declarations/references)
|
||||||
|
// ISelection selection = viewer.getSelection();
|
||||||
|
// Object obj = ((IStructuredSelection)selection).getFirstElement();
|
||||||
|
//
|
||||||
|
// if (aPart instanceof CEditor) {
|
||||||
|
// IAnnotationModel aModel = ((CEditor)aPart).getDocumentProvider().getAnnotationModel(aPart.getEditorInput());
|
||||||
|
// if ( aModel != null && obj instanceof TreeObject && !(((TreeObject)obj).getNode() instanceof IASTTranslationUnit) ) {
|
||||||
|
// Iterator itr = aModel.getAnnotationIterator();
|
||||||
|
// while (itr.hasNext()) {
|
||||||
|
// aModel.removeAnnotation((Annotation)itr.next());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// ASTViewAnnotation annotation = new ASTViewAnnotation();
|
||||||
|
// annotation.setType(CMarkerAnnotation.WARNING_ANNOTATION_TYPE);
|
||||||
|
// aModel.addAnnotation(annotation, new Position(((TreeObject)obj).getOffset(), ((TreeObject)obj).getLength()));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// TODO implement annotation for things like open declarations/references
|
||||||
|
// private class ASTViewAnnotation extends Annotation implements IAnnotationPresentation {
|
||||||
|
//
|
||||||
|
// /* (non-Javadoc)
|
||||||
|
// * @see org.eclipse.jface.text.source.IAnnotationPresentation#getLayer()
|
||||||
|
// */
|
||||||
|
// public int getLayer() {
|
||||||
|
// return IAnnotationAccessExtension.DEFAULT_LAYER;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /* (non-Javadoc)
|
||||||
|
// * @see org.eclipse.jface.text.source.IAnnotationPresentation#paint(org.eclipse.swt.graphics.GC, org.eclipse.swt.widgets.Canvas, org.eclipse.swt.graphics.Rectangle)
|
||||||
|
// */
|
||||||
|
// public void paint(GC gc, Canvas canvas, Rectangle r) {
|
||||||
|
// // TODO implement this annotation image for
|
||||||
|
// ImageUtilities.drawImage(ASTViewPluginImages.get(ASTViewPluginImages.IMG_TO_DRAW), gc, canvas, r, SWT.CENTER, SWT.TOP);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
private void hookSingleClickAction() {
|
||||||
|
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
||||||
|
public void selectionChanged(SelectionChangedEvent event) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
singleClickAction.run();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
private void showMessage(String message) {
|
||||||
|
MessageDialog.openInformation(
|
||||||
|
viewer.getControl().getShell(),
|
||||||
|
VIEW_NAME,
|
||||||
|
message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Passing the focus request to the viewer's control.
|
||||||
|
*/
|
||||||
|
public void setFocus() {
|
||||||
|
viewer.getControl().setFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFile(IFile file) {
|
||||||
|
this.file = file;
|
||||||
|
viewer.setContentProvider(new ViewContentProvider(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPart(IEditorPart part) {
|
||||||
|
this.part = part;
|
||||||
|
|
||||||
|
if (singleClickAction instanceof ASTHighlighterAction)
|
||||||
|
((ASTHighlighterAction)singleClickAction).setPart(part);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLang(ParserLanguage lang) {
|
||||||
|
this.lang = lang;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,122 @@
|
||||||
|
/**********************************************************************
|
||||||
|
* Copyright (c) 2005 IBM Canada and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v0.5
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v05.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Rational Software - Initial API and implementation
|
||||||
|
**********************************************************************/
|
||||||
|
package org.eclipse.cdt.ui.tests.DOMAST;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.testplugin.CTestPlugin;
|
||||||
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
import org.eclipse.jface.resource.ImageDescriptor;
|
||||||
|
import org.eclipse.jface.resource.ImageRegistry;
|
||||||
|
import org.eclipse.swt.graphics.Image;
|
||||||
|
import org.eclipse.swt.widgets.Display;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author dsteffle
|
||||||
|
*/
|
||||||
|
public class DOMASTPluginImages {
|
||||||
|
private static ImageRegistry imageRegistry = new ImageRegistry(CUIPlugin.getStandardDisplay());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the standard display to be used. The method first checks, if
|
||||||
|
* the thread calling this method has an associated display. If so, this
|
||||||
|
* display is returned. Otherwise the method returns the default display.
|
||||||
|
*/
|
||||||
|
public static Display getStandardDisplay() {
|
||||||
|
Display display= Display.getCurrent();
|
||||||
|
if (display == null) {
|
||||||
|
display= Display.getDefault();
|
||||||
|
}
|
||||||
|
return display;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Subdirectory (under the package containing this class) where 16 color images are
|
||||||
|
private static URL fgIconBaseURL;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
fgIconBaseURL= new URL(CTestPlugin.getDefault().getBundle().getEntry("/"), "icons/" ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
} catch (MalformedURLException e) {}
|
||||||
|
}
|
||||||
|
public static final String PLUGIN_ID = "org.eclipse.cdt.testplugin.CTestPlugin"; //$NON-NLS-1$
|
||||||
|
private static final String NAME_PREFIX= PLUGIN_ID + '.';
|
||||||
|
private static final int NAME_PREFIX_LENGTH= NAME_PREFIX.length();
|
||||||
|
public static final String ICON_PREFIX= "used/"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
public static final String IMG_IASTArrayModifier= NAME_PREFIX + "showasarray_co.gif"; //$NON-NLS-1$
|
||||||
|
public static final String IMG_IASTDeclaration= NAME_PREFIX + "cdeclaration_obj.gif"; //$NON-NLS-1$
|
||||||
|
public static final String IMG_IASTDeclarator= NAME_PREFIX + "variable_obj.gif"; //$NON-NLS-1$
|
||||||
|
public static final String IMG_IASTDeclSpecifier= NAME_PREFIX + "var_simple.gif"; //$NON-NLS-1$
|
||||||
|
public static final String IMG_IASTEnumerator= NAME_PREFIX + "enumerator_obj.gif"; //$NON-NLS-1$
|
||||||
|
public static final String IMG_IASTExpression= NAME_PREFIX + "expression_obj.gif"; //$NON-NLS-1$
|
||||||
|
public static final String IMG_IASTInitializer= NAME_PREFIX + "variable_local_obj.gif"; //$NON-NLS-1$
|
||||||
|
public static final String IMG_IASTName= NAME_PREFIX + "tnames_co.gif"; //$NON-NLS-1$
|
||||||
|
public static final String IMG_IASTParameterDeclaration= NAME_PREFIX + "var_declaration_obj.gif"; //$NON-NLS-1$
|
||||||
|
public static final String IMG_IASTPointerOperator= NAME_PREFIX + "var_pointer.gif"; //$NON-NLS-1$
|
||||||
|
public static final String IMG_IASTPreprocessorStatement= NAME_PREFIX + "define_obj.gif"; //$NON-NLS-1$
|
||||||
|
public static final String IMG_IASTProblem= NAME_PREFIX + "warning_obj.gif"; //$NON-NLS-1$
|
||||||
|
public static final String IMG_IASTSimpleDeclaration= NAME_PREFIX + "method_public_obj.gif"; //$NON-NLS-1$
|
||||||
|
public static final String IMG_IASTStatement= NAME_PREFIX + "statement_obj.gif"; //$NON-NLS-1$
|
||||||
|
public static final String IMG_IASTTranslationUnit= NAME_PREFIX + "source_attach_attrib.gif"; //$NON-NLS-1$
|
||||||
|
public static final String IMG_IASTTypeId= NAME_PREFIX + "types.gif"; //$NON-NLS-1$
|
||||||
|
public static final String IMG_ICASTDesignator= NAME_PREFIX + "watch_globals.gif"; //$NON-NLS-1$
|
||||||
|
public static final String IMG_ICPPASTConstructorChainInitializer = NAME_PREFIX + "jump_co.gif"; //$NON-NLS-1$
|
||||||
|
public static final String IMG_ICPPASTTemplateParameter = NAME_PREFIX + "disassembly.gif"; //$NON-NLS-1$
|
||||||
|
public static final String IMG_DEFAULT = NAME_PREFIX + "brkpd_obj.gif"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
public static final ImageDescriptor DESC_IASTArrayModifier= createManaged(ICON_PREFIX, IMG_IASTArrayModifier);
|
||||||
|
public static final ImageDescriptor DESC_IASTDeclaration= createManaged(ICON_PREFIX, IMG_IASTDeclaration);
|
||||||
|
public static final ImageDescriptor DESC_IASTDeclarator= createManaged(ICON_PREFIX, IMG_IASTDeclarator);
|
||||||
|
public static final ImageDescriptor DESC_IASTDeclSpecifier= createManaged(ICON_PREFIX, IMG_IASTDeclSpecifier);
|
||||||
|
public static final ImageDescriptor DESC_IASTEnumerator= createManaged(ICON_PREFIX, IMG_IASTEnumerator);
|
||||||
|
public static final ImageDescriptor DESC_IASTExpression= createManaged(ICON_PREFIX, IMG_IASTExpression);
|
||||||
|
public static final ImageDescriptor DESC_IASTInitializer= createManaged(ICON_PREFIX, IMG_IASTInitializer);
|
||||||
|
public static final ImageDescriptor DESC_IASTName= createManaged(ICON_PREFIX, IMG_IASTName);
|
||||||
|
public static final ImageDescriptor DESC_IASTParameterDeclaration= createManaged(ICON_PREFIX, IMG_IASTParameterDeclaration);
|
||||||
|
public static final ImageDescriptor DESC_IASTPointerOperator= createManaged(ICON_PREFIX, IMG_IASTPointerOperator);
|
||||||
|
public static final ImageDescriptor DESC_IASTPreprocessorStatement= createManaged(ICON_PREFIX, IMG_IASTPreprocessorStatement);
|
||||||
|
public static final ImageDescriptor DESC_IASTProblem= createManaged(ICON_PREFIX, IMG_IASTProblem);
|
||||||
|
public static final ImageDescriptor DESC_IASTSimpleDeclaration= createManaged(ICON_PREFIX, IMG_IASTSimpleDeclaration);
|
||||||
|
public static final ImageDescriptor DESC_IASTStatement= createManaged(ICON_PREFIX, IMG_IASTStatement);
|
||||||
|
public static final ImageDescriptor DESC_IASTTranslationUnit= createManaged(ICON_PREFIX, IMG_IASTTranslationUnit);
|
||||||
|
public static final ImageDescriptor DESC_IASTTypeId= createManaged(ICON_PREFIX, IMG_IASTTypeId);
|
||||||
|
public static final ImageDescriptor DESC_ICASTDesignator= createManaged(ICON_PREFIX, IMG_ICASTDesignator);
|
||||||
|
public static final ImageDescriptor DESC_ICPPASTConstructorChainInitializer= createManaged(ICON_PREFIX, IMG_ICPPASTConstructorChainInitializer);
|
||||||
|
public static final ImageDescriptor DESC_ICPPASTTemplateParameter= createManaged(ICON_PREFIX, IMG_ICPPASTTemplateParameter);
|
||||||
|
public static final ImageDescriptor DESC_DEFAULT= createManaged(ICON_PREFIX, IMG_DEFAULT);
|
||||||
|
|
||||||
|
private static ImageDescriptor createManaged(String prefix, String name) {
|
||||||
|
return createManaged(imageRegistry, prefix, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ImageDescriptor createManaged(ImageRegistry registry, String prefix, String name) {
|
||||||
|
ImageDescriptor result= ImageDescriptor.createFromURL(makeIconFileURL(prefix, name.substring(NAME_PREFIX_LENGTH)));
|
||||||
|
registry.put(name, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static URL makeIconFileURL(String prefix, String name) {
|
||||||
|
StringBuffer buffer= new StringBuffer(prefix);
|
||||||
|
buffer.append(name);
|
||||||
|
try {
|
||||||
|
return new URL(fgIconBaseURL, buffer.toString());
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
CUIPlugin.getDefault().log(e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Image get(String key) {
|
||||||
|
return imageRegistry.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
/**********************************************************************
|
||||||
|
* Copyright (c) 2005 IBM Canada and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v0.5
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v05.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Rational Software - Initial API and implementation
|
||||||
|
**********************************************************************/
|
||||||
|
package org.eclipse.cdt.ui.tests.DOMAST;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author dsteffle
|
||||||
|
*/
|
||||||
|
public interface IPopulateDOMASTAction {
|
||||||
|
public TreeParent getTree();
|
||||||
|
}
|
|
@ -0,0 +1,120 @@
|
||||||
|
/**********************************************************************
|
||||||
|
* Copyright (c) 2005 IBM Canada and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v0.5
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v05.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Rational Software - Initial API and implementation
|
||||||
|
**********************************************************************/
|
||||||
|
package org.eclipse.cdt.ui.tests.DOMAST;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.model.ISourceReference;
|
||||||
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
|
import org.eclipse.cdt.internal.core.model.TranslationUnit;
|
||||||
|
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||||
|
import org.eclipse.cdt.ui.tests.DOMAST.DOMAST;
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.jface.action.IAction;
|
||||||
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
|
import org.eclipse.ui.IEditorActionDelegate;
|
||||||
|
import org.eclipse.ui.IEditorPart;
|
||||||
|
import org.eclipse.ui.IObjectActionDelegate;
|
||||||
|
import org.eclipse.ui.IViewActionDelegate;
|
||||||
|
import org.eclipse.ui.IViewPart;
|
||||||
|
import org.eclipse.ui.IWorkbenchPart;
|
||||||
|
import org.eclipse.ui.PartInitException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author dsteffle
|
||||||
|
*/
|
||||||
|
public class OpenDOMViewAction implements IViewActionDelegate, IEditorActionDelegate, IObjectActionDelegate {
|
||||||
|
|
||||||
|
private static final String VIEW_ID = "org.eclipse.cdt.ui.tests.DOMAST.DOMAST"; //$NON-NLS-1$
|
||||||
|
IViewPart viewPart = null;
|
||||||
|
ISelection selection = null;
|
||||||
|
IFile file = null;
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
|
||||||
|
*/
|
||||||
|
public void init(IViewPart view) {
|
||||||
|
this.viewPart = view;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
|
||||||
|
*/
|
||||||
|
public void run(IAction action) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
Object obj = ((IStructuredSelection)selection).getFirstElement();
|
||||||
|
ITranslationUnit tu = null;
|
||||||
|
IEditorPart part = null;
|
||||||
|
if (obj instanceof ISourceReference) {
|
||||||
|
tu = ((ISourceReference) obj).getTranslationUnit();
|
||||||
|
if (tu != null) {
|
||||||
|
if (viewPart != null) {
|
||||||
|
if (obj instanceof ICElement) {
|
||||||
|
try {
|
||||||
|
part = EditorUtility.openInEditor(obj);
|
||||||
|
} catch (CModelException cme) {
|
||||||
|
} catch (PartInitException pie) {}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IViewPart tempView = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
tempView = viewPart.getSite().getPage().showView(VIEW_ID);
|
||||||
|
} catch (PartInitException pie) {}
|
||||||
|
|
||||||
|
if (tempView != null) {
|
||||||
|
if (tempView instanceof DOMAST) {
|
||||||
|
((DOMAST)tempView).setFile(file);
|
||||||
|
((DOMAST)tempView).setPart(part);
|
||||||
|
if (tu != null) {
|
||||||
|
((DOMAST)tempView).setLang(tu.isCXXLanguage() ? ParserLanguage.CPP : ParserLanguage.C);
|
||||||
|
}
|
||||||
|
((DOMAST)tempView).setContentProvider(((DOMAST)tempView).new ViewContentProvider(file));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
viewPart.getSite().getPage().activate(tempView);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
|
||||||
|
*/
|
||||||
|
public void selectionChanged(IAction action, ISelection selection) {
|
||||||
|
if (selection instanceof IStructuredSelection &&
|
||||||
|
((IStructuredSelection)selection).getFirstElement() instanceof TranslationUnit &&
|
||||||
|
((TranslationUnit)((IStructuredSelection)selection).getFirstElement()).getResource() instanceof IFile) {
|
||||||
|
this.file = (IFile)((TranslationUnit)((IStructuredSelection)selection).getFirstElement()).getResource();
|
||||||
|
}
|
||||||
|
this.selection = selection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart)
|
||||||
|
*/
|
||||||
|
public void setActiveEditor(IAction action, IEditorPart targetEditor) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
|
||||||
|
*/
|
||||||
|
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,96 @@
|
||||||
|
/**********************************************************************
|
||||||
|
* Copyright (c) 2005 IBM Canada and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v0.5
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v05.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Rational Software - Initial API and implementation
|
||||||
|
**********************************************************************/
|
||||||
|
package org.eclipse.cdt.ui.tests.DOMAST;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||||
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author dsteffle
|
||||||
|
*/
|
||||||
|
public class TreeObject implements IAdaptable {
|
||||||
|
private static final String IGCCAST_PREFIX = "IGCCAST"; //$NON-NLS-1$
|
||||||
|
private static final String IGNUAST_PREFIX = "IGNUAST"; //$NON-NLS-1$
|
||||||
|
private static final String IGPPAST_PREFIX = "IGPPAST"; //$NON-NLS-1$
|
||||||
|
private static final String ICPPAST_PREFIX = "ICPPAST"; //$NON-NLS-1$
|
||||||
|
private static final String ICAST_PREFIX = "ICAST"; //$NON-NLS-1$
|
||||||
|
private static final String IAST_PREFIX = "IAST"; //$NON-NLS-1$
|
||||||
|
private static final String START_OF_LIST = ": "; //$NON-NLS-1$
|
||||||
|
private static final String LIST_SEPARATOR = ", "; //$NON-NLS-1$
|
||||||
|
private static final String FILENAME_SEPARATOR = "."; //$NON-NLS-1$
|
||||||
|
private IASTNode node = null;
|
||||||
|
private TreeParent parent;
|
||||||
|
|
||||||
|
public TreeObject(IASTNode node) {
|
||||||
|
this.node = node;
|
||||||
|
}
|
||||||
|
public IASTNode getNode() {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
public void setParent(TreeParent parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
public TreeParent getParent() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasProperPrefix(String string) {
|
||||||
|
if (string.startsWith(IAST_PREFIX) ||
|
||||||
|
string.startsWith(ICAST_PREFIX) ||
|
||||||
|
string.startsWith(ICPPAST_PREFIX) ||
|
||||||
|
string.startsWith(IGPPAST_PREFIX) ||
|
||||||
|
string.startsWith(IGNUAST_PREFIX) ||
|
||||||
|
string.startsWith(IGCCAST_PREFIX))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
|
Class[] classes = node.getClass().getInterfaces();
|
||||||
|
for(int i=0; i<classes.length; i++) {
|
||||||
|
String interfaceName = classes[i].getName().substring(classes[i].getName().lastIndexOf(FILENAME_SEPARATOR) + 1);
|
||||||
|
if (hasProperPrefix(interfaceName)) {
|
||||||
|
buffer.append(interfaceName);
|
||||||
|
if (i+1 < classes.length && hasProperPrefix(classes[i+1].getName().substring(classes[i+1].getName().lastIndexOf(FILENAME_SEPARATOR) + 1)))
|
||||||
|
buffer.append(LIST_SEPARATOR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( node instanceof IASTName ) {
|
||||||
|
buffer.append(START_OF_LIST);
|
||||||
|
buffer.append(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
public Object getAdapter(Class key) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getOffset() {
|
||||||
|
if (node instanceof ASTNode)
|
||||||
|
return ((ASTNode)node).getOffset();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLength() {
|
||||||
|
if (node instanceof ASTNode)
|
||||||
|
return ((ASTNode)node).getLength();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
/**********************************************************************
|
||||||
|
* Copyright (c) 2005 IBM Canada and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v0.5
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v05.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Rational Software - Initial API and implementation
|
||||||
|
**********************************************************************/
|
||||||
|
package org.eclipse.cdt.ui.tests.DOMAST;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author dsteffle
|
||||||
|
*/
|
||||||
|
public class TreeParent extends TreeObject {
|
||||||
|
private ArrayList children; // TODO might want to use a HashTable/HashMap or wrap one so finding the parent node is faster
|
||||||
|
|
||||||
|
public TreeParent(IASTNode node) {
|
||||||
|
super(node);
|
||||||
|
children = new ArrayList();
|
||||||
|
}
|
||||||
|
public void addChild(TreeObject child) {
|
||||||
|
children.add(child);
|
||||||
|
child.setParent(this);
|
||||||
|
}
|
||||||
|
public void removeChild(TreeObject child) {
|
||||||
|
children.remove(child);
|
||||||
|
child.setParent(null);
|
||||||
|
}
|
||||||
|
public TreeObject [] getChildren() {
|
||||||
|
return (TreeObject [])children.toArray(new TreeObject[children.size()]);
|
||||||
|
}
|
||||||
|
public boolean hasChildren() {
|
||||||
|
return children.size()>0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private TreeParent findParentOfNode(TreeObject[] trees, IASTNode node) {
|
||||||
|
for (int i=0; i<trees.length; i++) {
|
||||||
|
|
||||||
|
if (trees[i] != null && trees[i] instanceof TreeParent) {
|
||||||
|
if ( ((TreeParent)trees[i]).getNode() == node.getParent() ) {
|
||||||
|
return (TreeParent)trees[i];
|
||||||
|
} else if ( ((TreeParent)trees[i]).hasChildren() ){
|
||||||
|
TreeParent tree = findParentOfNode( ((TreeParent)trees[i]).getChildren(), node );
|
||||||
|
if (tree != null) return tree;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null; // nothing found
|
||||||
|
}
|
||||||
|
|
||||||
|
public TreeParent findParentOfNode(IASTNode node) {
|
||||||
|
if (node == null || node.getParent() == null) return null;
|
||||||
|
|
||||||
|
Iterator itr = children.iterator();
|
||||||
|
while (itr.hasNext()) {
|
||||||
|
Object o = itr.next();
|
||||||
|
if (o != null && o instanceof TreeParent) {
|
||||||
|
if ( ((TreeParent)o).getNode() == node.getParent() ) {
|
||||||
|
return (TreeParent)o;
|
||||||
|
} else if ( ((TreeParent)o).hasChildren() ){
|
||||||
|
TreeParent tree = findParentOfNode( ((TreeParent)o).getChildren(), node );
|
||||||
|
if (tree != null) return tree;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null; // nothing found
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|