1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-28 19:35:36 +02:00

API cleanup & JavaDoc

This commit is contained in:
Andrew Gvozdev 2011-11-19 08:55:06 -05:00
parent ba7591a95b
commit da8e44baef
13 changed files with 222 additions and 210 deletions

View file

@ -141,17 +141,22 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
}
public void testAbstractBuiltinSpecsDetector_GettersSetters() throws Exception {
// define mock detector
{
// provider configured with null parameters
MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag();
detector.configureProvider(PROVIDER_ID, PROVIDER_NAME, null, null, null);
assertEquals(PROVIDER_ID, detector.getId());
assertEquals(PROVIDER_NAME, detector.getName());
assertEquals(null, detector.getLanguageScope());
assertEquals(null, detector.getSettingEntries(null, null, null));
assertEquals(null, detector.getCustomParameter());
assertEquals(false, detector.isExecuted());
}
{
// provider configured with non-null parameters
MockBuiltinSpecsDetectorExecutedFlag detector = new MockBuiltinSpecsDetectorExecutedFlag();
List<String> languages = new ArrayList<String>();
languages.add(LANGUAGE_ID);
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
@ -169,6 +174,7 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase {
detector.execute();
assertEquals(true, detector.isExecuted());
}
}
public void testAbstractBuiltinSpecsDetector_CloneAndEquals() throws Exception {
// define mock detector

View file

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) and others.
* Copyright (c) 2009, 2011 Andrew Gvozdev and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation
* Andrew Gvozdev - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.scannerconfig;

View file

@ -226,6 +226,25 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase {
}
}
/**
* LanguageSettingsBaseProvider is not allowed to be configured twice.
*/
public void testBaseProviderCantReconfigure() throws Exception {
// create LanguageSettingsBaseProvider
LanguageSettingsBaseProvider provider = new LanguageSettingsBaseProvider();
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
entries.add(new CIncludePathEntry("/usr/include/", 0));
// configure it
provider.configureProvider("id", "name", null, entries, null);
try {
// attempt to configure it twice should fail
provider.configureProvider("id", "name", null, entries, null);
fail("LanguageSettingsBaseProvider is not allowed to be configured twice");
} catch (UnsupportedOperationException e) {
}
}
/**
* TODO
*/
@ -299,27 +318,7 @@ public class LanguageSettingsExtensionsTests extends BaseTestCase {
assertFalse(LanguageSettingsExtensionManager.equalsExtensionProvider(providerShallow));
assertTrue(LanguageSettingsExtensionManager.equalsExtensionProviderShallow((ILanguageSettingsEditableProvider) providerShallow));
}
}
// /**
// * LanguageSettingsBaseProvider is not allowed to be configured twice.
// */
// public void testBaseProviderConfigure() throws Exception {
// // create LanguageSettingsBaseProvider
// LanguageSettingsBaseProvider provider = new LanguageSettingsBaseProvider();
// List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
// entries.add(new CIncludePathEntry("/usr/include/", 0));
// // configure it
// provider.configureProvider("id", "name", null, entries, null);
//
// try {
// // attempt to configure it twice should fail
// provider.configureProvider("id", "name", null, entries, null);
// fail("LanguageSettingsBaseProvider is not allowed to be configured twice");
// } catch (UnsupportedOperationException e) {
// }
// }
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2010 Andrew Gvozdev and others.
* Copyright (c) 2009, 2011 Andrew Gvozdev and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009 Andrew Gvozdev and others.
* Copyright (c) 2009, 2011 Andrew Gvozdev and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -1238,17 +1238,17 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
sampleLanguages.add(LANG_ID);
// create a model provider
class LanguageSettingsSerializableMock extends LanguageSettingsSerializableProvider implements Cloneable {
public LanguageSettingsSerializableMock(String id, String name) {
class MockSerializableProvider extends LanguageSettingsSerializableProvider implements Cloneable {
public MockSerializableProvider(String id, String name) {
super(id, name);
}
@Override
public LanguageSettingsSerializableMock clone() throws CloneNotSupportedException {
return (LanguageSettingsSerializableMock) super.clone();
public MockSerializableProvider clone() throws CloneNotSupportedException {
return (MockSerializableProvider) super.clone();
}
}
LanguageSettingsSerializableMock provider1 = new LanguageSettingsSerializableMock(PROVIDER_1, PROVIDER_NAME_1);
MockSerializableProvider provider1 = new MockSerializableProvider(PROVIDER_1, PROVIDER_NAME_1);
provider1.setLanguageScope(sampleLanguages);
provider1.setCustomParameter(CUSTOM_PARAMETER);
assertEquals(false, provider1.isStoringEntriesInProjectArea());
@ -1257,7 +1257,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
provider1.setSettingEntries(null, null, LANG_ID, sampleEntries_2);
// clone provider
LanguageSettingsSerializableMock providerClone = provider1.clone();
MockSerializableProvider providerClone = provider1.clone();
assertNotSame(provider1, providerClone);
assertTrue(provider1.equals(providerClone));
assertTrue(provider1.getClass()==providerClone.getClass());
@ -1286,17 +1286,17 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
sampleLanguages.add(LANG_ID);
// create a model provider
class LanguageSettingsSerializableMock extends LanguageSettingsSerializableProvider implements Cloneable {
public LanguageSettingsSerializableMock(String id, String name) {
class MockSerializableProvider extends LanguageSettingsSerializableProvider implements Cloneable {
public MockSerializableProvider(String id, String name) {
super(id, name);
}
@Override
public LanguageSettingsSerializableMock cloneShallow() throws CloneNotSupportedException {
return (LanguageSettingsSerializableMock) super.cloneShallow();
public MockSerializableProvider cloneShallow() throws CloneNotSupportedException {
return (MockSerializableProvider) super.cloneShallow();
}
}
LanguageSettingsSerializableMock provider1 = new LanguageSettingsSerializableMock(PROVIDER_1, PROVIDER_NAME_1);
MockSerializableProvider provider1 = new MockSerializableProvider(PROVIDER_1, PROVIDER_NAME_1);
provider1.setLanguageScope(sampleLanguages);
provider1.setCustomParameter(CUSTOM_PARAMETER);
assertEquals(false, provider1.isStoringEntriesInProjectArea());
@ -1307,7 +1307,7 @@ public class LanguageSettingsSerializableTests extends BaseTestCase {
provider1.setSettingEntries(null, null, null, entries);
// clone provider
LanguageSettingsSerializableMock providerClone = provider1.cloneShallow();
MockSerializableProvider providerClone = provider1.cloneShallow();
assertNotSame(provider1, providerClone);
assertFalse(provider1.equals(providerClone));
assertTrue(provider1.getClass()==providerClone.getClass());

View file

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) and others.
* Copyright (c) 2009, 2011 Andrew Gvozdev and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation
* Andrew Gvozdev - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.language.settings.providers;
@ -14,7 +14,6 @@ package org.eclipse.cdt.core.language.settings.providers;
import java.util.List;
import org.eclipse.cdt.core.AbstractExecutableExtensionBase;
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
import org.eclipse.core.resources.IResource;
@ -22,6 +21,7 @@ import org.eclipse.core.resources.IResource;
public class MockLanguageSettingsProvider extends AbstractExecutableExtensionBase
implements ILanguageSettingsProvider {
@Override
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
return null;
}

View file

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright (c) 2009, 2009 Andrew Gvozdev (Quoin Inc.) and others.
* Copyright (c) 2009, 2011 Andrew Gvozdev and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation
* Andrew Gvozdev - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.language.settings.providers;

View file

@ -24,7 +24,7 @@ import org.eclipse.core.resources.IResource;
* This interface is used to deliver additions to compiler options such as
* include paths (-I) or preprocessor defines (-D) and others (see
* {@link ICSettingEntry#INCLUDE_PATH} and other kinds).
* <br>
* <br><br>
* To define a provider like that use extension point
* {@code org.eclipse.cdt.core.LanguageSettingsProvider} and implement this
* interface. CDT provides a few general use implementations such as

View file

@ -18,11 +18,13 @@ import java.util.List;
import org.eclipse.cdt.core.AbstractExecutableExtensionBase;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsStorage;
import org.eclipse.cdt.internal.core.settings.model.SettingsModelMessages;
import org.eclipse.core.resources.IResource;
/**
* {@code LanguageSettingsBaseProvider} is a basic implementation of {@link ILanguageSettingsProvider}
* defined in {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point.
* for the extensions defined by {@code org.eclipse.cdt.core.LanguageSettingsProvider} extension point.
*
* This implementation supports "static" list of entries for languages specified in
* the extension point.
@ -43,10 +45,11 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas
* Default constructor.
*/
public LanguageSettingsBaseProvider() {
super();
}
/**
* Constructor. Creates an "empty" provider.
* Constructor. Creates an "empty" non-configured provider.
*
* @param id - id of the provider.
* @param name - name of the provider to be presented to a user.
@ -66,10 +69,11 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas
* @param entries - the list of language settings entries this provider provides.
* If {@code null} is passed, the provider creates an empty list.
*/
public LanguageSettingsBaseProvider(String id, String name, List<String> languages, List<ICLanguageSettingEntry> entries) {
public LanguageSettingsBaseProvider(String id, String name, List<String> languages,
List<ICLanguageSettingEntry> entries) {
super(id, name);
this.languageScope = languages!=null ? new ArrayList<String>(languages) : null;
this.entries = cloneList(entries);
this.entries = getPooledList(entries);
}
/**
@ -85,10 +89,11 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas
* @param customParameter - a custom parameter as the means to customize
* providers extending this class.
*/
public LanguageSettingsBaseProvider(String id, String name, List<String> languages, List<ICLanguageSettingEntry> entries, String customParameter) {
public LanguageSettingsBaseProvider(String id, String name, List<String> languages,
List<ICLanguageSettingEntry> entries, String customParameter) {
super(id, name);
this.languageScope = languages!=null ? new ArrayList<String>(languages) : null;
this.entries = cloneList(entries);
this.entries = getPooledList(entries);
this.customParameter = customParameter;
}
@ -97,8 +102,8 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas
* the extension point is done in 2 steps. First, the class is created as
* an executable extension using the default provider. Then this method is
* used to configure the provider.
*
* FIXME It is not allowed to reconfigure the provider.
*<br><br>
* It is not allowed to reconfigure the provider.
*
* @param id - id of the provider.
* @param name - name of the provider to be presented to a user.
@ -110,45 +115,53 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas
* @param customParameter - a custom parameter as the means to customize
* providers extending this class from extension definition in {@code plugin.xml}.
*
* FIXME @throws UnsupportedOperationException if an attempt to reconfigure provider is made.
* @throws UnsupportedOperationException if an attempt to reconfigure provider is made.
*/
public void configureProvider(String id, String name, List<String> languages, List<ICLanguageSettingEntry> entries, String customParameter) {
// if (this.entries!=null)
// throw new UnsupportedOperationException(SettingsModelMessages.getString("LanguageSettingsBaseProvider.CanBeConfiguredOnlyOnce")); //$NON-NLS-1$
public void configureProvider(String id, String name, List<String> languages,
List<ICLanguageSettingEntry> entries, String customParameter) {
if (this.entries!=null)
throw new UnsupportedOperationException(SettingsModelMessages.getString("LanguageSettingsBaseProvider.CanBeConfiguredOnlyOnce")); //$NON-NLS-1$
setId(id);
setName(name);
this.languageScope = languages!=null ? new ArrayList<String>(languages) : null;
this.entries = cloneList(entries);
this.entries = getPooledList(entries);
this.customParameter = customParameter;
}
private List<ICLanguageSettingEntry> getPooledList(List<ICLanguageSettingEntry> entries) {
if (entries != null) {
return LanguageSettingsStorage.getPooledList(entries);
}
return LanguageSettingsStorage.getPooledEmptyList();
}
/**
* {@inheritDoc}
* @param cfgDescription - configuration description.
* @param rc - resource such as file or folder.
*
* @param languageId - language id. If {@code null}, then entries defined for
* the language scope are returned. See {@link #getLanguageScope()}
*
* @return unmodifiable list of setting entries or {@code null} if no settings defined.
* the list is internally pooled and guaranteed to be the same object for equal
* lists.
*/
@Override
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription, IResource rc, String languageId) {
if (languageScope==null) {
if (entries==null)
return null;
return Collections.unmodifiableList(entries);
public List<ICLanguageSettingEntry> getSettingEntries(ICConfigurationDescription cfgDescription,
IResource rc, String languageId) {
if (languageScope == null) {
return entries;
}
for (String lang : languageScope) {
if (lang.equals(languageId)) {
if (entries==null)
return null;
return Collections.unmodifiableList(entries);
return entries;
}
}
return null;
}
/**
* @return the list of languages this provider provides for.
* @return the unmodifiable list of languages this provider provides for.
* If {@code null}, the provider provides for any language.
*/
public List<String> getLanguageScope() {
@ -163,13 +176,4 @@ public class LanguageSettingsBaseProvider extends AbstractExecutableExtensionBas
public String getCustomParameter() {
return customParameter;
}
/**
* @param entries
* @return copy of the list of the entries.
*/
private List<ICLanguageSettingEntry> cloneList(List<ICLanguageSettingEntry> entries) {
return entries!=null ? new ArrayList<ICLanguageSettingEntry>(entries) : null;
}
}

View file

@ -110,6 +110,7 @@ public class ScannerDiscoveryLegacySupport {
legacyProfiles = new HashMap<String, String>();
// InputTypes
// TODO -doublecheck
// legacyProfiles.put(inputTypeId, scannerConfigDiscoveryProfileId);
legacyProfiles.put("cdt.managedbuild.tool.gnu.c.compiler.input", "org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC|org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile");
legacyProfiles.put("cdt.managedbuild.tool.gnu.cpp.compiler.input", "org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP|org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile");
@ -120,6 +121,7 @@ public class ScannerDiscoveryLegacySupport {
legacyProfiles.put("cdt.managedbuild.tool.xlc.cpp.compiler.input", "org.eclipse.cdt.managedbuilder.xlc.core.XLCManagedMakePerProjectProfileCPP");
// Toolchains
// TODO -doublecheck
// legacyProfiles.put(toolchainId, scannerConfigDiscoveryProfileId);
}

View file

@ -71,7 +71,6 @@ public class LanguageSettingsExtensionManager {
loadProviderExtensions();
} catch (Throwable e) {
CCorePlugin.log("Error loading language settings providers extensions", e); //$NON-NLS-1$
} finally {
}
}
@ -79,7 +78,7 @@ public class LanguageSettingsExtensionManager {
* Load language settings providers contributed via the extension point.
*/
synchronized private static void loadProviderExtensions() {
// sort by name - for the providers taken from platform extensions
// sort by name - the providers defined via extensions are kept in separate list sorted
Set<ILanguageSettingsProvider> sortedProviders = new TreeSet<ILanguageSettingsProvider>(
new Comparator<ILanguageSettingsProvider>() {
@Override
@ -111,7 +110,7 @@ public class LanguageSettingsExtensionManager {
for (IExtension ext : extensions) {
for (IConfigurationElement cfgEl : ext.getConfigurationElements()) {
ILanguageSettingsProvider provider = null;
String id=null;
String id = null;
try {
if (cfgEl.getName().equals(ELEM_PROVIDER)) {
id = determineAttributeValue(cfgEl, ATTR_ID);
@ -169,8 +168,8 @@ public class LanguageSettingsExtensionManager {
for (IConfigurationElement ceLang : ce.getChildren(ELEM_LANGUAGE_SCOPE)) {
String langId = determineAttributeValue(ceLang, ATTR_ID);
if (langId.trim().length()>0) {
if (languages==null) {
if (langId.length() > 0) {
if (languages == null) {
languages = new ArrayList<String>();
}
languages.add(langId);
@ -192,8 +191,9 @@ public class LanguageSettingsExtensionManager {
ICLanguageSettingEntry entry = (ICLanguageSettingEntry) CDataUtil.createEntry(
entryKind, entryName, entryValue, null, flags);
if (entries == null)
if (entries == null) {
entries = new ArrayList<ICLanguageSettingEntry>();
}
entries.add(entry);
} catch (Exception e) {
@ -213,7 +213,7 @@ public class LanguageSettingsExtensionManager {
* Creates empty non-configured provider from extension point definition. The method will
* inspect extension registry for extension point "org.eclipse.cdt.core.LanguageSettingsProvider"
* to determine bundle and instantiate the class.
* ID and name of provider are assigned from first extension point encountered.
* ID and name of provider are assigned from the first encountered extension point specifying the class.
*
* @param className - full qualified class name of provider.
* @param registry - extension registry

View file

@ -65,7 +65,8 @@
<annotation>
<documentation>
A fully qualified name of the Java class that implements &lt;samp&gt;org.eclipse.cdt.core.settings.model.ILanguageSettingsProvider&lt;/samp&gt; interface. If empty, &lt;samp&gt;org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider&lt;/samp&gt; is used by default which provides basic functionality defined by this extension point.
If there is a need to configure a provider, attribute parameter could be used in a class extending &lt;samp&gt;LanguageSettingsBaseProvider&lt;/samp&gt;.
If there is a need to configure a provider in more deliberate way, attribute &lt;samp&gt;parameter&lt;/samp&gt; could be used in a class extending &lt;samp&gt;LanguageSettingsBaseProvider&lt;/samp&gt;.
Default constructor (constructor without arguments) of this class must be public and the package be exported in order to be able to instantiate via extension point.
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsBaseProvider:org.eclipse.cdt.core.settings.model.ILanguageSettingsProvider"/>
@ -89,7 +90,7 @@ If there is a need to configure a provider, attribute parameter could be used in
<attribute name="parameter" type="string">
<annotation>
<documentation>
A custom parameter to initialize provider. Used to deliver command for GCCBuiltinSpecsDetector as an example.
A custom parameter to initialize provider. For example, used to deliver command for GCCBuiltinSpecsDetector.
</documentation>
</annotation>
</attribute>
@ -256,7 +257,7 @@ For those cases where contributed settings entries (representing the compiler op
<meta.section type="copyright"/>
</appInfo>
<documentation>
Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) and others.
Copyright (c) 2009, 2011 Andrew Gvozdev and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at

View file

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright (c) 2009, 2010 Andrew Gvozdev (Quoin Inc.) and others.
* Copyright (c) 2009, 2011 Andrew Gvozdev and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Gvozdev (Quoin Inc.) - initial API and implementation
* Andrew Gvozdev - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core;