repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1 value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
osmdroid/osmdroid | osmdroid-android/src/main/java/org/osmdroid/views/overlay/IconOverlay.java | IconOverlay.draw | @Override
public void draw(Canvas canvas, Projection pj) {
if (mIcon == null)
return;
if (mPosition == null)
return;
pj.toPixels(mPosition, mPositionPixels);
int width = mIcon.getIntrinsicWidth();
int height = mIcon.getIntrinsicHeight();
Rect rect = new Rect(0, 0, width, height);
rect.offset(-(int)(mAnchorU*width), -(int)(mAnchorV*height));
mIcon.setBounds(rect);
mIcon.setAlpha((int) (mAlpha * 255));
float rotationOnScreen = (mFlat ? -mBearing : pj.getOrientation()-mBearing);
drawAt(canvas, mIcon, mPositionPixels.x, mPositionPixels.y, false, rotationOnScreen);
} | java | @Override
public void draw(Canvas canvas, Projection pj) {
if (mIcon == null)
return;
if (mPosition == null)
return;
pj.toPixels(mPosition, mPositionPixels);
int width = mIcon.getIntrinsicWidth();
int height = mIcon.getIntrinsicHeight();
Rect rect = new Rect(0, 0, width, height);
rect.offset(-(int)(mAnchorU*width), -(int)(mAnchorV*height));
mIcon.setBounds(rect);
mIcon.setAlpha((int) (mAlpha * 255));
float rotationOnScreen = (mFlat ? -mBearing : pj.getOrientation()-mBearing);
drawAt(canvas, mIcon, mPositionPixels.x, mPositionPixels.y, false, rotationOnScreen);
} | [
"@",
"Override",
"public",
"void",
"draw",
"(",
"Canvas",
"canvas",
",",
"Projection",
"pj",
")",
"{",
"if",
"(",
"mIcon",
"==",
"null",
")",
"return",
";",
"if",
"(",
"mPosition",
"==",
"null",
")",
"return",
";",
"pj",
".",
"toPixels",
"(",
"mPosit... | Draw the icon. | [
"Draw",
"the",
"icon",
"."
] | 3b178b2f078497dd88c137110e87aafe45ad2b16 | https://github.com/osmdroid/osmdroid/blob/3b178b2f078497dd88c137110e87aafe45ad2b16/osmdroid-android/src/main/java/org/osmdroid/views/overlay/IconOverlay.java#L49-L67 | train |
osmdroid/osmdroid | osmdroid-android/src/main/java/org/osmdroid/util/TileSystem.java | TileSystem.getX01FromLongitude | public double getX01FromLongitude(double longitude, boolean wrapEnabled) {
longitude = wrapEnabled ? Clip(longitude, getMinLongitude(), getMaxLongitude()) : longitude;
final double result = getX01FromLongitude(longitude);
return wrapEnabled ? Clip(result, 0, 1) : result;
} | java | public double getX01FromLongitude(double longitude, boolean wrapEnabled) {
longitude = wrapEnabled ? Clip(longitude, getMinLongitude(), getMaxLongitude()) : longitude;
final double result = getX01FromLongitude(longitude);
return wrapEnabled ? Clip(result, 0, 1) : result;
} | [
"public",
"double",
"getX01FromLongitude",
"(",
"double",
"longitude",
",",
"boolean",
"wrapEnabled",
")",
"{",
"longitude",
"=",
"wrapEnabled",
"?",
"Clip",
"(",
"longitude",
",",
"getMinLongitude",
"(",
")",
",",
"getMaxLongitude",
"(",
")",
")",
":",
"longi... | Converts a longitude to its "X01" value,
id est a double between 0 and 1 for the whole longitude range
@since 6.0.0 | [
"Converts",
"a",
"longitude",
"to",
"its",
"X01",
"value",
"id",
"est",
"a",
"double",
"between",
"0",
"and",
"1",
"for",
"the",
"whole",
"longitude",
"range"
] | 3b178b2f078497dd88c137110e87aafe45ad2b16 | https://github.com/osmdroid/osmdroid/blob/3b178b2f078497dd88c137110e87aafe45ad2b16/osmdroid-android/src/main/java/org/osmdroid/util/TileSystem.java#L219-L223 | train |
osmdroid/osmdroid | osmdroid-android/src/main/java/org/osmdroid/util/TileSystem.java | TileSystem.getY01FromLatitude | public double getY01FromLatitude(double latitude, boolean wrapEnabled) {
latitude = wrapEnabled ? Clip(latitude, getMinLatitude(), getMaxLatitude()) : latitude;
final double result = getY01FromLatitude(latitude);
return wrapEnabled ? Clip(result, 0, 1) : result;
} | java | public double getY01FromLatitude(double latitude, boolean wrapEnabled) {
latitude = wrapEnabled ? Clip(latitude, getMinLatitude(), getMaxLatitude()) : latitude;
final double result = getY01FromLatitude(latitude);
return wrapEnabled ? Clip(result, 0, 1) : result;
} | [
"public",
"double",
"getY01FromLatitude",
"(",
"double",
"latitude",
",",
"boolean",
"wrapEnabled",
")",
"{",
"latitude",
"=",
"wrapEnabled",
"?",
"Clip",
"(",
"latitude",
",",
"getMinLatitude",
"(",
")",
",",
"getMaxLatitude",
"(",
")",
")",
":",
"latitude",
... | Converts a latitude to its "Y01" value,
id est a double between 0 and 1 for the whole latitude range
@since 6.0.0 | [
"Converts",
"a",
"latitude",
"to",
"its",
"Y01",
"value",
"id",
"est",
"a",
"double",
"between",
"0",
"and",
"1",
"for",
"the",
"whole",
"latitude",
"range"
] | 3b178b2f078497dd88c137110e87aafe45ad2b16 | https://github.com/osmdroid/osmdroid/blob/3b178b2f078497dd88c137110e87aafe45ad2b16/osmdroid-android/src/main/java/org/osmdroid/util/TileSystem.java#L230-L234 | train |
osmdroid/osmdroid | osmdroid-android/src/main/java/org/osmdroid/views/overlay/infowindow/InfoWindow.java | InfoWindow.open | public void open(Object object, GeoPoint position, int offsetX, int offsetY) {
close(); //if it was already opened
mRelatedObject = object;
mPosition = position;
mOffsetX = offsetX;
mOffsetY = offsetY;
onOpen(object);
MapView.LayoutParams lp = new MapView.LayoutParams(
MapView.LayoutParams.WRAP_CONTENT,
MapView.LayoutParams.WRAP_CONTENT,
mPosition, MapView.LayoutParams.BOTTOM_CENTER,
mOffsetX, mOffsetY);
if (mMapView != null && mView != null) {
mMapView.addView(mView, lp);
mIsVisible = true;
} else {
Log.w(IMapView.LOGTAG, "Error trapped, InfoWindow.open mMapView: " + (mMapView == null ? "null" : "ok") + " mView: " + (mView == null ? "null" : "ok"));
}
} | java | public void open(Object object, GeoPoint position, int offsetX, int offsetY) {
close(); //if it was already opened
mRelatedObject = object;
mPosition = position;
mOffsetX = offsetX;
mOffsetY = offsetY;
onOpen(object);
MapView.LayoutParams lp = new MapView.LayoutParams(
MapView.LayoutParams.WRAP_CONTENT,
MapView.LayoutParams.WRAP_CONTENT,
mPosition, MapView.LayoutParams.BOTTOM_CENTER,
mOffsetX, mOffsetY);
if (mMapView != null && mView != null) {
mMapView.addView(mView, lp);
mIsVisible = true;
} else {
Log.w(IMapView.LOGTAG, "Error trapped, InfoWindow.open mMapView: " + (mMapView == null ? "null" : "ok") + " mView: " + (mView == null ? "null" : "ok"));
}
} | [
"public",
"void",
"open",
"(",
"Object",
"object",
",",
"GeoPoint",
"position",
",",
"int",
"offsetX",
",",
"int",
"offsetY",
")",
"{",
"close",
"(",
")",
";",
"//if it was already opened",
"mRelatedObject",
"=",
"object",
";",
"mPosition",
"=",
"position",
... | open the InfoWindow at the specified GeoPosition + offset.
If it was already opened, close it before reopening.
@param object the graphical object on which is hooked the view
@param position to place the window on the map
@param offsetX (&offsetY) the offset of the view to the position, in pixels.
This allows to offset the view from the object position. | [
"open",
"the",
"InfoWindow",
"at",
"the",
"specified",
"GeoPosition",
"+",
"offset",
".",
"If",
"it",
"was",
"already",
"opened",
"close",
"it",
"before",
"reopening",
"."
] | 3b178b2f078497dd88c137110e87aafe45ad2b16 | https://github.com/osmdroid/osmdroid/blob/3b178b2f078497dd88c137110e87aafe45ad2b16/osmdroid-android/src/main/java/org/osmdroid/views/overlay/infowindow/InfoWindow.java#L105-L124 | train |
osmdroid/osmdroid | osmdroid-android/src/main/java/org/osmdroid/views/overlay/infowindow/InfoWindow.java | InfoWindow.close | public void close() {
if (mIsVisible) {
mIsVisible = false;
((ViewGroup) mView.getParent()).removeView(mView);
onClose();
}
} | java | public void close() {
if (mIsVisible) {
mIsVisible = false;
((ViewGroup) mView.getParent()).removeView(mView);
onClose();
}
} | [
"public",
"void",
"close",
"(",
")",
"{",
"if",
"(",
"mIsVisible",
")",
"{",
"mIsVisible",
"=",
"false",
";",
"(",
"(",
"ViewGroup",
")",
"mView",
".",
"getParent",
"(",
")",
")",
".",
"removeView",
"(",
"mView",
")",
";",
"onClose",
"(",
")",
";",... | hides the info window, which triggers another render of the map | [
"hides",
"the",
"info",
"window",
"which",
"triggers",
"another",
"render",
"of",
"the",
"map"
] | 3b178b2f078497dd88c137110e87aafe45ad2b16 | https://github.com/osmdroid/osmdroid/blob/3b178b2f078497dd88c137110e87aafe45ad2b16/osmdroid-android/src/main/java/org/osmdroid/views/overlay/infowindow/InfoWindow.java#L151-L157 | train |
osmdroid/osmdroid | osmdroid-android/src/main/java/org/osmdroid/views/overlay/infowindow/InfoWindow.java | InfoWindow.onDetach | public void onDetach() {
close();
if (mView != null)
mView.setTag(null);
mView = null;
mMapView = null;
if (Configuration.getInstance().isDebugMode())
Log.d(IMapView.LOGTAG, "Marked detached");
} | java | public void onDetach() {
close();
if (mView != null)
mView.setTag(null);
mView = null;
mMapView = null;
if (Configuration.getInstance().isDebugMode())
Log.d(IMapView.LOGTAG, "Marked detached");
} | [
"public",
"void",
"onDetach",
"(",
")",
"{",
"close",
"(",
")",
";",
"if",
"(",
"mView",
"!=",
"null",
")",
"mView",
".",
"setTag",
"(",
"null",
")",
";",
"mView",
"=",
"null",
";",
"mMapView",
"=",
"null",
";",
"if",
"(",
"Configuration",
".",
"... | this destroys the window and all references to views | [
"this",
"destroys",
"the",
"window",
"and",
"all",
"references",
"to",
"views"
] | 3b178b2f078497dd88c137110e87aafe45ad2b16 | https://github.com/osmdroid/osmdroid/blob/3b178b2f078497dd88c137110e87aafe45ad2b16/osmdroid-android/src/main/java/org/osmdroid/views/overlay/infowindow/InfoWindow.java#L162-L170 | train |
osmdroid/osmdroid | osmdroid-android/src/main/java/org/osmdroid/views/overlay/infowindow/InfoWindow.java | InfoWindow.closeAllInfoWindowsOn | public static void closeAllInfoWindowsOn(MapView mapView) {
ArrayList<InfoWindow> opened = getOpenedInfoWindowsOn(mapView);
for (InfoWindow infoWindow : opened) {
infoWindow.close();
}
} | java | public static void closeAllInfoWindowsOn(MapView mapView) {
ArrayList<InfoWindow> opened = getOpenedInfoWindowsOn(mapView);
for (InfoWindow infoWindow : opened) {
infoWindow.close();
}
} | [
"public",
"static",
"void",
"closeAllInfoWindowsOn",
"(",
"MapView",
"mapView",
")",
"{",
"ArrayList",
"<",
"InfoWindow",
">",
"opened",
"=",
"getOpenedInfoWindowsOn",
"(",
"mapView",
")",
";",
"for",
"(",
"InfoWindow",
"infoWindow",
":",
"opened",
")",
"{",
"... | close all InfoWindows currently opened on this MapView
@param mapView | [
"close",
"all",
"InfoWindows",
"currently",
"opened",
"on",
"this",
"MapView"
] | 3b178b2f078497dd88c137110e87aafe45ad2b16 | https://github.com/osmdroid/osmdroid/blob/3b178b2f078497dd88c137110e87aafe45ad2b16/osmdroid-android/src/main/java/org/osmdroid/views/overlay/infowindow/InfoWindow.java#L181-L186 | train |
osmdroid/osmdroid | osmdroid-android/src/main/java/org/osmdroid/views/overlay/infowindow/InfoWindow.java | InfoWindow.getOpenedInfoWindowsOn | public static ArrayList<InfoWindow> getOpenedInfoWindowsOn(MapView mapView) {
int count = mapView.getChildCount();
ArrayList<InfoWindow> opened = new ArrayList<InfoWindow>(count);
for (int i = 0; i < count; i++) {
final View child = mapView.getChildAt(i);
Object tag = child.getTag();
if (tag != null && tag instanceof InfoWindow) {
InfoWindow infoWindow = (InfoWindow) tag;
opened.add(infoWindow);
}
}
return opened;
} | java | public static ArrayList<InfoWindow> getOpenedInfoWindowsOn(MapView mapView) {
int count = mapView.getChildCount();
ArrayList<InfoWindow> opened = new ArrayList<InfoWindow>(count);
for (int i = 0; i < count; i++) {
final View child = mapView.getChildAt(i);
Object tag = child.getTag();
if (tag != null && tag instanceof InfoWindow) {
InfoWindow infoWindow = (InfoWindow) tag;
opened.add(infoWindow);
}
}
return opened;
} | [
"public",
"static",
"ArrayList",
"<",
"InfoWindow",
">",
"getOpenedInfoWindowsOn",
"(",
"MapView",
"mapView",
")",
"{",
"int",
"count",
"=",
"mapView",
".",
"getChildCount",
"(",
")",
";",
"ArrayList",
"<",
"InfoWindow",
">",
"opened",
"=",
"new",
"ArrayList",... | return all InfoWindows currently opened on this MapView
@param mapView
@return | [
"return",
"all",
"InfoWindows",
"currently",
"opened",
"on",
"this",
"MapView"
] | 3b178b2f078497dd88c137110e87aafe45ad2b16 | https://github.com/osmdroid/osmdroid/blob/3b178b2f078497dd88c137110e87aafe45ad2b16/osmdroid-android/src/main/java/org/osmdroid/views/overlay/infowindow/InfoWindow.java#L194-L206 | train |
osmdroid/osmdroid | OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/data/SampleRace.java | SampleRace.getHalfKilometerManager | private MilestoneManager getHalfKilometerManager() {
final Path arrowPath = new Path(); // a simple arrow towards the right
arrowPath.moveTo(-5, -5);
arrowPath.lineTo(5, 0);
arrowPath.lineTo(-5, 5);
arrowPath.close();
final Paint backgroundPaint = getFillPaint(COLOR_BACKGROUND);
return new MilestoneManager( // display an arrow at 500m every 1km
new MilestoneMeterDistanceLister(500),
new MilestonePathDisplayer(0, true, arrowPath, backgroundPaint) {
@Override
protected void draw(final Canvas pCanvas, final Object pParameter) {
final int halfKilometers = (int)Math.round(((double)pParameter / 500));
if (halfKilometers % 2 == 0) {
return;
}
super.draw(pCanvas, pParameter);
}
}
);
} | java | private MilestoneManager getHalfKilometerManager() {
final Path arrowPath = new Path(); // a simple arrow towards the right
arrowPath.moveTo(-5, -5);
arrowPath.lineTo(5, 0);
arrowPath.lineTo(-5, 5);
arrowPath.close();
final Paint backgroundPaint = getFillPaint(COLOR_BACKGROUND);
return new MilestoneManager( // display an arrow at 500m every 1km
new MilestoneMeterDistanceLister(500),
new MilestonePathDisplayer(0, true, arrowPath, backgroundPaint) {
@Override
protected void draw(final Canvas pCanvas, final Object pParameter) {
final int halfKilometers = (int)Math.round(((double)pParameter / 500));
if (halfKilometers % 2 == 0) {
return;
}
super.draw(pCanvas, pParameter);
}
}
);
} | [
"private",
"MilestoneManager",
"getHalfKilometerManager",
"(",
")",
"{",
"final",
"Path",
"arrowPath",
"=",
"new",
"Path",
"(",
")",
";",
"// a simple arrow towards the right",
"arrowPath",
".",
"moveTo",
"(",
"-",
"5",
",",
"-",
"5",
")",
";",
"arrowPath",
".... | Half-kilometer milestones
@since 6.0.2 | [
"Half",
"-",
"kilometer",
"milestones"
] | 3b178b2f078497dd88c137110e87aafe45ad2b16 | https://github.com/osmdroid/osmdroid/blob/3b178b2f078497dd88c137110e87aafe45ad2b16/OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/data/SampleRace.java#L184-L204 | train |
osmdroid/osmdroid | osmdroid-geopackage/src/main/java/org/osmdroid/gpkg/overlay/OsmMapShapeConverter.java | OsmMapShapeConverter.toWgs84 | public Point toWgs84(Point point) {
if (projection != null) {
point = toWgs84.transform(point);
}
return point;
} | java | public Point toWgs84(Point point) {
if (projection != null) {
point = toWgs84.transform(point);
}
return point;
} | [
"public",
"Point",
"toWgs84",
"(",
"Point",
"point",
")",
"{",
"if",
"(",
"projection",
"!=",
"null",
")",
"{",
"point",
"=",
"toWgs84",
".",
"transform",
"(",
"point",
")",
";",
"}",
"return",
"point",
";",
"}"
] | Transform a projection point to WGS84
@param point
@return | [
"Transform",
"a",
"projection",
"point",
"to",
"WGS84"
] | 3b178b2f078497dd88c137110e87aafe45ad2b16 | https://github.com/osmdroid/osmdroid/blob/3b178b2f078497dd88c137110e87aafe45ad2b16/osmdroid-geopackage/src/main/java/org/osmdroid/gpkg/overlay/OsmMapShapeConverter.java#L161-L166 | train |
osmdroid/osmdroid | osmdroid-geopackage/src/main/java/org/osmdroid/gpkg/overlay/OsmMapShapeConverter.java | OsmMapShapeConverter.toProjection | public Point toProjection(Point point) {
if (projection != null) {
point = fromWgs84.transform(point);
}
return point;
} | java | public Point toProjection(Point point) {
if (projection != null) {
point = fromWgs84.transform(point);
}
return point;
} | [
"public",
"Point",
"toProjection",
"(",
"Point",
"point",
")",
"{",
"if",
"(",
"projection",
"!=",
"null",
")",
"{",
"point",
"=",
"fromWgs84",
".",
"transform",
"(",
"point",
")",
";",
"}",
"return",
"point",
";",
"}"
] | Transform a WGS84 point to the projection
@param point
@return | [
"Transform",
"a",
"WGS84",
"point",
"to",
"the",
"projection"
] | 3b178b2f078497dd88c137110e87aafe45ad2b16 | https://github.com/osmdroid/osmdroid/blob/3b178b2f078497dd88c137110e87aafe45ad2b16/osmdroid-geopackage/src/main/java/org/osmdroid/gpkg/overlay/OsmMapShapeConverter.java#L174-L179 | train |
osmdroid/osmdroid | osmdroid-geopackage/src/main/java/org/osmdroid/gpkg/overlay/OsmMapShapeConverter.java | OsmMapShapeConverter.addPolylineToMap | public static Polyline addPolylineToMap(MapView map,
Polyline polyline) {
if (polyline.getInfoWindow()==null)
polyline.setInfoWindow(new BasicInfoWindow(R.layout.bonuspack_bubble, map));
map.getOverlayManager().add(polyline);
return polyline;
} | java | public static Polyline addPolylineToMap(MapView map,
Polyline polyline) {
if (polyline.getInfoWindow()==null)
polyline.setInfoWindow(new BasicInfoWindow(R.layout.bonuspack_bubble, map));
map.getOverlayManager().add(polyline);
return polyline;
} | [
"public",
"static",
"Polyline",
"addPolylineToMap",
"(",
"MapView",
"map",
",",
"Polyline",
"polyline",
")",
"{",
"if",
"(",
"polyline",
".",
"getInfoWindow",
"(",
")",
"==",
"null",
")",
"polyline",
".",
"setInfoWindow",
"(",
"new",
"BasicInfoWindow",
"(",
... | Add a Polyline to the map
@param map
@param polyline
@return | [
"Add",
"a",
"Polyline",
"to",
"the",
"map"
] | 3b178b2f078497dd88c137110e87aafe45ad2b16 | https://github.com/osmdroid/osmdroid/blob/3b178b2f078497dd88c137110e87aafe45ad2b16/osmdroid-geopackage/src/main/java/org/osmdroid/gpkg/overlay/OsmMapShapeConverter.java#L706-L712 | train |
JakeWharton/DiskLruCache | src/main/java/com/jakewharton/disklrucache/DiskLruCache.java | DiskLruCache.close | public synchronized void close() throws IOException {
if (journalWriter == null) {
return; // Already closed.
}
for (Entry entry : new ArrayList<Entry>(lruEntries.values())) {
if (entry.currentEditor != null) {
entry.currentEditor.abort();
}
}
trimToSize();
journalWriter.close();
journalWriter = null;
} | java | public synchronized void close() throws IOException {
if (journalWriter == null) {
return; // Already closed.
}
for (Entry entry : new ArrayList<Entry>(lruEntries.values())) {
if (entry.currentEditor != null) {
entry.currentEditor.abort();
}
}
trimToSize();
journalWriter.close();
journalWriter = null;
} | [
"public",
"synchronized",
"void",
"close",
"(",
")",
"throws",
"IOException",
"{",
"if",
"(",
"journalWriter",
"==",
"null",
")",
"{",
"return",
";",
"// Already closed.",
"}",
"for",
"(",
"Entry",
"entry",
":",
"new",
"ArrayList",
"<",
"Entry",
">",
"(",
... | Closes this cache. Stored values will remain on the filesystem. | [
"Closes",
"this",
"cache",
".",
"Stored",
"values",
"will",
"remain",
"on",
"the",
"filesystem",
"."
] | 3e016356cfc7e5f9644a7a732fe0223e9742e024 | https://github.com/JakeWharton/DiskLruCache/blob/3e016356cfc7e5f9644a7a732fe0223e9742e024/src/main/java/com/jakewharton/disklrucache/DiskLruCache.java#L633-L645 | train |
alibaba/simpleimage | simpleimage.core/src/main/java/com/alibaba/simpleimage/codec/jpeg/JPEGDecoder.java | JPEGDecoder.isSOFnMarker | protected boolean isSOFnMarker(int marker) {
if (marker <= 0xC3 && marker >= 0xC0) {
return true;
}
if (marker <= 0xCB && marker >= 0xC5) {
return true;
}
if (marker <= 0xCF && marker >= 0xCD) {
return true;
}
return false;
} | java | protected boolean isSOFnMarker(int marker) {
if (marker <= 0xC3 && marker >= 0xC0) {
return true;
}
if (marker <= 0xCB && marker >= 0xC5) {
return true;
}
if (marker <= 0xCF && marker >= 0xCD) {
return true;
}
return false;
} | [
"protected",
"boolean",
"isSOFnMarker",
"(",
"int",
"marker",
")",
"{",
"if",
"(",
"marker",
"<=",
"0xC3",
"&&",
"marker",
">=",
"0xC0",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"marker",
"<=",
"0xCB",
"&&",
"marker",
">=",
"0xC5",
")",
"{",
... | can opt using array
@param marker
@return | [
"can",
"opt",
"using",
"array"
] | aabe559c267402b754c2ad606b796c4c6570788c | https://github.com/alibaba/simpleimage/blob/aabe559c267402b754c2ad606b796c4c6570788c/simpleimage.core/src/main/java/com/alibaba/simpleimage/codec/jpeg/JPEGDecoder.java#L627-L641 | train |
alibaba/simpleimage | simpleimage.core/src/main/java/com/alibaba/simpleimage/codec/jpeg/JPEGDecoder.java | JPEGDecoder.writeFull | protected void writeFull() {
byte[] imageData = rawImage.getData();
int numOfComponents = frameHeader.getNf();
int[] pixes = new int[numOfComponents * DCTSIZE2];
int blockIndex = 0;
int startCoordinate = 0, scanlineStride = numOfComponents * rawImage.getWidth(), row = 0;
x = 0;
y = 0;
for (int m = 0; m < MCUsPerColumn * MCUsPerRow; m++) {
blockIndex = 0;
// one MCU
for (int v = 0; v < maxVSampleFactor; v++) {
for (int h = 0; h < maxHSampleFactor; h++) {
row = y + 1;
startCoordinate = (y * rawImage.getWidth() + x) * numOfComponents;
// one block
for (int k = blockIndex * DCTSIZE2, i = 0; k < blockIndex * DCTSIZE2 + DCTSIZE2; k++) {
pixes[i++] = allMCUDatas[0][m][k];
if (numOfComponents > 1) {
pixes[i++] = allMCUDatas[1][m][k];
pixes[i++] = allMCUDatas[2][m][k];
}
if (numOfComponents > 3) {
pixes[i++] = allMCUDatas[3][m][k];
}
x++;
if (x % 8 == 0) {
y++;
x -= 8;
}
}
colorConvertor.convertBlock(pixes, 0, imageData, numOfComponents, startCoordinate, row,
scanlineStride);
blockIndex++;
x += 8;
y -= 8;
}
x -= maxHSampleFactor * 8;
y += 8;
}
x += maxHSampleFactor * 8;
y -= maxVSampleFactor * 8;
if (x >= rawImage.getWidth()) {
x = 0;
y += maxVSampleFactor * 8;
}
}
} | java | protected void writeFull() {
byte[] imageData = rawImage.getData();
int numOfComponents = frameHeader.getNf();
int[] pixes = new int[numOfComponents * DCTSIZE2];
int blockIndex = 0;
int startCoordinate = 0, scanlineStride = numOfComponents * rawImage.getWidth(), row = 0;
x = 0;
y = 0;
for (int m = 0; m < MCUsPerColumn * MCUsPerRow; m++) {
blockIndex = 0;
// one MCU
for (int v = 0; v < maxVSampleFactor; v++) {
for (int h = 0; h < maxHSampleFactor; h++) {
row = y + 1;
startCoordinate = (y * rawImage.getWidth() + x) * numOfComponents;
// one block
for (int k = blockIndex * DCTSIZE2, i = 0; k < blockIndex * DCTSIZE2 + DCTSIZE2; k++) {
pixes[i++] = allMCUDatas[0][m][k];
if (numOfComponents > 1) {
pixes[i++] = allMCUDatas[1][m][k];
pixes[i++] = allMCUDatas[2][m][k];
}
if (numOfComponents > 3) {
pixes[i++] = allMCUDatas[3][m][k];
}
x++;
if (x % 8 == 0) {
y++;
x -= 8;
}
}
colorConvertor.convertBlock(pixes, 0, imageData, numOfComponents, startCoordinate, row,
scanlineStride);
blockIndex++;
x += 8;
y -= 8;
}
x -= maxHSampleFactor * 8;
y += 8;
}
x += maxHSampleFactor * 8;
y -= maxVSampleFactor * 8;
if (x >= rawImage.getWidth()) {
x = 0;
y += maxVSampleFactor * 8;
}
}
} | [
"protected",
"void",
"writeFull",
"(",
")",
"{",
"byte",
"[",
"]",
"imageData",
"=",
"rawImage",
".",
"getData",
"(",
")",
";",
"int",
"numOfComponents",
"=",
"frameHeader",
".",
"getNf",
"(",
")",
";",
"int",
"[",
"]",
"pixes",
"=",
"new",
"int",
"[... | Used by progressive mode | [
"Used",
"by",
"progressive",
"mode"
] | aabe559c267402b754c2ad606b796c4c6570788c | https://github.com/alibaba/simpleimage/blob/aabe559c267402b754c2ad606b796c4c6570788c/simpleimage.core/src/main/java/com/alibaba/simpleimage/codec/jpeg/JPEGDecoder.java#L1101-L1163 | train |
alibaba/simpleimage | simpleimage.analyze/src/main/java/com/alibaba/simpleimage/analyze/search/tree/KMeansTreeNode.java | KMeansTreeNode.getValueId | public int getValueId(Clusterable c) {
currentItems++;
/*
* if(isLeafNode()) { return id; }
*/
int index = TreeUtils.findNearestNodeIndex(subNodes, c);
if (index >= 0) {
KMeansTreeNode node = subNodes.get(index);
return node.getValueId(c);
}
return id;
} | java | public int getValueId(Clusterable c) {
currentItems++;
/*
* if(isLeafNode()) { return id; }
*/
int index = TreeUtils.findNearestNodeIndex(subNodes, c);
if (index >= 0) {
KMeansTreeNode node = subNodes.get(index);
return node.getValueId(c);
}
return id;
} | [
"public",
"int",
"getValueId",
"(",
"Clusterable",
"c",
")",
"{",
"currentItems",
"++",
";",
"/*\r\n\t\t * if(isLeafNode()) { return id; }\r\n\t\t */",
"int",
"index",
"=",
"TreeUtils",
".",
"findNearestNodeIndex",
"(",
"subNodes",
",",
"c",
")",
";",
"if",
"(",
"... | Adds a clusterable to the current vocab tree for word creation | [
"Adds",
"a",
"clusterable",
"to",
"the",
"current",
"vocab",
"tree",
"for",
"word",
"creation"
] | aabe559c267402b754c2ad606b796c4c6570788c | https://github.com/alibaba/simpleimage/blob/aabe559c267402b754c2ad606b796c4c6570788c/simpleimage.analyze/src/main/java/com/alibaba/simpleimage/analyze/search/tree/KMeansTreeNode.java#L97-L108 | train |
alibaba/simpleimage | simpleimage.core/src/main/java/com/alibaba/simpleimage/util/NodeUtils.java | NodeUtils.cloneNode | public static Node cloneNode(Node node) {
if(node == null) {
return null;
}
IIOMetadataNode newNode = new IIOMetadataNode(node.getNodeName());
//clone user object
if(node instanceof IIOMetadataNode) {
IIOMetadataNode iioNode = (IIOMetadataNode)node;
Object obj = iioNode.getUserObject();
if(obj instanceof byte[]) {
byte[] copyBytes = ((byte[])obj).clone();
newNode.setUserObject(copyBytes);
}
}
//clone attributes
NamedNodeMap attrs = node.getAttributes();
for(int i = 0; i < attrs.getLength(); i++ ) {
Node attr = attrs.item(i);
newNode.setAttribute(attr.getNodeName(), attr.getNodeValue());
}
//clone children
NodeList children = node.getChildNodes();
for(int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
newNode.appendChild(cloneNode(child));
}
return newNode;
} | java | public static Node cloneNode(Node node) {
if(node == null) {
return null;
}
IIOMetadataNode newNode = new IIOMetadataNode(node.getNodeName());
//clone user object
if(node instanceof IIOMetadataNode) {
IIOMetadataNode iioNode = (IIOMetadataNode)node;
Object obj = iioNode.getUserObject();
if(obj instanceof byte[]) {
byte[] copyBytes = ((byte[])obj).clone();
newNode.setUserObject(copyBytes);
}
}
//clone attributes
NamedNodeMap attrs = node.getAttributes();
for(int i = 0; i < attrs.getLength(); i++ ) {
Node attr = attrs.item(i);
newNode.setAttribute(attr.getNodeName(), attr.getNodeValue());
}
//clone children
NodeList children = node.getChildNodes();
for(int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
newNode.appendChild(cloneNode(child));
}
return newNode;
} | [
"public",
"static",
"Node",
"cloneNode",
"(",
"Node",
"node",
")",
"{",
"if",
"(",
"node",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"IIOMetadataNode",
"newNode",
"=",
"new",
"IIOMetadataNode",
"(",
"node",
".",
"getNodeName",
"(",
")",
")",
... | Currently only use by GIFStreamMetadata and GIFImageMetadata
@param node
@return | [
"Currently",
"only",
"use",
"by",
"GIFStreamMetadata",
"and",
"GIFImageMetadata"
] | aabe559c267402b754c2ad606b796c4c6570788c | https://github.com/alibaba/simpleimage/blob/aabe559c267402b754c2ad606b796c4c6570788c/simpleimage.core/src/main/java/com/alibaba/simpleimage/util/NodeUtils.java#L35-L66 | train |
alibaba/simpleimage | simpleimage.analyze/src/main/java/com/alibaba/simpleimage/analyze/search/cluster/impl/AbstractClusterBuilder.java | AbstractClusterBuilder.calculateInitialClusters | protected Cluster[] calculateInitialClusters(List<? extends Clusterable> values, int numClusters){
Cluster[] clusters = new Cluster[numClusters];
//choose centers and create the initial clusters
Random random = new Random(1);
Set<Integer> clusterCenters = new HashSet<Integer>();
for ( int i = 0; i < numClusters; i++ ){
int index = random.nextInt(values.size());
while ( clusterCenters.contains(index) ){
index = random.nextInt(values.size());
}
clusterCenters.add(index);
clusters[i] = new Cluster(values.get(index).getLocation(),i);
}
return clusters;
} | java | protected Cluster[] calculateInitialClusters(List<? extends Clusterable> values, int numClusters){
Cluster[] clusters = new Cluster[numClusters];
//choose centers and create the initial clusters
Random random = new Random(1);
Set<Integer> clusterCenters = new HashSet<Integer>();
for ( int i = 0; i < numClusters; i++ ){
int index = random.nextInt(values.size());
while ( clusterCenters.contains(index) ){
index = random.nextInt(values.size());
}
clusterCenters.add(index);
clusters[i] = new Cluster(values.get(index).getLocation(),i);
}
return clusters;
} | [
"protected",
"Cluster",
"[",
"]",
"calculateInitialClusters",
"(",
"List",
"<",
"?",
"extends",
"Clusterable",
">",
"values",
",",
"int",
"numClusters",
")",
"{",
"Cluster",
"[",
"]",
"clusters",
"=",
"new",
"Cluster",
"[",
"numClusters",
"]",
";",
"//choose... | Calculates the initial clusters randomly, this could be replaced with a better algorithm
@param values
@param numClusters
@return | [
"Calculates",
"the",
"initial",
"clusters",
"randomly",
"this",
"could",
"be",
"replaced",
"with",
"a",
"better",
"algorithm"
] | aabe559c267402b754c2ad606b796c4c6570788c | https://github.com/alibaba/simpleimage/blob/aabe559c267402b754c2ad606b796c4c6570788c/simpleimage.analyze/src/main/java/com/alibaba/simpleimage/analyze/search/cluster/impl/AbstractClusterBuilder.java#L80-L94 | train |
alibaba/simpleimage | simpleimage.analyze/src/main/java/com/alibaba/simpleimage/analyze/search/cluster/impl/Cluster.java | Cluster.getClusterMean | public float[] getClusterMean(){
float[] normedCurrentLocation = new float[mCurrentMeanLocation.length];
for ( int i = 0; i < mCurrentMeanLocation.length; i++ ){
normedCurrentLocation[i] = mCurrentMeanLocation[i]/((float)mClusterItems.size());
}
return normedCurrentLocation;
} | java | public float[] getClusterMean(){
float[] normedCurrentLocation = new float[mCurrentMeanLocation.length];
for ( int i = 0; i < mCurrentMeanLocation.length; i++ ){
normedCurrentLocation[i] = mCurrentMeanLocation[i]/((float)mClusterItems.size());
}
return normedCurrentLocation;
} | [
"public",
"float",
"[",
"]",
"getClusterMean",
"(",
")",
"{",
"float",
"[",
"]",
"normedCurrentLocation",
"=",
"new",
"float",
"[",
"mCurrentMeanLocation",
".",
"length",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"mCurrentMeanLocation",
... | Get the current mean value of the cluster's items
@return | [
"Get",
"the",
"current",
"mean",
"value",
"of",
"the",
"cluster",
"s",
"items"
] | aabe559c267402b754c2ad606b796c4c6570788c | https://github.com/alibaba/simpleimage/blob/aabe559c267402b754c2ad606b796c4c6570788c/simpleimage.analyze/src/main/java/com/alibaba/simpleimage/analyze/search/cluster/impl/Cluster.java#L37-L43 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/time/RadialPickerLayout.java | RadialPickerLayout.setItem | private void setItem(int index, Timepoint time) {
time = roundToValidTime(time, index);
mCurrentTime = time;
reselectSelector(time, false, index);
} | java | private void setItem(int index, Timepoint time) {
time = roundToValidTime(time, index);
mCurrentTime = time;
reselectSelector(time, false, index);
} | [
"private",
"void",
"setItem",
"(",
"int",
"index",
",",
"Timepoint",
"time",
")",
"{",
"time",
"=",
"roundToValidTime",
"(",
"time",
",",
"index",
")",
";",
"mCurrentTime",
"=",
"time",
";",
"reselectSelector",
"(",
"time",
",",
"false",
",",
"index",
")... | Set either the hour, the minute or the second. Will set the internal value, and set the selection. | [
"Set",
"either",
"the",
"hour",
"the",
"minute",
"or",
"the",
"second",
".",
"Will",
"set",
"the",
"internal",
"value",
"and",
"set",
"the",
"selection",
"."
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/time/RadialPickerLayout.java#L255-L259 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/time/RadialPickerLayout.java | RadialPickerLayout.isHourInnerCircle | private boolean isHourInnerCircle(int hourOfDay) {
// We'll have the 00 hours on the outside circle.
boolean isMorning = hourOfDay <= 12 && hourOfDay != 0;
// In the version 2 layout the circles are swapped
if (mController.getVersion() != TimePickerDialog.Version.VERSION_1) isMorning = !isMorning;
return mIs24HourMode && isMorning;
} | java | private boolean isHourInnerCircle(int hourOfDay) {
// We'll have the 00 hours on the outside circle.
boolean isMorning = hourOfDay <= 12 && hourOfDay != 0;
// In the version 2 layout the circles are swapped
if (mController.getVersion() != TimePickerDialog.Version.VERSION_1) isMorning = !isMorning;
return mIs24HourMode && isMorning;
} | [
"private",
"boolean",
"isHourInnerCircle",
"(",
"int",
"hourOfDay",
")",
"{",
"// We'll have the 00 hours on the outside circle.",
"boolean",
"isMorning",
"=",
"hourOfDay",
"<=",
"12",
"&&",
"hourOfDay",
"!=",
"0",
";",
"// In the version 2 layout the circles are swapped",
... | Check if a given hour appears in the outer circle or the inner circle
@return true if the hour is in the inner circle, false if it's in the outer circle. | [
"Check",
"if",
"a",
"given",
"hour",
"appears",
"in",
"the",
"outer",
"circle",
"or",
"the",
"inner",
"circle"
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/time/RadialPickerLayout.java#L265-L271 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/time/RadialPickerLayout.java | RadialPickerLayout.getCurrentlyShowingValue | private int getCurrentlyShowingValue() {
int currentIndex = getCurrentItemShowing();
switch(currentIndex) {
case HOUR_INDEX:
return mCurrentTime.getHour();
case MINUTE_INDEX:
return mCurrentTime.getMinute();
case SECOND_INDEX:
return mCurrentTime.getSecond();
default:
return -1;
}
} | java | private int getCurrentlyShowingValue() {
int currentIndex = getCurrentItemShowing();
switch(currentIndex) {
case HOUR_INDEX:
return mCurrentTime.getHour();
case MINUTE_INDEX:
return mCurrentTime.getMinute();
case SECOND_INDEX:
return mCurrentTime.getSecond();
default:
return -1;
}
} | [
"private",
"int",
"getCurrentlyShowingValue",
"(",
")",
"{",
"int",
"currentIndex",
"=",
"getCurrentItemShowing",
"(",
")",
";",
"switch",
"(",
"currentIndex",
")",
"{",
"case",
"HOUR_INDEX",
":",
"return",
"mCurrentTime",
".",
"getHour",
"(",
")",
";",
"case"... | If the hours are showing, return the current hour. If the minutes are showing, return the
current minute. | [
"If",
"the",
"hours",
"are",
"showing",
"return",
"the",
"current",
"hour",
".",
"If",
"the",
"minutes",
"are",
"showing",
"return",
"the",
"current",
"minute",
"."
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/time/RadialPickerLayout.java#L293-L305 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/time/RadialPickerLayout.java | RadialPickerLayout.roundToValidTime | private Timepoint roundToValidTime(Timepoint newSelection, int currentItemShowing) {
switch(currentItemShowing) {
case HOUR_INDEX:
return mController.roundToNearest(newSelection, null);
case MINUTE_INDEX:
return mController.roundToNearest(newSelection, Timepoint.TYPE.HOUR);
default:
return mController.roundToNearest(newSelection, Timepoint.TYPE.MINUTE);
}
} | java | private Timepoint roundToValidTime(Timepoint newSelection, int currentItemShowing) {
switch(currentItemShowing) {
case HOUR_INDEX:
return mController.roundToNearest(newSelection, null);
case MINUTE_INDEX:
return mController.roundToNearest(newSelection, Timepoint.TYPE.HOUR);
default:
return mController.roundToNearest(newSelection, Timepoint.TYPE.MINUTE);
}
} | [
"private",
"Timepoint",
"roundToValidTime",
"(",
"Timepoint",
"newSelection",
",",
"int",
"currentItemShowing",
")",
"{",
"switch",
"(",
"currentItemShowing",
")",
"{",
"case",
"HOUR_INDEX",
":",
"return",
"mController",
".",
"roundToNearest",
"(",
"newSelection",
"... | Snap the input to a selectable value
@param newSelection Timepoint - Time which should be rounded
@param currentItemShowing int - The index of the current view
@return Timepoint - the rounded value | [
"Snap",
"the",
"input",
"to",
"a",
"selectable",
"value"
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/time/RadialPickerLayout.java#L438-L447 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/time/RadialPickerLayout.java | RadialPickerLayout.trySettingInputEnabled | public boolean trySettingInputEnabled(boolean inputEnabled) {
if (mDoingTouch && !inputEnabled) {
// If we're trying to disable input, but we're in the middle of a touch event,
// we'll allow the touch event to continue before disabling input.
return false;
}
mInputEnabled = inputEnabled;
mGrayBox.setVisibility(inputEnabled? View.INVISIBLE : View.VISIBLE);
return true;
} | java | public boolean trySettingInputEnabled(boolean inputEnabled) {
if (mDoingTouch && !inputEnabled) {
// If we're trying to disable input, but we're in the middle of a touch event,
// we'll allow the touch event to continue before disabling input.
return false;
}
mInputEnabled = inputEnabled;
mGrayBox.setVisibility(inputEnabled? View.INVISIBLE : View.VISIBLE);
return true;
} | [
"public",
"boolean",
"trySettingInputEnabled",
"(",
"boolean",
"inputEnabled",
")",
"{",
"if",
"(",
"mDoingTouch",
"&&",
"!",
"inputEnabled",
")",
"{",
"// If we're trying to disable input, but we're in the middle of a touch event,",
"// we'll allow the touch event to continue befo... | Set touch input as enabled or disabled, for use with keyboard mode. | [
"Set",
"touch",
"input",
"as",
"enabled",
"or",
"disabled",
"for",
"use",
"with",
"keyboard",
"mode",
"."
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/time/RadialPickerLayout.java#L878-L888 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/Utils.java | Utils.getPulseAnimator | public static ObjectAnimator getPulseAnimator(View labelToAnimate, float decreaseRatio,
float increaseRatio) {
Keyframe k0 = Keyframe.ofFloat(0f, 1f);
Keyframe k1 = Keyframe.ofFloat(0.275f, decreaseRatio);
Keyframe k2 = Keyframe.ofFloat(0.69f, increaseRatio);
Keyframe k3 = Keyframe.ofFloat(1f, 1f);
PropertyValuesHolder scaleX = PropertyValuesHolder.ofKeyframe("scaleX", k0, k1, k2, k3);
PropertyValuesHolder scaleY = PropertyValuesHolder.ofKeyframe("scaleY", k0, k1, k2, k3);
ObjectAnimator pulseAnimator =
ObjectAnimator.ofPropertyValuesHolder(labelToAnimate, scaleX, scaleY);
pulseAnimator.setDuration(PULSE_ANIMATOR_DURATION);
return pulseAnimator;
} | java | public static ObjectAnimator getPulseAnimator(View labelToAnimate, float decreaseRatio,
float increaseRatio) {
Keyframe k0 = Keyframe.ofFloat(0f, 1f);
Keyframe k1 = Keyframe.ofFloat(0.275f, decreaseRatio);
Keyframe k2 = Keyframe.ofFloat(0.69f, increaseRatio);
Keyframe k3 = Keyframe.ofFloat(1f, 1f);
PropertyValuesHolder scaleX = PropertyValuesHolder.ofKeyframe("scaleX", k0, k1, k2, k3);
PropertyValuesHolder scaleY = PropertyValuesHolder.ofKeyframe("scaleY", k0, k1, k2, k3);
ObjectAnimator pulseAnimator =
ObjectAnimator.ofPropertyValuesHolder(labelToAnimate, scaleX, scaleY);
pulseAnimator.setDuration(PULSE_ANIMATOR_DURATION);
return pulseAnimator;
} | [
"public",
"static",
"ObjectAnimator",
"getPulseAnimator",
"(",
"View",
"labelToAnimate",
",",
"float",
"decreaseRatio",
",",
"float",
"increaseRatio",
")",
"{",
"Keyframe",
"k0",
"=",
"Keyframe",
".",
"ofFloat",
"(",
"0f",
",",
"1f",
")",
";",
"Keyframe",
"k1"... | Render an animator to pulsate a view in place.
@param labelToAnimate the view to pulsate.
@return The animator object. Use .start() to begin. | [
"Render",
"an",
"animator",
"to",
"pulsate",
"a",
"view",
"in",
"place",
"."
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/Utils.java#L64-L78 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/Utils.java | Utils.trimToMidnight | public static Calendar trimToMidnight(Calendar calendar) {
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar;
} | java | public static Calendar trimToMidnight(Calendar calendar) {
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar;
} | [
"public",
"static",
"Calendar",
"trimToMidnight",
"(",
"Calendar",
"calendar",
")",
"{",
"calendar",
".",
"set",
"(",
"Calendar",
".",
"HOUR_OF_DAY",
",",
"0",
")",
";",
"calendar",
".",
"set",
"(",
"Calendar",
".",
"MINUTE",
",",
"0",
")",
";",
"calenda... | Trims off all time information, effectively setting it to midnight
Makes it easier to compare at just the day level
@param calendar The Calendar object to trim
@return The trimmed Calendar object | [
"Trims",
"off",
"all",
"time",
"information",
"effectively",
"setting",
"it",
"to",
"midnight",
"Makes",
"it",
"easier",
"to",
"compare",
"at",
"just",
"the",
"day",
"level"
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/Utils.java#L150-L156 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/date/DatePickerDialog.java | DatePickerDialog.newInstance | @SuppressWarnings("unused")
public static DatePickerDialog newInstance(OnDateSetListener callback) {
Calendar now = Calendar.getInstance();
return DatePickerDialog.newInstance(callback, now);
} | java | @SuppressWarnings("unused")
public static DatePickerDialog newInstance(OnDateSetListener callback) {
Calendar now = Calendar.getInstance();
return DatePickerDialog.newInstance(callback, now);
} | [
"@",
"SuppressWarnings",
"(",
"\"unused\"",
")",
"public",
"static",
"DatePickerDialog",
"newInstance",
"(",
"OnDateSetListener",
"callback",
")",
"{",
"Calendar",
"now",
"=",
"Calendar",
".",
"getInstance",
"(",
")",
";",
"return",
"DatePickerDialog",
".",
"newIn... | Create a new DatePickerDialog instance initialised to the current system date.
@param callback How the parent is notified that the date is set.
@return a new DatePickerDialog instance | [
"Create",
"a",
"new",
"DatePickerDialog",
"instance",
"initialised",
"to",
"the",
"current",
"system",
"date",
"."
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/date/DatePickerDialog.java#L214-L218 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/date/DatePickerDialog.java | DatePickerDialog.setHighlightedDays | @SuppressWarnings("unused")
public void setHighlightedDays(Calendar[] highlightedDays) {
for (Calendar highlightedDay : highlightedDays) {
this.highlightedDays.add(Utils.trimToMidnight((Calendar) highlightedDay.clone()));
}
if (mDayPickerView != null) mDayPickerView.onChange();
} | java | @SuppressWarnings("unused")
public void setHighlightedDays(Calendar[] highlightedDays) {
for (Calendar highlightedDay : highlightedDays) {
this.highlightedDays.add(Utils.trimToMidnight((Calendar) highlightedDay.clone()));
}
if (mDayPickerView != null) mDayPickerView.onChange();
} | [
"@",
"SuppressWarnings",
"(",
"\"unused\"",
")",
"public",
"void",
"setHighlightedDays",
"(",
"Calendar",
"[",
"]",
"highlightedDays",
")",
"{",
"for",
"(",
"Calendar",
"highlightedDay",
":",
"highlightedDays",
")",
"{",
"this",
".",
"highlightedDays",
".",
"add... | Sets an array of dates which should be highlighted when the picker is drawn
@param highlightedDays an Array of Calendar objects containing the dates to be highlighted | [
"Sets",
"an",
"array",
"of",
"dates",
"which",
"should",
"be",
"highlighted",
"when",
"the",
"picker",
"is",
"drawn"
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/date/DatePickerDialog.java#L814-L820 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/date/DatePickerDialog.java | DatePickerDialog.setTimeZone | @SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
public void setTimeZone(TimeZone timeZone) {
mTimezone = timeZone;
mCalendar.setTimeZone(timeZone);
YEAR_FORMAT.setTimeZone(timeZone);
MONTH_FORMAT.setTimeZone(timeZone);
DAY_FORMAT.setTimeZone(timeZone);
} | java | @SuppressWarnings("DeprecatedIsStillUsed")
@Deprecated
public void setTimeZone(TimeZone timeZone) {
mTimezone = timeZone;
mCalendar.setTimeZone(timeZone);
YEAR_FORMAT.setTimeZone(timeZone);
MONTH_FORMAT.setTimeZone(timeZone);
DAY_FORMAT.setTimeZone(timeZone);
} | [
"@",
"SuppressWarnings",
"(",
"\"DeprecatedIsStillUsed\"",
")",
"@",
"Deprecated",
"public",
"void",
"setTimeZone",
"(",
"TimeZone",
"timeZone",
")",
"{",
"mTimezone",
"=",
"timeZone",
";",
"mCalendar",
".",
"setTimeZone",
"(",
"timeZone",
")",
";",
"YEAR_FORMAT",... | Set which timezone the picker should use
This has been deprecated in favor of setting the TimeZone using the constructor that
takes a Calendar object
@param timeZone The timezone to use | [
"Set",
"which",
"timezone",
"the",
"picker",
"should",
"use"
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/date/DatePickerDialog.java#L984-L992 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/date/DatePickerDialog.java | DatePickerDialog.setLocale | public void setLocale(Locale locale) {
mLocale = locale;
mWeekStart = Calendar.getInstance(mTimezone, mLocale).getFirstDayOfWeek();
YEAR_FORMAT = new SimpleDateFormat("yyyy", locale);
MONTH_FORMAT = new SimpleDateFormat("MMM", locale);
DAY_FORMAT = new SimpleDateFormat("dd", locale);
} | java | public void setLocale(Locale locale) {
mLocale = locale;
mWeekStart = Calendar.getInstance(mTimezone, mLocale).getFirstDayOfWeek();
YEAR_FORMAT = new SimpleDateFormat("yyyy", locale);
MONTH_FORMAT = new SimpleDateFormat("MMM", locale);
DAY_FORMAT = new SimpleDateFormat("dd", locale);
} | [
"public",
"void",
"setLocale",
"(",
"Locale",
"locale",
")",
"{",
"mLocale",
"=",
"locale",
";",
"mWeekStart",
"=",
"Calendar",
".",
"getInstance",
"(",
"mTimezone",
",",
"mLocale",
")",
".",
"getFirstDayOfWeek",
"(",
")",
";",
"YEAR_FORMAT",
"=",
"new",
"... | Set a custom locale to be used when generating various strings in the picker
@param locale Locale | [
"Set",
"a",
"custom",
"locale",
"to",
"be",
"used",
"when",
"generating",
"various",
"strings",
"in",
"the",
"picker"
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/date/DatePickerDialog.java#L998-L1004 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/HapticFeedbackController.java | HapticFeedbackController.start | public void start() {
if (hasVibratePermission(mContext)) {
mVibrator = (Vibrator) mContext.getSystemService(Service.VIBRATOR_SERVICE);
}
// Setup a listener for changes in haptic feedback settings
mIsGloballyEnabled = checkGlobalSetting(mContext);
Uri uri = Settings.System.getUriFor(Settings.System.HAPTIC_FEEDBACK_ENABLED);
mContext.getContentResolver().registerContentObserver(uri, false, mContentObserver);
} | java | public void start() {
if (hasVibratePermission(mContext)) {
mVibrator = (Vibrator) mContext.getSystemService(Service.VIBRATOR_SERVICE);
}
// Setup a listener for changes in haptic feedback settings
mIsGloballyEnabled = checkGlobalSetting(mContext);
Uri uri = Settings.System.getUriFor(Settings.System.HAPTIC_FEEDBACK_ENABLED);
mContext.getContentResolver().registerContentObserver(uri, false, mContentObserver);
} | [
"public",
"void",
"start",
"(",
")",
"{",
"if",
"(",
"hasVibratePermission",
"(",
"mContext",
")",
")",
"{",
"mVibrator",
"=",
"(",
"Vibrator",
")",
"mContext",
".",
"getSystemService",
"(",
"Service",
".",
"VIBRATOR_SERVICE",
")",
";",
"}",
"// Setup a list... | Call to setup the controller. | [
"Call",
"to",
"setup",
"the",
"controller",
"."
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/HapticFeedbackController.java#L44-L53 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/HapticFeedbackController.java | HapticFeedbackController.hasVibratePermission | private boolean hasVibratePermission(Context context) {
PackageManager pm = context.getPackageManager();
int hasPerm = pm.checkPermission(android.Manifest.permission.VIBRATE, context.getPackageName());
return hasPerm == PackageManager.PERMISSION_GRANTED;
} | java | private boolean hasVibratePermission(Context context) {
PackageManager pm = context.getPackageManager();
int hasPerm = pm.checkPermission(android.Manifest.permission.VIBRATE, context.getPackageName());
return hasPerm == PackageManager.PERMISSION_GRANTED;
} | [
"private",
"boolean",
"hasVibratePermission",
"(",
"Context",
"context",
")",
"{",
"PackageManager",
"pm",
"=",
"context",
".",
"getPackageManager",
"(",
")",
";",
"int",
"hasPerm",
"=",
"pm",
".",
"checkPermission",
"(",
"android",
".",
"Manifest",
".",
"perm... | Method to verify that vibrate permission has been granted.
Allows users of the library to disabled vibrate support if desired.
@return true if Vibrate permission has been granted | [
"Method",
"to",
"verify",
"that",
"vibrate",
"permission",
"has",
"been",
"granted",
"."
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/HapticFeedbackController.java#L61-L65 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java | TimePickerDialog.newInstance | @SuppressWarnings("SameParameterValue")
public static TimePickerDialog newInstance(OnTimeSetListener callback,
int hourOfDay, int minute, int second, boolean is24HourMode) {
TimePickerDialog ret = new TimePickerDialog();
ret.initialize(callback, hourOfDay, minute, second, is24HourMode);
return ret;
} | java | @SuppressWarnings("SameParameterValue")
public static TimePickerDialog newInstance(OnTimeSetListener callback,
int hourOfDay, int minute, int second, boolean is24HourMode) {
TimePickerDialog ret = new TimePickerDialog();
ret.initialize(callback, hourOfDay, minute, second, is24HourMode);
return ret;
} | [
"@",
"SuppressWarnings",
"(",
"\"SameParameterValue\"",
")",
"public",
"static",
"TimePickerDialog",
"newInstance",
"(",
"OnTimeSetListener",
"callback",
",",
"int",
"hourOfDay",
",",
"int",
"minute",
",",
"int",
"second",
",",
"boolean",
"is24HourMode",
")",
"{",
... | Create a new TimePickerDialog instance with a given intial selection
@param callback How the parent is notified that the time is set.
@param hourOfDay The initial hour of the dialog.
@param minute The initial minute of the dialog.
@param second The initial second of the dialog.
@param is24HourMode True to render 24 hour mode, false to render AM / PM selectors.
@return a new TimePickerDialog instance. | [
"Create",
"a",
"new",
"TimePickerDialog",
"instance",
"with",
"a",
"given",
"intial",
"selection"
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java#L197-L203 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java | TimePickerDialog.newInstance | public static TimePickerDialog newInstance(OnTimeSetListener callback,
int hourOfDay, int minute, boolean is24HourMode) {
return TimePickerDialog.newInstance(callback, hourOfDay, minute, 0, is24HourMode);
} | java | public static TimePickerDialog newInstance(OnTimeSetListener callback,
int hourOfDay, int minute, boolean is24HourMode) {
return TimePickerDialog.newInstance(callback, hourOfDay, minute, 0, is24HourMode);
} | [
"public",
"static",
"TimePickerDialog",
"newInstance",
"(",
"OnTimeSetListener",
"callback",
",",
"int",
"hourOfDay",
",",
"int",
"minute",
",",
"boolean",
"is24HourMode",
")",
"{",
"return",
"TimePickerDialog",
".",
"newInstance",
"(",
"callback",
",",
"hourOfDay",... | Create a new TimePickerDialog instance with a given initial selection
@param callback How the parent is notified that the time is set.
@param hourOfDay The initial hour of the dialog.
@param minute The initial minute of the dialog.
@param is24HourMode True to render 24 hour mode, false to render AM / PM selectors.
@return a new TimePickerDialog instance. | [
"Create",
"a",
"new",
"TimePickerDialog",
"instance",
"with",
"a",
"given",
"initial",
"selection"
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java#L213-L216 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java | TimePickerDialog.newInstance | @SuppressWarnings({"unused", "SameParameterValue"})
public static TimePickerDialog newInstance(OnTimeSetListener callback, boolean is24HourMode) {
Calendar now = Calendar.getInstance();
return TimePickerDialog.newInstance(callback, now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), is24HourMode);
} | java | @SuppressWarnings({"unused", "SameParameterValue"})
public static TimePickerDialog newInstance(OnTimeSetListener callback, boolean is24HourMode) {
Calendar now = Calendar.getInstance();
return TimePickerDialog.newInstance(callback, now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), is24HourMode);
} | [
"@",
"SuppressWarnings",
"(",
"{",
"\"unused\"",
",",
"\"SameParameterValue\"",
"}",
")",
"public",
"static",
"TimePickerDialog",
"newInstance",
"(",
"OnTimeSetListener",
"callback",
",",
"boolean",
"is24HourMode",
")",
"{",
"Calendar",
"now",
"=",
"Calendar",
".",
... | Create a new TimePickerDialog instance initialized to the current system time
@param callback How the parent is notified that the time is set.
@param is24HourMode True to render 24 hour mode, false to render AM / PM selectors.
@return a new TimePickerDialog instance. | [
"Create",
"a",
"new",
"TimePickerDialog",
"instance",
"initialized",
"to",
"the",
"current",
"system",
"time"
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java#L224-L228 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java | TimePickerDialog.processKeyUp | private boolean processKeyUp(int keyCode) {
if (keyCode == KeyEvent.KEYCODE_TAB) {
if(mInKbMode) {
if (isTypedTimeFullyLegal()) {
finishKbMode(true);
}
return true;
}
} else if (keyCode == KeyEvent.KEYCODE_ENTER) {
if (mInKbMode) {
if (!isTypedTimeFullyLegal()) {
return true;
}
finishKbMode(false);
}
if (mCallback != null) {
mCallback.onTimeSet(this,
mTimePicker.getHours(), mTimePicker.getMinutes(), mTimePicker.getSeconds());
}
dismiss();
return true;
} else if (keyCode == KeyEvent.KEYCODE_DEL) {
if (mInKbMode) {
if (!mTypedTimes.isEmpty()) {
int deleted = deleteLastTypedKey();
String deletedKeyStr;
if (deleted == getAmOrPmKeyCode(AM)) {
deletedKeyStr = mAmText;
} else if (deleted == getAmOrPmKeyCode(PM)) {
deletedKeyStr = mPmText;
} else {
deletedKeyStr = String.format(mLocale, "%d", getValFromKeyCode(deleted));
}
Utils.tryAccessibilityAnnounce(mTimePicker,
String.format(mDeletedKeyFormat, deletedKeyStr));
updateDisplay(true);
}
}
} else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1
|| keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3
|| keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
|| keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7
|| keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9
|| (!mIs24HourMode &&
(keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
if (!mInKbMode) {
if (mTimePicker == null) {
// Something's wrong, because time picker should definitely not be null.
Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
return true;
}
mTypedTimes.clear();
tryStartingKbMode(keyCode);
return true;
}
// We're already in keyboard mode.
if (addKeyIfLegal(keyCode)) {
updateDisplay(false);
}
return true;
}
return false;
} | java | private boolean processKeyUp(int keyCode) {
if (keyCode == KeyEvent.KEYCODE_TAB) {
if(mInKbMode) {
if (isTypedTimeFullyLegal()) {
finishKbMode(true);
}
return true;
}
} else if (keyCode == KeyEvent.KEYCODE_ENTER) {
if (mInKbMode) {
if (!isTypedTimeFullyLegal()) {
return true;
}
finishKbMode(false);
}
if (mCallback != null) {
mCallback.onTimeSet(this,
mTimePicker.getHours(), mTimePicker.getMinutes(), mTimePicker.getSeconds());
}
dismiss();
return true;
} else if (keyCode == KeyEvent.KEYCODE_DEL) {
if (mInKbMode) {
if (!mTypedTimes.isEmpty()) {
int deleted = deleteLastTypedKey();
String deletedKeyStr;
if (deleted == getAmOrPmKeyCode(AM)) {
deletedKeyStr = mAmText;
} else if (deleted == getAmOrPmKeyCode(PM)) {
deletedKeyStr = mPmText;
} else {
deletedKeyStr = String.format(mLocale, "%d", getValFromKeyCode(deleted));
}
Utils.tryAccessibilityAnnounce(mTimePicker,
String.format(mDeletedKeyFormat, deletedKeyStr));
updateDisplay(true);
}
}
} else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1
|| keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3
|| keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
|| keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7
|| keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9
|| (!mIs24HourMode &&
(keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
if (!mInKbMode) {
if (mTimePicker == null) {
// Something's wrong, because time picker should definitely not be null.
Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
return true;
}
mTypedTimes.clear();
tryStartingKbMode(keyCode);
return true;
}
// We're already in keyboard mode.
if (addKeyIfLegal(keyCode)) {
updateDisplay(false);
}
return true;
}
return false;
} | [
"private",
"boolean",
"processKeyUp",
"(",
"int",
"keyCode",
")",
"{",
"if",
"(",
"keyCode",
"==",
"KeyEvent",
".",
"KEYCODE_TAB",
")",
"{",
"if",
"(",
"mInKbMode",
")",
"{",
"if",
"(",
"isTypedTimeFullyLegal",
"(",
")",
")",
"{",
"finishKbMode",
"(",
"t... | For keyboard mode, processes key events.
@param keyCode the pressed key.
@return true if the key was successfully processed, false otherwise. | [
"For",
"keyboard",
"mode",
"processes",
"key",
"events",
"."
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/time/TimePickerDialog.java#L1287-L1349 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/date/MonthView.java | MonthView.setMonthParams | public void setMonthParams(int selectedDay, int year, int month, int weekStart) {
if (month == -1 && year == -1) {
throw new InvalidParameterException("You must specify month and year for this view");
}
mSelectedDay = selectedDay;
// Allocate space for caching the day numbers and focus values
mMonth = month;
mYear = year;
// Figure out what day today is
//final Time today = new Time(Time.getCurrentTimezone());
//today.setToNow();
final Calendar today = Calendar.getInstance(mController.getTimeZone(), mController.getLocale());
mHasToday = false;
mToday = -1;
mCalendar.set(Calendar.MONTH, mMonth);
mCalendar.set(Calendar.YEAR, mYear);
mCalendar.set(Calendar.DAY_OF_MONTH, 1);
mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK);
if (weekStart != -1) {
mWeekStart = weekStart;
} else {
mWeekStart = mCalendar.getFirstDayOfWeek();
}
mNumCells = mCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
for (int i = 0; i < mNumCells; i++) {
final int day = i + 1;
if (sameDay(day, today)) {
mHasToday = true;
mToday = day;
}
}
mNumRows = calculateNumRows();
// Invalidate cached accessibility information.
mTouchHelper.invalidateRoot();
} | java | public void setMonthParams(int selectedDay, int year, int month, int weekStart) {
if (month == -1 && year == -1) {
throw new InvalidParameterException("You must specify month and year for this view");
}
mSelectedDay = selectedDay;
// Allocate space for caching the day numbers and focus values
mMonth = month;
mYear = year;
// Figure out what day today is
//final Time today = new Time(Time.getCurrentTimezone());
//today.setToNow();
final Calendar today = Calendar.getInstance(mController.getTimeZone(), mController.getLocale());
mHasToday = false;
mToday = -1;
mCalendar.set(Calendar.MONTH, mMonth);
mCalendar.set(Calendar.YEAR, mYear);
mCalendar.set(Calendar.DAY_OF_MONTH, 1);
mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK);
if (weekStart != -1) {
mWeekStart = weekStart;
} else {
mWeekStart = mCalendar.getFirstDayOfWeek();
}
mNumCells = mCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
for (int i = 0; i < mNumCells; i++) {
final int day = i + 1;
if (sameDay(day, today)) {
mHasToday = true;
mToday = day;
}
}
mNumRows = calculateNumRows();
// Invalidate cached accessibility information.
mTouchHelper.invalidateRoot();
} | [
"public",
"void",
"setMonthParams",
"(",
"int",
"selectedDay",
",",
"int",
"year",
",",
"int",
"month",
",",
"int",
"weekStart",
")",
"{",
"if",
"(",
"month",
"==",
"-",
"1",
"&&",
"year",
"==",
"-",
"1",
")",
"{",
"throw",
"new",
"InvalidParameterExce... | Sets all the parameters for displaying this week. The only required
parameter is the week number. Other parameters have a default value and
will only update if a new value is included, except for focus month,
which will always default to no focus month if no value is passed in. | [
"Sets",
"all",
"the",
"parameters",
"for",
"displaying",
"this",
"week",
".",
"The",
"only",
"required",
"parameter",
"is",
"the",
"week",
"number",
".",
"Other",
"parameters",
"have",
"a",
"default",
"value",
"and",
"will",
"only",
"update",
"if",
"a",
"n... | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/date/MonthView.java#L291-L332 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/date/MonthView.java | MonthView.getDayFromLocation | public int getDayFromLocation(float x, float y) {
final int day = getInternalDayFromLocation(x, y);
if (day < 1 || day > mNumCells) {
return -1;
}
return day;
} | java | public int getDayFromLocation(float x, float y) {
final int day = getInternalDayFromLocation(x, y);
if (day < 1 || day > mNumCells) {
return -1;
}
return day;
} | [
"public",
"int",
"getDayFromLocation",
"(",
"float",
"x",
",",
"float",
"y",
")",
"{",
"final",
"int",
"day",
"=",
"getInternalDayFromLocation",
"(",
"x",
",",
"y",
")",
";",
"if",
"(",
"day",
"<",
"1",
"||",
"day",
">",
"mNumCells",
")",
"{",
"retur... | Calculates the day that the given x position is in, accounting for week
number. Returns the day or -1 if the position wasn't in a day.
@param x The x position of the touch event
@return The day number, or -1 if the position wasn't in a day | [
"Calculates",
"the",
"day",
"that",
"the",
"given",
"x",
"position",
"is",
"in",
"accounting",
"for",
"week",
"number",
".",
"Returns",
"the",
"day",
"or",
"-",
"1",
"if",
"the",
"position",
"wasn",
"t",
"in",
"a",
"day",
"."
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/date/MonthView.java#L503-L509 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/date/MonthView.java | MonthView.getInternalDayFromLocation | protected int getInternalDayFromLocation(float x, float y) {
int dayStart = mEdgePadding;
if (x < dayStart || x > mWidth - mEdgePadding) {
return -1;
}
// Selection is (x - start) / (pixels/day) == (x -s) * day / pixels
int row = (int) (y - getMonthHeaderSize()) / mRowHeight;
int column = (int) ((x - dayStart) * mNumDays / (mWidth - dayStart - mEdgePadding));
int day = column - findDayOffset() + 1;
day += row * mNumDays;
return day;
} | java | protected int getInternalDayFromLocation(float x, float y) {
int dayStart = mEdgePadding;
if (x < dayStart || x > mWidth - mEdgePadding) {
return -1;
}
// Selection is (x - start) / (pixels/day) == (x -s) * day / pixels
int row = (int) (y - getMonthHeaderSize()) / mRowHeight;
int column = (int) ((x - dayStart) * mNumDays / (mWidth - dayStart - mEdgePadding));
int day = column - findDayOffset() + 1;
day += row * mNumDays;
return day;
} | [
"protected",
"int",
"getInternalDayFromLocation",
"(",
"float",
"x",
",",
"float",
"y",
")",
"{",
"int",
"dayStart",
"=",
"mEdgePadding",
";",
"if",
"(",
"x",
"<",
"dayStart",
"||",
"x",
">",
"mWidth",
"-",
"mEdgePadding",
")",
"{",
"return",
"-",
"1",
... | Calculates the day that the given x position is in, accounting for week
number.
@param x The x position of the touch event
@return The day number | [
"Calculates",
"the",
"day",
"that",
"the",
"given",
"x",
"position",
"is",
"in",
"accounting",
"for",
"week",
"number",
"."
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/date/MonthView.java#L518-L530 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/date/MonthView.java | MonthView.getWeekDayLabel | private String getWeekDayLabel(Calendar day) {
Locale locale = mController.getLocale();
// Localised short version of the string is not available on API < 18
if (Build.VERSION.SDK_INT < 18) {
String dayName = new SimpleDateFormat("E", locale).format(day.getTime());
String dayLabel = dayName.toUpperCase(locale).substring(0, 1);
// Chinese labels should be fetched right to left
if (locale.equals(Locale.CHINA) || locale.equals(Locale.CHINESE) || locale.equals(Locale.SIMPLIFIED_CHINESE) || locale.equals(Locale.TRADITIONAL_CHINESE)) {
int len = dayName.length();
dayLabel = dayName.substring(len - 1, len);
}
// Most hebrew labels should select the second to last character
if (locale.getLanguage().equals("he") || locale.getLanguage().equals("iw")) {
if (mDayLabelCalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) {
int len = dayName.length();
dayLabel = dayName.substring(len - 2, len - 1);
} else {
// I know this is duplication, but it makes the code easier to grok by
// having all hebrew code in the same block
dayLabel = dayName.toUpperCase(locale).substring(0, 1);
}
}
// Catalan labels should be two digits in lowercase
if (locale.getLanguage().equals("ca"))
dayLabel = dayName.toLowerCase().substring(0, 2);
// Correct single character label in Spanish is X
if (locale.getLanguage().equals("es") && day.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY)
dayLabel = "X";
return dayLabel;
}
// Getting the short label is a one liner on API >= 18
if (weekDayLabelFormatter == null) {
weekDayLabelFormatter = new SimpleDateFormat("EEEEE", locale);
}
return weekDayLabelFormatter.format(day.getTime());
} | java | private String getWeekDayLabel(Calendar day) {
Locale locale = mController.getLocale();
// Localised short version of the string is not available on API < 18
if (Build.VERSION.SDK_INT < 18) {
String dayName = new SimpleDateFormat("E", locale).format(day.getTime());
String dayLabel = dayName.toUpperCase(locale).substring(0, 1);
// Chinese labels should be fetched right to left
if (locale.equals(Locale.CHINA) || locale.equals(Locale.CHINESE) || locale.equals(Locale.SIMPLIFIED_CHINESE) || locale.equals(Locale.TRADITIONAL_CHINESE)) {
int len = dayName.length();
dayLabel = dayName.substring(len - 1, len);
}
// Most hebrew labels should select the second to last character
if (locale.getLanguage().equals("he") || locale.getLanguage().equals("iw")) {
if (mDayLabelCalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) {
int len = dayName.length();
dayLabel = dayName.substring(len - 2, len - 1);
} else {
// I know this is duplication, but it makes the code easier to grok by
// having all hebrew code in the same block
dayLabel = dayName.toUpperCase(locale).substring(0, 1);
}
}
// Catalan labels should be two digits in lowercase
if (locale.getLanguage().equals("ca"))
dayLabel = dayName.toLowerCase().substring(0, 2);
// Correct single character label in Spanish is X
if (locale.getLanguage().equals("es") && day.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY)
dayLabel = "X";
return dayLabel;
}
// Getting the short label is a one liner on API >= 18
if (weekDayLabelFormatter == null) {
weekDayLabelFormatter = new SimpleDateFormat("EEEEE", locale);
}
return weekDayLabelFormatter.format(day.getTime());
} | [
"private",
"String",
"getWeekDayLabel",
"(",
"Calendar",
"day",
")",
"{",
"Locale",
"locale",
"=",
"mController",
".",
"getLocale",
"(",
")",
";",
"// Localised short version of the string is not available on API < 18",
"if",
"(",
"Build",
".",
"VERSION",
".",
"SDK_IN... | Return a 1 or 2 letter String for use as a weekday label
@param day The day for which to generate a label
@return The weekday label | [
"Return",
"a",
"1",
"or",
"2",
"letter",
"String",
"for",
"use",
"as",
"a",
"weekday",
"label"
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/date/MonthView.java#L571-L612 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/time/RadialTextsView.java | RadialTextsView.calculateGridSizes | private void calculateGridSizes(float numbersRadius, float xCenter, float yCenter,
float textSize, float[] textGridHeights, float[] textGridWidths) {
/*
* The numbers need to be drawn in a 7x7 grid, representing the points on the Unit Circle.
*/
float offset1 = numbersRadius;
// cos(30) = a / r => r * cos(30) = a => r * √3/2 = a
float offset2 = numbersRadius * ((float) Math.sqrt(3)) / 2f;
// sin(30) = o / r => r * sin(30) = o => r / 2 = a
float offset3 = numbersRadius / 2f;
mPaint.setTextSize(textSize);
mSelectedPaint.setTextSize(textSize);
mInactivePaint.setTextSize(textSize);
// We'll need yTextBase to be slightly lower to account for the text's baseline.
yCenter -= (mPaint.descent() + mPaint.ascent()) / 2;
textGridHeights[0] = yCenter - offset1;
textGridWidths[0] = xCenter - offset1;
textGridHeights[1] = yCenter - offset2;
textGridWidths[1] = xCenter - offset2;
textGridHeights[2] = yCenter - offset3;
textGridWidths[2] = xCenter - offset3;
textGridHeights[3] = yCenter;
textGridWidths[3] = xCenter;
textGridHeights[4] = yCenter + offset3;
textGridWidths[4] = xCenter + offset3;
textGridHeights[5] = yCenter + offset2;
textGridWidths[5] = xCenter + offset2;
textGridHeights[6] = yCenter + offset1;
textGridWidths[6] = xCenter + offset1;
} | java | private void calculateGridSizes(float numbersRadius, float xCenter, float yCenter,
float textSize, float[] textGridHeights, float[] textGridWidths) {
/*
* The numbers need to be drawn in a 7x7 grid, representing the points on the Unit Circle.
*/
float offset1 = numbersRadius;
// cos(30) = a / r => r * cos(30) = a => r * √3/2 = a
float offset2 = numbersRadius * ((float) Math.sqrt(3)) / 2f;
// sin(30) = o / r => r * sin(30) = o => r / 2 = a
float offset3 = numbersRadius / 2f;
mPaint.setTextSize(textSize);
mSelectedPaint.setTextSize(textSize);
mInactivePaint.setTextSize(textSize);
// We'll need yTextBase to be slightly lower to account for the text's baseline.
yCenter -= (mPaint.descent() + mPaint.ascent()) / 2;
textGridHeights[0] = yCenter - offset1;
textGridWidths[0] = xCenter - offset1;
textGridHeights[1] = yCenter - offset2;
textGridWidths[1] = xCenter - offset2;
textGridHeights[2] = yCenter - offset3;
textGridWidths[2] = xCenter - offset3;
textGridHeights[3] = yCenter;
textGridWidths[3] = xCenter;
textGridHeights[4] = yCenter + offset3;
textGridWidths[4] = xCenter + offset3;
textGridHeights[5] = yCenter + offset2;
textGridWidths[5] = xCenter + offset2;
textGridHeights[6] = yCenter + offset1;
textGridWidths[6] = xCenter + offset1;
} | [
"private",
"void",
"calculateGridSizes",
"(",
"float",
"numbersRadius",
",",
"float",
"xCenter",
",",
"float",
"yCenter",
",",
"float",
"textSize",
",",
"float",
"[",
"]",
"textGridHeights",
",",
"float",
"[",
"]",
"textGridWidths",
")",
"{",
"/*\n * The... | Using the trigonometric Unit Circle, calculate the positions that the text will need to be
drawn at based on the specified circle radius. Place the values in the textGridHeights and
textGridWidths parameters. | [
"Using",
"the",
"trigonometric",
"Unit",
"Circle",
"calculate",
"the",
"positions",
"that",
"the",
"text",
"will",
"need",
"to",
"be",
"drawn",
"at",
"based",
"on",
"the",
"specified",
"circle",
"radius",
".",
"Place",
"the",
"values",
"in",
"the",
"textGrid... | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/time/RadialTextsView.java#L265-L295 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/time/RadialTextsView.java | RadialTextsView.drawTexts | private void drawTexts(Canvas canvas, float textSize, Typeface typeface, String[] texts,
float[] textGridWidths, float[] textGridHeights) {
mPaint.setTextSize(textSize);
mPaint.setTypeface(typeface);
Paint[] textPaints = assignTextColors(texts);
canvas.drawText(texts[0], textGridWidths[3], textGridHeights[0], textPaints[0]);
canvas.drawText(texts[1], textGridWidths[4], textGridHeights[1], textPaints[1]);
canvas.drawText(texts[2], textGridWidths[5], textGridHeights[2], textPaints[2]);
canvas.drawText(texts[3], textGridWidths[6], textGridHeights[3], textPaints[3]);
canvas.drawText(texts[4], textGridWidths[5], textGridHeights[4], textPaints[4]);
canvas.drawText(texts[5], textGridWidths[4], textGridHeights[5], textPaints[5]);
canvas.drawText(texts[6], textGridWidths[3], textGridHeights[6], textPaints[6]);
canvas.drawText(texts[7], textGridWidths[2], textGridHeights[5], textPaints[7]);
canvas.drawText(texts[8], textGridWidths[1], textGridHeights[4], textPaints[8]);
canvas.drawText(texts[9], textGridWidths[0], textGridHeights[3], textPaints[9]);
canvas.drawText(texts[10], textGridWidths[1], textGridHeights[2], textPaints[10]);
canvas.drawText(texts[11], textGridWidths[2], textGridHeights[1], textPaints[11]);
} | java | private void drawTexts(Canvas canvas, float textSize, Typeface typeface, String[] texts,
float[] textGridWidths, float[] textGridHeights) {
mPaint.setTextSize(textSize);
mPaint.setTypeface(typeface);
Paint[] textPaints = assignTextColors(texts);
canvas.drawText(texts[0], textGridWidths[3], textGridHeights[0], textPaints[0]);
canvas.drawText(texts[1], textGridWidths[4], textGridHeights[1], textPaints[1]);
canvas.drawText(texts[2], textGridWidths[5], textGridHeights[2], textPaints[2]);
canvas.drawText(texts[3], textGridWidths[6], textGridHeights[3], textPaints[3]);
canvas.drawText(texts[4], textGridWidths[5], textGridHeights[4], textPaints[4]);
canvas.drawText(texts[5], textGridWidths[4], textGridHeights[5], textPaints[5]);
canvas.drawText(texts[6], textGridWidths[3], textGridHeights[6], textPaints[6]);
canvas.drawText(texts[7], textGridWidths[2], textGridHeights[5], textPaints[7]);
canvas.drawText(texts[8], textGridWidths[1], textGridHeights[4], textPaints[8]);
canvas.drawText(texts[9], textGridWidths[0], textGridHeights[3], textPaints[9]);
canvas.drawText(texts[10], textGridWidths[1], textGridHeights[2], textPaints[10]);
canvas.drawText(texts[11], textGridWidths[2], textGridHeights[1], textPaints[11]);
} | [
"private",
"void",
"drawTexts",
"(",
"Canvas",
"canvas",
",",
"float",
"textSize",
",",
"Typeface",
"typeface",
",",
"String",
"[",
"]",
"texts",
",",
"float",
"[",
"]",
"textGridWidths",
",",
"float",
"[",
"]",
"textGridHeights",
")",
"{",
"mPaint",
".",
... | Draw the 12 text values at the positions specified by the textGrid parameters. | [
"Draw",
"the",
"12",
"text",
"values",
"at",
"the",
"positions",
"specified",
"by",
"the",
"textGrid",
"parameters",
"."
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/time/RadialTextsView.java#L311-L328 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/time/RadialSelectorView.java | RadialSelectorView.setSelection | public void setSelection(int selectionDegrees, boolean isInnerCircle, boolean forceDrawDot) {
mSelectionDegrees = selectionDegrees;
mSelectionRadians = selectionDegrees * Math.PI / 180;
mForceDrawDot = forceDrawDot;
if (mHasInnerCircle) {
if (isInnerCircle) {
mNumbersRadiusMultiplier = mInnerNumbersRadiusMultiplier;
} else {
mNumbersRadiusMultiplier = mOuterNumbersRadiusMultiplier;
}
}
} | java | public void setSelection(int selectionDegrees, boolean isInnerCircle, boolean forceDrawDot) {
mSelectionDegrees = selectionDegrees;
mSelectionRadians = selectionDegrees * Math.PI / 180;
mForceDrawDot = forceDrawDot;
if (mHasInnerCircle) {
if (isInnerCircle) {
mNumbersRadiusMultiplier = mInnerNumbersRadiusMultiplier;
} else {
mNumbersRadiusMultiplier = mOuterNumbersRadiusMultiplier;
}
}
} | [
"public",
"void",
"setSelection",
"(",
"int",
"selectionDegrees",
",",
"boolean",
"isInnerCircle",
",",
"boolean",
"forceDrawDot",
")",
"{",
"mSelectionDegrees",
"=",
"selectionDegrees",
";",
"mSelectionRadians",
"=",
"selectionDegrees",
"*",
"Math",
".",
"PI",
"/",... | Set the selection.
@param selectionDegrees The degrees to be selected.
@param isInnerCircle Whether the selection should be in the inner circle or outer. Will be
ignored if hasInnerCircle was initialized to false.
@param forceDrawDot Whether to force the dot in the center of the selection circle to be
drawn. If false, the dot will be drawn only when the degrees is not a multiple of 30, i.e.
the selection is not on a visible number. | [
"Set",
"the",
"selection",
"."
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/time/RadialSelectorView.java#L156-L168 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/date/DayPickerView.java | DayPickerView.setUpRecyclerView | protected void setUpRecyclerView(DatePickerDialog.ScrollOrientation scrollOrientation) {
setVerticalScrollBarEnabled(false);
setFadingEdgeLength(0);
int gravity = scrollOrientation == DatePickerDialog.ScrollOrientation.VERTICAL
? Gravity.TOP
: Gravity.START;
GravitySnapHelper helper = new GravitySnapHelper(gravity, position -> {
// Leverage the fact that the SnapHelper figures out which position is shown and
// pass this on to our PageListener after the snap has happened
if (pageListener != null) pageListener.onPageChanged(position);
});
helper.attachToRecyclerView(this);
} | java | protected void setUpRecyclerView(DatePickerDialog.ScrollOrientation scrollOrientation) {
setVerticalScrollBarEnabled(false);
setFadingEdgeLength(0);
int gravity = scrollOrientation == DatePickerDialog.ScrollOrientation.VERTICAL
? Gravity.TOP
: Gravity.START;
GravitySnapHelper helper = new GravitySnapHelper(gravity, position -> {
// Leverage the fact that the SnapHelper figures out which position is shown and
// pass this on to our PageListener after the snap has happened
if (pageListener != null) pageListener.onPageChanged(position);
});
helper.attachToRecyclerView(this);
} | [
"protected",
"void",
"setUpRecyclerView",
"(",
"DatePickerDialog",
".",
"ScrollOrientation",
"scrollOrientation",
")",
"{",
"setVerticalScrollBarEnabled",
"(",
"false",
")",
";",
"setFadingEdgeLength",
"(",
"0",
")",
";",
"int",
"gravity",
"=",
"scrollOrientation",
"=... | Sets all the required fields for the list view. Override this method to
set a different list view behavior. | [
"Sets",
"all",
"the",
"required",
"fields",
"for",
"the",
"list",
"view",
".",
"Override",
"this",
"method",
"to",
"set",
"a",
"different",
"list",
"view",
"behavior",
"."
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/date/DayPickerView.java#L113-L125 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/date/AccessibleDateAnimator.java | AccessibleDateAnimator.dispatchPopulateAccessibilityEvent | @Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
// Clear the event's current text so that only the current date will be spoken.
event.getText().clear();
int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR |
DateUtils.FORMAT_SHOW_WEEKDAY;
String dateString = DateUtils.formatDateTime(getContext(), mDateMillis, flags);
event.getText().add(dateString);
return true;
}
return super.dispatchPopulateAccessibilityEvent(event);
} | java | @Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
// Clear the event's current text so that only the current date will be spoken.
event.getText().clear();
int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR |
DateUtils.FORMAT_SHOW_WEEKDAY;
String dateString = DateUtils.formatDateTime(getContext(), mDateMillis, flags);
event.getText().add(dateString);
return true;
}
return super.dispatchPopulateAccessibilityEvent(event);
} | [
"@",
"Override",
"public",
"boolean",
"dispatchPopulateAccessibilityEvent",
"(",
"AccessibilityEvent",
"event",
")",
"{",
"if",
"(",
"event",
".",
"getEventType",
"(",
")",
"==",
"AccessibilityEvent",
".",
"TYPE_WINDOW_STATE_CHANGED",
")",
"{",
"// Clear the event's cur... | Announce the currently-selected date when launched. | [
"Announce",
"the",
"currently",
"-",
"selected",
"date",
"when",
"launched",
"."
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/date/AccessibleDateAnimator.java#L39-L52 | train |
wdullaer/MaterialDateTimePicker | library/src/main/java/com/wdullaer/materialdatetimepicker/time/AmPmCirclesView.java | AmPmCirclesView.getIsTouchingAmOrPm | public int getIsTouchingAmOrPm(float xCoord, float yCoord) {
if (!mDrawValuesReady) {
return -1;
}
int squaredYDistance = (int) ((yCoord - mAmPmYCenter)*(yCoord - mAmPmYCenter));
int distanceToAmCenter =
(int) Math.sqrt((xCoord - mAmXCenter)*(xCoord - mAmXCenter) + squaredYDistance);
if (distanceToAmCenter <= mAmPmCircleRadius && !mAmDisabled) {
return AM;
}
int distanceToPmCenter =
(int) Math.sqrt((xCoord - mPmXCenter)*(xCoord - mPmXCenter) + squaredYDistance);
if (distanceToPmCenter <= mAmPmCircleRadius && !mPmDisabled) {
return PM;
}
// Neither was close enough.
return -1;
} | java | public int getIsTouchingAmOrPm(float xCoord, float yCoord) {
if (!mDrawValuesReady) {
return -1;
}
int squaredYDistance = (int) ((yCoord - mAmPmYCenter)*(yCoord - mAmPmYCenter));
int distanceToAmCenter =
(int) Math.sqrt((xCoord - mAmXCenter)*(xCoord - mAmXCenter) + squaredYDistance);
if (distanceToAmCenter <= mAmPmCircleRadius && !mAmDisabled) {
return AM;
}
int distanceToPmCenter =
(int) Math.sqrt((xCoord - mPmXCenter)*(xCoord - mPmXCenter) + squaredYDistance);
if (distanceToPmCenter <= mAmPmCircleRadius && !mPmDisabled) {
return PM;
}
// Neither was close enough.
return -1;
} | [
"public",
"int",
"getIsTouchingAmOrPm",
"(",
"float",
"xCoord",
",",
"float",
"yCoord",
")",
"{",
"if",
"(",
"!",
"mDrawValuesReady",
")",
"{",
"return",
"-",
"1",
";",
"}",
"int",
"squaredYDistance",
"=",
"(",
"int",
")",
"(",
"(",
"yCoord",
"-",
"mAm... | Calculate whether the coordinates are touching the AM or PM circle. | [
"Calculate",
"whether",
"the",
"coordinates",
"are",
"touching",
"the",
"AM",
"or",
"PM",
"circle",
"."
] | 0a8fe28f19db4f5a5a6cfc525a852416232873a8 | https://github.com/wdullaer/MaterialDateTimePicker/blob/0a8fe28f19db4f5a5a6cfc525a852416232873a8/library/src/main/java/com/wdullaer/materialdatetimepicker/time/AmPmCirclesView.java#L135-L156 | train |
spotbugs/spotbugs | spotbugs-ant/src/main/java/edu/umd/cs/findbugs/anttask/FindBugsTask.java | FindBugsTask.setExcludeFilter | public void setExcludeFilter(File filterFile) {
if (filterFile != null && filterFile.length() > 0) {
excludeFile = filterFile;
} else {
if (filterFile != null) {
log("Warning: exclude filter file " + filterFile
+ (filterFile.exists() ? " is empty" : " does not exist"));
}
excludeFile = null;
}
} | java | public void setExcludeFilter(File filterFile) {
if (filterFile != null && filterFile.length() > 0) {
excludeFile = filterFile;
} else {
if (filterFile != null) {
log("Warning: exclude filter file " + filterFile
+ (filterFile.exists() ? " is empty" : " does not exist"));
}
excludeFile = null;
}
} | [
"public",
"void",
"setExcludeFilter",
"(",
"File",
"filterFile",
")",
"{",
"if",
"(",
"filterFile",
"!=",
"null",
"&&",
"filterFile",
".",
"length",
"(",
")",
">",
"0",
")",
"{",
"excludeFile",
"=",
"filterFile",
";",
"}",
"else",
"{",
"if",
"(",
"filt... | Set the exclude filter file
@param filterFile
exclude filter file | [
"Set",
"the",
"exclude",
"filter",
"file"
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs-ant/src/main/java/edu/umd/cs/findbugs/anttask/FindBugsTask.java#L421-L431 | train |
spotbugs/spotbugs | spotbugs-ant/src/main/java/edu/umd/cs/findbugs/anttask/FindBugsTask.java | FindBugsTask.setIncludeFilter | public void setIncludeFilter(File filterFile) {
if (filterFile != null && filterFile.length() > 0) {
includeFile = filterFile;
} else {
if (filterFile != null) {
log("Warning: include filter file " + filterFile
+ (filterFile.exists() ? " is empty" : " does not exist"));
}
includeFile = null;
}
} | java | public void setIncludeFilter(File filterFile) {
if (filterFile != null && filterFile.length() > 0) {
includeFile = filterFile;
} else {
if (filterFile != null) {
log("Warning: include filter file " + filterFile
+ (filterFile.exists() ? " is empty" : " does not exist"));
}
includeFile = null;
}
} | [
"public",
"void",
"setIncludeFilter",
"(",
"File",
"filterFile",
")",
"{",
"if",
"(",
"filterFile",
"!=",
"null",
"&&",
"filterFile",
".",
"length",
"(",
")",
">",
"0",
")",
"{",
"includeFile",
"=",
"filterFile",
";",
"}",
"else",
"{",
"if",
"(",
"filt... | Set the include filter file
@param filterFile
include filter file | [
"Set",
"the",
"include",
"filter",
"file"
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs-ant/src/main/java/edu/umd/cs/findbugs/anttask/FindBugsTask.java#L439-L449 | train |
spotbugs/spotbugs | spotbugs-ant/src/main/java/edu/umd/cs/findbugs/anttask/FindBugsTask.java | FindBugsTask.setBaselineBugs | public void setBaselineBugs(File baselineBugs) {
if (baselineBugs != null && baselineBugs.length() > 0) {
this.baselineBugs = baselineBugs;
} else {
if (baselineBugs != null) {
log("Warning: baseline bugs file " + baselineBugs
+ (baselineBugs.exists() ? " is empty" : " does not exist"));
}
this.baselineBugs = null;
}
} | java | public void setBaselineBugs(File baselineBugs) {
if (baselineBugs != null && baselineBugs.length() > 0) {
this.baselineBugs = baselineBugs;
} else {
if (baselineBugs != null) {
log("Warning: baseline bugs file " + baselineBugs
+ (baselineBugs.exists() ? " is empty" : " does not exist"));
}
this.baselineBugs = null;
}
} | [
"public",
"void",
"setBaselineBugs",
"(",
"File",
"baselineBugs",
")",
"{",
"if",
"(",
"baselineBugs",
"!=",
"null",
"&&",
"baselineBugs",
".",
"length",
"(",
")",
">",
"0",
")",
"{",
"this",
".",
"baselineBugs",
"=",
"baselineBugs",
";",
"}",
"else",
"{... | Set the baseline bugs file
@param baselineBugs
baseline bugs file | [
"Set",
"the",
"baseline",
"bugs",
"file"
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs-ant/src/main/java/edu/umd/cs/findbugs/anttask/FindBugsTask.java#L457-L467 | train |
spotbugs/spotbugs | spotbugs-ant/src/main/java/edu/umd/cs/findbugs/anttask/FindBugsTask.java | FindBugsTask.setAuxClasspath | public void setAuxClasspath(Path src) {
boolean nonEmpty = false;
String[] elementList = src.list();
for (String anElementList : elementList) {
if (!"".equals(anElementList)) {
nonEmpty = true;
break;
}
}
if (nonEmpty) {
if (auxClasspath == null) {
auxClasspath = src;
} else {
auxClasspath.append(src);
}
}
} | java | public void setAuxClasspath(Path src) {
boolean nonEmpty = false;
String[] elementList = src.list();
for (String anElementList : elementList) {
if (!"".equals(anElementList)) {
nonEmpty = true;
break;
}
}
if (nonEmpty) {
if (auxClasspath == null) {
auxClasspath = src;
} else {
auxClasspath.append(src);
}
}
} | [
"public",
"void",
"setAuxClasspath",
"(",
"Path",
"src",
")",
"{",
"boolean",
"nonEmpty",
"=",
"false",
";",
"String",
"[",
"]",
"elementList",
"=",
"src",
".",
"list",
"(",
")",
";",
"for",
"(",
"String",
"anElementList",
":",
"elementList",
")",
"{",
... | the auxclasspath to use.
@param src
auxclasspath to use | [
"the",
"auxclasspath",
"to",
"use",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs-ant/src/main/java/edu/umd/cs/findbugs/anttask/FindBugsTask.java#L495-L513 | train |
spotbugs/spotbugs | spotbugs-ant/src/main/java/edu/umd/cs/findbugs/anttask/FindBugsTask.java | FindBugsTask.setAuxClasspathRef | public void setAuxClasspathRef(Reference r) {
Path path = createAuxClasspath();
path.setRefid(r);
path.toString(); // Evaluated for its side-effects (throwing a
// BuildException)
} | java | public void setAuxClasspathRef(Reference r) {
Path path = createAuxClasspath();
path.setRefid(r);
path.toString(); // Evaluated for its side-effects (throwing a
// BuildException)
} | [
"public",
"void",
"setAuxClasspathRef",
"(",
"Reference",
"r",
")",
"{",
"Path",
"path",
"=",
"createAuxClasspath",
"(",
")",
";",
"path",
".",
"setRefid",
"(",
"r",
")",
";",
"path",
".",
"toString",
"(",
")",
";",
"// Evaluated for its side-effects (throwing... | Adds a reference to a sourcepath defined elsewhere.
@param r
reference to a sourcepath defined elsewhere | [
"Adds",
"a",
"reference",
"to",
"a",
"sourcepath",
"defined",
"elsewhere",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs-ant/src/main/java/edu/umd/cs/findbugs/anttask/FindBugsTask.java#L533-L538 | train |
spotbugs/spotbugs | spotbugs-ant/src/main/java/edu/umd/cs/findbugs/anttask/FindBugsTask.java | FindBugsTask.setAuxAnalyzepath | public void setAuxAnalyzepath(Path src) {
boolean nonEmpty = false;
String[] elementList = src.list();
for (String anElementList : elementList) {
if (!"".equals(anElementList)) {
nonEmpty = true;
break;
}
}
if (nonEmpty) {
if (auxAnalyzepath == null) {
auxAnalyzepath = src;
} else {
auxAnalyzepath.append(src);
}
}
} | java | public void setAuxAnalyzepath(Path src) {
boolean nonEmpty = false;
String[] elementList = src.list();
for (String anElementList : elementList) {
if (!"".equals(anElementList)) {
nonEmpty = true;
break;
}
}
if (nonEmpty) {
if (auxAnalyzepath == null) {
auxAnalyzepath = src;
} else {
auxAnalyzepath.append(src);
}
}
} | [
"public",
"void",
"setAuxAnalyzepath",
"(",
"Path",
"src",
")",
"{",
"boolean",
"nonEmpty",
"=",
"false",
";",
"String",
"[",
"]",
"elementList",
"=",
"src",
".",
"list",
"(",
")",
";",
"for",
"(",
"String",
"anElementList",
":",
"elementList",
")",
"{",... | the auxAnalyzepath to use.
@param src
auxAnalyzepath | [
"the",
"auxAnalyzepath",
"to",
"use",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs-ant/src/main/java/edu/umd/cs/findbugs/anttask/FindBugsTask.java#L546-L564 | train |
spotbugs/spotbugs | spotbugs-ant/src/main/java/edu/umd/cs/findbugs/anttask/FindBugsTask.java | FindBugsTask.setSourcePath | public void setSourcePath(Path src) {
if (sourcePath == null) {
sourcePath = src;
} else {
sourcePath.append(src);
}
} | java | public void setSourcePath(Path src) {
if (sourcePath == null) {
sourcePath = src;
} else {
sourcePath.append(src);
}
} | [
"public",
"void",
"setSourcePath",
"(",
"Path",
"src",
")",
"{",
"if",
"(",
"sourcePath",
"==",
"null",
")",
"{",
"sourcePath",
"=",
"src",
";",
"}",
"else",
"{",
"sourcePath",
".",
"append",
"(",
"src",
")",
";",
"}",
"}"
] | the sourcepath to use.
@param src
sourcepath | [
"the",
"sourcepath",
"to",
"use",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs-ant/src/main/java/edu/umd/cs/findbugs/anttask/FindBugsTask.java#L594-L600 | train |
spotbugs/spotbugs | spotbugs-ant/src/main/java/edu/umd/cs/findbugs/anttask/FindBugsTask.java | FindBugsTask.setExcludePath | public void setExcludePath(Path src) {
if (excludePath == null) {
excludePath = src;
} else {
excludePath.append(src);
}
} | java | public void setExcludePath(Path src) {
if (excludePath == null) {
excludePath = src;
} else {
excludePath.append(src);
}
} | [
"public",
"void",
"setExcludePath",
"(",
"Path",
"src",
")",
"{",
"if",
"(",
"excludePath",
"==",
"null",
")",
"{",
"excludePath",
"=",
"src",
";",
"}",
"else",
"{",
"excludePath",
".",
"append",
"(",
"src",
")",
";",
"}",
"}"
] | the excludepath to use.
@param src
excludepath | [
"the",
"excludepath",
"to",
"use",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs-ant/src/main/java/edu/umd/cs/findbugs/anttask/FindBugsTask.java#L630-L636 | train |
spotbugs/spotbugs | spotbugs-ant/src/main/java/edu/umd/cs/findbugs/anttask/FindBugsTask.java | FindBugsTask.setIncludePath | public void setIncludePath(Path src) {
if (includePath == null) {
includePath = src;
} else {
includePath.append(src);
}
} | java | public void setIncludePath(Path src) {
if (includePath == null) {
includePath = src;
} else {
includePath.append(src);
}
} | [
"public",
"void",
"setIncludePath",
"(",
"Path",
"src",
")",
"{",
"if",
"(",
"includePath",
"==",
"null",
")",
"{",
"includePath",
"=",
"src",
";",
"}",
"else",
"{",
"includePath",
".",
"append",
"(",
"src",
")",
";",
"}",
"}"
] | the includepath to use.
@param src
includepath | [
"the",
"includepath",
"to",
"use",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs-ant/src/main/java/edu/umd/cs/findbugs/anttask/FindBugsTask.java#L666-L672 | train |
spotbugs/spotbugs | spotbugs-ant/src/main/java/edu/umd/cs/findbugs/anttask/FindBugsTask.java | FindBugsTask.checkParameters | @Override
protected void checkParameters() {
super.checkParameters();
if (projectFile == null && classLocations.size() == 0 && filesets.size() == 0 && dirsets.size() == 0 && auxAnalyzepath == null) {
throw new BuildException("either projectfile, <class/>, <fileset/> or <auxAnalyzepath/> child "
+ "elements must be defined for task <" + getTaskName() + "/>", getLocation());
}
if (outputFormat != null
&& !("xml".equalsIgnoreCase(outputFormat.trim()) || "xml:withMessages".equalsIgnoreCase(outputFormat.trim())
|| "html".equalsIgnoreCase(outputFormat.trim()) || "text".equalsIgnoreCase(outputFormat.trim())
|| "xdocs".equalsIgnoreCase(outputFormat.trim()) || "emacs".equalsIgnoreCase(outputFormat.trim()))) {
throw new BuildException("output attribute must be either " + "'text', 'xml', 'html', 'xdocs' or 'emacs' for task <"
+ getTaskName() + "/>", getLocation());
}
if (reportLevel != null
&& !("experimental".equalsIgnoreCase(reportLevel.trim()) || "low".equalsIgnoreCase(reportLevel.trim())
|| "medium".equalsIgnoreCase(reportLevel.trim()) || "high".equalsIgnoreCase(reportLevel.trim()))) {
throw new BuildException("reportlevel attribute must be either "
+ "'experimental' or 'low' or 'medium' or 'high' for task <" + getTaskName() + "/>", getLocation());
}
// FindBugs allows both, so there's no apparent reason for this check
// if ( excludeFile != null && includeFile != null ) {
// throw new BuildException("only one of excludeFile and includeFile " +
// " attributes may be used in task <" + getTaskName() + "/>",
// getLocation());
// }
List<String> efforts = Arrays.asList( "min", "less", "default", "more", "max");
if (effort != null && !efforts.contains(effort)) {
throw new BuildException("effort attribute must be one of " + efforts);
}
} | java | @Override
protected void checkParameters() {
super.checkParameters();
if (projectFile == null && classLocations.size() == 0 && filesets.size() == 0 && dirsets.size() == 0 && auxAnalyzepath == null) {
throw new BuildException("either projectfile, <class/>, <fileset/> or <auxAnalyzepath/> child "
+ "elements must be defined for task <" + getTaskName() + "/>", getLocation());
}
if (outputFormat != null
&& !("xml".equalsIgnoreCase(outputFormat.trim()) || "xml:withMessages".equalsIgnoreCase(outputFormat.trim())
|| "html".equalsIgnoreCase(outputFormat.trim()) || "text".equalsIgnoreCase(outputFormat.trim())
|| "xdocs".equalsIgnoreCase(outputFormat.trim()) || "emacs".equalsIgnoreCase(outputFormat.trim()))) {
throw new BuildException("output attribute must be either " + "'text', 'xml', 'html', 'xdocs' or 'emacs' for task <"
+ getTaskName() + "/>", getLocation());
}
if (reportLevel != null
&& !("experimental".equalsIgnoreCase(reportLevel.trim()) || "low".equalsIgnoreCase(reportLevel.trim())
|| "medium".equalsIgnoreCase(reportLevel.trim()) || "high".equalsIgnoreCase(reportLevel.trim()))) {
throw new BuildException("reportlevel attribute must be either "
+ "'experimental' or 'low' or 'medium' or 'high' for task <" + getTaskName() + "/>", getLocation());
}
// FindBugs allows both, so there's no apparent reason for this check
// if ( excludeFile != null && includeFile != null ) {
// throw new BuildException("only one of excludeFile and includeFile " +
// " attributes may be used in task <" + getTaskName() + "/>",
// getLocation());
// }
List<String> efforts = Arrays.asList( "min", "less", "default", "more", "max");
if (effort != null && !efforts.contains(effort)) {
throw new BuildException("effort attribute must be one of " + efforts);
}
} | [
"@",
"Override",
"protected",
"void",
"checkParameters",
"(",
")",
"{",
"super",
".",
"checkParameters",
"(",
")",
";",
"if",
"(",
"projectFile",
"==",
"null",
"&&",
"classLocations",
".",
"size",
"(",
")",
"==",
"0",
"&&",
"filesets",
".",
"size",
"(",
... | Check that all required attributes have been set | [
"Check",
"that",
"all",
"required",
"attributes",
"have",
"been",
"set"
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs-ant/src/main/java/edu/umd/cs/findbugs/anttask/FindBugsTask.java#L752-L787 | train |
spotbugs/spotbugs | eclipsePlugin/src/de/tobject/findbugs/properties/DetectorProvider.java | DetectorProvider.isEclipsePluginDisabled | static boolean isEclipsePluginDisabled(String pluginId, Map<URI, Plugin> allPlugins) {
for (Plugin plugin : allPlugins.values()) {
if(pluginId.equals(plugin.getPluginId())) {
return false;
}
}
return true;
} | java | static boolean isEclipsePluginDisabled(String pluginId, Map<URI, Plugin> allPlugins) {
for (Plugin plugin : allPlugins.values()) {
if(pluginId.equals(plugin.getPluginId())) {
return false;
}
}
return true;
} | [
"static",
"boolean",
"isEclipsePluginDisabled",
"(",
"String",
"pluginId",
",",
"Map",
"<",
"URI",
",",
"Plugin",
">",
"allPlugins",
")",
"{",
"for",
"(",
"Plugin",
"plugin",
":",
"allPlugins",
".",
"values",
"(",
")",
")",
"{",
"if",
"(",
"pluginId",
".... | Eclipse plugin can be disabled ONLY by user, so it must NOT be in the
list of loaded plugins | [
"Eclipse",
"plugin",
"can",
"be",
"disabled",
"ONLY",
"by",
"user",
"so",
"it",
"must",
"NOT",
"be",
"in",
"the",
"list",
"of",
"loaded",
"plugins"
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/eclipsePlugin/src/de/tobject/findbugs/properties/DetectorProvider.java#L135-L142 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/ba/DataflowCFGPrinter.java | DataflowCFGPrinter.printCFG | public static <Fact, AnalysisType extends BasicAbstractDataflowAnalysis<Fact>> void printCFG(
Dataflow<Fact, AnalysisType> dataflow, PrintStream out) {
DataflowCFGPrinter<Fact, AnalysisType> printer = new DataflowCFGPrinter<>(dataflow);
printer.print(out);
} | java | public static <Fact, AnalysisType extends BasicAbstractDataflowAnalysis<Fact>> void printCFG(
Dataflow<Fact, AnalysisType> dataflow, PrintStream out) {
DataflowCFGPrinter<Fact, AnalysisType> printer = new DataflowCFGPrinter<>(dataflow);
printer.print(out);
} | [
"public",
"static",
"<",
"Fact",
",",
"AnalysisType",
"extends",
"BasicAbstractDataflowAnalysis",
"<",
"Fact",
">",
">",
"void",
"printCFG",
"(",
"Dataflow",
"<",
"Fact",
",",
"AnalysisType",
">",
"dataflow",
",",
"PrintStream",
"out",
")",
"{",
"DataflowCFGPrin... | Print CFG annotated with results from given dataflow analysis.
@param <Fact>
Dataflow fact type
@param <AnalysisType>
Dataflow analysis type
@param dataflow
dataflow driver
@param out
PrintStream to use | [
"Print",
"CFG",
"annotated",
"with",
"results",
"from",
"given",
"dataflow",
"analysis",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/DataflowCFGPrinter.java#L107-L111 | train |
spotbugs/spotbugs | eclipsePlugin/src/de/tobject/findbugs/classify/AccuracyClassificationPulldownAction.java | AccuracyClassificationPulldownAction.fillMenu | private void fillMenu() {
isBugItem = new MenuItem(menu, SWT.RADIO);
isBugItem.setText("Bug");
notBugItem = new MenuItem(menu, SWT.RADIO);
notBugItem.setText("Not Bug");
isBugItem.addSelectionListener(new SelectionAdapter() {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
* .swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
if (bugInstance != null) {
classifyWarning(bugInstance, true);
}
}
});
notBugItem.addSelectionListener(new SelectionAdapter() {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
* .swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
if (bugInstance != null) {
classifyWarning(bugInstance, false);
}
}
});
menu.addMenuListener(new MenuAdapter() {
@Override
public void menuShown(MenuEvent e) {
// Before showing the menu, sync its contents
// with the current BugInstance (if any)
if (DEBUG) {
System.out.println("Synchronizing menu!");
}
syncMenu();
}
});
} | java | private void fillMenu() {
isBugItem = new MenuItem(menu, SWT.RADIO);
isBugItem.setText("Bug");
notBugItem = new MenuItem(menu, SWT.RADIO);
notBugItem.setText("Not Bug");
isBugItem.addSelectionListener(new SelectionAdapter() {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
* .swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
if (bugInstance != null) {
classifyWarning(bugInstance, true);
}
}
});
notBugItem.addSelectionListener(new SelectionAdapter() {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
* .swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
if (bugInstance != null) {
classifyWarning(bugInstance, false);
}
}
});
menu.addMenuListener(new MenuAdapter() {
@Override
public void menuShown(MenuEvent e) {
// Before showing the menu, sync its contents
// with the current BugInstance (if any)
if (DEBUG) {
System.out.println("Synchronizing menu!");
}
syncMenu();
}
});
} | [
"private",
"void",
"fillMenu",
"(",
")",
"{",
"isBugItem",
"=",
"new",
"MenuItem",
"(",
"menu",
",",
"SWT",
".",
"RADIO",
")",
";",
"isBugItem",
".",
"setText",
"(",
"\"Bug\"",
")",
";",
"notBugItem",
"=",
"new",
"MenuItem",
"(",
"menu",
",",
"SWT",
... | Fill the classification menu. | [
"Fill",
"the",
"classification",
"menu",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/eclipsePlugin/src/de/tobject/findbugs/classify/AccuracyClassificationPulldownAction.java#L98-L147 | train |
spotbugs/spotbugs | eclipsePlugin/src/de/tobject/findbugs/classify/AccuracyClassificationPulldownAction.java | AccuracyClassificationPulldownAction.syncMenu | private void syncMenu() {
if (bugInstance != null) {
isBugItem.setEnabled(true);
notBugItem.setEnabled(true);
BugProperty isBugProperty = bugInstance.lookupProperty(BugProperty.IS_BUG);
if (isBugProperty == null) {
// Unclassified
isBugItem.setSelection(false);
notBugItem.setSelection(false);
} else {
boolean isBug = isBugProperty.getValueAsBoolean();
isBugItem.setSelection(isBug);
notBugItem.setSelection(!isBug);
}
} else {
// No bug instance, so uncheck and disable the menu items
if (DEBUG) {
System.out.println("No bug instance found, disabling menu items");
}
isBugItem.setEnabled(false);
notBugItem.setEnabled(false);
isBugItem.setSelection(false);
notBugItem.setSelection(false);
}
} | java | private void syncMenu() {
if (bugInstance != null) {
isBugItem.setEnabled(true);
notBugItem.setEnabled(true);
BugProperty isBugProperty = bugInstance.lookupProperty(BugProperty.IS_BUG);
if (isBugProperty == null) {
// Unclassified
isBugItem.setSelection(false);
notBugItem.setSelection(false);
} else {
boolean isBug = isBugProperty.getValueAsBoolean();
isBugItem.setSelection(isBug);
notBugItem.setSelection(!isBug);
}
} else {
// No bug instance, so uncheck and disable the menu items
if (DEBUG) {
System.out.println("No bug instance found, disabling menu items");
}
isBugItem.setEnabled(false);
notBugItem.setEnabled(false);
isBugItem.setSelection(false);
notBugItem.setSelection(false);
}
} | [
"private",
"void",
"syncMenu",
"(",
")",
"{",
"if",
"(",
"bugInstance",
"!=",
"null",
")",
"{",
"isBugItem",
".",
"setEnabled",
"(",
"true",
")",
";",
"notBugItem",
".",
"setEnabled",
"(",
"true",
")",
";",
"BugProperty",
"isBugProperty",
"=",
"bugInstance... | Update menu to match currently selected BugInstance. | [
"Update",
"menu",
"to",
"match",
"currently",
"selected",
"BugInstance",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/eclipsePlugin/src/de/tobject/findbugs/classify/AccuracyClassificationPulldownAction.java#L257-L282 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/ba/bcp/PatternMatcher.java | PatternMatcher.execute | public PatternMatcher execute() throws DataflowAnalysisException {
workList.addLast(cfg.getEntry());
while (!workList.isEmpty()) {
BasicBlock basicBlock = workList.removeLast();
visitedBlockMap.put(basicBlock, basicBlock);
// Scan instructions of basic block for possible matches
BasicBlock.InstructionIterator i = basicBlock.instructionIterator();
while (i.hasNext()) {
attemptMatch(basicBlock, i.duplicate());
i.next();
}
// Add successors of the basic block (which haven't been visited
// already)
Iterator<BasicBlock> succIterator = cfg.successorIterator(basicBlock);
while (succIterator.hasNext()) {
BasicBlock succ = succIterator.next();
if (visitedBlockMap.get(succ) == null) {
workList.addLast(succ);
}
}
}
return this;
} | java | public PatternMatcher execute() throws DataflowAnalysisException {
workList.addLast(cfg.getEntry());
while (!workList.isEmpty()) {
BasicBlock basicBlock = workList.removeLast();
visitedBlockMap.put(basicBlock, basicBlock);
// Scan instructions of basic block for possible matches
BasicBlock.InstructionIterator i = basicBlock.instructionIterator();
while (i.hasNext()) {
attemptMatch(basicBlock, i.duplicate());
i.next();
}
// Add successors of the basic block (which haven't been visited
// already)
Iterator<BasicBlock> succIterator = cfg.successorIterator(basicBlock);
while (succIterator.hasNext()) {
BasicBlock succ = succIterator.next();
if (visitedBlockMap.get(succ) == null) {
workList.addLast(succ);
}
}
}
return this;
} | [
"public",
"PatternMatcher",
"execute",
"(",
")",
"throws",
"DataflowAnalysisException",
"{",
"workList",
".",
"addLast",
"(",
"cfg",
".",
"getEntry",
"(",
")",
")",
";",
"while",
"(",
"!",
"workList",
".",
"isEmpty",
"(",
")",
")",
"{",
"BasicBlock",
"basi... | Search for examples of the ByteCodePattern.
@return this object
@throws DataflowAnalysisException
if the ValueNumberAnalysis did not produce useful values for
the method | [
"Search",
"for",
"examples",
"of",
"the",
"ByteCodePattern",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/bcp/PatternMatcher.java#L114-L140 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/ba/bcp/PatternMatcher.java | PatternMatcher.attemptMatch | private void attemptMatch(BasicBlock basicBlock, BasicBlock.InstructionIterator instructionIterator)
throws DataflowAnalysisException {
work(new State(basicBlock, instructionIterator, pattern.getFirst()));
} | java | private void attemptMatch(BasicBlock basicBlock, BasicBlock.InstructionIterator instructionIterator)
throws DataflowAnalysisException {
work(new State(basicBlock, instructionIterator, pattern.getFirst()));
} | [
"private",
"void",
"attemptMatch",
"(",
"BasicBlock",
"basicBlock",
",",
"BasicBlock",
".",
"InstructionIterator",
"instructionIterator",
")",
"throws",
"DataflowAnalysisException",
"{",
"work",
"(",
"new",
"State",
"(",
"basicBlock",
",",
"instructionIterator",
",",
... | Attempt to begin a match.
@param basicBlock
the basic block
@param instructionIterator
the instruction iterator positioned just before the first
instruction to be matched | [
"Attempt",
"to",
"begin",
"a",
"match",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/bcp/PatternMatcher.java#L159-L162 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/ba/generic/GenericUtilities.java | GenericUtilities.getString | public static final String getString(Type type) {
if (type instanceof GenericObjectType) {
return ((GenericObjectType) type).toString(true);
} else if (type instanceof ArrayType) {
return TypeCategory.asString((ArrayType) type);
} else {
return type.toString();
}
} | java | public static final String getString(Type type) {
if (type instanceof GenericObjectType) {
return ((GenericObjectType) type).toString(true);
} else if (type instanceof ArrayType) {
return TypeCategory.asString((ArrayType) type);
} else {
return type.toString();
}
} | [
"public",
"static",
"final",
"String",
"getString",
"(",
"Type",
"type",
")",
"{",
"if",
"(",
"type",
"instanceof",
"GenericObjectType",
")",
"{",
"return",
"(",
"(",
"GenericObjectType",
")",
"type",
")",
".",
"toString",
"(",
"true",
")",
";",
"}",
"el... | Get String representation of a Type including Generic information | [
"Get",
"String",
"representation",
"of",
"a",
"Type",
"including",
"Generic",
"information"
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/generic/GenericUtilities.java#L210-L218 | train |
spotbugs/spotbugs | spotbugs/src/gui/main/edu/umd/cs/findbugs/gui2/MainFrameLoadSaveHelper.java | MainFrameLoadSaveHelper.askToSave | private boolean askToSave() {
if (mainFrame.isProjectChanged()) {
int response = JOptionPane.showConfirmDialog(mainFrame, L10N.getLocalString("dlg.save_current_changes",
"The current project has been changed, Save current changes?"), L10N.getLocalString("dlg.save_changes",
"Save Changes?"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if (response == JOptionPane.YES_OPTION) {
if (mainFrame.getSaveFile() != null) {
save();
} else {
saveAs();
}
} else if (response == JOptionPane.CANCEL_OPTION)
{
return true;
// IF no, do nothing.
}
}
return false;
} | java | private boolean askToSave() {
if (mainFrame.isProjectChanged()) {
int response = JOptionPane.showConfirmDialog(mainFrame, L10N.getLocalString("dlg.save_current_changes",
"The current project has been changed, Save current changes?"), L10N.getLocalString("dlg.save_changes",
"Save Changes?"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if (response == JOptionPane.YES_OPTION) {
if (mainFrame.getSaveFile() != null) {
save();
} else {
saveAs();
}
} else if (response == JOptionPane.CANCEL_OPTION)
{
return true;
// IF no, do nothing.
}
}
return false;
} | [
"private",
"boolean",
"askToSave",
"(",
")",
"{",
"if",
"(",
"mainFrame",
".",
"isProjectChanged",
"(",
")",
")",
"{",
"int",
"response",
"=",
"JOptionPane",
".",
"showConfirmDialog",
"(",
"mainFrame",
",",
"L10N",
".",
"getLocalString",
"(",
"\"dlg.save_curre... | Returns true if cancelled | [
"Returns",
"true",
"if",
"cancelled"
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/gui/main/edu/umd/cs/findbugs/gui2/MainFrameLoadSaveHelper.java#L161-L180 | train |
spotbugs/spotbugs | spotbugs/src/gui/main/edu/umd/cs/findbugs/gui2/MainFrameLoadSaveHelper.java | MainFrameLoadSaveHelper.saveAnalysis | SaveReturn saveAnalysis(final File f) {
Future<Object> waiter = mainFrame.getBackgroundExecutor().submit(() -> {
BugSaver.saveBugs(f, mainFrame.getBugCollection(), mainFrame.getProject());
return null;
});
try {
waiter.get();
} catch (InterruptedException e) {
return SaveReturn.SAVE_ERROR;
} catch (ExecutionException e) {
return SaveReturn.SAVE_ERROR;
}
mainFrame.setProjectChanged(false);
return SaveReturn.SAVE_SUCCESSFUL;
} | java | SaveReturn saveAnalysis(final File f) {
Future<Object> waiter = mainFrame.getBackgroundExecutor().submit(() -> {
BugSaver.saveBugs(f, mainFrame.getBugCollection(), mainFrame.getProject());
return null;
});
try {
waiter.get();
} catch (InterruptedException e) {
return SaveReturn.SAVE_ERROR;
} catch (ExecutionException e) {
return SaveReturn.SAVE_ERROR;
}
mainFrame.setProjectChanged(false);
return SaveReturn.SAVE_SUCCESSFUL;
} | [
"SaveReturn",
"saveAnalysis",
"(",
"final",
"File",
"f",
")",
"{",
"Future",
"<",
"Object",
">",
"waiter",
"=",
"mainFrame",
".",
"getBackgroundExecutor",
"(",
")",
".",
"submit",
"(",
"(",
")",
"->",
"{",
"BugSaver",
".",
"saveBugs",
"(",
"f",
",",
"m... | Save current analysis as file passed in. Return SAVE_SUCCESSFUL if save
successful. Method doesn't do much. This method is more if need to do
other things in the future for saving analysis. And to keep saving naming
convention. | [
"Save",
"current",
"analysis",
"as",
"file",
"passed",
"in",
".",
"Return",
"SAVE_SUCCESSFUL",
"if",
"save",
"successful",
".",
"Method",
"doesn",
"t",
"do",
"much",
".",
"This",
"method",
"is",
"more",
"if",
"need",
"to",
"do",
"other",
"things",
"in",
... | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/gui/main/edu/umd/cs/findbugs/gui2/MainFrameLoadSaveHelper.java#L472-L489 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/ba/URLClassPath.java | URLClassPath.getClassPath | public String getClassPath() {
StringBuilder buf = new StringBuilder();
for (Entry entry : entryList) {
if (buf.length() > 0) {
buf.append(File.pathSeparator);
}
buf.append(entry.getURL());
}
return buf.toString();
} | java | public String getClassPath() {
StringBuilder buf = new StringBuilder();
for (Entry entry : entryList) {
if (buf.length() > 0) {
buf.append(File.pathSeparator);
}
buf.append(entry.getURL());
}
return buf.toString();
} | [
"public",
"String",
"getClassPath",
"(",
")",
"{",
"StringBuilder",
"buf",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"for",
"(",
"Entry",
"entry",
":",
"entryList",
")",
"{",
"if",
"(",
"buf",
".",
"length",
"(",
")",
">",
"0",
")",
"{",
"buf",
"... | Return the classpath string.
@return the classpath string | [
"Return",
"the",
"classpath",
"string",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/URLClassPath.java#L342-L351 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/ba/URLClassPath.java | URLClassPath.getInputStreamForResource | private InputStream getInputStreamForResource(String resourceName) {
// Try each classpath entry, in order, until we find one
// that has the resource. Catch and ignore IOExceptions.
// FIXME: The following code should throw IOException.
//
// URL.openStream() does not seem to distinguish
// whether the resource does not exist, vs. some
// transient error occurring while trying to access it.
// This is unfortunate, because we really should throw
// an exception out of this method in the latter case,
// since it means our knowledge of the classpath is
// incomplete.
//
// Short of reimplementing HTTP, etc., ourselves,
// there is probably nothing we can do about this problem.
for (Entry entry : entryList) {
InputStream in;
try {
in = entry.openStream(resourceName);
if (in != null) {
if (URLClassPathRepository.DEBUG) {
System.out.println("\t==> found " + resourceName + " in " + entry.getURL());
}
return in;
}
} catch (IOException ignore) {
// Ignore
}
}
if (URLClassPathRepository.DEBUG) {
System.out.println("\t==> could not find " + resourceName + " on classpath");
}
return null;
} | java | private InputStream getInputStreamForResource(String resourceName) {
// Try each classpath entry, in order, until we find one
// that has the resource. Catch and ignore IOExceptions.
// FIXME: The following code should throw IOException.
//
// URL.openStream() does not seem to distinguish
// whether the resource does not exist, vs. some
// transient error occurring while trying to access it.
// This is unfortunate, because we really should throw
// an exception out of this method in the latter case,
// since it means our knowledge of the classpath is
// incomplete.
//
// Short of reimplementing HTTP, etc., ourselves,
// there is probably nothing we can do about this problem.
for (Entry entry : entryList) {
InputStream in;
try {
in = entry.openStream(resourceName);
if (in != null) {
if (URLClassPathRepository.DEBUG) {
System.out.println("\t==> found " + resourceName + " in " + entry.getURL());
}
return in;
}
} catch (IOException ignore) {
// Ignore
}
}
if (URLClassPathRepository.DEBUG) {
System.out.println("\t==> could not find " + resourceName + " on classpath");
}
return null;
} | [
"private",
"InputStream",
"getInputStreamForResource",
"(",
"String",
"resourceName",
")",
"{",
"// Try each classpath entry, in order, until we find one",
"// that has the resource. Catch and ignore IOExceptions.",
"// FIXME: The following code should throw IOException.",
"//",
"// URL.open... | Open a stream to read given resource.
@param resourceName
name of resource to load, e.g. "java/lang/Object.class"
@return input stream to read resource, or null if resource could not be
found
@throws IOException
if an IO error occurs trying to determine whether or not the
resource exists | [
"Open",
"a",
"stream",
"to",
"read",
"given",
"resource",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/URLClassPath.java#L364-L399 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/ba/URLClassPath.java | URLClassPath.lookupClass | public JavaClass lookupClass(String className) throws ClassNotFoundException {
if (classesThatCantBeFound.contains(className)) {
throw new ClassNotFoundException("Error while looking for class " + className + ": class not found");
}
String resourceName = className.replace('.', '/') + ".class";
InputStream in = null;
boolean parsedClass = false;
try {
in = getInputStreamForResource(resourceName);
if (in == null) {
classesThatCantBeFound.add(className);
throw new ClassNotFoundException("Error while looking for class " + className + ": class not found");
}
ClassParser classParser = new ClassParser(in, resourceName);
JavaClass javaClass = classParser.parse();
parsedClass = true;
return javaClass;
} catch (IOException e) {
classesThatCantBeFound.add(className);
throw new ClassNotFoundException("IOException while looking for class " + className, e);
} finally {
if (in != null && !parsedClass) {
try {
in.close();
} catch (IOException ignore) {
// Ignore
}
}
}
} | java | public JavaClass lookupClass(String className) throws ClassNotFoundException {
if (classesThatCantBeFound.contains(className)) {
throw new ClassNotFoundException("Error while looking for class " + className + ": class not found");
}
String resourceName = className.replace('.', '/') + ".class";
InputStream in = null;
boolean parsedClass = false;
try {
in = getInputStreamForResource(resourceName);
if (in == null) {
classesThatCantBeFound.add(className);
throw new ClassNotFoundException("Error while looking for class " + className + ": class not found");
}
ClassParser classParser = new ClassParser(in, resourceName);
JavaClass javaClass = classParser.parse();
parsedClass = true;
return javaClass;
} catch (IOException e) {
classesThatCantBeFound.add(className);
throw new ClassNotFoundException("IOException while looking for class " + className, e);
} finally {
if (in != null && !parsedClass) {
try {
in.close();
} catch (IOException ignore) {
// Ignore
}
}
}
} | [
"public",
"JavaClass",
"lookupClass",
"(",
"String",
"className",
")",
"throws",
"ClassNotFoundException",
"{",
"if",
"(",
"classesThatCantBeFound",
".",
"contains",
"(",
"className",
")",
")",
"{",
"throw",
"new",
"ClassNotFoundException",
"(",
"\"Error while looking... | Look up a class from the classpath.
@param className
name of class to look up
@return the JavaClass object for the class
@throws ClassNotFoundException
if the class couldn't be found | [
"Look",
"up",
"a",
"class",
"from",
"the",
"classpath",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/URLClassPath.java#L412-L445 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/ba/URLClassPath.java | URLClassPath.getURLProtocol | public static String getURLProtocol(String urlString) {
String protocol = null;
int firstColon = urlString.indexOf(':');
if (firstColon >= 0) {
String specifiedProtocol = urlString.substring(0, firstColon);
if (FindBugs.knownURLProtocolSet.contains(specifiedProtocol)) {
protocol = specifiedProtocol;
}
}
return protocol;
} | java | public static String getURLProtocol(String urlString) {
String protocol = null;
int firstColon = urlString.indexOf(':');
if (firstColon >= 0) {
String specifiedProtocol = urlString.substring(0, firstColon);
if (FindBugs.knownURLProtocolSet.contains(specifiedProtocol)) {
protocol = specifiedProtocol;
}
}
return protocol;
} | [
"public",
"static",
"String",
"getURLProtocol",
"(",
"String",
"urlString",
")",
"{",
"String",
"protocol",
"=",
"null",
";",
"int",
"firstColon",
"=",
"urlString",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"firstColon",
">=",
"0",
")",
"{",
... | Get the URL protocol of given URL string.
@param urlString
the URL string
@return the protocol name ("http", "file", etc.), or null if there is no
protocol | [
"Get",
"the",
"URL",
"protocol",
"of",
"given",
"URL",
"string",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/URLClassPath.java#L466-L476 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/ba/URLClassPath.java | URLClassPath.getFileExtension | public static String getFileExtension(String fileName) {
int lastDot = fileName.lastIndexOf('.');
return (lastDot >= 0) ? fileName.substring(lastDot) : null;
} | java | public static String getFileExtension(String fileName) {
int lastDot = fileName.lastIndexOf('.');
return (lastDot >= 0) ? fileName.substring(lastDot) : null;
} | [
"public",
"static",
"String",
"getFileExtension",
"(",
"String",
"fileName",
")",
"{",
"int",
"lastDot",
"=",
"fileName",
".",
"lastIndexOf",
"(",
"'",
"'",
")",
";",
"return",
"(",
"lastDot",
">=",
"0",
")",
"?",
"fileName",
".",
"substring",
"(",
"last... | Get the file extension of given fileName.
@return the file extension, or null if there is no file extension | [
"Get",
"the",
"file",
"extension",
"of",
"given",
"fileName",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/URLClassPath.java#L483-L486 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFrame.java | ValueNumberFrame.killLoadsOfField | public void killLoadsOfField(XField field) {
if (!REDUNDANT_LOAD_ELIMINATION) {
return;
}
HashSet<AvailableLoad> killMe = new HashSet<>();
for (AvailableLoad availableLoad : getAvailableLoadMap().keySet()) {
if (availableLoad.getField().equals(field)) {
if (RLE_DEBUG) {
System.out.println("KILLING Load of " + availableLoad + " in " + this);
}
killMe.add(availableLoad);
}
}
killAvailableLoads(killMe);
} | java | public void killLoadsOfField(XField field) {
if (!REDUNDANT_LOAD_ELIMINATION) {
return;
}
HashSet<AvailableLoad> killMe = new HashSet<>();
for (AvailableLoad availableLoad : getAvailableLoadMap().keySet()) {
if (availableLoad.getField().equals(field)) {
if (RLE_DEBUG) {
System.out.println("KILLING Load of " + availableLoad + " in " + this);
}
killMe.add(availableLoad);
}
}
killAvailableLoads(killMe);
} | [
"public",
"void",
"killLoadsOfField",
"(",
"XField",
"field",
")",
"{",
"if",
"(",
"!",
"REDUNDANT_LOAD_ELIMINATION",
")",
"{",
"return",
";",
"}",
"HashSet",
"<",
"AvailableLoad",
">",
"killMe",
"=",
"new",
"HashSet",
"<>",
"(",
")",
";",
"for",
"(",
"A... | Kill all loads of given field.
@param field
the field | [
"Kill",
"all",
"loads",
"of",
"given",
"field",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/vna/ValueNumberFrame.java#L175-L189 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/xml/MetaCharacterMap.java | MetaCharacterMap.addMeta | public void addMeta(char meta, String replacement) {
metaCharacterSet.set(meta);
replacementMap.put(new String(new char[] { meta }), replacement);
} | java | public void addMeta(char meta, String replacement) {
metaCharacterSet.set(meta);
replacementMap.put(new String(new char[] { meta }), replacement);
} | [
"public",
"void",
"addMeta",
"(",
"char",
"meta",
",",
"String",
"replacement",
")",
"{",
"metaCharacterSet",
".",
"set",
"(",
"meta",
")",
";",
"replacementMap",
".",
"put",
"(",
"new",
"String",
"(",
"new",
"char",
"[",
"]",
"{",
"meta",
"}",
")",
... | Add a metacharacter and its replacement.
@param meta
the metacharacter
@param replacement
the String to replace the metacharacter with | [
"Add",
"a",
"metacharacter",
"and",
"its",
"replacement",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/xml/MetaCharacterMap.java#L53-L56 | train |
spotbugs/spotbugs | eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java | FindbugsPlugin.getResourceString | public static String getResourceString(String key) {
ResourceBundle bundle = FindbugsPlugin.getDefault().getResourceBundle();
try {
return bundle.getString(key);
} catch (MissingResourceException e) {
return key;
}
} | java | public static String getResourceString(String key) {
ResourceBundle bundle = FindbugsPlugin.getDefault().getResourceBundle();
try {
return bundle.getString(key);
} catch (MissingResourceException e) {
return key;
}
} | [
"public",
"static",
"String",
"getResourceString",
"(",
"String",
"key",
")",
"{",
"ResourceBundle",
"bundle",
"=",
"FindbugsPlugin",
".",
"getDefault",
"(",
")",
".",
"getResourceBundle",
"(",
")",
";",
"try",
"{",
"return",
"bundle",
".",
"getString",
"(",
... | Returns the string from the plugin's resource bundle, or 'key' if not
found. | [
"Returns",
"the",
"string",
"from",
"the",
"plugin",
"s",
"resource",
"bundle",
"or",
"key",
"if",
"not",
"found",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java#L456-L463 | train |
spotbugs/spotbugs | eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java | FindbugsPlugin.getFindBugsEnginePluginLocation | public static String getFindBugsEnginePluginLocation() {
// findbugs.home should be set to the directory the plugin is
// installed in.
URL u = plugin.getBundle().getEntry("/");
try {
URL bundleRoot = FileLocator.resolve(u);
String path = bundleRoot.getPath();
if (FindBugsBuilder.DEBUG) {
System.out.println("Pluginpath: " + path); //$NON-NLS-1$
}
if (path.endsWith("/eclipsePlugin/")) {
File f = new File(path);
f = f.getParentFile();
f = new File(f, "findbugs");
path = f.getPath() + "/";
}
return path;
} catch (IOException e) {
FindbugsPlugin.getDefault().logException(e, "IO Exception locating engine plugin");
}
return null;
} | java | public static String getFindBugsEnginePluginLocation() {
// findbugs.home should be set to the directory the plugin is
// installed in.
URL u = plugin.getBundle().getEntry("/");
try {
URL bundleRoot = FileLocator.resolve(u);
String path = bundleRoot.getPath();
if (FindBugsBuilder.DEBUG) {
System.out.println("Pluginpath: " + path); //$NON-NLS-1$
}
if (path.endsWith("/eclipsePlugin/")) {
File f = new File(path);
f = f.getParentFile();
f = new File(f, "findbugs");
path = f.getPath() + "/";
}
return path;
} catch (IOException e) {
FindbugsPlugin.getDefault().logException(e, "IO Exception locating engine plugin");
}
return null;
} | [
"public",
"static",
"String",
"getFindBugsEnginePluginLocation",
"(",
")",
"{",
"// findbugs.home should be set to the directory the plugin is",
"// installed in.",
"URL",
"u",
"=",
"plugin",
".",
"getBundle",
"(",
")",
".",
"getEntry",
"(",
"\"/\"",
")",
";",
"try",
... | Find the filesystem path of the FindBugs plugin directory.
@return the filesystem path of the FindBugs plugin directory, or null if
the FindBugs plugin directory cannot be found | [
"Find",
"the",
"filesystem",
"path",
"of",
"the",
"FindBugs",
"plugin",
"directory",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java#L508-L530 | train |
spotbugs/spotbugs | eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java | FindbugsPlugin.logException | public void logException(Throwable e, String message) {
logMessage(IStatus.ERROR, message, e);
} | java | public void logException(Throwable e, String message) {
logMessage(IStatus.ERROR, message, e);
} | [
"public",
"void",
"logException",
"(",
"Throwable",
"e",
",",
"String",
"message",
")",
"{",
"logMessage",
"(",
"IStatus",
".",
"ERROR",
",",
"message",
",",
"e",
")",
";",
"}"
] | Log an exception.
@param e
the exception
@param message
message describing how/why the exception occurred | [
"Log",
"an",
"exception",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java#L548-L550 | train |
spotbugs/spotbugs | eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java | FindbugsPlugin.getBugCollectionFile | public static IPath getBugCollectionFile(IProject project) {
// IPath path = project.getWorkingLocation(PLUGIN_ID); //
// project-specific but not user-specific?
IPath path = getDefault().getStateLocation(); // user-specific but not
// project-specific
return path.append(project.getName() + ".fbwarnings.xml");
} | java | public static IPath getBugCollectionFile(IProject project) {
// IPath path = project.getWorkingLocation(PLUGIN_ID); //
// project-specific but not user-specific?
IPath path = getDefault().getStateLocation(); // user-specific but not
// project-specific
return path.append(project.getName() + ".fbwarnings.xml");
} | [
"public",
"static",
"IPath",
"getBugCollectionFile",
"(",
"IProject",
"project",
")",
"{",
"// IPath path = project.getWorkingLocation(PLUGIN_ID); //",
"// project-specific but not user-specific?",
"IPath",
"path",
"=",
"getDefault",
"(",
")",
".",
"getStateLocation",
"(",
")... | Get the file resource used to store findbugs warnings for a project.
@param project
the project
@return the IPath to the file (which may not actually exist in the
filesystem yet) | [
"Get",
"the",
"file",
"resource",
"used",
"to",
"store",
"findbugs",
"warnings",
"for",
"a",
"project",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java#L610-L616 | train |
spotbugs/spotbugs | eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java | FindbugsPlugin.getBugCollection | public static SortedBugCollection getBugCollection(IProject project, IProgressMonitor monitor)
throws CoreException {
SortedBugCollection bugCollection = (SortedBugCollection) project.getSessionProperty(SESSION_PROPERTY_BUG_COLLECTION);
if (bugCollection == null) {
try {
readBugCollectionAndProject(project, monitor);
bugCollection = (SortedBugCollection) project.getSessionProperty(SESSION_PROPERTY_BUG_COLLECTION);
} catch (IOException e) {
FindbugsPlugin.getDefault().logException(e, "Could not read bug collection for project");
bugCollection = createDefaultEmptyBugCollection(project);
} catch (DocumentException e) {
FindbugsPlugin.getDefault().logException(e, "Could not read bug collection for project");
bugCollection = createDefaultEmptyBugCollection(project);
}
}
return bugCollection;
} | java | public static SortedBugCollection getBugCollection(IProject project, IProgressMonitor monitor)
throws CoreException {
SortedBugCollection bugCollection = (SortedBugCollection) project.getSessionProperty(SESSION_PROPERTY_BUG_COLLECTION);
if (bugCollection == null) {
try {
readBugCollectionAndProject(project, monitor);
bugCollection = (SortedBugCollection) project.getSessionProperty(SESSION_PROPERTY_BUG_COLLECTION);
} catch (IOException e) {
FindbugsPlugin.getDefault().logException(e, "Could not read bug collection for project");
bugCollection = createDefaultEmptyBugCollection(project);
} catch (DocumentException e) {
FindbugsPlugin.getDefault().logException(e, "Could not read bug collection for project");
bugCollection = createDefaultEmptyBugCollection(project);
}
}
return bugCollection;
} | [
"public",
"static",
"SortedBugCollection",
"getBugCollection",
"(",
"IProject",
"project",
",",
"IProgressMonitor",
"monitor",
")",
"throws",
"CoreException",
"{",
"SortedBugCollection",
"bugCollection",
"=",
"(",
"SortedBugCollection",
")",
"project",
".",
"getSessionPro... | Get the stored BugCollection for project. If there is no stored bug
collection for the project, or if an error occurs reading the stored bug
collection, a default empty collection is created and returned.
@param project
the eclipse project
@param monitor
a progress monitor
@return the stored BugCollection, never null
@throws CoreException | [
"Get",
"the",
"stored",
"BugCollection",
"for",
"project",
".",
"If",
"there",
"is",
"no",
"stored",
"bug",
"collection",
"for",
"the",
"project",
"or",
"if",
"an",
"error",
"occurs",
"reading",
"the",
"stored",
"bug",
"collection",
"a",
"default",
"empty",
... | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java#L653-L669 | train |
spotbugs/spotbugs | eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java | FindbugsPlugin.readBugCollectionAndProject | private static void readBugCollectionAndProject(IProject project, IProgressMonitor monitor)
throws IOException, DocumentException, CoreException {
SortedBugCollection bugCollection;
IPath bugCollectionPath = getBugCollectionFile(project);
// Don't turn the path to an IFile because it isn't local to the
// project.
// see the javadoc for org.eclipse.core.runtime.Plugin
File bugCollectionFile = bugCollectionPath.toFile();
if (!bugCollectionFile.exists()) {
// throw new
// FileNotFoundException(bugCollectionFile.getLocation().toOSString());
getDefault().logInfo("creating new bug collection: " + bugCollectionPath.toOSString());
createDefaultEmptyBugCollection(project); // since we no longer
// throw, have to do this
// here
return;
}
UserPreferences prefs = getUserPreferences(project);
bugCollection = new SortedBugCollection();
bugCollection.getProject().setGuiCallback(new EclipseGuiCallback(project));
bugCollection.readXML(bugCollectionFile);
cacheBugCollectionAndProject(project, bugCollection, bugCollection.getProject());
} | java | private static void readBugCollectionAndProject(IProject project, IProgressMonitor monitor)
throws IOException, DocumentException, CoreException {
SortedBugCollection bugCollection;
IPath bugCollectionPath = getBugCollectionFile(project);
// Don't turn the path to an IFile because it isn't local to the
// project.
// see the javadoc for org.eclipse.core.runtime.Plugin
File bugCollectionFile = bugCollectionPath.toFile();
if (!bugCollectionFile.exists()) {
// throw new
// FileNotFoundException(bugCollectionFile.getLocation().toOSString());
getDefault().logInfo("creating new bug collection: " + bugCollectionPath.toOSString());
createDefaultEmptyBugCollection(project); // since we no longer
// throw, have to do this
// here
return;
}
UserPreferences prefs = getUserPreferences(project);
bugCollection = new SortedBugCollection();
bugCollection.getProject().setGuiCallback(new EclipseGuiCallback(project));
bugCollection.readXML(bugCollectionFile);
cacheBugCollectionAndProject(project, bugCollection, bugCollection.getProject());
} | [
"private",
"static",
"void",
"readBugCollectionAndProject",
"(",
"IProject",
"project",
",",
"IProgressMonitor",
"monitor",
")",
"throws",
"IOException",
",",
"DocumentException",
",",
"CoreException",
"{",
"SortedBugCollection",
"bugCollection",
";",
"IPath",
"bugCollect... | Read saved bug collection and findbugs project from file. Will populate
the bug collection and findbugs project session properties if successful.
If there is no saved bug collection and project for the eclipse project,
then FileNotFoundException will be thrown.
@param project
the eclipse project
@param monitor
a progress monitor
@throws java.io.FileNotFoundException
the saved bug collection doesn't exist
@throws IOException
@throws DocumentException
@throws CoreException | [
"Read",
"saved",
"bug",
"collection",
"and",
"findbugs",
"project",
"from",
"file",
".",
"Will",
"populate",
"the",
"bug",
"collection",
"and",
"findbugs",
"project",
"session",
"properties",
"if",
"successful",
".",
"If",
"there",
"is",
"no",
"saved",
"bug",
... | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java#L703-L729 | train |
spotbugs/spotbugs | eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java | FindbugsPlugin.storeBugCollection | public static void storeBugCollection(IProject project, final SortedBugCollection bugCollection, IProgressMonitor monitor)
throws IOException, CoreException {
// Store the bug collection and findbugs project in the session
project.setSessionProperty(SESSION_PROPERTY_BUG_COLLECTION, bugCollection);
if (bugCollection != null) {
writeBugCollection(project, bugCollection, monitor);
}
} | java | public static void storeBugCollection(IProject project, final SortedBugCollection bugCollection, IProgressMonitor monitor)
throws IOException, CoreException {
// Store the bug collection and findbugs project in the session
project.setSessionProperty(SESSION_PROPERTY_BUG_COLLECTION, bugCollection);
if (bugCollection != null) {
writeBugCollection(project, bugCollection, monitor);
}
} | [
"public",
"static",
"void",
"storeBugCollection",
"(",
"IProject",
"project",
",",
"final",
"SortedBugCollection",
"bugCollection",
",",
"IProgressMonitor",
"monitor",
")",
"throws",
"IOException",
",",
"CoreException",
"{",
"// Store the bug collection and findbugs project i... | Store a new bug collection for a project. The collection is stored in the
session, and also in a file in the project.
@param project
the project
@param bugCollection
the bug collection
@param monitor
progress monitor
@throws IOException
@throws CoreException | [
"Store",
"a",
"new",
"bug",
"collection",
"for",
"a",
"project",
".",
"The",
"collection",
"is",
"stored",
"in",
"the",
"session",
"and",
"also",
"in",
"a",
"file",
"in",
"the",
"project",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java#L744-L753 | train |
spotbugs/spotbugs | eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java | FindbugsPlugin.saveCurrentBugCollection | public static void saveCurrentBugCollection(IProject project, IProgressMonitor monitor) throws CoreException {
if (isBugCollectionDirty(project)) {
SortedBugCollection bugCollection = (SortedBugCollection) project.getSessionProperty(SESSION_PROPERTY_BUG_COLLECTION);
if (bugCollection != null) {
writeBugCollection(project, bugCollection, monitor);
}
}
} | java | public static void saveCurrentBugCollection(IProject project, IProgressMonitor monitor) throws CoreException {
if (isBugCollectionDirty(project)) {
SortedBugCollection bugCollection = (SortedBugCollection) project.getSessionProperty(SESSION_PROPERTY_BUG_COLLECTION);
if (bugCollection != null) {
writeBugCollection(project, bugCollection, monitor);
}
}
} | [
"public",
"static",
"void",
"saveCurrentBugCollection",
"(",
"IProject",
"project",
",",
"IProgressMonitor",
"monitor",
")",
"throws",
"CoreException",
"{",
"if",
"(",
"isBugCollectionDirty",
"(",
"project",
")",
")",
"{",
"SortedBugCollection",
"bugCollection",
"=",
... | If necessary, save current bug collection for project to disk.
@param project
the project
@param monitor
a progress monitor
@throws CoreException | [
"If",
"necessary",
"save",
"current",
"bug",
"collection",
"for",
"project",
"to",
"disk",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java#L764-L772 | train |
spotbugs/spotbugs | eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java | FindbugsPlugin.getProjectPreferences | public static UserPreferences getProjectPreferences(IProject project, boolean forceRead) {
try {
UserPreferences prefs = (UserPreferences) project.getSessionProperty(SESSION_PROPERTY_USERPREFS);
if (prefs == null || forceRead) {
prefs = readUserPreferences(project);
if (prefs == null) {
prefs = getWorkspacePreferences().clone();
}
project.setSessionProperty(SESSION_PROPERTY_USERPREFS, prefs);
}
return prefs;
} catch (CoreException e) {
FindbugsPlugin.getDefault().logException(e, "Error getting SpotBugs preferences for project");
return getWorkspacePreferences().clone();
}
} | java | public static UserPreferences getProjectPreferences(IProject project, boolean forceRead) {
try {
UserPreferences prefs = (UserPreferences) project.getSessionProperty(SESSION_PROPERTY_USERPREFS);
if (prefs == null || forceRead) {
prefs = readUserPreferences(project);
if (prefs == null) {
prefs = getWorkspacePreferences().clone();
}
project.setSessionProperty(SESSION_PROPERTY_USERPREFS, prefs);
}
return prefs;
} catch (CoreException e) {
FindbugsPlugin.getDefault().logException(e, "Error getting SpotBugs preferences for project");
return getWorkspacePreferences().clone();
}
} | [
"public",
"static",
"UserPreferences",
"getProjectPreferences",
"(",
"IProject",
"project",
",",
"boolean",
"forceRead",
")",
"{",
"try",
"{",
"UserPreferences",
"prefs",
"=",
"(",
"UserPreferences",
")",
"project",
".",
"getSessionProperty",
"(",
"SESSION_PROPERTY_US... | Get project own preferences set.
@param project
must be non null, exist and be opened
@param forceRead
@return current project preferences, independently if project preferences
are enabled or disabled for given project. | [
"Get",
"project",
"own",
"preferences",
"set",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java#L907-L922 | train |
spotbugs/spotbugs | eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java | FindbugsPlugin.saveUserPreferences | public static void saveUserPreferences(IProject project, final UserPreferences userPrefs) throws CoreException {
FileOutput userPrefsOutput = new FileOutput() {
@Override
public void writeFile(OutputStream os) throws IOException {
userPrefs.write(os);
}
@Override
public String getTaskDescription() {
return "writing user preferences";
}
};
if (project != null) {
// Make the new user preferences current for the project
project.setSessionProperty(SESSION_PROPERTY_USERPREFS, userPrefs);
IFile userPrefsFile = getUserPreferencesFile(project);
ensureReadWrite(userPrefsFile);
IO.writeFile(userPrefsFile, userPrefsOutput, null);
if (project.getFile(DEPRECATED_PREFS_PATH).equals(userPrefsFile)) {
String message = "Found old style FindBugs preferences for project '" + project.getName()
+ "'. This preferences are not at the default location: '" + DEFAULT_PREFS_PATH + "'." + " Please move '"
+ DEPRECATED_PREFS_PATH + "' to '" + DEFAULT_PREFS_PATH + "'.";
getDefault().logWarning(message);
}
} else {
// write the workspace preferences to the eclipse preference store
ByteArrayOutputStream bos = new ByteArrayOutputStream(10000);
try {
userPrefs.write(bos);
} catch (IOException e) {
getDefault().logException(e, "Failed to write user preferences");
return;
}
Properties props = new Properties();
try {
props.load(new ByteArrayInputStream(bos.toByteArray()));
} catch (IOException e) {
getDefault().logException(e, "Failed to save user preferences");
return;
}
IPreferenceStore store = getDefault().getPreferenceStore();
// Reset any existing custom group entries
resetStore(store, UserPreferences.KEY_PLUGIN);
resetStore(store, UserPreferences.KEY_EXCLUDE_BUGS);
resetStore(store, UserPreferences.KEY_EXCLUDE_FILTER);
resetStore(store, UserPreferences.KEY_INCLUDE_FILTER);
for (Entry<Object, Object> entry : props.entrySet()) {
store.putValue((String) entry.getKey(), (String) entry.getValue());
}
if(store instanceof IPersistentPreferenceStore){
IPersistentPreferenceStore store2 = (IPersistentPreferenceStore) store;
try {
store2.save();
} catch (IOException e) {
getDefault().logException(e, "Failed to save user preferences");
}
}
}
} | java | public static void saveUserPreferences(IProject project, final UserPreferences userPrefs) throws CoreException {
FileOutput userPrefsOutput = new FileOutput() {
@Override
public void writeFile(OutputStream os) throws IOException {
userPrefs.write(os);
}
@Override
public String getTaskDescription() {
return "writing user preferences";
}
};
if (project != null) {
// Make the new user preferences current for the project
project.setSessionProperty(SESSION_PROPERTY_USERPREFS, userPrefs);
IFile userPrefsFile = getUserPreferencesFile(project);
ensureReadWrite(userPrefsFile);
IO.writeFile(userPrefsFile, userPrefsOutput, null);
if (project.getFile(DEPRECATED_PREFS_PATH).equals(userPrefsFile)) {
String message = "Found old style FindBugs preferences for project '" + project.getName()
+ "'. This preferences are not at the default location: '" + DEFAULT_PREFS_PATH + "'." + " Please move '"
+ DEPRECATED_PREFS_PATH + "' to '" + DEFAULT_PREFS_PATH + "'.";
getDefault().logWarning(message);
}
} else {
// write the workspace preferences to the eclipse preference store
ByteArrayOutputStream bos = new ByteArrayOutputStream(10000);
try {
userPrefs.write(bos);
} catch (IOException e) {
getDefault().logException(e, "Failed to write user preferences");
return;
}
Properties props = new Properties();
try {
props.load(new ByteArrayInputStream(bos.toByteArray()));
} catch (IOException e) {
getDefault().logException(e, "Failed to save user preferences");
return;
}
IPreferenceStore store = getDefault().getPreferenceStore();
// Reset any existing custom group entries
resetStore(store, UserPreferences.KEY_PLUGIN);
resetStore(store, UserPreferences.KEY_EXCLUDE_BUGS);
resetStore(store, UserPreferences.KEY_EXCLUDE_FILTER);
resetStore(store, UserPreferences.KEY_INCLUDE_FILTER);
for (Entry<Object, Object> entry : props.entrySet()) {
store.putValue((String) entry.getKey(), (String) entry.getValue());
}
if(store instanceof IPersistentPreferenceStore){
IPersistentPreferenceStore store2 = (IPersistentPreferenceStore) store;
try {
store2.save();
} catch (IOException e) {
getDefault().logException(e, "Failed to save user preferences");
}
}
}
} | [
"public",
"static",
"void",
"saveUserPreferences",
"(",
"IProject",
"project",
",",
"final",
"UserPreferences",
"userPrefs",
")",
"throws",
"CoreException",
"{",
"FileOutput",
"userPrefsOutput",
"=",
"new",
"FileOutput",
"(",
")",
"{",
"@",
"Override",
"public",
"... | Save current UserPreferences for given project or workspace.
@param project
the project or null for workspace
@throws CoreException | [
"Save",
"current",
"UserPreferences",
"for",
"given",
"project",
"or",
"workspace",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java#L960-L1020 | train |
spotbugs/spotbugs | eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java | FindbugsPlugin.resetStore | private static void resetStore(IPreferenceStore store, String prefix) {
int start = 0;
// 99 is paranoia.
while(start < 99){
String name = prefix + start;
if(store.contains(name)){
store.setToDefault(name);
} else {
break;
}
start ++;
}
} | java | private static void resetStore(IPreferenceStore store, String prefix) {
int start = 0;
// 99 is paranoia.
while(start < 99){
String name = prefix + start;
if(store.contains(name)){
store.setToDefault(name);
} else {
break;
}
start ++;
}
} | [
"private",
"static",
"void",
"resetStore",
"(",
"IPreferenceStore",
"store",
",",
"String",
"prefix",
")",
"{",
"int",
"start",
"=",
"0",
";",
"// 99 is paranoia.",
"while",
"(",
"start",
"<",
"99",
")",
"{",
"String",
"name",
"=",
"prefix",
"+",
"start",
... | Removes all consequent enumerated keys from given store staring with given prefix | [
"Removes",
"all",
"consequent",
"enumerated",
"keys",
"from",
"given",
"store",
"staring",
"with",
"given",
"prefix"
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java#L1025-L1037 | train |
spotbugs/spotbugs | eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java | FindbugsPlugin.ensureReadWrite | private static void ensureReadWrite(IFile file) throws CoreException {
/*
* fix for bug 1683264: we should checkout file before writing to it
*/
if (file.isReadOnly()) {
IStatus checkOutStatus = ResourcesPlugin.getWorkspace().validateEdit(new IFile[] { file }, null);
if (!checkOutStatus.isOK()) {
throw new CoreException(checkOutStatus);
}
}
} | java | private static void ensureReadWrite(IFile file) throws CoreException {
/*
* fix for bug 1683264: we should checkout file before writing to it
*/
if (file.isReadOnly()) {
IStatus checkOutStatus = ResourcesPlugin.getWorkspace().validateEdit(new IFile[] { file }, null);
if (!checkOutStatus.isOK()) {
throw new CoreException(checkOutStatus);
}
}
} | [
"private",
"static",
"void",
"ensureReadWrite",
"(",
"IFile",
"file",
")",
"throws",
"CoreException",
"{",
"/*\n * fix for bug 1683264: we should checkout file before writing to it\n */",
"if",
"(",
"file",
".",
"isReadOnly",
"(",
")",
")",
"{",
"IStatus",
... | Ensure that a file is writable. If not currently writable, check it as so
that we can edit it.
@param file
- file that should be made writable
@throws CoreException | [
"Ensure",
"that",
"a",
"file",
"is",
"writable",
".",
"If",
"not",
"currently",
"writable",
"check",
"it",
"as",
"so",
"that",
"we",
"can",
"edit",
"it",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java#L1047-L1057 | train |
spotbugs/spotbugs | eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java | FindbugsPlugin.readUserPreferences | private static UserPreferences readUserPreferences(IProject project) throws CoreException {
IFile userPrefsFile = getUserPreferencesFile(project);
if (!userPrefsFile.exists()) {
return null;
}
try {
// force is preventing us for out-of-sync exception if file was
// changed externally
InputStream in = userPrefsFile.getContents(true);
UserPreferences userPrefs = FindBugsPreferenceInitializer.createDefaultUserPreferences();
userPrefs.read(in);
return userPrefs;
} catch (IOException e) {
FindbugsPlugin.getDefault().logException(e, "Could not read user preferences for project");
return null;
}
} | java | private static UserPreferences readUserPreferences(IProject project) throws CoreException {
IFile userPrefsFile = getUserPreferencesFile(project);
if (!userPrefsFile.exists()) {
return null;
}
try {
// force is preventing us for out-of-sync exception if file was
// changed externally
InputStream in = userPrefsFile.getContents(true);
UserPreferences userPrefs = FindBugsPreferenceInitializer.createDefaultUserPreferences();
userPrefs.read(in);
return userPrefs;
} catch (IOException e) {
FindbugsPlugin.getDefault().logException(e, "Could not read user preferences for project");
return null;
}
} | [
"private",
"static",
"UserPreferences",
"readUserPreferences",
"(",
"IProject",
"project",
")",
"throws",
"CoreException",
"{",
"IFile",
"userPrefsFile",
"=",
"getUserPreferencesFile",
"(",
"project",
")",
";",
"if",
"(",
"!",
"userPrefsFile",
".",
"exists",
"(",
... | Read UserPreferences for project from the file in the project directory.
Returns null if the preferences have not been saved to a file, or if
there is an error reading the preferences file.
@param project
the project to get the UserPreferences for
@return the UserPreferences, or null if the UserPreferences file could
not be read
@throws CoreException | [
"Read",
"UserPreferences",
"for",
"project",
"from",
"the",
"file",
"in",
"the",
"project",
"directory",
".",
"Returns",
"null",
"if",
"the",
"preferences",
"have",
"not",
"been",
"saved",
"to",
"a",
"file",
"or",
"if",
"there",
"is",
"an",
"error",
"readi... | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java#L1070-L1086 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/RecursiveFileSearch.java | RecursiveFileSearch.search | public RecursiveFileSearch search() throws InterruptedException {
File baseFile = new File(baseDir);
String basePath = bestEffortCanonicalPath(baseFile);
directoryWorkList.add(baseFile);
directoriesScanned.add(basePath);
directoriesScannedList.add(basePath);
while (!directoryWorkList.isEmpty()) {
File dir = directoryWorkList.removeFirst();
if (!dir.isDirectory()) {
continue;
}
File[] contentList = dir.listFiles();
if (contentList == null) {
continue;
}
for (File aContentList : contentList) {
if (Thread.interrupted()) {
throw new InterruptedException();
}
File file = aContentList;
if (!fileFilter.accept(file)) {
continue;
}
if (file.isDirectory()) {
String myPath = bestEffortCanonicalPath(file);
if (myPath.startsWith(basePath) && directoriesScanned.add(myPath)) {
directoriesScannedList.add(myPath);
directoryWorkList.add(file);
}
} else {
resultList.add(file.getPath());
}
}
}
return this;
} | java | public RecursiveFileSearch search() throws InterruptedException {
File baseFile = new File(baseDir);
String basePath = bestEffortCanonicalPath(baseFile);
directoryWorkList.add(baseFile);
directoriesScanned.add(basePath);
directoriesScannedList.add(basePath);
while (!directoryWorkList.isEmpty()) {
File dir = directoryWorkList.removeFirst();
if (!dir.isDirectory()) {
continue;
}
File[] contentList = dir.listFiles();
if (contentList == null) {
continue;
}
for (File aContentList : contentList) {
if (Thread.interrupted()) {
throw new InterruptedException();
}
File file = aContentList;
if (!fileFilter.accept(file)) {
continue;
}
if (file.isDirectory()) {
String myPath = bestEffortCanonicalPath(file);
if (myPath.startsWith(basePath) && directoriesScanned.add(myPath)) {
directoriesScannedList.add(myPath);
directoryWorkList.add(file);
}
} else {
resultList.add(file.getPath());
}
}
}
return this;
} | [
"public",
"RecursiveFileSearch",
"search",
"(",
")",
"throws",
"InterruptedException",
"{",
"File",
"baseFile",
"=",
"new",
"File",
"(",
"baseDir",
")",
";",
"String",
"basePath",
"=",
"bestEffortCanonicalPath",
"(",
"baseFile",
")",
";",
"directoryWorkList",
".",... | Perform the search.
@return this object
@throws InterruptedException
if the thread is interrupted before the search completes | [
"Perform",
"the",
"search",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/RecursiveFileSearch.java#L83-L124 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/bcel/BCELUtil.java | BCELUtil.getMethodDescriptor | public static MethodDescriptor getMethodDescriptor(JavaClass jclass, Method method) {
return DescriptorFactory.instance().getMethodDescriptor(jclass.getClassName().replace('.', '/'), method.getName(),
method.getSignature(), method.isStatic());
} | java | public static MethodDescriptor getMethodDescriptor(JavaClass jclass, Method method) {
return DescriptorFactory.instance().getMethodDescriptor(jclass.getClassName().replace('.', '/'), method.getName(),
method.getSignature(), method.isStatic());
} | [
"public",
"static",
"MethodDescriptor",
"getMethodDescriptor",
"(",
"JavaClass",
"jclass",
",",
"Method",
"method",
")",
"{",
"return",
"DescriptorFactory",
".",
"instance",
"(",
")",
".",
"getMethodDescriptor",
"(",
"jclass",
".",
"getClassName",
"(",
")",
".",
... | Construct a MethodDescriptor from JavaClass and method.
@param jclass
a JavaClass
@param method
a Method belonging to the JavaClass
@return a MethodDescriptor identifying the method | [
"Construct",
"a",
"MethodDescriptor",
"from",
"JavaClass",
"and",
"method",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/bcel/BCELUtil.java#L52-L55 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/bcel/BCELUtil.java | BCELUtil.getClassDescriptor | public static ClassDescriptor getClassDescriptor(JavaClass jclass) {
return DescriptorFactory.instance().getClassDescriptor(ClassName.toSlashedClassName(jclass.getClassName()));
} | java | public static ClassDescriptor getClassDescriptor(JavaClass jclass) {
return DescriptorFactory.instance().getClassDescriptor(ClassName.toSlashedClassName(jclass.getClassName()));
} | [
"public",
"static",
"ClassDescriptor",
"getClassDescriptor",
"(",
"JavaClass",
"jclass",
")",
"{",
"return",
"DescriptorFactory",
".",
"instance",
"(",
")",
".",
"getClassDescriptor",
"(",
"ClassName",
".",
"toSlashedClassName",
"(",
"jclass",
".",
"getClassName",
"... | Construct a ClassDescriptor from a JavaClass.
@param jclass
a JavaClass
@return a ClassDescriptor identifying that JavaClass | [
"Construct",
"a",
"ClassDescriptor",
"from",
"a",
"JavaClass",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/bcel/BCELUtil.java#L64-L66 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/bcel/BCELUtil.java | BCELUtil.preTiger | public static boolean preTiger(JavaClass jclass) {
return jclass.getMajor() < JDK15_MAJOR || (jclass.getMajor() == JDK15_MAJOR && jclass.getMinor() < JDK15_MINOR);
} | java | public static boolean preTiger(JavaClass jclass) {
return jclass.getMajor() < JDK15_MAJOR || (jclass.getMajor() == JDK15_MAJOR && jclass.getMinor() < JDK15_MINOR);
} | [
"public",
"static",
"boolean",
"preTiger",
"(",
"JavaClass",
"jclass",
")",
"{",
"return",
"jclass",
".",
"getMajor",
"(",
")",
"<",
"JDK15_MAJOR",
"||",
"(",
"jclass",
".",
"getMajor",
"(",
")",
"==",
"JDK15_MAJOR",
"&&",
"jclass",
".",
"getMinor",
"(",
... | Checks if classfile was compiled for pre 1.5 target | [
"Checks",
"if",
"classfile",
"was",
"compiled",
"for",
"pre",
"1",
".",
"5",
"target"
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/bcel/BCELUtil.java#L75-L78 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/Plugin.java | Plugin.addBugCategory | public void addBugCategory(BugCategory bugCategory) {
BugCategory old = bugCategories.get(bugCategory.getCategory());
if (old != null) {
throw new IllegalArgumentException("Category already exists");
}
bugCategories.put(bugCategory.getCategory(), bugCategory);
} | java | public void addBugCategory(BugCategory bugCategory) {
BugCategory old = bugCategories.get(bugCategory.getCategory());
if (old != null) {
throw new IllegalArgumentException("Category already exists");
}
bugCategories.put(bugCategory.getCategory(), bugCategory);
} | [
"public",
"void",
"addBugCategory",
"(",
"BugCategory",
"bugCategory",
")",
"{",
"BugCategory",
"old",
"=",
"bugCategories",
".",
"get",
"(",
"bugCategory",
".",
"getCategory",
"(",
")",
")",
";",
"if",
"(",
"old",
"!=",
"null",
")",
"{",
"throw",
"new",
... | Add a BugCategory reported by the Plugin.
@param bugCategory | [
"Add",
"a",
"BugCategory",
"reported",
"by",
"the",
"Plugin",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/Plugin.java#L272-L278 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/Plugin.java | Plugin.getFactoryByShortName | public DetectorFactory getFactoryByShortName(final String shortName) {
return findFirstMatchingFactory(factory -> factory.getShortName().equals(shortName));
} | java | public DetectorFactory getFactoryByShortName(final String shortName) {
return findFirstMatchingFactory(factory -> factory.getShortName().equals(shortName));
} | [
"public",
"DetectorFactory",
"getFactoryByShortName",
"(",
"final",
"String",
"shortName",
")",
"{",
"return",
"findFirstMatchingFactory",
"(",
"factory",
"->",
"factory",
".",
"getShortName",
"(",
")",
".",
"equals",
"(",
"shortName",
")",
")",
";",
"}"
] | Look up a DetectorFactory by short name.
@param shortName
the short name
@return the DetectorFactory | [
"Look",
"up",
"a",
"DetectorFactory",
"by",
"short",
"name",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/Plugin.java#L317-L319 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/Plugin.java | Plugin.getFactoryByFullName | public DetectorFactory getFactoryByFullName(final String fullName) {
return findFirstMatchingFactory(factory -> factory.getFullName().equals(fullName));
} | java | public DetectorFactory getFactoryByFullName(final String fullName) {
return findFirstMatchingFactory(factory -> factory.getFullName().equals(fullName));
} | [
"public",
"DetectorFactory",
"getFactoryByFullName",
"(",
"final",
"String",
"fullName",
")",
"{",
"return",
"findFirstMatchingFactory",
"(",
"factory",
"->",
"factory",
".",
"getFullName",
"(",
")",
".",
"equals",
"(",
"fullName",
")",
")",
";",
"}"
] | Look up a DetectorFactory by full name.
@param fullName
the full name
@return the DetectorFactory | [
"Look",
"up",
"a",
"DetectorFactory",
"by",
"full",
"name",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/Plugin.java#L328-L330 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/ba/jsr305/DirectlyRelevantTypeQualifiersDatabase.java | DirectlyRelevantTypeQualifiersDatabase.getDirectlyRelevantTypeQualifiers | public Collection<TypeQualifierValue<?>> getDirectlyRelevantTypeQualifiers(MethodDescriptor m) {
Collection<TypeQualifierValue<?>> result = methodToDirectlyRelevantQualifiersMap.get(m);
if (result != null) {
return result;
}
return Collections.<TypeQualifierValue<?>> emptyList();
} | java | public Collection<TypeQualifierValue<?>> getDirectlyRelevantTypeQualifiers(MethodDescriptor m) {
Collection<TypeQualifierValue<?>> result = methodToDirectlyRelevantQualifiersMap.get(m);
if (result != null) {
return result;
}
return Collections.<TypeQualifierValue<?>> emptyList();
} | [
"public",
"Collection",
"<",
"TypeQualifierValue",
"<",
"?",
">",
">",
"getDirectlyRelevantTypeQualifiers",
"(",
"MethodDescriptor",
"m",
")",
"{",
"Collection",
"<",
"TypeQualifierValue",
"<",
"?",
">",
">",
"result",
"=",
"methodToDirectlyRelevantQualifiersMap",
"."... | Get the directly-relevant type qualifiers applied to given method.
@param m
MethodDescriptor identifying a method
@return Collection of type qualifiers applied directly to that method | [
"Get",
"the",
"directly",
"-",
"relevant",
"type",
"qualifiers",
"applied",
"to",
"given",
"method",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/jsr305/DirectlyRelevantTypeQualifiersDatabase.java#L58-L64 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/ba/jsr305/DirectlyRelevantTypeQualifiersDatabase.java | DirectlyRelevantTypeQualifiersDatabase.setDirectlyRelevantTypeQualifiers | public void setDirectlyRelevantTypeQualifiers(MethodDescriptor methodDescriptor, Collection<TypeQualifierValue<?>> qualifiers) {
methodToDirectlyRelevantQualifiersMap.put(methodDescriptor, qualifiers);
allKnownQualifiers.addAll(qualifiers);
} | java | public void setDirectlyRelevantTypeQualifiers(MethodDescriptor methodDescriptor, Collection<TypeQualifierValue<?>> qualifiers) {
methodToDirectlyRelevantQualifiersMap.put(methodDescriptor, qualifiers);
allKnownQualifiers.addAll(qualifiers);
} | [
"public",
"void",
"setDirectlyRelevantTypeQualifiers",
"(",
"MethodDescriptor",
"methodDescriptor",
",",
"Collection",
"<",
"TypeQualifierValue",
"<",
"?",
">",
">",
"qualifiers",
")",
"{",
"methodToDirectlyRelevantQualifiersMap",
".",
"put",
"(",
"methodDescriptor",
",",... | Set the collection of directly-relevant type qualifiers for a given
method.
@param methodDescriptor
MethodDescriptor identifying a method
@param qualifiers
collection of directly-relevant type qualifiers for the method | [
"Set",
"the",
"collection",
"of",
"directly",
"-",
"relevant",
"type",
"qualifiers",
"for",
"a",
"given",
"method",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/jsr305/DirectlyRelevantTypeQualifiersDatabase.java#L84-L87 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/detect/InheritanceUnsafeGetResource.java | InheritanceUnsafeGetResource.adjustPriority | private int adjustPriority(int priority) {
try {
Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2();
if (!subtypes2.hasSubtypes(getClassDescriptor())) {
priority++;
} else {
Set<ClassDescriptor> mySubtypes = subtypes2.getSubtypes(getClassDescriptor());
String myPackagename = getThisClass().getPackageName();
for (ClassDescriptor c : mySubtypes) {
if (c.equals(getClassDescriptor())) {
continue;
}
if (!c.getPackageName().equals(myPackagename)) {
priority--;
break;
}
}
}
} catch (ClassNotFoundException e) {
bugReporter.reportMissingClass(e);
}
return priority;
} | java | private int adjustPriority(int priority) {
try {
Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2();
if (!subtypes2.hasSubtypes(getClassDescriptor())) {
priority++;
} else {
Set<ClassDescriptor> mySubtypes = subtypes2.getSubtypes(getClassDescriptor());
String myPackagename = getThisClass().getPackageName();
for (ClassDescriptor c : mySubtypes) {
if (c.equals(getClassDescriptor())) {
continue;
}
if (!c.getPackageName().equals(myPackagename)) {
priority--;
break;
}
}
}
} catch (ClassNotFoundException e) {
bugReporter.reportMissingClass(e);
}
return priority;
} | [
"private",
"int",
"adjustPriority",
"(",
"int",
"priority",
")",
"{",
"try",
"{",
"Subtypes2",
"subtypes2",
"=",
"AnalysisContext",
".",
"currentAnalysisContext",
"(",
")",
".",
"getSubtypes2",
"(",
")",
";",
"if",
"(",
"!",
"subtypes2",
".",
"hasSubtypes",
... | Adjust the priority of a warning about to be reported.
@param priority
initial priority
@return adjusted priority | [
"Adjust",
"the",
"priority",
"of",
"a",
"warning",
"about",
"to",
"be",
"reported",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/InheritanceUnsafeGetResource.java#L136-L162 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/DetectorFactoryCollection.java | DetectorFactoryCollection.registerDetector | void registerDetector(DetectorFactory factory) {
if (FindBugs.DEBUG) {
System.out.println("Registering detector: " + factory.getFullName());
}
String detectorName = factory.getShortName();
if(!factoryList.contains(factory)) {
factoryList.add(factory);
} else {
LOGGER.log(Level.WARNING, "Trying to add already registered factory: " + factory +
", " + factory.getPlugin());
}
factoriesByName.put(detectorName, factory);
factoriesByDetectorClassName.put(factory.getFullName(), factory);
} | java | void registerDetector(DetectorFactory factory) {
if (FindBugs.DEBUG) {
System.out.println("Registering detector: " + factory.getFullName());
}
String detectorName = factory.getShortName();
if(!factoryList.contains(factory)) {
factoryList.add(factory);
} else {
LOGGER.log(Level.WARNING, "Trying to add already registered factory: " + factory +
", " + factory.getPlugin());
}
factoriesByName.put(detectorName, factory);
factoriesByDetectorClassName.put(factory.getFullName(), factory);
} | [
"void",
"registerDetector",
"(",
"DetectorFactory",
"factory",
")",
"{",
"if",
"(",
"FindBugs",
".",
"DEBUG",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Registering detector: \"",
"+",
"factory",
".",
"getFullName",
"(",
")",
")",
";",
"}",
"S... | Register a DetectorFactory. | [
"Register",
"a",
"DetectorFactory",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/DetectorFactoryCollection.java#L268-L281 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/DetectorFactoryCollection.java | DetectorFactoryCollection.lookupBugPattern | public @CheckForNull BugPattern lookupBugPattern(String bugType) {
if (bugType == null) {
return null;
}
return bugPatternMap.get(bugType);
} | java | public @CheckForNull BugPattern lookupBugPattern(String bugType) {
if (bugType == null) {
return null;
}
return bugPatternMap.get(bugType);
} | [
"public",
"@",
"CheckForNull",
"BugPattern",
"lookupBugPattern",
"(",
"String",
"bugType",
")",
"{",
"if",
"(",
"bugType",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"bugPatternMap",
".",
"get",
"(",
"bugType",
")",
";",
"}"
] | Look up bug pattern.
@param bugType
the bug type for the bug pattern
@return the BugPattern, or null if it can't be found | [
"Look",
"up",
"bug",
"pattern",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/DetectorFactoryCollection.java#L475-L480 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/DetectorFactoryCollection.java | DetectorFactoryCollection.getBugCategories | public Collection<String> getBugCategories() {
ArrayList<String> result = new ArrayList<>(categoryDescriptionMap.size());
for(BugCategory c : categoryDescriptionMap.values()) {
if (!c.isHidden()) {
result.add(c.getCategory());
}
}
return result;
} | java | public Collection<String> getBugCategories() {
ArrayList<String> result = new ArrayList<>(categoryDescriptionMap.size());
for(BugCategory c : categoryDescriptionMap.values()) {
if (!c.isHidden()) {
result.add(c.getCategory());
}
}
return result;
} | [
"public",
"Collection",
"<",
"String",
">",
"getBugCategories",
"(",
")",
"{",
"ArrayList",
"<",
"String",
">",
"result",
"=",
"new",
"ArrayList",
"<>",
"(",
"categoryDescriptionMap",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"BugCategory",
"c",
":",
... | Get a Collection containing all known bug category keys. E.g.,
"CORRECTNESS", "MT_CORRECTNESS", "PERFORMANCE", etc.
Excludes hidden bug categories
@return Collection of bug category keys. | [
"Get",
"a",
"Collection",
"containing",
"all",
"known",
"bug",
"category",
"keys",
".",
"E",
".",
"g",
".",
"CORRECTNESS",
"MT_CORRECTNESS",
"PERFORMANCE",
"etc",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/DetectorFactoryCollection.java#L539-L547 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindInconsistentSync2.java | FindInconsistentSync2.isGetterMethod | public static boolean isGetterMethod(ClassContext classContext, Method method) {
MethodGen methodGen = classContext.getMethodGen(method);
if (methodGen == null) {
return false;
}
InstructionList il = methodGen.getInstructionList();
// System.out.println("Checking getter method: " + method.getName());
if (il.getLength() > 60) {
return false;
}
int count = 0;
Iterator<InstructionHandle> it = il.iterator();
while (it.hasNext()) {
InstructionHandle ih = it.next();
switch (ih.getInstruction().getOpcode()) {
case Const.GETFIELD:
count++;
if (count > 1) {
return false;
}
break;
case Const.PUTFIELD:
case Const.BALOAD:
case Const.CALOAD:
case Const.DALOAD:
case Const.FALOAD:
case Const.IALOAD:
case Const.LALOAD:
case Const.SALOAD:
case Const.AALOAD:
case Const.BASTORE:
case Const.CASTORE:
case Const.DASTORE:
case Const.FASTORE:
case Const.IASTORE:
case Const.LASTORE:
case Const.SASTORE:
case Const.AASTORE:
case Const.PUTSTATIC:
return false;
case Const.INVOKESTATIC:
case Const.INVOKEVIRTUAL:
case Const.INVOKEINTERFACE:
case Const.INVOKESPECIAL:
case Const.GETSTATIC:
// no-op
}
}
// System.out.println("Found getter method: " + method.getName());
return true;
} | java | public static boolean isGetterMethod(ClassContext classContext, Method method) {
MethodGen methodGen = classContext.getMethodGen(method);
if (methodGen == null) {
return false;
}
InstructionList il = methodGen.getInstructionList();
// System.out.println("Checking getter method: " + method.getName());
if (il.getLength() > 60) {
return false;
}
int count = 0;
Iterator<InstructionHandle> it = il.iterator();
while (it.hasNext()) {
InstructionHandle ih = it.next();
switch (ih.getInstruction().getOpcode()) {
case Const.GETFIELD:
count++;
if (count > 1) {
return false;
}
break;
case Const.PUTFIELD:
case Const.BALOAD:
case Const.CALOAD:
case Const.DALOAD:
case Const.FALOAD:
case Const.IALOAD:
case Const.LALOAD:
case Const.SALOAD:
case Const.AALOAD:
case Const.BASTORE:
case Const.CASTORE:
case Const.DASTORE:
case Const.FASTORE:
case Const.IASTORE:
case Const.LASTORE:
case Const.SASTORE:
case Const.AASTORE:
case Const.PUTSTATIC:
return false;
case Const.INVOKESTATIC:
case Const.INVOKEVIRTUAL:
case Const.INVOKEINTERFACE:
case Const.INVOKESPECIAL:
case Const.GETSTATIC:
// no-op
}
}
// System.out.println("Found getter method: " + method.getName());
return true;
} | [
"public",
"static",
"boolean",
"isGetterMethod",
"(",
"ClassContext",
"classContext",
",",
"Method",
"method",
")",
"{",
"MethodGen",
"methodGen",
"=",
"classContext",
".",
"getMethodGen",
"(",
"method",
")",
";",
"if",
"(",
"methodGen",
"==",
"null",
")",
"{"... | Determine whether or not the the given method is a getter method. I.e.,
if it just returns the value of an instance field.
@param classContext
the ClassContext for the class containing the method
@param method
the method | [
"Determine",
"whether",
"or",
"not",
"the",
"the",
"given",
"method",
"is",
"a",
"getter",
"method",
".",
"I",
".",
"e",
".",
"if",
"it",
"just",
"returns",
"the",
"value",
"of",
"an",
"instance",
"field",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindInconsistentSync2.java#L813-L865 | train |
spotbugs/spotbugs | spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindInconsistentSync2.java | FindInconsistentSync2.getStats | private FieldStats getStats(XField field) {
FieldStats stats = statMap.get(field);
if (stats == null) {
stats = new FieldStats(field);
statMap.put(field, stats);
}
return stats;
} | java | private FieldStats getStats(XField field) {
FieldStats stats = statMap.get(field);
if (stats == null) {
stats = new FieldStats(field);
statMap.put(field, stats);
}
return stats;
} | [
"private",
"FieldStats",
"getStats",
"(",
"XField",
"field",
")",
"{",
"FieldStats",
"stats",
"=",
"statMap",
".",
"get",
"(",
"field",
")",
";",
"if",
"(",
"stats",
"==",
"null",
")",
"{",
"stats",
"=",
"new",
"FieldStats",
"(",
"field",
")",
";",
"... | Get the access statistics for given field. | [
"Get",
"the",
"access",
"statistics",
"for",
"given",
"field",
"."
] | f6365c6eea6515035bded38efa4a7c8b46ccf28c | https://github.com/spotbugs/spotbugs/blob/f6365c6eea6515035bded38efa4a7c8b46ccf28c/spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindInconsistentSync2.java#L870-L877 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.