mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Hoda Amer.
- The core patch modifies the CModelBuilder to recognize pointers to functions. - The tests patch changes the CModelElementsTests and puts the pointer to function test back in its original place (as a variable). - The ui patch modifies the NewClassWizard to use search in finding a base class ( the new indexer must be on for it to work ).
This commit is contained in:
parent
7b4de80105
commit
5aae8a1f5d
8 changed files with 131 additions and 89 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
2003-07-30 Hoda Amer
|
||||||
|
The CModelElementsTests has the pointer to function test back in its original place
|
||||||
|
(a variable)
|
||||||
|
|
||||||
2003-07-30 Victor Mozgin
|
2003-07-30 Victor Mozgin
|
||||||
Moved testBug39532() from ASTFailedTests.java to QuickParseASTTests.java.
|
Moved testBug39532() from ASTFailedTests.java to QuickParseASTTests.java.
|
||||||
|
|
||||||
|
|
|
@ -306,10 +306,10 @@ public class CModelElementsTests extends TestCase {
|
||||||
checkLineNumbers((CElement)var3, 75, 75);
|
checkLineNumbers((CElement)var3, 75, 75);
|
||||||
|
|
||||||
// MyPackage ---> function pointer: orig_malloc_hook
|
// MyPackage ---> function pointer: orig_malloc_hook
|
||||||
// IVariable vDecl2 = (IVariable) nsVars.get(3);
|
IVariable vDecl2 = (IVariable) nsVars.get(3);
|
||||||
// assertEquals(vDecl2.getElementName(), new String("orig_malloc_hook"));
|
assertEquals(vDecl2.getElementName(), new String("orig_malloc_hook"));
|
||||||
// assertEquals(vDecl2.getTypeName(), new String ("void*(*)(const char*, int, size_t)"));
|
assertEquals(vDecl2.getTypeName(), new String ("void*(*)(const char*, int, size_t)"));
|
||||||
// checkLineNumbers((CElement)vDecl2, 81, 81);
|
checkLineNumbers((CElement)vDecl2, 81, 81);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkVariableDeclarations(IParent namespace){
|
private void checkVariableDeclarations(IParent namespace){
|
||||||
|
@ -324,20 +324,14 @@ public class CModelElementsTests extends TestCase {
|
||||||
private void checkFunctions(IParent namespace){
|
private void checkFunctions(IParent namespace){
|
||||||
ArrayList nsFunctionDeclarations = namespace.getChildrenOfType(ICElement.C_FUNCTION_DECLARATION);
|
ArrayList nsFunctionDeclarations = namespace.getChildrenOfType(ICElement.C_FUNCTION_DECLARATION);
|
||||||
|
|
||||||
// MyPackage ---> function pointer: orig_malloc_hook
|
|
||||||
IFunctionDeclaration pointerToFunction = (IFunctionDeclaration) nsFunctionDeclarations.get(0);
|
|
||||||
assertEquals(pointerToFunction.getElementName(), new String("orig_malloc_hook"));
|
|
||||||
// assertEquals(pointerToFunction.getReturnType(), new String ("void*(*)(const char*, int, size_t)"));
|
|
||||||
checkLineNumbers((CElement)pointerToFunction, 81, 81);
|
|
||||||
|
|
||||||
// MyPackage ---> function: void foo()
|
// MyPackage ---> function: void foo()
|
||||||
IFunctionDeclaration f1 = (IFunctionDeclaration) nsFunctionDeclarations.get(1);
|
IFunctionDeclaration f1 = (IFunctionDeclaration) nsFunctionDeclarations.get(0);
|
||||||
assertEquals(f1.getElementName(), new String("foo"));
|
assertEquals(f1.getElementName(), new String("foo"));
|
||||||
assertEquals(f1.getReturnType(), new String("void"));
|
assertEquals(f1.getReturnType(), new String("void"));
|
||||||
checkLineNumbers((CElement)f1, 85, 85);
|
checkLineNumbers((CElement)f1, 85, 85);
|
||||||
|
|
||||||
// MyPackage ---> function: char* foo(int&, char**)
|
// MyPackage ---> function: char* foo(int&, char**)
|
||||||
IFunctionDeclaration f2 = (IFunctionDeclaration) nsFunctionDeclarations.get(2);
|
IFunctionDeclaration f2 = (IFunctionDeclaration) nsFunctionDeclarations.get(1);
|
||||||
assertEquals(f2.getElementName(), new String("foo"));
|
assertEquals(f2.getElementName(), new String("foo"));
|
||||||
assertEquals(f2.getReturnType(), new String("char*"));
|
assertEquals(f2.getReturnType(), new String("char*"));
|
||||||
checkLineNumbers((CElement)f2, 87, 88);
|
checkLineNumbers((CElement)f2, 87, 88);
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
2003-07-30 Hoda Amer
|
||||||
|
The C Model recognizes pointers to functions.
|
||||||
|
|
||||||
2003-07-29 Alain Magloire
|
2003-07-29 Alain Magloire
|
||||||
|
|
||||||
To discover if an application has debug info for DWARF-2 format
|
To discover if an application has debug info for DWARF-2 format
|
||||||
|
|
|
@ -165,22 +165,7 @@ public class CModelBuilder {
|
||||||
generateModelElements(parent, (IASTTypedefDeclaration) declaration);
|
generateModelElements(parent, (IASTTypedefDeclaration) declaration);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if ((declaration instanceof IASTPointerToFunction)
|
createSimpleElement(parent, declaration, false);
|
||||||
|| (declaration instanceof IASTPointerToMethod))
|
|
||||||
{
|
|
||||||
createPointerToFunction(parent, declaration, false);
|
|
||||||
}
|
|
||||||
// variable or field
|
|
||||||
else */
|
|
||||||
if (declaration instanceof IASTVariable)
|
|
||||||
{
|
|
||||||
createVariableSpecification(parent, (IASTVariable)declaration, false);
|
|
||||||
}
|
|
||||||
// function or method
|
|
||||||
else if(declaration instanceof IASTFunction )
|
|
||||||
{
|
|
||||||
createFunctionSpecification(parent, (IASTFunction)declaration, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void generateModelElements (Parent parent, IASTNamespaceDefinition declaration) throws ASTNotImplementedException{
|
protected void generateModelElements (Parent parent, IASTNamespaceDefinition declaration) throws ASTNotImplementedException{
|
||||||
|
@ -208,31 +193,13 @@ public class CModelBuilder {
|
||||||
CElement element = createAbstractElement(parent, abstractDeclaration , true);
|
CElement element = createAbstractElement(parent, abstractDeclaration , true);
|
||||||
// set the element position
|
// set the element position
|
||||||
element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset());
|
element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset());
|
||||||
// set the element lines
|
|
||||||
//element.setLines(templateDeclaration.getTopLine(), templateDeclaration.getBottomLine());
|
|
||||||
// set the template parameters
|
// set the template parameters
|
||||||
String[] parameterTypes = getTemplateParameters(templateDeclaration);
|
String[] parameterTypes = getTemplateParameters(templateDeclaration);
|
||||||
ITemplate classTemplate = (ITemplate) element;
|
ITemplate classTemplate = (ITemplate) element;
|
||||||
classTemplate.setTemplateParameterTypes(parameterTypes);
|
classTemplate.setTemplateParameterTypes(parameterTypes);
|
||||||
}
|
}
|
||||||
ITemplate template = null;
|
ITemplate template = null;
|
||||||
|
template = (ITemplate) createSimpleElement(parent, declaration, true);
|
||||||
/* if ((declaration instanceof IASTPointerToFunction)
|
|
||||||
|| (declaration instanceof IASTPointerToMethod))
|
|
||||||
{
|
|
||||||
template = (ITemplate) createPointerToFunction(parent, declaration, true);
|
|
||||||
}
|
|
||||||
// template of variable or field
|
|
||||||
else */
|
|
||||||
if (declaration instanceof IASTVariable)
|
|
||||||
{
|
|
||||||
template = (ITemplate) createVariableSpecification(parent, (IASTVariable)declaration, true);
|
|
||||||
}
|
|
||||||
// Template of function or method
|
|
||||||
else if(declaration instanceof IASTFunction )
|
|
||||||
{
|
|
||||||
template = (ITemplate) createFunctionSpecification(parent, (IASTFunction)declaration, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(template != null){
|
if(template != null){
|
||||||
CElement element = (CElement)template;
|
CElement element = (CElement)template;
|
||||||
|
@ -278,6 +245,21 @@ public class CModelBuilder {
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CElement createSimpleElement(Parent parent, IASTDeclaration declaration, boolean isTemplate)throws ASTNotImplementedException{
|
||||||
|
|
||||||
|
CElement element = null;
|
||||||
|
if (declaration instanceof IASTVariable)
|
||||||
|
{
|
||||||
|
element = createVariableSpecification(parent, (IASTVariable)declaration, isTemplate);
|
||||||
|
}
|
||||||
|
// function or method
|
||||||
|
else if(declaration instanceof IASTFunction )
|
||||||
|
{
|
||||||
|
element = createFunctionSpecification(parent, (IASTFunction)declaration, isTemplate);
|
||||||
|
}
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
protected Include createInclusion(Parent parent, IASTInclusion inclusion){
|
protected Include createInclusion(Parent parent, IASTInclusion inclusion){
|
||||||
// create element
|
// create element
|
||||||
Include element = new Include((CElement)parent, inclusion.getName(), !inclusion.isLocal());
|
Include element = new Include((CElement)parent, inclusion.getName(), !inclusion.isLocal());
|
||||||
|
@ -642,9 +624,22 @@ public class CModelBuilder {
|
||||||
type.append(getPointerOperation(declaration));
|
type.append(getPointerOperation(declaration));
|
||||||
type.append(getArrayQualifiers(declaration));
|
type.append(getArrayQualifiers(declaration));
|
||||||
|
|
||||||
|
type.append(getPointerToFunctionType(declaration));
|
||||||
return type.toString();
|
return type.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getPointerToFunctionType(IASTAbstractDeclaration declaration){
|
||||||
|
StringBuffer type = new StringBuffer();
|
||||||
|
ASTPointerOperator po = declaration.getPointerToFunctionOperator();
|
||||||
|
if(po != null){
|
||||||
|
type.append("(");
|
||||||
|
type.append(getPointerOperator(po));
|
||||||
|
type.append(")");
|
||||||
|
String[] parameters =getParameterTypes(declaration.getParameters());
|
||||||
|
type.append(getParametersString(parameters));
|
||||||
|
}
|
||||||
|
return type.toString();
|
||||||
|
}
|
||||||
private String getDeclarationType(IASTAbstractDeclaration declaration){
|
private String getDeclarationType(IASTAbstractDeclaration declaration){
|
||||||
StringBuffer type = new StringBuffer();
|
StringBuffer type = new StringBuffer();
|
||||||
|
|
||||||
|
@ -686,21 +681,28 @@ public class CModelBuilder {
|
||||||
Iterator i = declaration.getPointerOperators();
|
Iterator i = declaration.getPointerOperators();
|
||||||
while(i.hasNext()){
|
while(i.hasNext()){
|
||||||
ASTPointerOperator po = (ASTPointerOperator) i.next();
|
ASTPointerOperator po = (ASTPointerOperator) i.next();
|
||||||
if(po == ASTPointerOperator.POINTER)
|
pointerString.append(getPointerOperator(po));
|
||||||
pointerString.append("*");
|
|
||||||
|
|
||||||
if(po == ASTPointerOperator.REFERENCE)
|
|
||||||
pointerString.append("&");
|
|
||||||
|
|
||||||
if(po == ASTPointerOperator.CONST_POINTER)
|
|
||||||
pointerString.append(" const");
|
|
||||||
|
|
||||||
if(po == ASTPointerOperator.VOLATILE_POINTER)
|
|
||||||
pointerString.append(" volatile");
|
|
||||||
}
|
}
|
||||||
return pointerString.toString();
|
return pointerString.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getPointerOperator(ASTPointerOperator po){
|
||||||
|
String pointerString ="";
|
||||||
|
if(po == ASTPointerOperator.POINTER)
|
||||||
|
pointerString = ("*");
|
||||||
|
|
||||||
|
if(po == ASTPointerOperator.REFERENCE)
|
||||||
|
pointerString =("&");
|
||||||
|
|
||||||
|
if(po == ASTPointerOperator.CONST_POINTER)
|
||||||
|
pointerString =("* const");
|
||||||
|
|
||||||
|
if(po == ASTPointerOperator.VOLATILE_POINTER)
|
||||||
|
pointerString =("* volatile");
|
||||||
|
|
||||||
|
return pointerString;
|
||||||
|
}
|
||||||
|
|
||||||
private String getArrayQualifiers(IASTAbstractDeclaration declaration){
|
private String getArrayQualifiers(IASTAbstractDeclaration declaration){
|
||||||
StringBuffer arrayString = new StringBuffer();
|
StringBuffer arrayString = new StringBuffer();
|
||||||
Iterator i = declaration.getArrayModifiers();
|
Iterator i = declaration.getArrayModifiers();
|
||||||
|
@ -714,18 +716,21 @@ public class CModelBuilder {
|
||||||
private String[] getFunctionParameterTypes(IASTFunction functionDeclaration)
|
private String[] getFunctionParameterTypes(IASTFunction functionDeclaration)
|
||||||
{
|
{
|
||||||
Iterator parameters = functionDeclaration.getParameters();
|
Iterator parameters = functionDeclaration.getParameters();
|
||||||
List paramList = new ArrayList();
|
return getParameterTypes(parameters);
|
||||||
while (parameters.hasNext()){
|
}
|
||||||
|
|
||||||
|
private String[] getParameterTypes(Iterator parameters){
|
||||||
|
List paramList = new ArrayList();
|
||||||
|
while (parameters.hasNext()){
|
||||||
IASTParameterDeclaration param = (IASTParameterDeclaration)parameters.next();
|
IASTParameterDeclaration param = (IASTParameterDeclaration)parameters.next();
|
||||||
paramList.add(getType(param));
|
paramList.add(getType(param));
|
||||||
}
|
}
|
||||||
String[] parameterTypes = new String[paramList.size()];
|
String[] parameterTypes = new String[paramList.size()];
|
||||||
for(int i=0; i<paramList.size(); ++i){
|
for(int i=0; i<paramList.size(); ++i){
|
||||||
parameterTypes[i] = (String)paramList.get(i);
|
parameterTypes[i] = (String)paramList.get(i);
|
||||||
}
|
}
|
||||||
return parameterTypes;
|
return parameterTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getParametersString(String[] parameterTypes)
|
private String getParametersString(String[] parameterTypes)
|
||||||
{
|
{
|
||||||
StringBuffer parameters = new StringBuffer("");
|
StringBuffer parameters = new StringBuffer("");
|
||||||
|
|
|
@ -72,6 +72,14 @@ public class BasicSearchMatch implements IMatch {
|
||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IPath getLocation() {
|
||||||
|
if(resource != null)
|
||||||
|
return resource.getLocation();
|
||||||
|
else if (path != null)
|
||||||
|
return path;
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
|
||||||
public int getStartOffset() {
|
public int getStartOffset() {
|
||||||
return startOffset;
|
return startOffset;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
package org.eclipse.cdt.core.search;
|
package org.eclipse.cdt.core.search;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
|
@ -33,6 +34,8 @@ public interface IMatch {
|
||||||
|
|
||||||
IResource getResource();
|
IResource getResource();
|
||||||
|
|
||||||
|
IPath getLocation();
|
||||||
|
|
||||||
int getStartOffset();
|
int getStartOffset();
|
||||||
|
|
||||||
int getEndOffset();
|
int getEndOffset();
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
2003-07-30 Hoda Amer
|
||||||
|
The New Class Wizard uses search to look for base classes in the workspace.
|
||||||
|
|
||||||
2003-07-29 Andrew Niefer
|
2003-07-29 Andrew Niefer
|
||||||
- Refactoring Search Result Collecting:
|
- Refactoring Search Result Collecting:
|
||||||
* CSearchResultCollector now extends BasicSearchResultCollector
|
* CSearchResultCollector now extends BasicSearchResultCollector
|
||||||
|
|
|
@ -15,7 +15,7 @@ import java.io.ByteArrayInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.LinkedList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -27,6 +27,12 @@ import org.eclipse.cdt.core.model.IOpenable;
|
||||||
import org.eclipse.cdt.core.model.IParent;
|
import org.eclipse.cdt.core.model.IParent;
|
||||||
import org.eclipse.cdt.core.model.IStructure;
|
import org.eclipse.cdt.core.model.IStructure;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
||||||
|
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
|
||||||
|
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||||
|
import org.eclipse.cdt.core.search.ICSearchPattern;
|
||||||
|
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||||
|
import org.eclipse.cdt.core.search.SearchEngine;
|
||||||
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
|
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
|
||||||
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
|
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
|
||||||
import org.eclipse.cdt.internal.ui.dialogs.StatusUtil;
|
import org.eclipse.cdt.internal.ui.dialogs.StatusUtil;
|
||||||
|
@ -42,7 +48,7 @@ import org.eclipse.cdt.internal.ui.wizards.dialogfields.SelectionButtonDialogFie
|
||||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.Separator;
|
import org.eclipse.cdt.internal.ui.wizards.dialogfields.Separator;
|
||||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
|
import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
|
||||||
import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringDialogField;
|
import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringDialogField;
|
||||||
import org.eclipse.cdt.ui.CElementLabelProvider;
|
import org.eclipse.cdt.ui.CSearchResultLabelProvider;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.cdt.ui.CodeGeneration;
|
import org.eclipse.cdt.ui.CodeGeneration;
|
||||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||||
|
@ -103,7 +109,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
||||||
// the created class element
|
// the created class element
|
||||||
private /*IStructure*/ ICElement createdClass = null;
|
private /*IStructure*/ ICElement createdClass = null;
|
||||||
|
|
||||||
private ArrayList elementsOfTypeClassInProject = null;
|
private List elementsOfTypeClassInProject = null;
|
||||||
|
|
||||||
// Controls
|
// Controls
|
||||||
private StringDialogField fClassNameDialogField;
|
private StringDialogField fClassNameDialogField;
|
||||||
|
@ -119,6 +125,9 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
||||||
protected IStatus fClassNameStatus;
|
protected IStatus fClassNameStatus;
|
||||||
protected IStatus fBaseClassStatus;
|
protected IStatus fBaseClassStatus;
|
||||||
|
|
||||||
|
BasicSearchResultCollector resultCollector;
|
||||||
|
SearchEngine searchEngine;
|
||||||
|
|
||||||
// -------------------- Initialization ------------------
|
// -------------------- Initialization ------------------
|
||||||
public NewClassWizardPage(IStructuredSelection selection) {
|
public NewClassWizardPage(IStructuredSelection selection) {
|
||||||
super(PAGE_NAME);
|
super(PAGE_NAME);
|
||||||
|
@ -163,6 +172,9 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
||||||
fClassNameStatus= new StatusInfo();
|
fClassNameStatus= new StatusInfo();
|
||||||
fBaseClassStatus= new StatusInfo();
|
fBaseClassStatus= new StatusInfo();
|
||||||
|
|
||||||
|
resultCollector = new BasicSearchResultCollector ();
|
||||||
|
searchEngine = new SearchEngine();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
|
@ -297,9 +309,9 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
||||||
|
|
||||||
private void classPageChangeControlPressed(DialogField field) {
|
private void classPageChangeControlPressed(DialogField field) {
|
||||||
if (field == fBaseClassDialogField) {
|
if (field == fBaseClassDialogField) {
|
||||||
ICElement element= chooseBaseClass();
|
BasicSearchMatch element= (BasicSearchMatch)chooseBaseClass();
|
||||||
if (element != null) {
|
if (element != null) {
|
||||||
fBaseClassDialogField.setText(element.getElementName());
|
fBaseClassDialogField.setText(element.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -376,7 +388,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getChildrenOfTypeClass(IParent parent, ArrayList elementsFound, IProgressMonitor monitor, int worked){
|
private void getChildrenOfTypeClass(IParent parent, List elementsFound, IProgressMonitor monitor, int worked){
|
||||||
ICElement[] elements = parent.getChildren();
|
ICElement[] elements = parent.getChildren();
|
||||||
monitor.worked( worked );
|
monitor.worked( worked );
|
||||||
|
|
||||||
|
@ -391,20 +403,29 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList getClassElementsInProject(){
|
private void searchForClasses(ICProject cProject, List elementsFound, IProgressMonitor monitor, int worked){
|
||||||
|
ICSearchPattern pattern = SearchEngine.createSearchPattern( "*", ICSearchConstants.CLASS, ICSearchConstants.DECLARATIONS, false );
|
||||||
|
// TODO: change that to project scope later
|
||||||
|
ICSearchScope scope = SearchEngine.createWorkspaceScope();;
|
||||||
|
|
||||||
|
searchEngine.search(CUIPlugin.getWorkspace(), pattern, scope, resultCollector);
|
||||||
|
elementsFound.addAll(resultCollector.getSearchResults());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List getClassElementsInProject(){
|
||||||
return elementsOfTypeClassInProject;
|
return elementsOfTypeClassInProject;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList findClassElementsInProject(){
|
private List findClassElementsInProject(){
|
||||||
if(eSelection == null){
|
if(eSelection == null){
|
||||||
return new ArrayList();
|
return new LinkedList();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( elementsOfTypeClassInProject != null ){
|
if( elementsOfTypeClassInProject != null ){
|
||||||
return elementsOfTypeClassInProject;
|
return elementsOfTypeClassInProject;
|
||||||
}
|
}
|
||||||
|
|
||||||
elementsOfTypeClassInProject = new ArrayList();
|
elementsOfTypeClassInProject = new LinkedList();
|
||||||
IRunnableWithProgress runnable= new IRunnableWithProgress() {
|
IRunnableWithProgress runnable= new IRunnableWithProgress() {
|
||||||
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
|
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
|
||||||
if (monitor == null) {
|
if (monitor == null) {
|
||||||
|
@ -413,7 +434,8 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
||||||
monitor.beginTask(NewWizardMessages.getString("NewClassWizardPage.operations.getProjectClasses"), 5); //$NON-NLS-1$
|
monitor.beginTask(NewWizardMessages.getString("NewClassWizardPage.operations.getProjectClasses"), 5); //$NON-NLS-1$
|
||||||
try{
|
try{
|
||||||
ICProject cProject = eSelection.getCProject();
|
ICProject cProject = eSelection.getCProject();
|
||||||
getChildrenOfTypeClass((IParent)cProject, elementsOfTypeClassInProject, monitor, 1);
|
searchForClasses(cProject, elementsOfTypeClassInProject, monitor, 1);
|
||||||
|
//getChildrenOfTypeClass((IParent)cProject, elementsOfTypeClassInProject, monitor, 1);
|
||||||
monitor.worked(5);
|
monitor.worked(5);
|
||||||
} finally{
|
} finally{
|
||||||
monitor.done();
|
monitor.done();
|
||||||
|
@ -431,18 +453,18 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
||||||
return elementsOfTypeClassInProject;
|
return elementsOfTypeClassInProject;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ICElement chooseBaseClass(){
|
protected Object chooseBaseClass(){
|
||||||
// find the available classes in this project
|
// find the available classes in this project
|
||||||
ArrayList elementsFound = findClassElementsInProject();
|
List elementsFound = findClassElementsInProject();
|
||||||
|
|
||||||
ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), new CElementLabelProvider());
|
ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), new CSearchResultLabelProvider());
|
||||||
dialog.setTitle(NewWizardMessages.getString("BaseClassSelectionDialog.title")); //$NON-NLS-1$
|
dialog.setTitle(NewWizardMessages.getString("BaseClassSelectionDialog.title")); //$NON-NLS-1$
|
||||||
dialog.setMessage(NewWizardMessages.getString("BaseClassSelectionDialog.message")); //$NON-NLS-1$
|
dialog.setMessage(NewWizardMessages.getString("BaseClassSelectionDialog.message")); //$NON-NLS-1$
|
||||||
dialog.setElements(elementsFound.toArray());
|
dialog.setElements(elementsFound.toArray());
|
||||||
dialog.setFilter("*");
|
dialog.setFilter("*");
|
||||||
|
|
||||||
if (dialog.open() == ElementListSelectionDialog.OK) {
|
if (dialog.open() == ElementListSelectionDialog.OK) {
|
||||||
ICElement element= (ICElement) dialog.getFirstResult();
|
Object element= dialog.getFirstResult();
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -738,11 +760,11 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
||||||
if((baseClassName != null) && (baseClassName.length() > 0))
|
if((baseClassName != null) && (baseClassName.length() > 0))
|
||||||
{
|
{
|
||||||
extendingBase = true;
|
extendingBase = true;
|
||||||
ArrayList classElements = findClassElementsInProject();
|
List classElements = findClassElementsInProject();
|
||||||
ICElement baseClass = findInList(baseClassName, classElements);
|
BasicSearchMatch baseClass = (BasicSearchMatch)findInList(baseClassName, classElements);
|
||||||
|
|
||||||
if(baseClass != null){
|
if(baseClass != null){
|
||||||
baseClassFileName = baseClass.getUnderlyingResource().getName();
|
baseClassFileName = baseClass.getLocation().toString();
|
||||||
} else {
|
} else {
|
||||||
baseClassFileName = baseClassName + HEADER_EXT;
|
baseClassFileName = baseClassName + HEADER_EXT;
|
||||||
}
|
}
|
||||||
|
@ -930,7 +952,7 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
||||||
// class name must follow the C/CPP convensions
|
// class name must follow the C/CPP convensions
|
||||||
|
|
||||||
// if class does not exist, give warning
|
// if class does not exist, give warning
|
||||||
ArrayList elementsFound = findClassElementsInProject();
|
List elementsFound = findClassElementsInProject();
|
||||||
if(!foundInList(getBaseClassName(), elementsFound)){
|
if(!foundInList(getBaseClassName(), elementsFound)){
|
||||||
status.setWarning(NewWizardMessages.getString("NewClassWizardPage.warning.BaseClassNotExists")); //$NON-NLS-1$
|
status.setWarning(NewWizardMessages.getString("NewClassWizardPage.warning.BaseClassNotExists")); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
@ -938,17 +960,17 @@ public class NewClassWizardPage extends WizardPage implements Listener {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ICElement findInList(String name, ArrayList elements){
|
private Object findInList(String name, List elements){
|
||||||
Iterator i = elements.iterator();
|
Iterator i = elements.iterator();
|
||||||
while (i.hasNext()){
|
while (i.hasNext()){
|
||||||
ICElement element = (ICElement)i.next();
|
BasicSearchMatch element = (BasicSearchMatch)i.next();
|
||||||
if (name.equals(element.getElementName()))
|
if (name.equals(element.getName()))
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean foundInList(String name, ArrayList elements){
|
private boolean foundInList(String name, List elements){
|
||||||
if(findInList(name, elements) != null)
|
if(findInList(name, elements) != null)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue