1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

2004-09-07 Alain Magloire

Part of the uncoming work to supply formatting in CDT
	* schema/CodeFormatter.exsd
	* src/org/eclipse/cdt/core/CodePreferenceConstants.java
	* src/org/eclipse/cdt/core/ToolFactory.java
	* src/org/eclipse/cdt/core/formatter/CodeFormatter.java
	* src/org/eclipse/cdt/core/formatter/CodeFormatterConstants.java
	* src/org/eclipse/cdt/internal/core/CCorePreferenceInitializer.java
	* plugin.properties
	* plugin.xml
This commit is contained in:
Alain Magloire 2004-09-07 20:23:30 +00:00
parent 9ac724d2ed
commit 08d72e6639
9 changed files with 360 additions and 0 deletions

View file

@ -1,3 +1,15 @@
2004-09-07 Alain Magloire
Part of the uncoming work to supply formatting in CDT
* schema/CodeFormatter.exsd
* src/org/eclipse/cdt/core/CodePreferenceConstants.java
* src/org/eclipse/cdt/core/ToolFactory.java
* src/org/eclipse/cdt/core/formatter/CodeFormatter.java
* src/org/eclipse/cdt/core/formatter/CodeFormatterConstants.java
* src/org/eclipse/cdt/internal/core/CCorePreferenceInitializer.java
* plugin.properties
* plugin.xml
2004-09-03 Alain Magloire
Provide the extension for the Core Plugin Preference Initializer.

View file

@ -20,6 +20,8 @@ CBuildConsole.name=C Builder Console
CProject.name=C Project
ProcessList.name=Process List
ErrorParser.name=Error Parser
CodeFormatter.name=C/C++ Code Formatter
CodeFormatter.name=C/C++ Code Formatters
CTaskName=C/C++ Task
@ -54,3 +56,8 @@ fragmentName.qnx = C/C++ Development Tools Core for QNX
fragmentName.solaris = C/C++ Development Tools Core for Solaris
fragmentName.win32 = C/C++ Development Tools Core for Windows
fragmentName.macosx = C/C++ Development Tools Core for MacOS X
CodeFormatter.name=C/C++ Code Formatter
CodeFormatter.name=C/C++ Code Formatters
DefaultCodeFormatter.name=Default Formatter
DefaultCodeFormatter.name=Default Formatter

View file

@ -19,6 +19,7 @@
<import plugin="org.eclipse.core.resources"/>
<import plugin="org.eclipse.team.core"/>
<import plugin="org.eclipse.core.runtime"/>
<import plugin="org.eclipse.text"/>
</requires>
@ -53,6 +54,7 @@
<extension-point id="CFileType" name="CFileType" schema="schema/CFileType.exsd"/>
<extension-point id="CFileTypeAssociation" name="CFileTypeAssociation" schema="schema/CFileTypeAssociation.exsd"/>
<extension-point id="PathEntryContainerInitializer" name="%PathEntryContainerInitializer" schema="schema/PathEntryContainerInitializer.exsd"/>
<extension-point id="CodeFormatter" name="CodeFormatter.name" schema="schema/CodeFormatter.exsd"/>
<!-- =================================================================================== -->
<!-- Define the list of the Binary Parser provided by the CDT -->
@ -438,6 +440,15 @@
type="org.eclipse.core.resources.problemmarker">
</super>
</extension>
<!--extension
id="codeFormatters"
name="%CodeFormatters.name"
point="org.eclipse.cdt.core.CodeFormatter">
<codeFormatter
class="org.eclipse.cdt.internal.formatter.DefaultCodeFormatter"
name="%DefaultCodeFormatter.name"
id="org.eclipse.cdt.core.defaultCodeFormatter"/>
</extension-->
<!-- =================================================================================== -->
<!-- Initialize the preference for the Core Plugin -->

View file

