mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix NPE bug 36976.
This commit is contained in:
parent
452d55abef
commit
c8cfea5fba
1 changed files with 148 additions and 110 deletions
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.compare;
|
package org.eclipse.cdt.internal.ui.compare;
|
||||||
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -26,6 +25,7 @@ import org.eclipse.cdt.internal.core.dom.EnumerationSpecifier;
|
||||||
import org.eclipse.cdt.internal.core.dom.IOffsetable;
|
import org.eclipse.cdt.internal.core.dom.IOffsetable;
|
||||||
import org.eclipse.cdt.internal.core.dom.Inclusion;
|
import org.eclipse.cdt.internal.core.dom.Inclusion;
|
||||||
import org.eclipse.cdt.internal.core.dom.Macro;
|
import org.eclipse.cdt.internal.core.dom.Macro;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.Name;
|
||||||
import org.eclipse.cdt.internal.core.dom.NamespaceDefinition;
|
import org.eclipse.cdt.internal.core.dom.NamespaceDefinition;
|
||||||
import org.eclipse.cdt.internal.core.dom.ParameterDeclarationClause;
|
import org.eclipse.cdt.internal.core.dom.ParameterDeclarationClause;
|
||||||
import org.eclipse.cdt.internal.core.dom.SimpleDeclaration;
|
import org.eclipse.cdt.internal.core.dom.SimpleDeclaration;
|
||||||
|
@ -35,7 +35,6 @@ import org.eclipse.cdt.internal.core.dom.TypeSpecifier;
|
||||||
import org.eclipse.cdt.internal.core.parser.Parser;
|
import org.eclipse.cdt.internal.core.parser.Parser;
|
||||||
import org.eclipse.cdt.internal.parser.IStructurizerCallback;
|
import org.eclipse.cdt.internal.parser.IStructurizerCallback;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author alain
|
* @author alain
|
||||||
* TODO: this should be remove when the new parser provides proper callbacks.
|
* TODO: this should be remove when the new parser provides proper callbacks.
|
||||||
|
@ -46,7 +45,6 @@ public class ComparatorModelBuilder {
|
||||||
IStructurizerCallback callback;
|
IStructurizerCallback callback;
|
||||||
String code;
|
String code;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public ComparatorModelBuilder(IStructurizerCallback cb, String buffer) {
|
public ComparatorModelBuilder(IStructurizerCallback cb, String buffer) {
|
||||||
|
@ -72,8 +70,7 @@ public class ComparatorModelBuilder {
|
||||||
IOffsetable offsetable = (IOffsetable) i.next();
|
IOffsetable offsetable = (IOffsetable) i.next();
|
||||||
if (offsetable instanceof Inclusion) {
|
if (offsetable instanceof Inclusion) {
|
||||||
createInclusion((Inclusion) offsetable);
|
createInclusion((Inclusion) offsetable);
|
||||||
}
|
} else if (offsetable instanceof Macro) {
|
||||||
else if (offsetable instanceof Macro){
|
|
||||||
createMacro((Macro) offsetable);
|
createMacro((Macro) offsetable);
|
||||||
} else if (offsetable instanceof Declaration) {
|
} else if (offsetable instanceof Declaration) {
|
||||||
generateModelElements((Declaration) offsetable);
|
generateModelElements((Declaration) offsetable);
|
||||||
|
@ -163,14 +160,16 @@ public class ComparatorModelBuilder {
|
||||||
ParameterDeclarationClause pdc = declarator.getParms();
|
ParameterDeclarationClause pdc = declarator.getParms();
|
||||||
if (pdc == null) {
|
if (pdc == null) {
|
||||||
createVariableSpecification(simpleDeclaration, declarator);
|
createVariableSpecification(simpleDeclaration, declarator);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
createFunctionSpecification(simpleDeclaration, declarator, pdc, false);
|
createFunctionSpecification(simpleDeclaration, declarator, pdc, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createTemplateElement(TemplateDeclaration templateDeclaration, SimpleDeclaration simpleDeclaration, Declarator declarator){
|
private void createTemplateElement(
|
||||||
|
TemplateDeclaration templateDeclaration,
|
||||||
|
SimpleDeclaration simpleDeclaration,
|
||||||
|
Declarator declarator) {
|
||||||
// TODO: no template in the old parser
|
// TODO: no template in the old parser
|
||||||
ParameterDeclarationClause pdc = declarator.getParms();
|
ParameterDeclarationClause pdc = declarator.getParms();
|
||||||
if (pdc != null) {
|
if (pdc != null) {
|
||||||
|
@ -191,9 +190,14 @@ public class ComparatorModelBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createEnumeration(EnumerationSpecifier enumSpecifier) {
|
private void createEnumeration(EnumerationSpecifier enumSpecifier) {
|
||||||
callback.structDeclBegin(enumSpecifier.getName().toString(), ICElement.C_ENUMERATION,
|
callback.structDeclBegin(
|
||||||
enumSpecifier.getName().getStartOffset(), enumSpecifier.getName().length(),
|
enumSpecifier.getName().toString(),
|
||||||
enumSpecifier.getStartingOffset(), 0, 0);
|
ICElement.C_ENUMERATION,
|
||||||
|
enumSpecifier.getName().getStartOffset(),
|
||||||
|
enumSpecifier.getName().length(),
|
||||||
|
enumSpecifier.getStartingOffset(),
|
||||||
|
0,
|
||||||
|
0);
|
||||||
callback.structDeclEnd(enumSpecifier.getTotalLength(), 0);
|
callback.structDeclEnd(enumSpecifier.getTotalLength(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,8 +205,7 @@ public class ComparatorModelBuilder {
|
||||||
// create element
|
// create element
|
||||||
String className = (classSpecifier.getName() == null) ? "" : classSpecifier.getName().toString();
|
String className = (classSpecifier.getName() == null) ? "" : classSpecifier.getName().toString();
|
||||||
int kind;
|
int kind;
|
||||||
switch( classSpecifier.getClassKey() )
|
switch (classSpecifier.getClassKey()) {
|
||||||
{
|
|
||||||
case ClassKey.t_class :
|
case ClassKey.t_class :
|
||||||
kind = ICElement.C_CLASS;
|
kind = ICElement.C_CLASS;
|
||||||
break;
|
break;
|
||||||
|
@ -215,47 +218,82 @@ public class ComparatorModelBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
// set element position
|
// set element position
|
||||||
if( classSpecifier.getName() != null )
|
if (classSpecifier.getName() != null) {
|
||||||
{
|
callback.structDeclBegin(
|
||||||
callback.structDeclBegin(className, kind,
|
className,
|
||||||
classSpecifier.getName().getStartOffset(), classSpecifier.getName().length(),
|
kind,
|
||||||
classSpecifier.getStartingOffset(), 0, 0);
|
classSpecifier.getName().getStartOffset(),
|
||||||
}
|
classSpecifier.getName().length(),
|
||||||
else
|
classSpecifier.getStartingOffset(),
|
||||||
{
|
0,
|
||||||
callback.structDeclBegin(className, kind,
|
0);
|
||||||
classSpecifier.getClassKeyToken().getOffset(), classSpecifier.getClassKeyToken().getLength(),
|
} else {
|
||||||
classSpecifier.getStartingOffset(), 0, 0);
|
callback.structDeclBegin(
|
||||||
|
className,
|
||||||
|
kind,
|
||||||
|
classSpecifier.getClassKeyToken().getOffset(),
|
||||||
|
classSpecifier.getClassKeyToken().getLength(),
|
||||||
|
classSpecifier.getStartingOffset(),
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
|
||||||
}
|
}
|
||||||
callback.structDeclBegin(className, kind,
|
callback.structDeclBegin(
|
||||||
classSpecifier.getClassKeyToken().getOffset(), classSpecifier.getClassKeyToken().getLength(),
|
className,
|
||||||
classSpecifier.getStartingOffset(), 0, 0);
|
kind,
|
||||||
|
classSpecifier.getClassKeyToken().getOffset(),
|
||||||
|
classSpecifier.getClassKeyToken().getLength(),
|
||||||
|
classSpecifier.getStartingOffset(),
|
||||||
|
0,
|
||||||
|
0);
|
||||||
callback.structDeclEnd(classSpecifier.getTotalLength(), 0);
|
callback.structDeclEnd(classSpecifier.getTotalLength(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createTypeDef(Declarator declarator, SimpleDeclaration simpleDeclaration) {
|
private void createTypeDef(Declarator declarator, SimpleDeclaration simpleDeclaration) {
|
||||||
// TODO:No typedef in the old callback
|
// TODO:No typedef in the old callback
|
||||||
String declaratorName = declarator.getName().toString();
|
Name domName = (declarator.getDeclarator() != null) ? declarator.getDeclarator().getName() : declarator.getName();
|
||||||
callback.fieldDecl(declaratorName,
|
String declaratorName = domName.toString();
|
||||||
declarator.getName().getStartOffset(), declarator.getName().length(),
|
callback.fieldDecl(
|
||||||
simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength(),
|
declaratorName,
|
||||||
0, 0, 0);
|
domName.getStartOffset(),
|
||||||
|
domName.length(),
|
||||||
|
simpleDeclaration.getStartingOffset(),
|
||||||
|
simpleDeclaration.getTotalLength(),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createVariableSpecification(SimpleDeclaration simpleDeclaration, Declarator declarator) {
|
private void createVariableSpecification(SimpleDeclaration simpleDeclaration, Declarator declarator) {
|
||||||
String declaratorName = declarator.getName().toString();
|
Name domName = (declarator.getDeclarator() != null) ? declarator.getDeclarator().getName() : declarator.getName();
|
||||||
callback.fieldDecl(declaratorName, declarator.getName().getStartOffset(), declarator.getName().length(),
|
String declaratorName = domName.toString();
|
||||||
simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength(), 0, 0, 0);
|
callback.fieldDecl(
|
||||||
|
declaratorName,
|
||||||
|
domName.getStartOffset(),
|
||||||
|
domName.length(),
|
||||||
|
simpleDeclaration.getStartingOffset(),
|
||||||
|
simpleDeclaration.getTotalLength(),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createFunctionSpecification(SimpleDeclaration simpleDeclaration, Declarator declarator, ParameterDeclarationClause pdc, boolean isTemplate){
|
private void createFunctionSpecification(
|
||||||
String declaratorName = declarator.getName().toString();
|
SimpleDeclaration simpleDeclaration,
|
||||||
callback.functionDeclBegin(declaratorName,
|
Declarator declarator,
|
||||||
declarator.getName().getStartOffset(), declarator.getName().length(),
|
ParameterDeclarationClause pdc,
|
||||||
simpleDeclaration.getStartingOffset(), 0, 0, 0);
|
boolean isTemplate) {
|
||||||
|
Name domName = (declarator.getDeclarator() != null) ? declarator.getDeclarator().getName() : declarator.getName();
|
||||||
|
String declaratorName = domName.toString();
|
||||||
|
callback.functionDeclBegin(
|
||||||
|
declaratorName,
|
||||||
|
domName.getStartOffset(),
|
||||||
|
domName.length(),
|
||||||
|
simpleDeclaration.getStartingOffset(),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0);
|
||||||
callback.functionDeclEnd(simpleDeclaration.getTotalLength(), 0, simpleDeclaration.isFunctionDefinition());
|
callback.functionDeclEnd(simpleDeclaration.getTotalLength(), 0, simpleDeclaration.isFunctionDefinition());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue