Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2014-06-04 17:37:21 +0000
committerSergey Prigogin2014-06-04 17:43:15 +0000
commit7df3a1a6884912bc83efd3f6aeb31ba09125fc6d (patch)
tree0486b4796a04768e5fcea1d9b0094f396202c7b2
parent5982b57a42796ca39d70499efd2b9e2e42eb7a41 (diff)
downloadorg.eclipse.cdt-7df3a1a6884912bc83efd3f6aeb31ba09125fc6d.tar.gz
org.eclipse.cdt-7df3a1a6884912bc83efd3f6aeb31ba09125fc6d.tar.xz
org.eclipse.cdt-7df3a1a6884912bc83efd3f6aeb31ba09125fc6d.zip
Bug 436616 - NPE in ASTCommenter$PreprocessorRangeChecker.checkOffsets
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenter.java36
1 files changed, 20 insertions, 16 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenter.java
index 9fd70e52f6f..921e594e941 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/ASTCommenter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2013 Institute for Software, HSR Hochschule fuer Technik
+ * Copyright (c) 2008, 2014 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -41,12 +41,13 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
/**
* This is the starting point of the entire comment handling process. The creation of the
- * NodeCommentMap is based on the IASTTranslationUnit. From this TranslationUnit the comments
- * are extracted and skipped if they belong not to the same workspace. An ASTCommenterVisitor
- * is initialized with this collection of comments. And the visit process can start.
+ * {@link NodeCommentMap} is based on the {@link IASTTranslationUnit}. From this translation unit
+ * the comments are extracted and skipped if they belong not to the same workspace.
+ * An {@link ASTCommenterVisitor} is initialized with this collection of comments. And the visit
+ * process can start.
*
- * @see org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommenter
- * @see org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap
+ * @see NodeCommenter
+ * @see NodeCommentMap
*
* @author Guido Zgraggen IFS
*/
@@ -65,20 +66,23 @@ public class ASTCommenter {
private int checkOffsets(IASTNode node) {
IASTFileLocation nodeLocation = node.getFileLocation();
+ if (nodeLocation == null)
+ return PROCESS_SKIP;
+
int nodeEndOffset = nodeLocation.getNodeOffset() + nodeLocation.getNodeLength();
- int status = PROCESS_CONTINUE;
- boolean nodeInBetweenCommentAndPpStmt = nodeEndOffset > commentLocation.getNodeOffset() && nodeEndOffset < ppStmtOffset;
+ boolean nodeInBetweenCommentAndPpStmt =
+ nodeEndOffset > commentLocation.getNodeOffset() && nodeEndOffset < ppStmtOffset;
if (isCommentOnSameLine(node) || nodeInBetweenCommentAndPpStmt) {
isPrePpStmtComment = false;
- status = PROCESS_ABORT;
+ return PROCESS_ABORT;
} else if (nodeEndOffset < commentLocation.getNodeOffset()) {
- status = PROCESS_SKIP;
+ return PROCESS_SKIP;
} else if (nodeLocation.getNodeOffset() > ppStmtOffset) {
- status = PROCESS_ABORT;
+ return PROCESS_ABORT;
}
- return status;
+ return PROCESS_CONTINUE;
}
private boolean isCommentOnSameLine(IASTNode node) {
@@ -184,8 +188,8 @@ public class ASTCommenter {
}
/**
- * Adds all comments given in {@code ast} to the {@code commentMap}. Calling this twice will have no
- * effect.
+ * Adds all comments given in {@code ast} to the {@code commentMap}. Calling this twice has
+ * no effect.
*
* @param ast
* the AST which contains the comments to add
@@ -197,7 +201,7 @@ public class ASTCommenter {
return;
}
IASTComment[] commentsArray = ast.getComments();
- List<IASTComment> comments = new ArrayList<IASTComment>(commentsArray.length);
+ List<IASTComment> comments = new ArrayList<>(commentsArray.length);
for (IASTComment comment : commentsArray) {
if (comment.isPartOfTranslationUnitFile()) {
comments.add(comment);
@@ -245,7 +249,7 @@ public class ASTCommenter {
return;
}
- List<IASTComment> freestandingComments = new ArrayList<IASTComment>(comments.size());
+ List<IASTComment> freestandingComments = new ArrayList<>(comments.size());
Iterator<IASTPreprocessorStatement> statementsIter = preprocessorStatements.iterator();
Iterator<IASTComment> commentIter = comments.iterator();
IASTPreprocessorStatement curStatement = getNextNodeInTu(statementsIter);

Back to the top