@ -0,0 +1,116 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.cdt.core">
<annotation>
<appInfo>
<meta.schema plugin="org.eclipse.cdt.core" id="CodeFormatter" name="CodeFormatter.name"/>
</appInfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<complexType>
<sequence>
<element ref="codeFormatter" minOccurs="1" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="codeFormatter">
<complexType>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
A unique name that will be used to reference this code formatter
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string" use="required">
<annotation>
<documentation>
A translatable name that will be used for presenting this formatter in the UI.
</documentation>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
a fully qualified name of the Java class that implements &lt;samp&gt;org.eclipse.cdt.core.formatter.CodeFormatter&lt;/samp&gt; abstract class.
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn="org.eclipse.cdt.core.formatter.CodeFormatter"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="apiInfo"/>
</appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="copyright"/>
</appInfo>
<documentation>
</documentation>
</annotation>
</schema>

View file

@ -34,4 +34,15 @@ public class CCorePreferenceConstants {
*/
public static final String TRANSLATION_TASK_PRIORITIES = CCorePlugin.PLUGIN_ID + ".translation.taskPriorities"; //$NON-NLS-1$
/**
* Active code formatter ID.
* @see #getDefaultOptions
*/
public static final String CODE_FORMATTER = CCorePlugin.PLUGIN_ID + ".code_formatter"; //$NON-NLS-1$
/**
* Default code formatter
*/
public static final String DEFAULT_CODE_FORMATTER = CCorePlugin.PLUGIN_ID + ".defaultCodeFormatter"; //$NON-NLS-1$
}

View file

@ -0,0 +1,76 @@
/*
* Created on Aug 17, 2004
*
* Copyright 2004, QNX Software Systems Ltd. All Rights Reserved.
*
* This source code may contain confidential information of QNX Software
* Systems Ltd. (QSSL) and its licensors. Any use, reproduction,
* modification, disclosure, distribution or transfer of this software,
* or any software which includes or is based upon any of this code, is
* prohibited unless expressly authorized by QSSL by written agreement. For
* more information (including whether this source code file has been
* published) please email licensing@qnx.com.
*/
package org.eclipse.cdt.core;
import java.util.Map;
import org.eclipse.cdt.core.formatter.CodeFormatter;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
/**
* @author AChapiro
*/
public class ToolFactory {
/**
* Create an instance of the built-in code formatter.
* @param options - the options map to use for formatting with the default code formatter. Recognized options
* are documented on <code>CCorePlugin#getDefaultOptions()</code>. If set to <code>null</code>, then use
* the current settings from <code>CCorePlugin#getOptions</code>.
* @return an instance of the built-in code formatter
* @see CodeFormatter
* @see CCorePlugin#getOptions()
*/
public static CodeFormatter createCodeFormatter(Map options){
if (options == null)
options = CCorePlugin.getOptions();
String formatterID = (String)options.get(CCorePreferenceConstants.CODE_FORMATTER);
IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
IExtensionPoint extension = Platform.getExtensionRegistry().
getExtensionPoint(CCorePlugin.PLUGIN_ID, "CodeFormatter");
if (extension != null) {
IExtension[] extensions = extension.getExtensions();
for(int i = 0; i < extensions.length; i++){
IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
for(int j = 0; j < configElements.length; j++){
String initializerID = configElements[j].getAttribute("id"); //$NON-NLS-1$
if (initializerID != null && initializerID.equals(formatterID)){
try {
Object execExt = configElements[j].createExecutableExtension("class"); //$NON-NLS-1$
if (execExt instanceof CodeFormatter){
CodeFormatter formatter = (CodeFormatter)execExt;
formatter.setOptions(options);
return formatter;
}
} catch(CoreException e) {
//TODO: add more reasonable error processing
e.printStackTrace();
break;
}
}
}
}
}
// TODO: open this code later
// return new DefaultCodeFormatter(options);
return null;
}
}

View file

