mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Victor Mozgin
CTaskTagsReconciler refactoring.
This commit is contained in:
parent
91fe88d338
commit
4961729ef8
9 changed files with 199 additions and 165 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
2003-07-04 Victor Mozgin
|
||||||
|
Added CTaskTagsReconciler.
|
||||||
|
|
||||||
2003-07-03 Bogdan Gheorghe
|
2003-07-03 Bogdan Gheorghe
|
||||||
Added support for adding individual source files to the
|
Added support for adding individual source files to the
|
||||||
index.
|
index.
|
||||||
|
|
|
@ -17,20 +17,18 @@ import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CTaskTagsReconciler;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICModelMarker;
|
|
||||||
import org.eclipse.cdt.core.model.INamespace;
|
import org.eclipse.cdt.core.model.INamespace;
|
||||||
import org.eclipse.cdt.core.model.IParent;
|
import org.eclipse.cdt.core.model.IParent;
|
||||||
import org.eclipse.cdt.core.model.IStructure;
|
import org.eclipse.cdt.core.model.IStructure;
|
||||||
import org.eclipse.cdt.core.model.ITemplate;
|
import org.eclipse.cdt.core.model.ITemplate;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.parser.ITranslationResult;
|
|
||||||
import org.eclipse.cdt.core.parser.IParser;
|
import org.eclipse.cdt.core.parser.IParser;
|
||||||
import org.eclipse.cdt.core.parser.IProblem;
|
import org.eclipse.cdt.core.parser.IProblemReporter;
|
||||||
|
import org.eclipse.cdt.core.parser.ITranslationResult;
|
||||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
import org.eclipse.cdt.internal.core.dom.ArrayQualifier;
|
import org.eclipse.cdt.internal.core.dom.ArrayQualifier;
|
||||||
|
@ -57,20 +55,11 @@ import org.eclipse.cdt.internal.core.dom.TemplateDeclaration;
|
||||||
import org.eclipse.cdt.internal.core.dom.TemplateParameter;
|
import org.eclipse.cdt.internal.core.dom.TemplateParameter;
|
||||||
import org.eclipse.cdt.internal.core.dom.TranslationUnit;
|
import org.eclipse.cdt.internal.core.dom.TranslationUnit;
|
||||||
import org.eclipse.cdt.internal.core.dom.TypeSpecifier;
|
import org.eclipse.cdt.internal.core.dom.TypeSpecifier;
|
||||||
import org.eclipse.cdt.internal.core.parser.DefaultErrorHandlingPolicies;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.TranslationResult;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.TranslationOptions;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.ITranslationResultRequestor;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.Name;
|
import org.eclipse.cdt.internal.core.parser.Name;
|
||||||
import org.eclipse.cdt.internal.core.parser.problem.DefaultProblemFactory;
|
|
||||||
import org.eclipse.cdt.internal.core.parser.problem.ProblemReporter;
|
|
||||||
import org.eclipse.core.resources.IMarker;
|
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
|
||||||
|
|
||||||
|
|
||||||
public class CModelBuilder implements ITranslationResultRequestor {
|
public class CModelBuilder {
|
||||||
|
|
||||||
protected org.eclipse.cdt.internal.core.model.TranslationUnit translationUnit;
|
protected org.eclipse.cdt.internal.core.model.TranslationUnit translationUnit;
|
||||||
protected Map newElements;
|
protected Map newElements;
|
||||||
|
@ -84,21 +73,21 @@ public class CModelBuilder implements ITranslationResultRequestor {
|
||||||
|
|
||||||
DOMBuilder domBuilder = new DOMBuilder();
|
DOMBuilder domBuilder = new DOMBuilder();
|
||||||
|
|
||||||
// create a problem reporter
|
|
||||||
Map options = null;
|
Map options = null;
|
||||||
|
IProject currentProject = null;
|
||||||
|
|
||||||
if (translationUnit != null && translationUnit.getCProject() != null) {
|
if (translationUnit != null && translationUnit.getCProject() != null) {
|
||||||
options = translationUnit.getCProject().getOptions(true);
|
options = translationUnit.getCProject().getOptions(true);
|
||||||
|
currentProject = translationUnit.getCProject().getProject();
|
||||||
}
|
}
|
||||||
TranslationOptions cOptions = new TranslationOptions(options);
|
|
||||||
ProblemReporter problemReporter = new ProblemReporter(
|
// create problem reporter
|
||||||
DefaultErrorHandlingPolicies.proceedWithAllProblems(),
|
IProblemReporter problemReporter = ParserFactory.createProblemReporter(options);
|
||||||
cOptions,
|
|
||||||
new DefaultProblemFactory()
|
|
||||||
);
|
|
||||||
|
|
||||||
// create translation result
|
// create translation result
|
||||||
TranslationResult unitResult = new TranslationResult(translationUnit);
|
ITranslationResult unitResult = ParserFactory.createTranslationResult(translationUnit.getPath().lastSegment());
|
||||||
|
|
||||||
|
// create parser
|
||||||
IParser parser = ParserFactory.createParser(
|
IParser parser = ParserFactory.createParser(
|
||||||
ParserFactory.createScanner(
|
ParserFactory.createScanner(
|
||||||
new StringReader(
|
new StringReader(
|
||||||
|
@ -113,12 +102,12 @@ public class CModelBuilder implements ITranslationResultRequestor {
|
||||||
problemReporter, unitResult
|
problemReporter, unitResult
|
||||||
);
|
);
|
||||||
|
|
||||||
if( translationUnit.getCProject() != null )
|
if( currentProject != null )
|
||||||
{
|
{
|
||||||
IProject currentProject = translationUnit.getCProject().getProject();
|
|
||||||
boolean hasCppNature = CoreModel.getDefault().hasCCNature(currentProject);
|
boolean hasCppNature = CoreModel.getDefault().hasCCNature(currentProject);
|
||||||
parser.setCppNature(hasCppNature);
|
parser.setCppNature(hasCppNature);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
parser.parse();
|
parser.parse();
|
||||||
|
@ -140,7 +129,7 @@ public class CModelBuilder implements ITranslationResultRequestor {
|
||||||
}
|
}
|
||||||
|
|
||||||
// process translation results
|
// process translation results
|
||||||
acceptResult(unitResult);
|
CTaskTagsReconciler.getInstance().acceptResult(translationUnit, unitResult);
|
||||||
|
|
||||||
// For the debuglog to take place, you have to call
|
// For the debuglog to take place, you have to call
|
||||||
// Util.setDebugging(true);
|
// Util.setDebugging(true);
|
||||||
|
@ -1055,100 +1044,4 @@ public class CModelBuilder implements ITranslationResultRequestor {
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ITranslatorRequestor#acceptResult(ITranslationResult)
|
|
||||||
*/
|
|
||||||
public void acceptResult(ITranslationResult result) {
|
|
||||||
ITranslationUnit translationUnit = result.getTranslationUnit();
|
|
||||||
|
|
||||||
try {
|
|
||||||
updateTasksFor(translationUnit, result); // record tasks
|
|
||||||
} catch (CoreException e) {
|
|
||||||
System.out.println("Exception while accepting parse results");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateTasksFor(ITranslationUnit sourceFile, ITranslationResult result) throws CoreException {
|
|
||||||
IProblem[] tasks = result.getTasks();
|
|
||||||
|
|
||||||
storeTasksFor(sourceFile, tasks);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void storeTasksFor(ITranslationUnit sourceFile, IProblem[] tasks) throws CoreException {
|
|
||||||
if (sourceFile == null) return;
|
|
||||||
|
|
||||||
if (tasks == null) tasks = new IProblem[0];
|
|
||||||
|
|
||||||
IResource resource = sourceFile.getResource();
|
|
||||||
IMarker[] existingTaskMarkers = resource.findMarkers(ICModelMarker.TASK_MARKER, false, IResource.DEPTH_ONE);
|
|
||||||
HashSet taskSet = new HashSet();
|
|
||||||
|
|
||||||
if (existingTaskMarkers != null)
|
|
||||||
for (int i=0; i<existingTaskMarkers.length; i++)
|
|
||||||
taskSet.add(existingTaskMarkers[i]);
|
|
||||||
|
|
||||||
taskLoop:
|
|
||||||
for (int i = 0, l = tasks.length; i < l; i++) {
|
|
||||||
IProblem task = tasks[i];
|
|
||||||
if (task.getID() == IProblem.Task) {
|
|
||||||
|
|
||||||
int priority = IMarker.PRIORITY_NORMAL;
|
|
||||||
String compilerPriority = task.getArguments()[2];
|
|
||||||
if (CCorePlugin.TRANSLATION_TASK_PRIORITY_HIGH.equals(compilerPriority))
|
|
||||||
priority = IMarker.PRIORITY_HIGH;
|
|
||||||
else if (CCorePlugin.TRANSLATION_TASK_PRIORITY_LOW.equals(compilerPriority))
|
|
||||||
priority = IMarker.PRIORITY_LOW;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Try to find matching markers and don't put in duplicates
|
|
||||||
*/
|
|
||||||
if ((existingTaskMarkers != null) && (existingTaskMarkers.length > 0)) {
|
|
||||||
for (int j = 0; j < existingTaskMarkers.length; j++) {
|
|
||||||
if (
|
|
||||||
(((Integer) existingTaskMarkers[j].getAttribute(IMarker.LINE_NUMBER)).intValue() == task.getSourceLineNumber())
|
|
||||||
&& (((Integer) existingTaskMarkers[j].getAttribute(IMarker.PRIORITY)).intValue() == priority)
|
|
||||||
&& (((Integer) existingTaskMarkers[j].getAttribute(IMarker.CHAR_START)).intValue() == task.getSourceStart())
|
|
||||||
&& (((Integer) existingTaskMarkers[j].getAttribute(IMarker.CHAR_END)).intValue() == task.getSourceEnd()+1)
|
|
||||||
&& (((String) existingTaskMarkers[j].getAttribute(IMarker.MESSAGE)).equals(task.getMessage()))
|
|
||||||
) {
|
|
||||||
taskSet.remove(existingTaskMarkers[j]);
|
|
||||||
continue taskLoop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
IMarker marker = resource.createMarker(ICModelMarker.TASK_MARKER);
|
|
||||||
|
|
||||||
marker.setAttributes(
|
|
||||||
new String[] {
|
|
||||||
IMarker.MESSAGE,
|
|
||||||
IMarker.PRIORITY,
|
|
||||||
IMarker.DONE,
|
|
||||||
IMarker.CHAR_START,
|
|
||||||
IMarker.CHAR_END,
|
|
||||||
IMarker.LINE_NUMBER,
|
|
||||||
IMarker.USER_EDITABLE,
|
|
||||||
},
|
|
||||||
new Object[] {
|
|
||||||
task.getMessage(),
|
|
||||||
new Integer(priority),
|
|
||||||
new Boolean(false),
|
|
||||||
new Integer(task.getSourceStart()),
|
|
||||||
new Integer(task.getSourceEnd() + 1),
|
|
||||||
new Integer(task.getSourceLineNumber()),
|
|
||||||
new Boolean(false),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove all obsolete markers
|
|
||||||
Iterator setI = taskSet.iterator();
|
|
||||||
while (setI.hasNext()) {
|
|
||||||
IMarker marker = (IMarker)setI.next();
|
|
||||||
marker.delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
2003-07-04 Victor Mozgin
|
||||||
|
Added CTaskTagsReconciler.
|
||||||
|
Extended ParserFactory with createProblemReporter() and createTranslationResult().
|
||||||
|
|
||||||
2003-07-02 Victor Mozgin
|
2003-07-02 Victor Mozgin
|
||||||
Fixed PR 39501 : Parser problems with throw clauses.
|
Fixed PR 39501 : Parser problems with throw clauses.
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
package org.eclipse.cdt.core.parser;
|
package org.eclipse.cdt.core.parser;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
//import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author vmozgin
|
* @author vmozgin
|
||||||
|
@ -23,7 +23,7 @@ public interface ITranslationResult {
|
||||||
/**
|
/**
|
||||||
* Answer the initial translation unit corresponding to the present translation result
|
* Answer the initial translation unit corresponding to the present translation result
|
||||||
*/
|
*/
|
||||||
public abstract ITranslationUnit getTranslationUnit();
|
// public abstract ITranslationUnit getTranslationUnit();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Answer the initial file name
|
* Answer the initial file name
|
||||||
|
|
|
@ -14,14 +14,20 @@ import java.io.Reader;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
//import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.DefaultErrorHandlingPolicies;
|
||||||
import org.eclipse.cdt.internal.core.parser.LineOffsetReconciler;
|
import org.eclipse.cdt.internal.core.parser.LineOffsetReconciler;
|
||||||
import org.eclipse.cdt.internal.core.parser.NullSourceElementRequestor;
|
import org.eclipse.cdt.internal.core.parser.NullSourceElementRequestor;
|
||||||
import org.eclipse.cdt.internal.core.parser.Parser;
|
import org.eclipse.cdt.internal.core.parser.Parser;
|
||||||
import org.eclipse.cdt.internal.core.parser.Preprocessor;
|
import org.eclipse.cdt.internal.core.parser.Preprocessor;
|
||||||
import org.eclipse.cdt.internal.core.parser.Scanner;
|
import org.eclipse.cdt.internal.core.parser.Scanner;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.TranslationOptions;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.TranslationResult;
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.full.FullParseASTFactory;
|
import org.eclipse.cdt.internal.core.parser.ast.full.FullParseASTFactory;
|
||||||
import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory;
|
import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.problem.DefaultProblemFactory;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.problem.ProblemReporter;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,5 +89,20 @@ public class ParserFactory {
|
||||||
return new LineOffsetReconciler( input );
|
return new LineOffsetReconciler( input );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IProblemReporter createProblemReporter( Map options )
|
||||||
|
{
|
||||||
|
ITranslationOptions cOptions = new TranslationOptions(options);
|
||||||
|
IProblemReporter problemReporter = new ProblemReporter(
|
||||||
|
DefaultErrorHandlingPolicies.proceedWithAllProblems(),
|
||||||
|
cOptions,
|
||||||
|
new DefaultProblemFactory()
|
||||||
|
);
|
||||||
|
|
||||||
|
return problemReporter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ITranslationResult createTranslationResult( String fileName/*ITranslationUnit tu*/ )
|
||||||
|
{
|
||||||
|
return new TranslationResult( fileName /* tu */ );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Common Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
* http://www.eclipse.org/legal/cpl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* IBM Corporation - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.internal.core.parser;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ITranslationResult;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A callback interface for receiving translation results.
|
|
||||||
*/
|
|
||||||
public interface ITranslationResultRequestor {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Accept a translation result.
|
|
||||||
*/
|
|
||||||
public void acceptResult(ITranslationResult result);
|
|
||||||
}
|
|
|
@ -21,7 +21,7 @@ package org.eclipse.cdt.internal.core.parser;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.*;
|
import org.eclipse.cdt.core.parser.*;
|
||||||
import org.eclipse.cdt.core.parser.IProblem;
|
import org.eclipse.cdt.core.parser.IProblem;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
//import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
|
||||||
public class TranslationResult implements ITranslationResult {
|
public class TranslationResult implements ITranslationResult {
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ public class TranslationResult implements ITranslationResult {
|
||||||
public IProblem tasks[];
|
public IProblem tasks[];
|
||||||
public int problemCount;
|
public int problemCount;
|
||||||
public int taskCount;
|
public int taskCount;
|
||||||
public ITranslationUnit translationUnit;
|
// public ITranslationUnit translationUnit;
|
||||||
private int maxProblemPerUnit;
|
private int maxProblemPerUnit;
|
||||||
|
|
||||||
public int unitIndex, totalUnitsKnown;
|
public int unitIndex, totalUnitsKnown;
|
||||||
|
@ -49,12 +49,17 @@ public class TranslationResult implements ITranslationResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int DEFAULT_MAX_PROBLEMS_PER_UNIT = 100;
|
public static final int DEFAULT_MAX_PROBLEMS_PER_UNIT = 100;
|
||||||
|
/*
|
||||||
public TranslationResult(
|
public TranslationResult(
|
||||||
ITranslationUnit translationUnit) {
|
ITranslationUnit translationUnit) {
|
||||||
this(translationUnit, 1, 1, DEFAULT_MAX_PROBLEMS_PER_UNIT);
|
this(translationUnit, 1, 1, DEFAULT_MAX_PROBLEMS_PER_UNIT);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
public TranslationResult(
|
||||||
|
String fileName) {
|
||||||
|
this(fileName.toCharArray(), 1, 1, DEFAULT_MAX_PROBLEMS_PER_UNIT);
|
||||||
|
}
|
||||||
|
/*
|
||||||
public TranslationResult(
|
public TranslationResult(
|
||||||
ITranslationUnit translationUnit,
|
ITranslationUnit translationUnit,
|
||||||
int unitIndex,
|
int unitIndex,
|
||||||
|
@ -67,7 +72,7 @@ public class TranslationResult implements ITranslationResult {
|
||||||
this.totalUnitsKnown = totalUnitsKnown;
|
this.totalUnitsKnown = totalUnitsKnown;
|
||||||
this.maxProblemPerUnit = maxProblemPerUnit;
|
this.maxProblemPerUnit = maxProblemPerUnit;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
private int computePriority(IProblem problem) {
|
private int computePriority(IProblem problem) {
|
||||||
|
|
||||||
|
@ -141,9 +146,9 @@ public class TranslationResult implements ITranslationResult {
|
||||||
/**
|
/**
|
||||||
* Answer the initial translation unit corresponding to the present translation result
|
* Answer the initial translation unit corresponding to the present translation result
|
||||||
*/
|
*/
|
||||||
public ITranslationUnit getTranslationUnit() {
|
// public ITranslationUnit getTranslationUnit() {
|
||||||
return translationUnit;
|
// return translationUnit;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Answer the initial file name
|
* Answer the initial file name
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.parser.problem;
|
package org.eclipse.cdt.internal.core.parser.problem;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
//import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.parser.IProblem;
|
import org.eclipse.cdt.core.parser.IProblem;
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ public class DefaultProblem implements IProblem {
|
||||||
this.line = line;
|
this.line = line;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String errorReportSource(ITranslationUnit translationUnit) {
|
public String errorReportSource(char[] source) {
|
||||||
//extra from the source the innacurate token
|
//extra from the source the innacurate token
|
||||||
//and "highlight" it using some underneath ^^^^^
|
//and "highlight" it using some underneath ^^^^^
|
||||||
//put some context around too.
|
//put some context around too.
|
||||||
|
@ -58,7 +58,7 @@ public class DefaultProblem implements IProblem {
|
||||||
final char SPACE = '\u0020';
|
final char SPACE = '\u0020';
|
||||||
final char MARK = '^';
|
final char MARK = '^';
|
||||||
final char TAB = '\t';
|
final char TAB = '\t';
|
||||||
char[] source = translationUnit.getContents();
|
//char[] source = translationUnit.getContents();
|
||||||
//the next code tries to underline the token.....
|
//the next code tries to underline the token.....
|
||||||
//it assumes (for a good display) that token source does not
|
//it assumes (for a good display) that token source does not
|
||||||
//contain any \r \n. This is false on statements !
|
//contain any \r \n. This is false on statements !
|
||||||
|
|
|
@ -0,0 +1,132 @@
|
||||||
|
package org.eclipse.cdt.core;
|
||||||
|
|
||||||
|
/**********************************************************************
|
||||||
|
* Copyright (c) 2002,2003 Rational Software Corporation and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v0.5
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v05.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Rational Software - Initial API and implementation
|
||||||
|
***********************************************************************/
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
import org.eclipse.cdt.core.model.ICModelMarker;
|
||||||
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
import org.eclipse.cdt.core.parser.ITranslationResult;
|
||||||
|
import org.eclipse.cdt.core.parser.IProblem;
|
||||||
|
|
||||||
|
import org.eclipse.core.resources.IMarker;
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
|
|
||||||
|
public class CTaskTagsReconciler {
|
||||||
|
|
||||||
|
private static CTaskTagsReconciler instance = null;
|
||||||
|
|
||||||
|
private CTaskTagsReconciler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CTaskTagsReconciler getInstance() {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new CTaskTagsReconciler();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void acceptResult(ITranslationUnit translationUnit, ITranslationResult result) {
|
||||||
|
try {
|
||||||
|
updateTasksFor(translationUnit, result); // record tasks
|
||||||
|
} catch (CoreException e) {
|
||||||
|
System.out.println("Exception while accepting parse results");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateTasksFor(ITranslationUnit sourceFile, ITranslationResult result) throws CoreException {
|
||||||
|
IProblem[] tasks = result.getTasks();
|
||||||
|
|
||||||
|
storeTasksFor(sourceFile, tasks);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void storeTasksFor(ITranslationUnit sourceFile, IProblem[] tasks) throws CoreException {
|
||||||
|
if (sourceFile == null) return;
|
||||||
|
|
||||||
|
if (tasks == null) tasks = new IProblem[0];
|
||||||
|
|
||||||
|
IResource resource = sourceFile.getResource();
|
||||||
|
IMarker[] existingTaskMarkers = resource.findMarkers(ICModelMarker.TASK_MARKER, false, IResource.DEPTH_ONE);
|
||||||
|
HashSet taskSet = new HashSet();
|
||||||
|
|
||||||
|
if (existingTaskMarkers != null)
|
||||||
|
for (int i=0; i<existingTaskMarkers.length; i++)
|
||||||
|
taskSet.add(existingTaskMarkers[i]);
|
||||||
|
|
||||||
|
taskLoop:
|
||||||
|
for (int i = 0, l = tasks.length; i < l; i++) {
|
||||||
|
IProblem task = tasks[i];
|
||||||
|
if (task.getID() == IProblem.Task) {
|
||||||
|
|
||||||
|
int priority = IMarker.PRIORITY_NORMAL;
|
||||||
|
String compilerPriority = task.getArguments()[2];
|
||||||
|
if (CCorePlugin.TRANSLATION_TASK_PRIORITY_HIGH.equals(compilerPriority))
|
||||||
|
priority = IMarker.PRIORITY_HIGH;
|
||||||
|
else if (CCorePlugin.TRANSLATION_TASK_PRIORITY_LOW.equals(compilerPriority))
|
||||||
|
priority = IMarker.PRIORITY_LOW;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Try to find matching markers and don't put in duplicates
|
||||||
|
*/
|
||||||
|
if ((existingTaskMarkers != null) && (existingTaskMarkers.length > 0)) {
|
||||||
|
for (int j = 0; j < existingTaskMarkers.length; j++) {
|
||||||
|
if (
|
||||||
|
(((Integer) existingTaskMarkers[j].getAttribute(IMarker.LINE_NUMBER)).intValue() == task.getSourceLineNumber())
|
||||||
|
&& (((Integer) existingTaskMarkers[j].getAttribute(IMarker.PRIORITY)).intValue() == priority)
|
||||||
|
&& (((Integer) existingTaskMarkers[j].getAttribute(IMarker.CHAR_START)).intValue() == task.getSourceStart())
|
||||||
|
&& (((Integer) existingTaskMarkers[j].getAttribute(IMarker.CHAR_END)).intValue() == task.getSourceEnd()+1)
|
||||||
|
&& (((String) existingTaskMarkers[j].getAttribute(IMarker.MESSAGE)).equals(task.getMessage()))
|
||||||
|
) {
|
||||||
|
taskSet.remove(existingTaskMarkers[j]);
|
||||||
|
continue taskLoop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IMarker marker = resource.createMarker(ICModelMarker.TASK_MARKER);
|
||||||
|
|
||||||
|
marker.setAttributes(
|
||||||
|
new String[] {
|
||||||
|
IMarker.MESSAGE,
|
||||||
|
IMarker.PRIORITY,
|
||||||
|
IMarker.DONE,
|
||||||
|
IMarker.CHAR_START,
|
||||||
|
IMarker.CHAR_END,
|
||||||
|
IMarker.LINE_NUMBER,
|
||||||
|
IMarker.USER_EDITABLE,
|
||||||
|
},
|
||||||
|
new Object[] {
|
||||||
|
task.getMessage(),
|
||||||
|
new Integer(priority),
|
||||||
|
new Boolean(false),
|
||||||
|
new Integer(task.getSourceStart()),
|
||||||
|
new Integer(task.getSourceEnd() + 1),
|
||||||
|
new Integer(task.getSourceLineNumber()),
|
||||||
|
new Boolean(false),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove all obsolete markers
|
||||||
|
Iterator setI = taskSet.iterator();
|
||||||
|
while (setI.hasNext()) {
|
||||||
|
IMarker marker = (IMarker)setI.next();
|
||||||
|
marker.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue