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;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
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.Inclusion;
|
||||
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.ParameterDeclarationClause;
|
||||
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.parser.IStructurizerCallback;
|
||||
|
||||
|
||||
/**
|
||||
* @author alain
|
||||
* TODO: this should be remove when the new parser provides proper callbacks.
|
||||
|
@ -46,7 +45,6 @@ public class ComparatorModelBuilder {
|
|||
IStructurizerCallback callback;
|
||||
String code;
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public ComparatorModelBuilder(IStructurizerCallback cb, String buffer) {
|
||||
|
@ -72,8 +70,7 @@ public class ComparatorModelBuilder {
|
|||
IOffsetable offsetable = (IOffsetable) i.next();
|
||||
if (offsetable instanceof Inclusion) {
|
||||
createInclusion((Inclusion) offsetable);
|
||||
}
|
||||
else if (offsetable instanceof Macro){
|
||||
} else if (offsetable instanceof Macro) {
|
||||
createMacro((Macro) offsetable);
|
||||
} else if (offsetable instanceof Declaration) {
|
||||
generateModelElements((Declaration) offsetable);
|
||||
|
@ -163,14 +160,16 @@ public class ComparatorModelBuilder {
|
|||
ParameterDeclarationClause pdc = declarator.getParms();
|
||||
if (pdc == null) {
|
||||
createVariableSpecification(simpleDeclaration, declarator);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
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
|
||||
ParameterDeclarationClause pdc = declarator.getParms();
|
||||
if (pdc != null) {
|
||||
|
@ -191,9 +190,14 @@ public class ComparatorModelBuilder {
|
|||
}
|
||||
|
||||
private void createEnumeration(EnumerationSpecifier enumSpecifier) {
|
||||
callback.structDeclBegin(enumSpecifier.getName().toString(), ICElement.C_ENUMERATION,
|
||||
enumSpecifier.getName().getStartOffset(), enumSpecifier.getName().length(),
|
||||
enumSpecifier.getStartingOffset(), 0, 0);
|
||||
callback.structDeclBegin(
|
||||
enumSpecifier.getName().toString(),
|
||||
ICElement.C_ENUMERATION,
|
||||
enumSpecifier.getName().getStartOffset(),
|
||||
enumSpecifier.getName().length(),
|
||||
enumSpecifier.getStartingOffset(),
|
||||
0,
|
||||
0);
|
||||
callback.structDeclEnd(enumSpecifier.getTotalLength(), 0);
|
||||
}
|
||||
|
||||
|
@ -201,8 +205,7 @@ public class ComparatorModelBuilder {
|
|||
// create element
|
||||
String className = (classSpecifier.getName() == null) ? "" : classSpecifier.getName().toString();
|
||||
int kind;
|
||||
switch( classSpecifier.getClassKey() )
|
||||
{
|
||||
switch (classSpecifier.getClassKey()) {
|
||||
case ClassKey.t_class :
|
||||
kind = ICElement.C_CLASS;
|
||||
break;
|
||||
|
@ -215,47 +218,82 @@ public class ComparatorModelBuilder {
|
|||
}
|
||||
|
||||
// set element position
|
||||
if( classSpecifier.getName() != null )
|
||||
{
|
||||
callback.structDeclBegin(className, kind,
|
||||
classSpecifier.getName().getStartOffset(), classSpecifier.getName().length(),
|
||||
classSpecifier.getStartingOffset(), 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
callback.structDeclBegin(className, kind,
|
||||
classSpecifier.getClassKeyToken().getOffset(), classSpecifier.getClassKeyToken().getLength(),
|
||||
classSpecifier.getStartingOffset(), 0, 0);
|
||||
if (classSpecifier.getName() != null) {
|
||||
callback.structDeclBegin(
|
||||
className,
|
||||
kind,
|
||||
classSpecifier.getName().getStartOffset(),
|
||||
classSpecifier.getName().length(),
|
||||
classSpecifier.getStartingOffset(),
|
||||
0,
|
||||
0);
|
||||
} else {
|
||||
callback.structDeclBegin(
|
||||
className,
|
||||
kind,
|
||||
classSpecifier.getClassKeyToken().getOffset(),
|
||||
classSpecifier.getClassKeyToken().getLength(),
|
||||
classSpecifier.getStartingOffset(),
|
||||
0,
|
||||
0);
|
||||
|
||||
}
|
||||
callback.structDeclBegin(className, kind,
|
||||
classSpecifier.getClassKeyToken().getOffset(), classSpecifier.getClassKeyToken().getLength(),
|
||||
classSpecifier.getStartingOffset(), 0, 0);
|
||||
callback.structDeclBegin(
|
||||
className,
|
||||
kind,
|
||||
classSpecifier.getClassKeyToken().getOffset(),
|
||||
classSpecifier.getClassKeyToken().getLength(),
|
||||
classSpecifier.getStartingOffset(),
|
||||
0,
|
||||
0);
|
||||
callback.structDeclEnd(classSpecifier.getTotalLength(), 0);
|
||||
}
|
||||
|
||||
private void createTypeDef(Declarator declarator, SimpleDeclaration simpleDeclaration) {
|
||||
// TODO:No typedef in the old callback
|
||||
String declaratorName = declarator.getName().toString();
|
||||
callback.fieldDecl(declaratorName,
|
||||
declarator.getName().getStartOffset(), declarator.getName().length(),
|
||||
simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength(),
|
||||
0, 0, 0);
|
||||
Name domName = (declarator.getDeclarator() != null) ? declarator.getDeclarator().getName() : declarator.getName();
|
||||
String declaratorName = domName.toString();
|
||||
callback.fieldDecl(
|
||||
declaratorName,
|
||||
domName.getStartOffset(),
|
||||
domName.length(),
|
||||
simpleDeclaration.getStartingOffset(),
|
||||
simpleDeclaration.getTotalLength(),
|
||||
0,
|
||||
0,
|
||||
0);
|
||||
}
|
||||
|
||||
private void createVariableSpecification(SimpleDeclaration simpleDeclaration, Declarator declarator) {
|
||||
String declaratorName = declarator.getName().toString();
|
||||
callback.fieldDecl(declaratorName, declarator.getName().getStartOffset(), declarator.getName().length(),
|
||||
simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength(), 0, 0, 0);
|
||||
Name domName = (declarator.getDeclarator() != null) ? declarator.getDeclarator().getName() : declarator.getName();
|
||||
String declaratorName = domName.toString();
|
||||
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){
|
||||
String declaratorName = declarator.getName().toString();
|
||||
callback.functionDeclBegin(declaratorName,
|
||||
declarator.getName().getStartOffset(), declarator.getName().length(),
|
||||
simpleDeclaration.getStartingOffset(), 0, 0, 0);
|
||||
private void createFunctionSpecification(
|
||||
SimpleDeclaration simpleDeclaration,
|
||||
Declarator declarator,
|
||||
ParameterDeclarationClause pdc,
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue