1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Clean up and javadoc

This commit is contained in:
Alena Laskavaia 2010-05-25 01:33:23 +00:00
parent 63954a8d48
commit 6a49ab36dd
12 changed files with 211 additions and 130 deletions

View file

@ -25,6 +25,7 @@ public class Messages extends NLS {
public static String CodanApplication_Usage;
public static String CodanApplication_verbose_option;
public static String CodanBuilder_Code_Analysis_On;
public static String FileScopeProblemPreference_Label;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);

View file

@ -6,3 +6,4 @@ CodanApplication_Options=Options:
CodanApplication_all_option= -all - run on all projects in workspace
CodanApplication_verbose_option= -verbose - print verbose build information
CodanBuilder_Code_Analysis_On=Code analysis on
FileScopeProblemPreference_Label=Exclusion and Inclusion

View file

@ -17,22 +17,17 @@ import java.io.StreamTokenizer;
/**
* Default implementation of problem preference. It keeps preference metadata
* together with preference itself.
* together with preference value. Some implementations may separate them.
*
*/
public abstract class AbstractProblemPreference implements IProblemPreference {
public static final String PARAM = "param"; //$NON-NLS-1$
protected String key;
protected String label;
protected String toolTip = null;
protected PreferenceType type;
protected String uiInfo;
private String key = PARAM;
private String label = ""; //$NON-NLS-1$
private String toolTip = null;
private String uiInfo;
private IProblemPreference parent;
public PreferenceType getType() {
return type;
}
public String getLabel() {
return label;
}
@ -50,11 +45,13 @@ public abstract class AbstractProblemPreference implements IProblemPreference {
}
public void setKey(String key) {
if (key == null)
throw new NullPointerException("key"); //$NON-NLS-1$
if (isValidIdentifier(key))
this.key = key;
else
throw new IllegalArgumentException(
"Key must have java identifier syntax or number, i.e no dots and other funky stuff"); //$NON-NLS-1$
"Key must have java identifier syntax or number, i.e no dots and other funky stuff: " + key); //$NON-NLS-1$
}
protected boolean isValidIdentifier(String id) {
@ -81,12 +78,6 @@ public abstract class AbstractProblemPreference implements IProblemPreference {
this.toolTip = tooltip;
}
public void setType(PreferenceType type) {
if (type == null)
throw new NullPointerException("Type cannot be null"); //$NON-NLS-1$
this.type = type;
}
public void setUiInfo(String uiinfo) {
this.uiInfo = uiinfo;
}
@ -136,7 +127,7 @@ public abstract class AbstractProblemPreference implements IProblemPreference {
/**
* @param parent
* the parent to set
* the parent to set
*/
public void setParent(IProblemPreference parent) {
this.parent = parent;

View file

@ -22,30 +22,32 @@ import java.util.regex.Pattern;
*
*/
public class BasicProblemPreference extends AbstractProblemPreference {
Object value;
{
key = PARAM;
type = PreferenceType.TYPE_STRING;
protected Object value;
private PreferenceType type = PreferenceType.TYPE_STRING;
public PreferenceType getType() {
return type;
}
public void setType(PreferenceType type) {
if (type == null)
throw new NullPointerException("Type cannot be null"); //$NON-NLS-1$
this.type = type;
}
/**
* Generate an info with given key and label
*
* @param key
* - property id (use in actual property hash of a checker)
* - property id (use in actual property hash of a checker)
* @param label
* - label to be shown to user
* - label to be shown to user
* @param type
* - parameter type
* - parameter type
* @return
*/
public BasicProblemPreference(String key, String label, PreferenceType type) {
if (key == null)
throw new NullPointerException("key"); //$NON-NLS-1$
if (type == null)
throw new NullPointerException("type"); //$NON-NLS-1$
setKey(key);
setLabel(label);
this(key, label);
setType(type);
}
@ -53,9 +55,9 @@ public class BasicProblemPreference extends AbstractProblemPreference {
* Generate an info with given key and label
*
* @param key
* - property id (use in actual property hash of a checker)
* - property id (use in actual property hash of a checker)
* @param label
* - label to be shown to user
* - label to be shown to user
* @return
*/
public BasicProblemPreference(String key, String label) {
@ -113,7 +115,7 @@ public class BasicProblemPreference extends AbstractProblemPreference {
@Override
public String toString() {
return "(" + type + ")" + key + ((value == null) ? "" : "=" + value); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
return "(" + type + ")" + getKey() + ((value == null) ? "" : "=" + value); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
}
@Override

View file

@ -16,6 +16,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.codan.core.Messages;
import org.eclipse.cdt.codan.internal.core.CharOperation;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@ -26,7 +27,9 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/**
* TODO: add description
* Custom preference for resource scope
*
* @noextend This class is not intended to be extended by clients.
*/
public class FileScopeProblemPreference extends AbstractProblemPreference {
public static final String KEY = "fileScope"; //$NON-NLS-1$
@ -38,13 +41,18 @@ public class FileScopeProblemPreference extends AbstractProblemPreference {
public FileScopeProblemPreference() {
setKey(KEY);
setLabel("File Exclusion and Inclusion");
setType(PreferenceType.TYPE_CUSTOM);
setLabel(Messages.FileScopeProblemPreference_Label);
}
public PreferenceType getType() {
return PreferenceType.TYPE_CUSTOM;
}
/**
* Get attribute. Possible keys are EXCUSION and INCLUSION
*
* @param key
* @return
* @return class attribute for given key
*/
public IPath[] getAttribute(String key) {
if (key == EXCLUSION)
@ -54,6 +62,11 @@ public class FileScopeProblemPreference extends AbstractProblemPreference {
return null;
}
/**
* Set attribute to a value. Possible keys are EXCUSION and INCLUSION
*
* @param key
*/
public void setAttribute(String key, IPath[] value) {
if (key == EXCLUSION)
exclusion = value.clone();
@ -62,7 +75,8 @@ public class FileScopeProblemPreference extends AbstractProblemPreference {
}
/**
* @return
* @return null for workspace, or project of the resource it is applicable
* for
*/
public IProject getProject() {
if (resource != null)
@ -71,7 +85,7 @@ public class FileScopeProblemPreference extends AbstractProblemPreference {
}
/**
* @return
* @return path of the resource it is applicable to
*/
public IPath getPath() {
if (resource != null)
@ -83,14 +97,14 @@ public class FileScopeProblemPreference extends AbstractProblemPreference {
/**
* @param resource
* the resource to set
* the resource to set
*/
public void setResource(IResource resource) {
this.resource = resource;
}
/**
* @return the resource
* @return the resource for which scope is define. Null if workspace.
*/
public IResource getResource() {
return resource;
@ -101,12 +115,7 @@ public class FileScopeProblemPreference extends AbstractProblemPreference {
+ exportPathList(EXCLUSION, exclusion);
}
/**
* @param inclusion2
* @param inclusion3
* @return
*/
private String exportPathList(String key, IPath[] arr) {
protected String exportPathList(String key, IPath[] arr) {
String res = key + "=>("; //$NON-NLS-1$
for (int i = 0; i < arr.length; i++) {
if (i != 0)
@ -116,13 +125,6 @@ public class FileScopeProblemPreference extends AbstractProblemPreference {
return res + ")"; //$NON-NLS-1$
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.cdt.codan.core.param.AbstractProblemPreference#importValue
* (java.io.StreamTokenizer)
*/
@Override
public void importValue(StreamTokenizer tokenizer) throws IOException {
List<IPath> inc = importPathList(tokenizer, INCLUSION);
@ -132,11 +134,6 @@ public class FileScopeProblemPreference extends AbstractProblemPreference {
exclusion = exc.toArray(new IPath[exc.size()]);
}
/**
* @param tokenizer
* @param c
* @throws IOException
*/
private void checkChar(StreamTokenizer tokenizer, char c)
throws IOException {
tokenizer.nextToken();
@ -144,12 +141,6 @@ public class FileScopeProblemPreference extends AbstractProblemPreference {
throw new IllegalArgumentException("Expected " + c); //$NON-NLS-1$
}
/**
* @param tokenizer
* @param inclusion2
* @throws IOException
* @throws IllegalAccessException
*/
private void checkKeyword(StreamTokenizer tokenizer, String keyword)
throws IOException {
tokenizer.nextToken();
@ -219,28 +210,29 @@ public class FileScopeProblemPreference extends AbstractProblemPreference {
}
/**
* @param file
* @return
* Checks that resource denotated by the given path is in scope (defined by
* exclusion/inclusion settings of this class). In inclusion list is defined
* check first if it belongs to it, returns false if not.
* Then checks if it belongs to exclusion list and return false if it is.
*
* @param path
* - resource path
* @return true is given path is in scope
*/
public boolean isInScope(IPath file) {
public boolean isInScope(IPath path) {
//System.err.println("test " + file + " " + exportValue());
if (inclusion.length > 0) {
if (!matchesFilter(file, inclusion))
if (!matchesFilter(path, inclusion))
return false;
}
if (exclusion.length > 0) {
if (matchesFilter(file, exclusion))
if (matchesFilter(path, exclusion))
return false;
}
return true;
}
/**
* @param resourcePath
* @param inclusion2
* @return
*/
private boolean matchesFilter(IPath resourcePath, IPath[] paths) {
public boolean matchesFilter(IPath resourcePath, IPath[] paths) {
char[] path = resourcePath.toString().toCharArray();
for (int i = 0, length = paths.length; i < length; i++) {
char[] pattern = paths[i].toString().toCharArray();

View file

@ -11,10 +11,14 @@
package org.eclipse.cdt.codan.core.param;
/**
* Value of the problem preference. If more than one it can be composite, i.e.
* map. Instead of implementing this interface use
* Problem preference. If problem has more than one it can be composite, i.e.
* map. Instead of implementing this interface clients must extend
* {@link AbstractProblemPreference} class.
*
* Problem Preference constist of preference metadata
* (IProblemPreferenceDescriptor)
* and value of preference (IProblemPreferenceValue).
*
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/

View file

@ -28,7 +28,7 @@ public interface IProblemPreferenceCompositeDescriptor {
IProblemPreference getChildDescriptor(String key);
/**
* Available if type is list or map. Returns array of children.
* Available for composite types. Returns array of children.
*
* @return
*/

View file

@ -17,9 +17,26 @@ package org.eclipse.cdt.codan.core.param;
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface IProblemPreferenceCompositeValue {
/**
* Returns value of the child element of a given key
*
* @param key
* @return
*/
Object getChildValue(String key);
/**
* Sets the value of the child element of a given key
*
* @param key
* @param value
*/
void setChildValue(String key, Object value);
/**
* Removes child element matching the given key
*
* @param key
*/
void removeChildValue(String key);
}

View file

@ -15,7 +15,7 @@ import java.util.List;
import java.util.Map;
/**
* Problem parameter usually key=value settings that allow to alter checker
* Problem parameter usually key=value settings that allows to alter checker
* behaviour for given problem. For example if checker finds violation of naming
* conventions for function, parameter would be the pattern of allowed names.
*
@ -84,17 +84,18 @@ public interface IProblemPreferenceDescriptor extends Cloneable {
/**
* type of the parameter, supports boolean, integer, string, file, list and
* hash. If list is the value - it is an array - subparameter can be
* accessed by number, if hash is the value - it is a hash - subparameter
* can be accesses by name
* map. For list type child preference can be
* accessed by number (index), if map is the type child preference can be
* accessed by a key (string)
*
* @return string value of the type
* @return type of the preference
*/
PreferenceType getType();
/**
* Additional info on how it is represented in the ui, for example boolean
* can be represented as checkbox, drop-down and so on, Values TBD
* can be represented as checkbox, drop-down and so on, Values TBD.
* Not supported at the moment.
*
* @return ui info or null if not set
*/
@ -108,7 +109,7 @@ public interface IProblemPreferenceDescriptor extends Cloneable {
String getLabel();
/**
* Detailed explanation of parameter
* Detailed explanation of parameter. Not supported at the moment.
*
* @return the toolTip text
*/
@ -118,7 +119,10 @@ public interface IProblemPreferenceDescriptor extends Cloneable {
IProblemPreference getParent();
public void setParent(IProblemPreference parent);
/**
* Combined key of values from parents plus itself separated by dot
*
* @return
*/
String getQualifiedKey();
}

View file

@ -12,7 +12,8 @@ package org.eclipse.cdt.codan.core.param;
/**
* Value of the problem preference. If more than one it can be composite, i.e.
* map
* map.Extend {@link AbstractProblemPreference} class
* to implement this interface.
*
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.

View file

@ -29,36 +29,34 @@ public class ListProblemPreference extends AbstractProblemPreference implements
/**
* @param key
* - key to access this preference
* @param label
* - label to be shown in UI
*/
public ListProblemPreference(String key, String label) {
setKey(key);
setLabel(label);
}
@Override
public PreferenceType getType() {
return PreferenceType.TYPE_LIST;
}
@Override
public void setType(PreferenceType type) {
throw new UnsupportedOperationException();
}
/**
* Set child descriptor (all elements have the same)
* Set child descriptor (all elements have the same). Value and key
* of the it would be ignored and reset.
*
* @param i
* @param info
* @param desc
* @return
*/
public IProblemPreference setChildDescriptor(IProblemPreference info) {
childDescriptor = info;
childDescriptor.setValue(null);
((AbstractProblemPreference) childDescriptor)
.setKey(COMMON_DESCRIPTOR_KEY);
return info;
public IProblemPreference setChildDescriptor(IProblemPreference desc) {
childDescriptor = desc;
if (desc != null) {
childDescriptor.setValue(null);
((AbstractProblemPreference) childDescriptor)
.setKey(COMMON_DESCRIPTOR_KEY);
}
return desc;
}
/**
@ -76,10 +74,22 @@ public class ListProblemPreference extends AbstractProblemPreference implements
return getChildDescriptor(key);
}
/**
* Returns descriptor of the child elements
*
* @return
*/
public IProblemPreference getChildDescriptor() {
return childDescriptor;
}
/**
* Returns cloned descriptor of the i'th child. Modifying return value would
* not affect internal state of the list element.
*
* @param i
* @return
*/
public IProblemPreference getChildDescriptor(int i) {
Object value = list.get(i);
AbstractProblemPreference desc = (AbstractProblemPreference) childDescriptor
@ -94,7 +104,7 @@ public class ListProblemPreference extends AbstractProblemPreference implements
* If key is null or # return generic descriptor with null value.
*
* @throws NumberFormatException
* if key is not number
* if key is not number
*/
public IProblemPreference getChildDescriptor(String key)
throws NumberFormatException {
@ -113,6 +123,9 @@ public class ListProblemPreference extends AbstractProblemPreference implements
return getChildDescriptor(iv.intValue());
}
/**
* Return array of clones values of child preferences.
*/
public IProblemPreference[] getChildDescriptors() {
IProblemPreference[] res = new IProblemPreference[list.size()];
for (int i = 0; i < res.length; i++) {
@ -122,8 +135,12 @@ public class ListProblemPreference extends AbstractProblemPreference implements
}
public Object getChildValue(String key) {
IProblemPreference childInfo = getChildDescriptor(key);
return childInfo.getValue();
int index = Integer.parseInt(key);
return getChildValue(index);
}
public Object getChildValue(int index) {
return list.get(index);
}
public void setChildValue(String key, Object value) {
@ -131,11 +148,7 @@ public class ListProblemPreference extends AbstractProblemPreference implements
setChildValue(i, value);
}
/**
* @param i
* @param value
*/
protected void setChildValue(int i, Object value) {
public void setChildValue(int i, Object value) {
if (value != null) {
while (i >= list.size()) {
list.add(null);
@ -229,23 +242,44 @@ public class ListProblemPreference extends AbstractProblemPreference implements
}
}
/**
* If info key is '#' resets common descritors to null, otherwise removes
* value
*/
public void removeChildDescriptor(IProblemPreference info) {
throw new UnsupportedOperationException();
if (info.getKey().equals(COMMON_DESCRIPTOR_KEY))
setChildDescriptor(null);
else
removeChildValue(info.getKey());
}
/**
* @return children size
*/
public int size() {
return list.size();
}
/**
* Removes all values from the list
*/
public void clear() {
list.clear();
}
/**
* Return array of values of children elements.
*/
@Override
public Object getValue() {
return getValues();
}
/**
* Sets list value to values of array given as argument.
*
* @param value - must be Object[]
*/
@Override
public void setValue(Object value) {
Object[] values = (Object[]) value;
@ -264,6 +298,9 @@ public class ListProblemPreference extends AbstractProblemPreference implements
return childDescriptor + ":" + list.toString(); //$NON-NLS-1$
}
/**
* Return array of values of children elements.
*/
public Object[] getValues() {
return list.toArray(new Object[list.size()]);
}

View file

@ -40,27 +40,21 @@ public class MapProblemPreference extends AbstractProblemPreference implements
/**
* @param key
* - key for itself
* - key for itself
* @param label
* - label for this group of parameters
* - label for this group of parameters
*/
public MapProblemPreference(String key, String label) {
setKey(key);
setLabel(label);
}
@Override
public PreferenceType getType() {
return PreferenceType.TYPE_MAP;
}
@Override
public void setType(PreferenceType type) {
throw new UnsupportedOperationException();
}
/**
* Get parameter into for element by key
* Get parameter preference for element by key
*
*/
public IProblemPreference getChildDescriptor(String key) {
@ -68,32 +62,52 @@ public class MapProblemPreference extends AbstractProblemPreference implements
}
/**
* Put parameter info into the map for element with the key equals to
* info.getKey()
* Adds or replaces child descriptor and value for the element with the key
* equals to desc.getKey(). The desc object would be put in the map, some of
* its field may be modified.
*
* @param i
* @param info
* @param desc
*/
public IProblemPreference addChildDescriptor(IProblemPreference desc) {
desc.setParent(this);
((AbstractProblemPreference) desc).setParent(this);
hash.put(desc.getKey(), desc);
return desc;
}
/**
* Return list of child descriptors. Client should threat returned value as
* read only,
* and not assume that modifying its elements would modify actual child
* values.
*/
public IProblemPreference[] getChildDescriptors() {
return hash.values().toArray(
new IProblemPreference[hash.values().size()]);
}
/**
* Returns value of the child element by its key
*/
public Object getChildValue(String key) {
IProblemPreference childInfo = getChildDescriptor(key);
return childInfo.getValue();
}
/**
* Set child value by its key
*/
public void setChildValue(String key, Object value) {
getChildDescriptor(key).setValue(value);
IProblemPreference pref = getChildDescriptor(key);
if (pref == null)
throw new IllegalArgumentException("Preference for " + key //$NON-NLS-1$
+ " must exists before setting its value"); //$NON-NLS-1$
pref.setValue(value);
hash.put(key, pref); // cannot assume getChildDescriptor returns shared value
}
/**
* Removes child value and descriptor by key
*/
public void removeChildValue(String key) {
hash.remove(key);
}
@ -170,8 +184,11 @@ public class MapProblemPreference extends AbstractProblemPreference implements
}
}
/**
* Removes child descriptor by its key
*/
public void removeChildDescriptor(IProblemPreference info) {
hash.remove(info);
hash.remove(info.getKey());
}
public int size() {
@ -187,6 +204,11 @@ public class MapProblemPreference extends AbstractProblemPreference implements
return hash.values().toString();
}
/**
* Value of this preference is a map key=>value of child preferences.
* Modifying this returned map would not change internal state of this
* object.
*/
@Override
public Object getValue() {
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
@ -198,6 +220,14 @@ public class MapProblemPreference extends AbstractProblemPreference implements
return map;
}
/**
* Set values for this object child elements. Elements are not present in
* this map would be removed.
* Preference descriptors for the keys must be set before calling this
* method, unless value if instanceof IProblemPreference.
*
* @param value - must be Map<String,Object>
*/
@SuppressWarnings("unchecked")
@Override
public void setValue(Object value) {
@ -212,6 +242,7 @@ public class MapProblemPreference extends AbstractProblemPreference implements
if (value2 instanceof IProblemPreference) {
hash.put(key, (IProblemPreference) value2);
} else {
setChildValue(key, value2);
IProblemPreference pref = hash2.get(key);
pref.setValue(value2);
hash.put(key, pref);