diff options
Diffstat (limited to 'rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/CDTMiner.java')
-rw-r--r-- | rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/CDTMiner.java | 79 |
1 files changed, 76 insertions, 3 deletions
diff --git a/rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/CDTMiner.java b/rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/CDTMiner.java index 56d65da56..8fd0b753b 100644 --- a/rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/CDTMiner.java +++ b/rdt/org.eclipse.ptp.rdt.core/miners/org/eclipse/ptp/internal/rdt/core/miners/CDTMiner.java @@ -21,6 +21,7 @@ import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; +import java.util.Stack; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTCompletionNode; @@ -69,6 +70,9 @@ import org.eclipse.ptp.internal.rdt.core.includebrowser.IIndexIncludeValue; import org.eclipse.ptp.internal.rdt.core.includebrowser.IndexIncludeValue; import org.eclipse.ptp.internal.rdt.core.index.DummyName; import org.eclipse.ptp.internal.rdt.core.index.IndexQueries; +import org.eclipse.ptp.internal.rdt.core.miners.RemoteFoldingRegionsHandler.StatementRegion; +import org.eclipse.ptp.internal.rdt.core.miners.RemoteFoldingRegionsHandler.StatementVisitor; +import org.eclipse.ptp.internal.rdt.core.miners.RemoteFoldingRegionsHandler.Branch; import org.eclipse.ptp.internal.rdt.core.model.CModelBuilder2; import org.eclipse.ptp.internal.rdt.core.model.CProject; import org.eclipse.ptp.internal.rdt.core.model.IIndexLocationConverterFactory; @@ -80,6 +84,7 @@ import org.eclipse.ptp.internal.rdt.core.search.RemoteSearchMatch; import org.eclipse.ptp.internal.rdt.core.search.RemoteSearchQuery; import org.eclipse.ptp.internal.rdt.core.typehierarchy.THGraph; import org.eclipse.ptp.internal.rdt.core.typehierarchy.TypeHierarchyUtil; +import org.eclipse.ptp.internal.rdt.core.navigation.FoldingRegionsResult; import org.eclipse.ptp.internal.rdt.core.navigation.OpenDeclarationResult; import org.eclipse.rse.dstore.universal.miners.UniversalServerUtilities; @@ -98,6 +103,7 @@ public class CDTMiner extends Miner { public static final String T_INDEX_STRING_DESCRIPTOR = "Type.Index.String"; //$NON-NLS-1$ public static final String T_INDEX_FILENAME_DESCRIPTOR = "Type.Scope.Filename"; //$NON-NLS-1$ public static final String T_INDEX_INT_DESCRIPTOR = "Type.Index.Int"; //$NON-NLS-1$ + public static final String T_INDEX_BOOLEAN_DESCRIPTOR = "Type.Index.Boolean"; //$NON-NLS-1$ public static final String T_INDEX_DELTA_CHANGED = "Type.Index.Delta.Changed"; //$NON-NLS-1$ public static final String T_INDEX_DELTA_ADDED = "Type.Index.Delta.Added"; //$NON-NLS-1$ public static final String T_INDEX_DELTA_REMOVED = "Type.Index.Delta.Removed"; //$NON-NLS-1$ @@ -152,9 +158,11 @@ public class CDTMiner extends Miner { public static final String C_INCLUDES_FIND_INCLUDE = "C_INCLUDES_FIND_INCLUDE"; //$NON-NLS-1$ public static final String T_INCLUDES_FIND_INCLUDE_RESULT = "Type.Includes.Find.Include.Result"; //$NON-NLS-1$ - //semantic highlighting + //semantic highlighting and code folding public static final String C_SEMANTIC_HIGHTLIGHTING_COMPUTE_POSITIONS = "C_SEMANTIC_HIGHTLIGHTING_COMPUTE_POSITIONS"; //$NON-NLS-1$ public static final String T_HIGHTLIGHTING_POSITIONS_RESULT = "Highlighting.Positions.Result"; //$NON-NLS-1$ + public static final String C_CODE_FOLDING_COMPUTE_REGIONS = "C_CODE_FOLDING_COMPUTE_REGIONS"; //$NON-NLS-1$ + public static final String T_CODE_FOLDING_RESULT = "Folding.Region.Result"; //$NON-NLS-1$ public static String LINE_SEPARATOR; @@ -692,6 +700,21 @@ public class CDTMiner extends Miner { UniversalServerUtilities.logError(LOG_TAG, e.toString(), e, _dataStore); } } + else if (name.equals(C_CODE_FOLDING_COMPUTE_REGIONS)) { + try { + String scopeName = getString(theCommand, 1); + ITranslationUnit tu = (ITranslationUnit) Serializer.deserialize(getString(theCommand, 2)); + int docSize = getInteger(theCommand, 3); + boolean preprocessorFoldingEnabled = getBoolean(theCommand, 4); + boolean statementsFoldingEnabled = getBoolean(theCommand, 5); + + hanleComputeCodeFoldingRegions(scopeName, tu, status, statementsFoldingEnabled, preprocessorFoldingEnabled, docSize); + } catch (IOException e) { + UniversalServerUtilities.logError(LOG_TAG, e.toString(), e, _dataStore); + } catch (ClassNotFoundException e) { + UniversalServerUtilities.logError(LOG_TAG, e.toString(), e, _dataStore); + } + } return status; } @@ -701,7 +724,7 @@ public class CDTMiner extends Miner { IIndex index = RemoteIndexManager.getInstance().getIndexForScope(scopeName, _dataStore); index.acquireReadLock(); try { - IASTTranslationUnit ast = tu.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS); + IASTTranslationUnit ast = tu.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS | ITranslationUnit.AST_PARSE_INACTIVE_CODE); PositionCollector collector = new PositionCollector(true); ast.accept(collector); ArrayList<ArrayList<Integer>> positionList = collector.getPositions(); @@ -727,6 +750,55 @@ public class CDTMiner extends Miner { } } + protected void hanleComputeCodeFoldingRegions(String scopeName, ITranslationUnit tu, DataElement status, + boolean statementsFoldingEnabled, boolean preprocessorFoldingEnabled, int docSize) { + try { + final Stack<StatementRegion> iral = new Stack<StatementRegion>(); + List<Branch> branches = new ArrayList<Branch>(); + IIndex index = RemoteIndexManager.getInstance().getIndexForScope(scopeName, _dataStore); + index.acquireReadLock(); + try { + IASTTranslationUnit ast = tu.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS | ITranslationUnit.AST_PARSE_INACTIVE_CODE); + + if (ast == null) { + return; + } + String fileName = ast.getFilePath(); + if (fileName == null) { + return; + } + + RemoteFoldingRegionsHandler rfrh = new RemoteFoldingRegionsHandler(); + FoldingRegionsResult result = new FoldingRegionsResult(); + + if (statementsFoldingEnabled) { + StatementVisitor sv = rfrh.createStatementVisitor(iral); + ast.accept(sv); + result.iral = iral; + } + if (preprocessorFoldingEnabled) { + rfrh.computePreprocessorFoldingStructure(ast, docSize, branches); + result.branches = branches; + } + + String resultString = Serializer.serialize(result); + status.getDataStore().createObject(status, T_CODE_FOLDING_RESULT, resultString); + } + finally { + index.releaseReadLock(); + } + } catch (IOException e) { + UniversalServerUtilities.logError(LOG_TAG, e.toString(), e, _dataStore); + } catch (CoreException e) { + UniversalServerUtilities.logError(LOG_TAG, e.toString(), e, _dataStore); + } catch (InterruptedException e) { + UniversalServerUtilities.logError(LOG_TAG, e.toString(), e, _dataStore); + } + finally { + statusDone(status); + } + } + protected void handleIndexFileMove(String scopeName, String newIndexLocation, DataElement status) throws IOException { String actualLocation = RemoteIndexManager.getInstance().moveIndexFile(scopeName, newIndexLocation, _dataStore); status.getDataStore().createObject(status, T_MOVE_INDEX_FILE_RESULT, actualLocation); @@ -1428,8 +1500,9 @@ public class CDTMiner extends Miner { createCommandDescriptor(schemaRoot, "Find input from element", C_TYPE_HIERARCHY_FIND_INPUT1, false); //$NON-NLS-1$ createCommandDescriptor(schemaRoot, "Find input from text selection", C_TYPE_HIERARCHY_FIND_INPUT2, false); //$NON-NLS-1$ - // semantic highlighting + // semantic highlighting and code folding createCommandDescriptor(schemaRoot, "Compute added & removed positions for semantic highlighting", C_SEMANTIC_HIGHTLIGHTING_COMPUTE_POSITIONS, false); //$NON-NLS-1$ + createCommandDescriptor(schemaRoot, "Compute code folding regions for the Remote C Editor", C_CODE_FOLDING_COMPUTE_REGIONS, false); //$NON-NLS-1$ // navigation createCommandDescriptor(schemaRoot, "Open declaration", C_NAVIGATION_OPEN_DECLARATION, false); //$NON-NLS-1$ |