mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-30 21:55:31 +02:00
Merge remote-tracking branch 'cdt/master' into sd90
This commit is contained in:
commit
f21f305ff2
10 changed files with 153 additions and 85 deletions
|
@ -38,6 +38,7 @@ import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
|||
import org.eclipse.cdt.core.testplugin.ResourceHelper;
|
||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||
import org.eclipse.cdt.internal.core.XmlUtil;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
|
||||
import org.eclipse.cdt.managedbuilder.language.settings.providers.AbstractBuildCommandParser;
|
||||
import org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser;
|
||||
|
@ -104,6 +105,8 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
|
|||
protected void tearDown() throws Exception {
|
||||
try {
|
||||
Job.getJobManager().join(AbstractBuildCommandParser.JOB_FAMILY_BUILD_COMMAND_PARSER, null);
|
||||
Job.getJobManager().join(LanguageSettingsProvidersSerializer.JOB_FAMILY_SERIALIZE_LANGUAGE_SETTINGS_PROJECT, null);
|
||||
Job.getJobManager().join(LanguageSettingsProvidersSerializer.JOB_FAMILY_SERIALIZE_LANGUAGE_SETTINGS_WORKSPACE, null);
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
|
|||
import org.eclipse.cdt.managedbuilder.internal.core.ManagedMakeMessages;
|
||||
import org.eclipse.cdt.utils.CommandLineUtil;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
|
@ -58,6 +57,7 @@ import org.eclipse.core.runtime.Platform;
|
|||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.core.runtime.content.IContentType;
|
||||
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
|
@ -380,14 +380,17 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti
|
|||
}
|
||||
};
|
||||
|
||||
IProject project = null;
|
||||
ISchedulingRule rule = null;
|
||||
if (currentCfgDescription != null) {
|
||||
ICProjectDescription prjDescription = currentCfgDescription.getProjectDescription();
|
||||
if (prjDescription != null) {
|
||||
project = prjDescription.getProject();
|
||||
rule = prjDescription.getProject();
|
||||
}
|
||||
}
|
||||
job.setRule(project);
|
||||
if (rule == null) {
|
||||
rule = ResourcesPlugin.getWorkspace().getRoot();
|
||||
}
|
||||
job.setRule(rule);
|
||||
job.schedule();
|
||||
|
||||
// AG FIXME - temporary log to remove before CDT Juno release
|
||||
|
|
|
@ -61,13 +61,10 @@ public class ProblemBindingChecker extends AbstractIndexAstChecker {
|
|||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.codan.core.model.AbstractCheckerWithProblemPreferences#initPreferences(org.eclipse.cdt.codan.core.model.IProblemWorkingCopy)
|
||||
*/
|
||||
@Override
|
||||
public void initPreferences(IProblemWorkingCopy problem) {
|
||||
super.initPreferences(problem);
|
||||
// these checkers should not run on full or incremental build
|
||||
// This checker should not run on full or incremental build
|
||||
getLaunchModePreference(problem).enableInLaunchModes(CheckerLaunchMode.RUN_AS_YOU_TYPE, CheckerLaunchMode.RUN_ON_DEMAND);
|
||||
}
|
||||
|
||||
|
@ -150,9 +147,8 @@ public class ProblemBindingChecker extends AbstractIndexAstChecker {
|
|||
handleMemberProblem(name, parentNode, problemBinding, contextFlagsString);
|
||||
} else if (parentNode instanceof IASTNamedTypeSpecifier) {
|
||||
reportProblem(ERR_ID_TypeResolutionProblem, name, name.getRawSignature(), contextFlagsString);
|
||||
}
|
||||
// Probably a variable
|
||||
else {
|
||||
} else {
|
||||
// Probably a variable
|
||||
handleVariableProblem(name, contextFlagsString);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,8 +23,10 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
|||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.testplugin.ResourceHelper;
|
||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsProvidersSerializer;
|
||||
import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
|
||||
/**
|
||||
* Test cases to cover {@link ILanguageSettingsChangeListener} capabilities.
|
||||
|
@ -83,6 +85,12 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
protected void tearDown() throws Exception {
|
||||
LanguageSettingsManager.unregisterLanguageSettingsChangeListener(mockLseListener);
|
||||
LanguageSettingsManager.setWorkspaceProviders(null);
|
||||
try {
|
||||
Job.getJobManager().join(LanguageSettingsProvidersSerializer.JOB_FAMILY_SERIALIZE_LANGUAGE_SETTINGS_PROJECT, null);
|
||||
Job.getJobManager().join(LanguageSettingsProvidersSerializer.JOB_FAMILY_SERIALIZE_LANGUAGE_SETTINGS_WORKSPACE, null);
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
super.tearDown(); // includes ResourceHelper cleanup
|
||||
}
|
||||
|
||||
|
@ -557,6 +565,8 @@ public class LanguageSettingsListenersTests extends BaseTestCase {
|
|||
}
|
||||
|
||||
{
|
||||
// wait until serializing has finished
|
||||
Job.getJobManager().join(LanguageSettingsProvidersSerializer.JOB_FAMILY_SERIALIZE_LANGUAGE_SETTINGS_WORKSPACE, null);
|
||||
// close project
|
||||
project.close(null);
|
||||
assertEquals(0, MockListenerRegisterer.getCount(PROVIDER_CUSTOM_GLOBAL));
|
||||
|
|
|
@ -47,12 +47,14 @@ import org.eclipse.core.resources.IProject;
|
|||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.resources.WorkspaceJob;
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.ListenerList;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.ILock;
|
||||
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
||||
|
@ -76,8 +78,9 @@ public class LanguageSettingsProvidersSerializer {
|
|||
public static final String ELEM_PROVIDER = LanguageSettingsExtensionManager.ELEM_PROVIDER;
|
||||
public static final String ELEM_LANGUAGE_SCOPE = LanguageSettingsExtensionManager.ELEM_LANGUAGE_SCOPE;
|
||||
|
||||
private static final String JOB_FAMILY_SERIALIZE_LANGUAGE_SETTINGS_PROJECT = "CDT_JOB_FAMILY_SERIALIZE_LANGUAGE_SETTINGS_PROJECT"; //$NON-NLS-1$
|
||||
private static final String JOB_FAMILY_SERIALIZE_LANGUAGE_SETTINGS_WORKSPACE = "CDT_JOB_FAMILY_SERIALIZE_LANGUAGE_SETTINGS_WORKSPACE"; //$NON-NLS-1$
|
||||
public static final String JOB_FAMILY_SERIALIZE_LANGUAGE_SETTINGS_PROJECT = "CDT_JOB_FAMILY_SERIALIZE_LANGUAGE_SETTINGS_PROJECT"; //$NON-NLS-1$
|
||||
public static final String JOB_FAMILY_SERIALIZE_LANGUAGE_SETTINGS_WORKSPACE = "CDT_JOB_FAMILY_SERIALIZE_LANGUAGE_SETTINGS_WORKSPACE"; //$NON-NLS-1$
|
||||
|
||||
private static final String PREFERENCE_WORSPACE_PROVIDERS_SET = "language.settings.providers.workspace.prefs.toggle"; //$NON-NLS-1$
|
||||
private static final String CPROJECT_STORAGE_MODULE = "org.eclipse.cdt.core.LanguageSettingsProviders"; //$NON-NLS-1$
|
||||
private static final String STORAGE_WORKSPACE_LANGUAGE_SETTINGS = "language.settings.xml"; //$NON-NLS-1$
|
||||
|
@ -368,7 +371,7 @@ public class LanguageSettingsProvidersSerializer {
|
|||
*/
|
||||
public static void setWorkspaceProviders(List<ILanguageSettingsProvider> providers) throws CoreException {
|
||||
setWorkspaceProvidersInternal(providers);
|
||||
serializeLanguageSettingsWorkspace();
|
||||
serializeLanguageSettingsWorkspaceInBackground();
|
||||
// generate preference change event for preference change listeners (value is not intended to be used)
|
||||
IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID);
|
||||
prefs.putBoolean(PREFERENCE_WORSPACE_PROVIDERS_SET, ! prefs.getBoolean(PREFERENCE_WORSPACE_PROVIDERS_SET, false));
|
||||
|
@ -565,9 +568,9 @@ public class LanguageSettingsProvidersSerializer {
|
|||
}
|
||||
}
|
||||
|
||||
Job job = new Job(SettingsModelMessages.getString("LanguageSettingsProvidersSerializer.SerializeJobName")) { //$NON-NLS-1$
|
||||
Job job = new WorkspaceJob(SettingsModelMessages.getString("LanguageSettingsProvidersSerializer.SerializeJobName")) { //$NON-NLS-1$
|
||||
@Override
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
|
||||
try {
|
||||
monitor.beginTask(SettingsModelMessages.getString("LanguageSettingsProvidersSerializer.SerializingForWorkspace"), //$NON-NLS-1$
|
||||
TICKS_SERIALIZING);
|
||||
|
@ -587,7 +590,6 @@ public class LanguageSettingsProvidersSerializer {
|
|||
}
|
||||
};
|
||||
|
||||
job.setRule(null);
|
||||
job.schedule();
|
||||
}
|
||||
|
||||
|
@ -596,6 +598,17 @@ public class LanguageSettingsProvidersSerializer {
|
|||
* Load language settings for workspace.
|
||||
*/
|
||||
public static void loadLanguageSettingsWorkspace() {
|
||||
// ensure completion of any scheduled background serialization
|
||||
try {
|
||||
Job.getJobManager().join(JOB_FAMILY_SERIALIZE_LANGUAGE_SETTINGS_WORKSPACE, null);
|
||||
} catch (OperationCanceledException e) {
|
||||
return;
|
||||
} catch (InterruptedException e) {
|
||||
CCorePlugin.log(e);
|
||||
// restore interrupted status
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
List <ILanguageSettingsProvider> providers = null;
|
||||
|
||||
URI uriStoreWsp = getStoreInWorkspaceArea(STORAGE_WORKSPACE_LANGUAGE_SETTINGS);
|
||||
|
|
|
@ -555,10 +555,10 @@ class ASTFunctionStyleMacroDefinition extends ASTMacroDefinition implements IAST
|
|||
int endIdx= Math.min(fExpansionNumber - defOffset, image.length);
|
||||
char start= '(';
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
while(idx < endIdx && image[idx] != start)
|
||||
while (idx < endIdx && image[idx] != start)
|
||||
idx++;
|
||||
idx++;
|
||||
while(idx < endIdx && Character.isWhitespace(image[idx]))
|
||||
while (idx < endIdx && Character.isWhitespace(image[idx]))
|
||||
idx++;
|
||||
start= ',';
|
||||
|
||||
|
@ -800,7 +800,8 @@ class ASTMacroExpansionLocation implements IASTMacroExpansionLocation, org.eclip
|
|||
|
||||
@Override
|
||||
public IASTFileLocation asFileLocation() {
|
||||
return ((LocationCtxContainer) fContext.getParent()).createFileLocation(fContext.fOffsetInParent, fContext.fEndOffsetInParent-fContext.fOffsetInParent);
|
||||
return ((LocationCtxContainer) fContext.getParent()).createFileLocation(fContext.fOffsetInParent,
|
||||
fContext.fEndOffsetInParent - fContext.fOffsetInParent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,7 +12,6 @@ package org.eclipse.cdt.internal.core.parser.scanner;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -657,11 +656,10 @@ public class LocationMap implements ILocationResolver {
|
|||
|
||||
@Override
|
||||
public IASTPreprocessorMacroDefinition[] getMacroDefinitions() {
|
||||
ArrayList<Object> result= new ArrayList<Object>();
|
||||
for (Iterator<ASTPreprocessorNode> iterator = fDirectives.iterator(); iterator.hasNext();) {
|
||||
Object directive= iterator.next();
|
||||
ArrayList<IASTPreprocessorMacroDefinition> result= new ArrayList<IASTPreprocessorMacroDefinition>();
|
||||
for (ASTPreprocessorNode directive : fDirectives) {
|
||||
if (directive instanceof IASTPreprocessorMacroDefinition) {
|
||||
result.add(directive);
|
||||
result.add((IASTPreprocessorMacroDefinition) directive);
|
||||
}
|
||||
}
|
||||
return result.toArray(new IASTPreprocessorMacroDefinition[result.size()]);
|
||||
|
@ -669,11 +667,10 @@ public class LocationMap implements ILocationResolver {
|
|||
|
||||
@Override
|
||||
public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
|
||||
ArrayList<Object> result= new ArrayList<Object>();
|
||||
for (Iterator<ASTPreprocessorNode> iterator = fDirectives.iterator(); iterator.hasNext();) {
|
||||
Object directive= iterator.next();
|
||||
ArrayList<IASTPreprocessorIncludeStatement> result= new ArrayList<IASTPreprocessorIncludeStatement>();
|
||||
for (ASTPreprocessorNode directive : fDirectives) {
|
||||
if (directive instanceof IASTPreprocessorIncludeStatement) {
|
||||
result.add(directive);
|
||||
result.add((IASTPreprocessorIncludeStatement) directive);
|
||||
}
|
||||
}
|
||||
return result.toArray(new IASTPreprocessorIncludeStatement[result.size()]);
|
||||
|
|
|
@ -635,13 +635,13 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
|
||||
@Override
|
||||
public int visit(IASTDeclaration node) {
|
||||
if (!startNode(node)) {
|
||||
if (!enterNode(node)) {
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
try {
|
||||
return formatDeclaration(node);
|
||||
} finally {
|
||||
finishNode(node);
|
||||
exitNode(node);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -695,7 +695,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
*/
|
||||
@Override
|
||||
public int visit(IASTName node) {
|
||||
if (!startNode(node)) { return PROCESS_SKIP; }
|
||||
if (!enterNode(node)) { return PROCESS_SKIP; }
|
||||
try {
|
||||
if (node instanceof ICPPASTQualifiedName) {
|
||||
visit((ICPPASTQualifiedName) node);
|
||||
|
@ -705,7 +705,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
formatRaw(node);
|
||||
}
|
||||
} finally {
|
||||
finishNode(node);
|
||||
exitNode(node);
|
||||
}
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
@ -726,7 +726,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
}
|
||||
}
|
||||
|
||||
if (!startNode(node)) { return PROCESS_SKIP; }
|
||||
if (!enterNode(node)) { return PROCESS_SKIP; }
|
||||
try {
|
||||
if (node instanceof IASTEqualsInitializer) {
|
||||
visit((IASTEqualsInitializer) node);
|
||||
|
@ -738,7 +738,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
formatRaw(node);
|
||||
}
|
||||
} finally {
|
||||
finishNode(node);
|
||||
exitNode(node);
|
||||
}
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
@ -748,7 +748,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
*/
|
||||
@Override
|
||||
public int visit(IASTParameterDeclaration node) {
|
||||
if (!startNode(node)) { return PROCESS_SKIP; }
|
||||
if (!enterNode(node)) { return PROCESS_SKIP; }
|
||||
try {
|
||||
// decl-specifier
|
||||
final IASTDeclSpecifier declSpec= node.getDeclSpecifier();
|
||||
|
@ -765,7 +765,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
declarator.accept(this);
|
||||
}
|
||||
} finally {
|
||||
finishNode(node);
|
||||
exitNode(node);
|
||||
}
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
@ -775,7 +775,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
*/
|
||||
@Override
|
||||
public int visit(IASTDeclarator node) {
|
||||
if (!startNode(node)) { return PROCESS_SKIP; }
|
||||
if (!enterNode(node)) { return PROCESS_SKIP; }
|
||||
|
||||
try {
|
||||
// Common to all declarators
|
||||
|
@ -827,7 +827,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
initializer.accept(this);
|
||||
}
|
||||
} finally {
|
||||
finishNode(node);
|
||||
exitNode(node);
|
||||
}
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
@ -852,7 +852,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
*/
|
||||
@Override
|
||||
public int visit(IASTDeclSpecifier node) {
|
||||
if (!startNode(node)) { return PROCESS_SKIP; }
|
||||
if (!enterNode(node)) { return PROCESS_SKIP; }
|
||||
try {
|
||||
if (node instanceof ICPPASTCompositeTypeSpecifier) {
|
||||
visit((ICPPASTCompositeTypeSpecifier) node);
|
||||
|
@ -870,7 +870,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
formatRaw(node);
|
||||
}
|
||||
} finally {
|
||||
finishNode(node);
|
||||
exitNode(node);
|
||||
}
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
@ -880,7 +880,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
*/
|
||||
@Override
|
||||
public int visit(IASTExpression node) {
|
||||
if (!startNode(node)) { return PROCESS_SKIP; }
|
||||
if (!enterNode(node)) { return PROCESS_SKIP; }
|
||||
try {
|
||||
if (node instanceof IASTArraySubscriptExpression) {
|
||||
visit((IASTArraySubscriptExpression) node);
|
||||
|
@ -918,7 +918,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
formatRaw(node);
|
||||
}
|
||||
} finally {
|
||||
finishNode(node);
|
||||
exitNode(node);
|
||||
}
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
@ -931,7 +931,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
if (getCurrentPosition() <= nodeOffset(node) && startsWithMacroExpansion(node)) {
|
||||
scribe.printCommentPreservingNewLines();
|
||||
}
|
||||
if (!startNode(node)) { return PROCESS_SKIP; }
|
||||
if (!enterNode(node)) { return PROCESS_SKIP; }
|
||||
int indentLevel= scribe.indentationLevel;
|
||||
try {
|
||||
if (node instanceof IASTCompoundStatement) {
|
||||
|
@ -985,7 +985,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
}
|
||||
}
|
||||
} finally {
|
||||
finishNode(node);
|
||||
exitNode(node);
|
||||
}
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
@ -995,7 +995,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
*/
|
||||
@Override
|
||||
public int visit(IASTTypeId node) {
|
||||
if (!startNode(node)) { return PROCESS_SKIP; }
|
||||
if (!enterNode(node)) { return PROCESS_SKIP; }
|
||||
try {
|
||||
if (node instanceof IASTProblemHolder) {
|
||||
throw new ASTProblemException(((IASTProblemHolder) node).getProblem());
|
||||
|
@ -1015,7 +1015,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
declarator.accept(this);
|
||||
}
|
||||
} finally {
|
||||
finishNode(node);
|
||||
exitNode(node);
|
||||
}
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
@ -1025,7 +1025,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
*/
|
||||
@Override
|
||||
public int visit(IASTEnumerator enumerator) {
|
||||
if (!startNode(enumerator)) { return PROCESS_SKIP; }
|
||||
if (!enterNode(enumerator)) { return PROCESS_SKIP; }
|
||||
try {
|
||||
// name
|
||||
enumerator.getName().accept(this);
|
||||
|
@ -1040,7 +1040,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
value.accept(this);
|
||||
}
|
||||
} finally {
|
||||
finishNode(enumerator);
|
||||
exitNode(enumerator);
|
||||
}
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
@ -1050,7 +1050,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
*/
|
||||
@Override
|
||||
public int visit(ICPPASTBaseSpecifier specifier) {
|
||||
if (!startNode(specifier)) { return PROCESS_SKIP; }
|
||||
if (!enterNode(specifier)) { return PROCESS_SKIP; }
|
||||
try {
|
||||
boolean needSpace= false;
|
||||
loop: while (true) {
|
||||
|
@ -1072,7 +1072,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
}
|
||||
specifier.getName().accept(this);
|
||||
} finally {
|
||||
finishNode(specifier);
|
||||
exitNode(specifier);
|
||||
}
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
@ -1082,7 +1082,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
*/
|
||||
@Override
|
||||
public int visit(ICPPASTNamespaceDefinition node) {
|
||||
if (!startNode(node)) { return PROCESS_SKIP; }
|
||||
if (!enterNode(node)) { return PROCESS_SKIP; }
|
||||
try {
|
||||
final int line= scribe.line;
|
||||
// namespace <name>
|
||||
|
@ -1104,7 +1104,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
}
|
||||
formatClosingBrace(preferences.brace_position_for_namespace_declaration);
|
||||
} finally {
|
||||
finishNode(node);
|
||||
exitNode(node);
|
||||
}
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
@ -1206,7 +1206,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
*/
|
||||
@Override
|
||||
public int visit(ICPPASTTemplateParameter node) {
|
||||
if (!startNode(node)) { return PROCESS_SKIP; }
|
||||
if (!enterNode(node)) { return PROCESS_SKIP; }
|
||||
try {
|
||||
if (node instanceof ICPPASTSimpleTypeTemplateParameter) {
|
||||
visit((ICPPASTSimpleTypeTemplateParameter) node);
|
||||
|
@ -1218,7 +1218,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
} catch (ASTProblemException e) {
|
||||
skipNode(node);
|
||||
} finally {
|
||||
finishNode(node);
|
||||
exitNode(node);
|
||||
}
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
@ -1284,12 +1284,12 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
}
|
||||
|
||||
private int visit(ICPPASTConstructorInitializer node) {
|
||||
if (!startNode(node)) { return PROCESS_SKIP; }
|
||||
if (!enterNode(node)) { return PROCESS_SKIP; }
|
||||
try {
|
||||
// Format like a function call
|
||||
formatFunctionCallArguments(node.getArguments());
|
||||
} finally {
|
||||
finishNode(node);
|
||||
exitNode(node);
|
||||
}
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
@ -1372,7 +1372,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
|
||||
// Body
|
||||
if (bodyStmt instanceof IASTCompoundStatement) {
|
||||
if (startNode(bodyStmt)) {
|
||||
if (enterNode(bodyStmt)) {
|
||||
try {
|
||||
if (getCurrentPosition() <= nodeOffset(bodyStmt)) {
|
||||
formatLeftCurlyBrace(line, preferences.brace_position_for_method_declaration);
|
||||
|
@ -1382,7 +1382,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
preferences.insert_space_before_opening_brace_in_method_declaration,
|
||||
preferences.indent_statements_compare_to_body);
|
||||
} finally {
|
||||
finishNode(bodyStmt);
|
||||
exitNode(bodyStmt);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -1903,23 +1903,23 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
if (preferences.indent_body_declarations_compare_to_access_specifier) {
|
||||
scribe.unIndent();
|
||||
}
|
||||
if (startNode(declaration)) {
|
||||
if (enterNode(declaration)) {
|
||||
try {
|
||||
scribe.startNewLine();
|
||||
visit((ICPPASTVisibilityLabel) declaration);
|
||||
scribe.startNewLine();
|
||||
} finally {
|
||||
finishNode(declaration);
|
||||
exitNode(declaration);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (startNode(declaration)) {
|
||||
if (enterNode(declaration)) {
|
||||
try {
|
||||
if (getCurrentPosition() <= nodeOffset(declaration))
|
||||
scribe.startNewLine();
|
||||
formatDeclaration(declaration);
|
||||
} finally {
|
||||
finishNode(declaration);
|
||||
exitNode(declaration);
|
||||
}
|
||||
} else {
|
||||
skipNode(declaration);
|
||||
|
@ -3211,7 +3211,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
scribe.exitAlignment(alignment, true);
|
||||
|
||||
if (body instanceof IASTCompoundStatement && !startsWithMacroExpansion(body)) {
|
||||
if (startNode(body)) {
|
||||
if (enterNode(body)) {
|
||||
try {
|
||||
if (getCurrentPosition() <= nodeOffset(body)) {
|
||||
formatLeftCurlyBrace(line, preferences.brace_position_for_block);
|
||||
|
@ -3221,7 +3221,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
preferences.insert_space_before_opening_brace_in_block,
|
||||
preferences.indent_statements_compare_to_block);
|
||||
} finally {
|
||||
finishNode(body);
|
||||
exitNode(body);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -3330,7 +3330,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
}
|
||||
} else {
|
||||
if (doNodesHaveSameOffset(node, thenStatement)) {
|
||||
startNode(thenStatement);
|
||||
enterNode(thenStatement);
|
||||
}
|
||||
if (elseStatement == null && preferences.keep_simple_if_on_one_line) {
|
||||
Alignment compactIfAlignment = scribe.createAlignment(
|
||||
|
@ -3567,7 +3567,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
} else {
|
||||
statements= Collections.singletonList(bodyStmt);
|
||||
}
|
||||
if (!startNode(bodyStmt)) { return PROCESS_SKIP; }
|
||||
if (!enterNode(bodyStmt)) { return PROCESS_SKIP; }
|
||||
try {
|
||||
final int statementsLength = statements.size();
|
||||
if (statementsLength != 0) {
|
||||
|
@ -3624,7 +3624,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
}
|
||||
bracePosition = preferences.brace_position_for_block_in_case;
|
||||
try {
|
||||
startNode(statement);
|
||||
enterNode(statement);
|
||||
formatBlock((IASTCompoundStatement) statement, bracePosition,
|
||||
preferences.insert_space_after_colon_in_case,
|
||||
preferences.indent_statements_compare_to_block);
|
||||
|
@ -3634,7 +3634,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
skipToNode(nextStatement);
|
||||
}
|
||||
} finally {
|
||||
finishNode(statement);
|
||||
exitNode(statement);
|
||||
}
|
||||
if (preferences.indent_switchstatements_compare_to_cases) {
|
||||
scribe.indent();
|
||||
|
@ -3642,7 +3642,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
} else {
|
||||
bracePosition = preferences.brace_position_for_block;
|
||||
try {
|
||||
startNode(statement);
|
||||
enterNode(statement);
|
||||
formatBlock((IASTCompoundStatement) statement, bracePosition,
|
||||
preferences.insert_space_before_opening_brace_in_block,
|
||||
preferences.indent_statements_compare_to_block);
|
||||
|
@ -3652,7 +3652,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
skipToNode(nextStatement);
|
||||
}
|
||||
} finally {
|
||||
finishNode(statement);
|
||||
exitNode(statement);
|
||||
}
|
||||
}
|
||||
wasAStatement = true;
|
||||
|
@ -3692,7 +3692,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
formatClosingBrace(brace_position);
|
||||
}
|
||||
} finally {
|
||||
finishNode(bodyStmt);
|
||||
exitNode(bodyStmt);
|
||||
}
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
@ -3752,8 +3752,8 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
* @param node the AST node to be tested
|
||||
* @return <code>false</code> if the node should be skipped
|
||||
*/
|
||||
private boolean startNode(IASTNode node) {
|
||||
scribe.startNode();
|
||||
private boolean enterNode(IASTNode node) {
|
||||
scribe.enterNode();
|
||||
if (node instanceof IASTProblemHolder) {
|
||||
return false;
|
||||
}
|
||||
|
@ -3796,7 +3796,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
*
|
||||
* @param node
|
||||
*/
|
||||
private void finishNode(IASTNode node) {
|
||||
private void exitNode(IASTNode node) {
|
||||
if (node instanceof IASTProblemHolder) {
|
||||
return;
|
||||
}
|
||||
|
@ -3929,13 +3929,13 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
if (stmt != null) {
|
||||
if (stmt instanceof IASTCompoundStatement && !startsWithMacroExpansion(stmt)) {
|
||||
formatLeftCurlyBrace(line, brace_position);
|
||||
if (startNode(stmt)) {
|
||||
if (enterNode(stmt)) {
|
||||
try {
|
||||
formatBlock((IASTCompoundStatement) stmt, brace_position,
|
||||
preferences.insert_space_before_opening_brace_in_block,
|
||||
preferences.indent_statements_compare_to_block);
|
||||
} finally {
|
||||
finishNode(stmt);
|
||||
exitNode(stmt);
|
||||
}
|
||||
}
|
||||
} else if (stmt instanceof IASTNullStatement) {
|
||||
|
@ -4172,7 +4172,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
!doNodeLocationsOverlap(statement, statements.get(i - 1))) {
|
||||
scribe.startNewLine();
|
||||
}
|
||||
if (!startNode(statement)) {
|
||||
if (!enterNode(statement)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
|
|
|
@ -1581,7 +1581,7 @@ public class Scribe {
|
|||
}
|
||||
}
|
||||
|
||||
public void startNode() {
|
||||
public void enterNode() {
|
||||
lastLineComment.contiguous = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -228,13 +229,16 @@ public class XmlUtil {
|
|||
return null;
|
||||
}
|
||||
|
||||
InputStream xmlStream;
|
||||
try {
|
||||
xmlStream = new FileInputStream(xmlFile);
|
||||
InputStream xmlStream = new FileInputStream(xmlFile);
|
||||
try {
|
||||
return loadXml(xmlStream);
|
||||
} finally {
|
||||
xmlStream.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new CoreException(CCorePlugin.createStatus(Messages.XmlUtil_InternalErrorLoading, e));
|
||||
}
|
||||
return loadXml(xmlStream);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -245,8 +249,16 @@ public class XmlUtil {
|
|||
* @throws CoreException if something goes wrong.
|
||||
*/
|
||||
public static Document loadXml(IFile xmlFile) throws CoreException {
|
||||
InputStream xmlStream = xmlFile.getContents();
|
||||
return loadXml(xmlStream);
|
||||
try {
|
||||
InputStream xmlStream = xmlFile.getContents();
|
||||
try {
|
||||
return loadXml(xmlStream);
|
||||
} finally {
|
||||
xmlStream.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new CoreException(CCorePlugin.createStatus(Messages.XmlUtil_InternalErrorLoading, e));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -273,13 +285,46 @@ public class XmlUtil {
|
|||
|
||||
XmlUtil.prettyFormat(doc);
|
||||
DOMSource source = new DOMSource(doc);
|
||||
StreamResult result = new StreamResult(new FileOutputStream(storeFile));
|
||||
StreamResult result = new StreamResult(getFileOutputStreamWorkaround(storeFile));
|
||||
transformer.transform(source, result);
|
||||
|
||||
result.getOutputStream().close();
|
||||
ResourcesUtil.refreshWorkspaceFiles(uriLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Workaround for Java problem on Windows with releasing buffers for memory-mapped files.
|
||||
*
|
||||
* @see "http://stackoverflow.com/questions/3602783/file-access-synchronized-on-java-object"
|
||||
* @see "http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6354433"
|
||||
* @see "http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4715154"
|
||||
* @see "http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4469299"
|
||||
*/
|
||||
private static FileOutputStream getFileOutputStreamWorkaround(java.io.File storeFile) throws FileNotFoundException {
|
||||
final int maxCount = 10;
|
||||
for (int i = 0; i <= maxCount; i++) {
|
||||
try {
|
||||
// there is no sleep on first round
|
||||
Thread.sleep(10 * i);
|
||||
} catch (InterruptedException e) {
|
||||
// restore interrupted status
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
try {
|
||||
return new FileOutputStream(storeFile);
|
||||
} catch (FileNotFoundException e) {
|
||||
// only apply workaround for the very specific exception
|
||||
if (i >= maxCount || !e.getMessage().contains("The requested operation cannot be performed on a file with a user-mapped section open")) { //$NON-NLS-1$
|
||||
throw e;
|
||||
}
|
||||
// CCorePlugin.log(new Status(IStatus.INFO, CCorePlugin.PLUGIN_ID, "Workaround for concurrent access to memory-mapped files applied, attempt " + (i + 1), e)); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
// will never get here
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize XML Document into a byte array.
|
||||
* @param doc - DOM Document to serialize.
|
||||
|
|
Loading…
Add table
Reference in a new issue