@ -0,0 +1,79 @@
/*******************************************************************************
* Copyright (c) 2000, 2004 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.core.formatter;
import java.util.Map;
import org.eclipse.jface.text.IDocument;
import org.eclipse.text.edits.TextEdit;
/**
* Specification for a generic source code formatter.
*
* @since 3.0
*/
public abstract class CodeFormatter {
/**
* Unknown kind
*/
public static final int K_UNKNOWN = 0x00;
/**
* Kind used to format an expression
*/
public static final int K_EXPRESSION = 0x01;
/**
* Kind used to format a set of statements
*/
public static final int K_STATEMENTS = 0x02;
/**
* Kind used to format a set of class body declarations
*/
public static final int K_CLASS_BODY_DECLARATIONS = 0x04;
/**
* Kind used to format a compilation unit
*/
public static final int K_COMPILATION_UNIT = 0x08;
/**
* Format <code>source</code>,
* and returns a text edit that correspond to the difference between the given string and the formatted string.
* It returns null if the given string cannot be formatted.
*
* If the offset position is matching a whitespace, the result can include whitespaces. It would be up to the
* caller to get rid of preceeding whitespaces.
*
* @param kind Use to specify the kind of the code snippet to format. It can be any of these:
* K_EXPRESSION, K_STATEMENTS, K_CLASS_BODY_DECLARATIONS, K_COMPILATION_UNIT, K_UNKNOWN
* @param file - file associated with this source (null if no file is associated)
* @param document the document to format
* @param offset the given offset to start recording the edits (inclusive).
* @param length the given length to stop recording the edits (exclusive).
* @param indentationLevel the initial indentation level, used
* to shift left/right the entire source fragment. An initial indentation
* level of zero or below has no effect.
* @param lineSeparator the line separator to use in formatted source,
* if set to <code>null</code>, then the platform default one will be used.
* @return the text edit
* @throws IllegalArgumentException if offset is lower than 0, length is lower than 0 or
* length is greater than source length.
*/
public abstract TextEdit format(int kind, IDocument document, int offset, int length, int indentationLevel, String lineSeparator);
/**
* @param options - general formatter options
*/
public abstract void setOptions(Map options);
}

View file

@ -0,0 +1,42 @@
/*
* Created on Sep 5, 2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package org.eclipse.cdt.core.formatter;
import org.eclipse.cdt.core.CCorePlugin;
/**
* @author Alex Chapiro
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class CodeFormatterConstants {
/**
* <pre>
* FORMATTER / Option for alignment of arguments in allocation expression
* - option id: "org.eclipse.jdt.core.formatter.language"
* - possible values: values proposed in class <code>ParserLanguage</code>
* - default: ParserLanguage.CPP
* </pre>
*/
public static final String FORMATTER_LANGUAGE = CCorePlugin.PLUGIN_ID + ".formatter.language"; //$NON-NLS-1$
/**
* <pre>
* FORMATTER / Option for alignment of arguments in allocation expression
* - option id: "org.eclipse.jdt.core.formatter.current_file"
* - possible values: object of class <code>IFile</code> or <code>null</code>
* - default: null
* </pre>
*/
public static final String FORMATTER_CURRENT_FILE = CCorePlugin.PLUGIN_ID + ".formatter.current_file"; //$NON-NLS-1$
}

View file

@ -17,6 +17,8 @@ import org.eclipse.cdt.core.CCorePreferenceConstants;
import org.eclipse.cdt.internal.core.model.CModelManager;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
// import org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager;
// import org.eclipse.jdt.internal.ui.preferences.formatter.ProfileStore;
public class CCorePreferenceInitializer extends AbstractPreferenceInitializer {
@ -34,6 +36,10 @@ public class CCorePreferenceInitializer extends AbstractPreferenceInitializer {
preferences.setDefault(CCorePreferenceConstants.TRANSLATION_TASK_PRIORITIES, CCorePreferenceConstants.DEFAULT_TASK_PRIORITY);
optionNames.add(CCorePreferenceConstants.TRANSLATION_TASK_PRIORITIES);
preferences.setDefault(CCorePreferenceConstants.CODE_FORMATTER, CCorePreferenceConstants.DEFAULT_CODE_FORMATTER);
optionNames.add(CCorePreferenceConstants.CODE_FORMATTER);
}
}