Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CaseBreakChecker.java16
-rw-r--r--codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java50
-rw-r--r--codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/CodanCommentMap.java49
-rw-r--r--codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java24
-rw-r--r--codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/ICodanCommentMap.java45
5 files changed, 113 insertions, 71 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CaseBreakChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CaseBreakChecker.java
index 76ed301ad58..29fe5ff3b64 100644
--- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CaseBreakChecker.java
+++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CaseBreakChecker.java
@@ -10,10 +10,8 @@
*******************************************************************************/
package org.eclipse.cdt.codan.internal.checkers;
-import org.eclipse.cdt.codan.checkers.CodanCheckersActivator;
import org.eclipse.cdt.codan.core.cxx.CxxAstUtils;
import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker;
-import org.eclipse.cdt.codan.core.cxx.model.CxxModelsCache;
import org.eclipse.cdt.codan.core.model.ICheckerWithPreferences;
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
@@ -120,12 +118,7 @@ public class CaseBreakChecker extends AbstractIndexAstChecker implements IChecke
_prev_normal_stmnt_offset = 0;
_prev_case_stmnt_offset = 0;
_prev_case_stmnt = null;
- //initilize cache
- try {
- CxxModelsCache.getInstance().getAst(getFile());
- } catch (Exception e) {
- CodanCheckersActivator.log(e);
- }
+ getCommentMap();
}
/**
@@ -215,7 +208,7 @@ public class CaseBreakChecker extends AbstractIndexAstChecker implements IChecke
* @return
*/
public IASTComment getLeadingComment(IASTStatement statement) {
- return CxxAstUtils.getInstance().getLeadingComment(statement);
+ return getCommentMap().getLastLeadingCommentForNode(statement);
}
@@ -224,7 +217,7 @@ public class CaseBreakChecker extends AbstractIndexAstChecker implements IChecke
* @return
*/
public IASTComment getFreestandingComment(IASTStatement statement) {
- return CxxAstUtils.getInstance().getFreestandingComment(statement);
+ return getCommentMap().getLastFreestandingCommentForNode(statement);
}
@Override
@@ -265,6 +258,9 @@ public class CaseBreakChecker extends AbstractIndexAstChecker implements IChecke
_checkEmptyCase = (Boolean) getPreference(getProblemById(ER_ID, getFile()), PARAM_EMPTY_CASE);
_noBreakComment = (String) getPreference(getProblemById(ER_ID, getFile()), PARAM_NO_BREAK_COMMENT);
SwitchFindingVisitor visitor = new SwitchFindingVisitor();
+
ast.accept(visitor);
}
+
+
}
diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java
index 262d60f9622..4fa38cc85e0 100644
--- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java
+++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java
@@ -14,14 +14,10 @@ package org.eclipse.cdt.codan.core.cxx;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
-import org.eclipse.cdt.codan.core.cxx.model.CxxModelsCache;
-import org.eclipse.cdt.codan.core.cxx.model.ICodanCommentMap;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
-import org.eclipse.cdt.core.dom.ast.IASTComment;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
@@ -395,51 +391,5 @@ public final class CxxAstUtils {
return functionNameExpression.getRawSignature().equals("exit"); //$NON-NLS-1$
}
- /**
- * @param statement
- * @return
- */
- public IASTComment getLeadingComment(IASTStatement statement) {
- IASTComment comment = null;
- ICodanCommentMap map = CxxModelsCache.getInstance().getCommentedNodeMap(statement.getTranslationUnit());
- if (map != null) {
- List<IASTComment> comms = map.getLeadingCommentsForNode(statement);
- if (comms.size() > 0) {
- comment = comms.get(comms.size() - 1);
- }
- }
- return comment;
- }
- /**
- * @param statement
- * @return
- */
- public IASTComment getTrailingComment(IASTStatement statement) {
- IASTComment comment = null;
- ICodanCommentMap map = CxxModelsCache.getInstance().getCommentedNodeMap(statement.getTranslationUnit());
- if (map != null) {
- List<IASTComment> comms = map.getTrailingCommentsForNode(statement);
- if (comms.size() > 0) {
- comment = comms.get(0);
- }
- }
- return comment;
- }
-
- /**
- * @param statement
- * @return
- */
- public IASTComment getFreestandingComment(IASTStatement statement) {
- IASTComment comment = null;
- ICodanCommentMap map = CxxModelsCache.getInstance().getCommentedNodeMap(statement.getTranslationUnit());
- if (map != null) {
- List<IASTComment> comms = map.getFreestandingForNode(statement);
- if (comms.size() > 0) {
- comment = comms.get(comms.size() - 1);
- }
- }
- return comment;
- }
}
diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/CodanCommentMap.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/CodanCommentMap.java
index 5bbe037273e..2f841f652f7 100644
--- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/CodanCommentMap.java
+++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/CodanCommentMap.java
@@ -18,7 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
/**
- * Implementation of ICodanCommentMap.
+ * Implementation of ICodanCommentMap.
*/
public class CodanCommentMap implements ICodanCommentMap {
private NodeCommentMap commentedNodeMap;
@@ -50,10 +50,53 @@ public class CodanCommentMap implements ICodanCommentMap {
return commentedNodeMap.getLeadingCommentsForNode(node);
}
- /* (non-Javadoc)
- * @see org.eclipse.cdt.codan.core.cxx.model.ICodanCommentMap#getFreestandingForNode(org.eclipse.cdt.core.dom.ast.IASTStatement)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.cdt.codan.core.cxx.model.ICodanCommentMap#getFreestandingForNode
+ * (org.eclipse.cdt.core.dom.ast.IASTStatement)
*/
public List<IASTComment> getFreestandingForNode(IASTNode node) {
return commentedNodeMap.getFreestandingCommentsForNode(node);
}
+
+ /**
+ * @param node
+ * @return
+ */
+ public IASTComment getLastLeadingCommentForNode(IASTNode node) {
+ IASTComment comment = null;
+ List<IASTComment> comms = getLeadingCommentsForNode(node);
+ if (comms.size() > 0) {
+ comment = comms.get(comms.size() - 1);
+ }
+ return comment;
+ }
+
+ /**
+ * @param node
+ * @return
+ */
+ public IASTComment getFirstTrailingCommentForNode(IASTNode node) {
+ IASTComment comment = null;
+ List<IASTComment> comms = getTrailingCommentsForNode(node);
+ if (comms.size() > 0) {
+ comment = comms.get(0);
+ }
+ return comment;
+ }
+
+ /**
+ * @param node
+ * @return
+ */
+ public IASTComment getLastFreestandingCommentForNode(IASTNode node) {
+ IASTComment comment = null;
+ List<IASTComment> comms = getFreestandingForNode(node);
+ if (comms.size() > 0) {
+ comment = comms.get(comms.size() - 1);
+ }
+ return comment;
+ }
}
diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java
index d72bb2ff00c..07e27652b05 100644
--- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java
+++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java
@@ -36,6 +36,7 @@ import org.eclipse.core.runtime.Path;
public abstract class AbstractIndexAstChecker extends AbstractCheckerWithProblemPreferences implements ICAstChecker,
IRunnableInEditorChecker {
private IFile file;
+ private ICodanCommentMap commentmap;
protected IFile getFile() {
return file;
@@ -46,6 +47,7 @@ public abstract class AbstractIndexAstChecker extends AbstractCheckerWithProblem
}
void processFile(IFile file) throws CoreException, InterruptedException {
+ commentmap = null;
IASTTranslationUnit ast = CxxModelsCache.getInstance().getAst(file);
if (ast == null)
return;
@@ -121,7 +123,29 @@ public abstract class AbstractIndexAstChecker extends AbstractCheckerWithProblem
IPath location = new Path(ast.getFilePath());
IFile astFile = ResourceLookup.selectFileForLocation(location, getProject());
file = astFile;
+ commentmap = null;
processAst(ast);
}
}
+
+ /**
+ * @return
+ *
+ */
+ protected ICodanCommentMap getCommentMap() {
+ if (commentmap == null) {
+ try {
+ CxxModelsCache cxxcache = CxxModelsCache.getInstance();
+ synchronized (cxxcache) {
+ IASTTranslationUnit ast = cxxcache.getAst(getFile());
+ commentmap = cxxcache.getCommentedNodeMap(ast);
+ return commentmap;
+ }
+
+ } catch (Exception e) {
+ Activator.log(e);
+ }
+ }
+ return commentmap;
+ }
}
diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/ICodanCommentMap.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/ICodanCommentMap.java
index 7a6d3184733..5894a8d6b84 100644
--- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/ICodanCommentMap.java
+++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/ICodanCommentMap.java
@@ -7,8 +7,7 @@
*
* Contributors:
* QNX Software Systems (Alena Laskavaia) - initial API and implementation
- *******************************************************************************/
-
+ *******************************************************************************/
package org.eclipse.cdt.codan.core.cxx.model;
import java.util.List;
@@ -21,24 +20,54 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
*/
public interface ICodanCommentMap {
/**
- * Returns an Collection of comments for the given node (after the node). This list contains all the comments
- * which are assigned to this specific node. If no comments are available an empty
+ * Returns an Collection of comments for the given node (after the node).
+ * This list contains all the comments
+ * which are assigned to this specific node. If no comments are available an
+ * empty
* collection is returned.
+ *
* @param node The key to fetch the associated comments.
* @return list of comments
*/
public List<IASTComment> getTrailingCommentsForNode(IASTNode node);
+
/**
- * Returns an Collection of comments for the given node (before the node). This list contains all the comments
- * which are assigned to this specific node. If no comments are available an empty
+ * Returns an Collection of comments for the given node (before the node).
+ * This list contains all the comments
+ * which are assigned to this specific node. If no comments are available an
+ * empty
* collection is returned.
+ *
* @param node The key to fetch the associated comments.
* @return list of comments
*/
public List<IASTComment> getLeadingCommentsForNode(IASTNode node);
+
+
/**
- * @param statement
- * @return
+ * Returns an ArrayList for the given node. This ArrayList contains all the comments
+ * which are assigned to this specific node. If no comments are available an empty
+ * ArrayList is returned.
+ * @param node The key to fetch the associated comments.
+ * @return ArrayList
*/
public List<IASTComment> getFreestandingForNode(IASTNode node);
+
+ /**
+ * @param node
+ * @return
+ */
+ public IASTComment getLastLeadingCommentForNode(IASTNode node);
+
+ /**
+ * @param node
+ * @return
+ */
+ public IASTComment getFirstTrailingCommentForNode(IASTNode node);
+
+ /**
+ * @param node
+ * @return
+ */
+ public IASTComment getLastFreestandingCommentForNode(IASTNode node);
}

Back to the top